Skip to content

Commit be5e5df

Browse files
committed
refine type of field formatters
1 parent 1caf908 commit be5e5df

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/sentry/static/sentry/app/views/organizationEventsV2/data.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import getDynamicText from 'app/utils/getDynamicText';
1212
import overflowEllipsis from 'app/styles/overflowEllipsis';
1313
import pinIcon from 'app/../images/location-pin.png';
1414
import space from 'app/styles/space';
15-
import {EventView} from 'app/types';
15+
import {EventView, Organization} from 'app/types';
16+
import {ReactRouterLocation} from 'app/types/reactRouter';
1617

1718
import {QueryLink} from './styles';
1819

@@ -92,12 +93,38 @@ export const ALL_VIEWS: Readonly<Array<EventView>> = deepFreeze([
9293
},
9394
]);
9495

96+
type EventData = {[key: string]: any};
97+
98+
type RenderFunctionBaggage = {
99+
organization: Organization;
100+
location: ReactRouterLocation;
101+
};
102+
103+
type RenderFunction = (
104+
field: string,
105+
data: EventData,
106+
baggage: RenderFunctionBaggage
107+
) => React.ReactNode;
108+
109+
type FieldFormatter = {
110+
sortField: boolean;
111+
renderFunc: RenderFunction;
112+
};
113+
114+
type FieldFormatters = {
115+
boolean: FieldFormatter;
116+
integer: FieldFormatter;
117+
number: FieldFormatter;
118+
date: FieldFormatter;
119+
string: FieldFormatter;
120+
};
121+
95122
/**
96123
* A mapping of field types to their rendering function.
97124
* This mapping is used when a field is not defined in SPECIAL_FIELDS
98125
* This mapping should match the output sentry.utils.snuba:get_json_type
99126
*/
100-
export const FIELD_FORMATTERS = {
127+
export const FIELD_FORMATTERS: FieldFormatters = {
101128
boolean: {
102129
sortField: true,
103130
renderFunc: (field, data, {organization, location}) => {

src/sentry/static/sentry/app/views/organizationEventsV2/table.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export default class Table extends React.Component<Props> {
7676
if (SPECIAL_FIELDS.hasOwnProperty(field)) {
7777
sortKey = SPECIAL_FIELDS[field].sortField ? field : null;
7878
} else if (FIELD_FORMATTERS.hasOwnProperty(field)) {
79-
sortKey = FIELD_FORMATTERS[field].sortField ? field : null;
79+
sortKey = FIELD_FORMATTERS[field as keyof typeof FIELD_FORMATTERS].sortField
80+
? field
81+
: null;
8082
}
8183

8284
if (sortKey === null) {

0 commit comments

Comments
 (0)