Skip to content

Commit 01a759e

Browse files
committed
refine type of special fields
1 parent be5e5df commit 01a759e

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

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

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ type RenderFunctionBaggage = {
100100
location: ReactRouterLocation;
101101
};
102102

103-
type RenderFunction = (
103+
type FieldFormatterRenderFunction = (
104104
field: string,
105105
data: EventData,
106106
baggage: RenderFunctionBaggage
107107
) => React.ReactNode;
108108

109109
type FieldFormatter = {
110110
sortField: boolean;
111-
renderFunc: RenderFunction;
111+
renderFunc: FieldFormatterRenderFunction;
112112
};
113113

114114
type FieldFormatters = {
@@ -185,14 +185,34 @@ export const FIELD_FORMATTERS: FieldFormatters = {
185185
},
186186
};
187187

188+
type SpecialFieldRenderFunc = (
189+
data: EventData,
190+
baggage: RenderFunctionBaggage
191+
) => React.ReactNode;
192+
193+
type SpecialField = {
194+
sortField: boolean;
195+
renderFunc: SpecialFieldRenderFunc;
196+
};
197+
198+
type SpecialFields = {
199+
transaction: SpecialField;
200+
title: SpecialField;
201+
type: SpecialField;
202+
project: SpecialField;
203+
user: SpecialField;
204+
issue_title: SpecialField;
205+
last_seen: SpecialField;
206+
};
207+
188208
/**
189209
* "Special fields" do not map 1:1 to an single column in the event database,
190210
* they are a UI concept that combines the results of multiple fields and
191211
* displays with a custom render function.
192212
*/
193-
export const SPECIAL_FIELDS = {
213+
export const SPECIAL_FIELDS: SpecialFields = {
194214
transaction: {
195-
sortField: 'transaction',
215+
sortField: true,
196216
renderFunc: (data, {location}) => {
197217
const target = {
198218
pathname: location.pathname,
@@ -211,7 +231,7 @@ export const SPECIAL_FIELDS = {
211231
},
212232
},
213233
title: {
214-
sortField: 'title',
234+
sortField: true,
215235
renderFunc: (data, {location}) => {
216236
const target = {
217237
pathname: location.pathname,
@@ -227,7 +247,7 @@ export const SPECIAL_FIELDS = {
227247
},
228248
},
229249
type: {
230-
sortField: 'event.type',
250+
sortField: true,
231251
renderFunc: (data, {location}) => {
232252
const target = {
233253
pathname: location.pathname,
@@ -256,7 +276,7 @@ export const SPECIAL_FIELDS = {
256276
},
257277
},
258278
user: {
259-
sortField: 'user.id',
279+
sortField: true,
260280
renderFunc: (data, {location}) => {
261281
const userObj = {
262282
id: data['user.id'],
@@ -286,7 +306,7 @@ export const SPECIAL_FIELDS = {
286306
},
287307
},
288308
issue_title: {
289-
sortField: 'issue_title',
309+
sortField: true,
290310
renderFunc: (data, {location}) => {
291311
const target = {
292312
pathname: location.pathname,
@@ -305,7 +325,7 @@ export const SPECIAL_FIELDS = {
305325
},
306326
},
307327
last_seen: {
308-
sortField: 'last_seen',
328+
sortField: true,
309329
renderFunc: data => {
310330
return (
311331
<Container>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export default class Table extends React.Component<Props> {
7474

7575
let sortKey: string | null = field;
7676
if (SPECIAL_FIELDS.hasOwnProperty(field)) {
77-
sortKey = SPECIAL_FIELDS[field].sortField ? field : null;
77+
sortKey = SPECIAL_FIELDS[field as keyof typeof SPECIAL_FIELDS].sortField
78+
? field
79+
: null;
7880
} else if (FIELD_FORMATTERS.hasOwnProperty(field)) {
7981
sortKey = FIELD_FORMATTERS[field as keyof typeof FIELD_FORMATTERS].sortField
8082
? field

0 commit comments

Comments
 (0)