Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(tsc): convert histogram index to FC #82484

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 21 additions & 28 deletions static/app/utils/performance/histogram/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Component} from 'react';
import type {Location} from 'history';

import type {SelectValue} from 'sentry/types/core';
import {browserHistory} from 'sentry/utils/browserHistory';
import {decodeScalar} from 'sentry/utils/queryString';
import {useNavigate} from 'sentry/utils/useNavigate';

import {FILTER_OPTIONS} from './constants';
import type {DataFilter} from './types';
Expand All @@ -22,34 +21,30 @@ type Props = {
zoomKeys: string[];
};

class Histogram extends Component<Props> {
isZoomed() {
const {location, zoomKeys} = this.props;
return zoomKeys.map(key => location.query[key]).some(value => value !== undefined);
}
function Histogram(props: Props) {
const {location, zoomKeys, children} = props;
const navigate = useNavigate();

handleResetView = () => {
const {location, zoomKeys} = this.props;
const isZoomed = () => {
return zoomKeys.map(key => location.query[key]).some(value => value !== undefined);
};

browserHistory.push({
const handleResetView = () => {
navigate({
pathname: location.pathname,
query: removeHistogramQueryStrings(location, zoomKeys),
});
};

getActiveFilter() {
const {location} = this.props;

const getActiveFilter = () => {
const dataFilter = location.query.dataFilter
? decodeScalar(location.query.dataFilter)
: FILTER_OPTIONS[0].value;
return FILTER_OPTIONS.find(item => item.value === dataFilter) || FILTER_OPTIONS[0];
}

handleFilterChange = (value: string) => {
const {location, zoomKeys} = this.props;
};

browserHistory.push({
const handleFilterChange = (value: string) => {
navigate({
pathname: location.pathname,
query: {
...removeHistogramQueryStrings(location, zoomKeys),
Expand All @@ -58,16 +53,14 @@ class Histogram extends Component<Props> {
});
};

render() {
const childrenProps = {
isZoomed: this.isZoomed(),
handleResetView: this.handleResetView,
activeFilter: this.getActiveFilter(),
handleFilterChange: this.handleFilterChange,
filterOptions: FILTER_OPTIONS,
};
return this.props.children(childrenProps);
}
const childrenProps = {
isZoomed: isZoomed(),
handleResetView,
activeFilter: getActiveFilter(),
handleFilterChange,
filterOptions: FILTER_OPTIONS,
};
return children(childrenProps);
}

export function removeHistogramQueryStrings(location: Location, zoomKeys: string[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {

import ProjectsStore from 'sentry/stores/projectsStore';
import type {Project} from 'sentry/types/project';
import {browserHistory} from 'sentry/utils/browserHistory';
import {useLocation} from 'sentry/utils/useLocation';
import {useNavigate} from 'sentry/utils/useNavigate';
import TransactionVitals from 'sentry/views/performance/transactionSummary/transactionVitals';
import {
VITAL_GROUPS,
Expand All @@ -25,6 +25,11 @@ import {
jest.mock('sentry/utils/useLocation');

const mockUseLocation = jest.mocked(useLocation);
jest.mock('sentry/utils/useNavigate', () => ({
useNavigate: jest.fn(),
}));
michellewzhang marked this conversation as resolved.
Show resolved Hide resolved

const mockUseNavigate = jest.mocked(useNavigate);

interface HistogramData {
count: number;
Expand Down Expand Up @@ -296,6 +301,8 @@ describe('Performance > Web Vitals', function () {
});

it('resets view properly', async function () {
const mockNavigate = jest.fn();
mockUseNavigate.mockReturnValue(mockNavigate);
const {organization, router} = initialize({
query: {
fidStart: '20',
Expand All @@ -310,7 +317,7 @@ describe('Performance > Web Vitals', function () {

await userEvent.click(screen.getByRole('button', {name: 'Reset View'}));

expect(browserHistory.push).toHaveBeenCalledWith({
expect(mockNavigate).toHaveBeenCalledWith({
query: expect.not.objectContaining(
ZOOM_KEYS.reduce((obj, key) => {
obj[key] = expect.anything();
Expand Down
Loading