Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions static/app/utils/discover/eventView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,25 @@ describe('EventView.fromSavedQueryOrLocation()', () => {

expect(eventView.team).toEqual(['myteams', 1]);
});

it('does not crash when saved query has undefined fields and no URL fields', () => {
const saved = {
id: '42',
name: 'homepage',
// fields intentionally omitted to simulate API returning undefined fields
query: 'event.type:error',
projects: [123],
version: 2,
dateUpdated: '2019-10-30T06:13:17.632096Z',
dateCreated: '2019-10-30T06:13:17.632078Z',
} as unknown as SavedQuery;

const location = LocationFixture({query: {}});

// Should not throw TypeError: Cannot read properties of undefined (reading 'map')
const eventView = EventView.fromSavedQueryOrLocation(saved, location);
expect(eventView.fields).toEqual([]);
});
});

describe('EventView.generateQueryStringObject()', () => {
Expand Down
2 changes: 1 addition & 1 deletion static/app/utils/discover/eventView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export class EventView {
}

static getFields(saved: NewQuery | SavedQuery) {
return saved.fields.map((field, i) => {
return (saved.fields ?? []).map((field, i) => {
const width = saved.widths?.[i] ? Number(saved.widths[i]) : COL_WIDTH_UNDEFINED;

return {field, width};
Expand Down
Loading