Skip to content

Commit 54865ba

Browse files
authored
revert history filters persistence changes (#1001)
1 parent dc34a02 commit 54865ba

File tree

9 files changed

+45
-337
lines changed

9 files changed

+45
-337
lines changed

src/views/workflow-history/__tests__/workflow-history.test.tsx

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { completedActivityTaskEvents } from '../__fixtures__/workflow-history-ac
2424
import { completedDecisionTaskEvents } from '../__fixtures__/workflow-history-decision-events';
2525
import WorkflowHistory from '../workflow-history';
2626
import { WorkflowHistoryContext } from '../workflow-history-context-provider/workflow-history-context-provider';
27-
import { type WorkflowHistoryEventFilteringType } from '../workflow-history-filters-type/workflow-history-filters-type.types';
2827

2928
jest.mock('@/hooks/use-page-query-params/use-page-query-params', () =>
3029
jest.fn(() => [{ historySelectedEventId: '1' }, jest.fn()])
@@ -299,34 +298,6 @@ describe('WorkflowHistory', () => {
299298
expect(await screen.findByText('Ungrouped Table')).toBeInTheDocument();
300299
expect(screen.getByText('Group')).toBeInTheDocument();
301300
});
302-
303-
it('should override history event types preference when query param is set', async () => {
304-
const {
305-
mockSetUngroupedViewUserPreference,
306-
mockSetHistoryEventTypesUserPreference,
307-
} = await setup({
308-
pageQueryParamsValues: {
309-
historyEventTypes: ['TIMER', 'SIGNAL'],
310-
ungroupedHistoryViewEnabled: false,
311-
},
312-
historyEventTypesPreference: ['ACTIVITY', 'DECISION'],
313-
});
314-
315-
expect(mockSetUngroupedViewUserPreference).not.toHaveBeenCalled();
316-
expect(mockSetHistoryEventTypesUserPreference).not.toHaveBeenCalled();
317-
});
318-
319-
it('should use preference when history event types query param is undefined', async () => {
320-
const { mockSetHistoryEventTypesUserPreference } = await setup({
321-
pageQueryParamsValues: {
322-
historyEventTypes: undefined,
323-
ungroupedHistoryViewEnabled: false,
324-
},
325-
historyEventTypesPreference: ['TIMER', 'SIGNAL'],
326-
});
327-
328-
expect(mockSetHistoryEventTypesUserPreference).not.toHaveBeenCalled();
329-
});
330301
});
331302

332303
async function setup({
@@ -338,7 +309,6 @@ async function setup({
338309
emptyEvents,
339310
withResetModal,
340311
ungroupedViewPreference,
341-
historyEventTypesPreference,
342312
}: {
343313
error?: boolean;
344314
summaryError?: boolean;
@@ -350,7 +320,6 @@ async function setup({
350320
emptyEvents?: boolean;
351321
withResetModal?: boolean;
352322
ungroupedViewPreference?: boolean;
353-
historyEventTypesPreference?: Array<WorkflowHistoryEventFilteringType>;
354323
}) {
355324
const user = userEvent.setup();
356325

@@ -365,8 +334,6 @@ async function setup({
365334
}
366335

367336
const mockSetUngroupedViewUserPreference = jest.fn();
368-
const mockSetHistoryEventTypesUserPreference = jest.fn();
369-
const mockClearHistoryEventTypesUserPreference = jest.fn();
370337

371338
type ReqResolver = (r: GetWorkflowHistoryResponse) => void;
372339
let requestResolver: ReqResolver = () => {};
@@ -381,11 +348,6 @@ async function setup({
381348
value={{
382349
ungroupedViewUserPreference: ungroupedViewPreference ?? null,
383350
setUngroupedViewUserPreference: mockSetUngroupedViewUserPreference,
384-
historyEventTypesUserPreference: historyEventTypesPreference ?? null,
385-
setHistoryEventTypesUserPreference:
386-
mockSetHistoryEventTypesUserPreference,
387-
clearHistoryEventTypesUserPreference:
388-
mockClearHistoryEventTypesUserPreference,
389351
}}
390352
>
391353
<WorkflowHistory
@@ -490,7 +452,5 @@ async function setup({
490452
...renderResult,
491453
mockSetQueryParams,
492454
mockSetUngroupedViewUserPreference,
493-
mockSetHistoryEventTypesUserPreference,
494-
mockClearHistoryEventTypesUserPreference,
495455
};
496456
}
Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { isArray } from 'lodash';
21
import { z } from 'zod';
32

4-
import { WORKFLOW_HISTORY_EVENT_FILTERING_TYPES } from '../workflow-history-filters-type/workflow-history-filters-type.constants';
5-
import { type WorkflowHistoryEventFilteringType } from '../workflow-history-filters-type/workflow-history-filters-type.types';
63
import { type WorkflowHistoryUserPreferenceConfig } from '../workflow-history.types';
74

85
const workflowHistoryUserPreferencesConfig = {
@@ -13,27 +10,6 @@ const workflowHistoryUserPreferencesConfig = {
1310
.refine((val) => val === 'true' || val === 'false')
1411
.transform((val) => val === 'true'),
1512
},
16-
historyEventTypes: {
17-
key: 'history-event-types',
18-
schema: z
19-
.string()
20-
.transform((arg) => {
21-
try {
22-
return JSON.parse(arg);
23-
} catch {
24-
return null;
25-
}
26-
})
27-
.refine(
28-
(val) =>
29-
isArray(val) &&
30-
val.every(
31-
(item): item is WorkflowHistoryEventFilteringType =>
32-
WORKFLOW_HISTORY_EVENT_FILTERING_TYPES.find((v) => v === item) !==
33-
undefined
34-
)
35-
),
36-
},
3713
} as const satisfies Record<string, WorkflowHistoryUserPreferenceConfig<any>>;
3814

3915
export default workflowHistoryUserPreferencesConfig;

src/views/workflow-history/workflow-history-context-provider/__tests__/workflow-history-context-provider.test.tsx

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,12 @@ const TestConsumer = () => {
1818
? 'null'
1919
: String(context.ungroupedViewUserPreference)}
2020
</div>
21-
<div data-testid="event-types-preference">
22-
{context.historyEventTypesUserPreference === null
23-
? 'null'
24-
: context.historyEventTypesUserPreference.join(',')}
25-
</div>
2621
<button onClick={() => context.setUngroupedViewUserPreference(true)}>
2722
Set Ungrouped True
2823
</button>
2924
<button onClick={() => context.setUngroupedViewUserPreference(false)}>
3025
Set Ungrouped False
3126
</button>
32-
<button
33-
onClick={() =>
34-
context.setHistoryEventTypesUserPreference(['TIMER', 'SIGNAL'])
35-
}
36-
>
37-
Set Event Types
38-
</button>
39-
<button onClick={() => context.clearHistoryEventTypesUserPreference()}>
40-
Clear Event Types
41-
</button>
4227
</div>
4328
);
4429
};
@@ -58,28 +43,17 @@ describe(WorkflowHistoryContextProvider.name, () => {
5843
const { mockGetLocalStorageValue } = setup({
5944
localStorageValues: {
6045
[workflowHistoryUserPreferencesConfig.ungroupedViewEnabled.key]: true,
61-
[workflowHistoryUserPreferencesConfig.historyEventTypes.key]: [
62-
'TIMER',
63-
'SIGNAL',
64-
],
6546
},
6647
});
6748

6849
expect(mockGetLocalStorageValue).toHaveBeenCalledWith(
6950
workflowHistoryUserPreferencesConfig.ungroupedViewEnabled.key,
7051
workflowHistoryUserPreferencesConfig.ungroupedViewEnabled.schema
7152
);
72-
expect(mockGetLocalStorageValue).toHaveBeenCalledWith(
73-
workflowHistoryUserPreferencesConfig.historyEventTypes.key,
74-
workflowHistoryUserPreferencesConfig.historyEventTypes.schema
75-
);
7653

7754
expect(screen.getByTestId('ungrouped-preference')).toHaveTextContent(
7855
'true'
7956
);
80-
expect(screen.getByTestId('event-types-preference')).toHaveTextContent(
81-
'TIMER,SIGNAL'
82-
);
8357
});
8458

8559
it('should initialize with null values when localStorage is empty', () => {
@@ -89,17 +63,10 @@ describe(WorkflowHistoryContextProvider.name, () => {
8963
workflowHistoryUserPreferencesConfig.ungroupedViewEnabled.key,
9064
workflowHistoryUserPreferencesConfig.ungroupedViewEnabled.schema
9165
);
92-
expect(mockGetLocalStorageValue).toHaveBeenCalledWith(
93-
workflowHistoryUserPreferencesConfig.historyEventTypes.key,
94-
workflowHistoryUserPreferencesConfig.historyEventTypes.schema
95-
);
9666

9767
expect(screen.getByTestId('ungrouped-preference')).toHaveTextContent(
9868
'null'
9969
);
100-
expect(screen.getByTestId('event-types-preference')).toHaveTextContent(
101-
'null'
102-
);
10370
});
10471

10572
it('should update ungrouped view preference and localStorage', () => {
@@ -128,46 +95,6 @@ describe(WorkflowHistoryContextProvider.name, () => {
12895
);
12996
});
13097

131-
it('should update history event types preference and localStorage', () => {
132-
const { mockSetLocalStorageValue } = setup();
133-
134-
const setEventTypesButton = screen.getByText('Set Event Types');
135-
fireEvent.click(setEventTypesButton);
136-
137-
expect(mockSetLocalStorageValue).toHaveBeenCalledWith(
138-
workflowHistoryUserPreferencesConfig.historyEventTypes.key,
139-
JSON.stringify(['TIMER', 'SIGNAL'])
140-
);
141-
expect(screen.getByTestId('event-types-preference')).toHaveTextContent(
142-
'TIMER,SIGNAL'
143-
);
144-
});
145-
146-
it('should clear history event types preference and localStorage', () => {
147-
const { mockClearLocalStorageValue } = setup({
148-
localStorageValues: {
149-
[workflowHistoryUserPreferencesConfig.historyEventTypes.key]: [
150-
'TIMER',
151-
'SIGNAL',
152-
],
153-
},
154-
});
155-
156-
expect(screen.getByTestId('event-types-preference')).toHaveTextContent(
157-
'TIMER,SIGNAL'
158-
);
159-
160-
const clearButton = screen.getByText('Clear Event Types');
161-
fireEvent.click(clearButton);
162-
163-
expect(mockClearLocalStorageValue).toHaveBeenCalledWith(
164-
workflowHistoryUserPreferencesConfig.historyEventTypes.key
165-
);
166-
expect(screen.getByTestId('event-types-preference')).toHaveTextContent(
167-
'null'
168-
);
169-
});
170-
17198
it('should maintain state across re-renders', () => {
17299
const { rerender } = setup();
173100

src/views/workflow-history/workflow-history-context-provider/workflow-history-context-provider.tsx

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ export default function WorkflowHistoryContextProvider({
2828
)
2929
);
3030

31-
const [historyEventTypesPreference, setHistoryEventTypesPreference] =
32-
useState(() =>
33-
getLocalStorageValue(
34-
workflowHistoryUserPreferencesConfig.historyEventTypes.key,
35-
workflowHistoryUserPreferencesConfig.historyEventTypes.schema
36-
)
37-
);
38-
3931
const setUngroupedViewUserPreference = useCallback(
4032
(isUngroupedHistoryViewEnabled: boolean) => {
4133
setLocalStorageValue(
@@ -47,32 +39,11 @@ export default function WorkflowHistoryContextProvider({
4739
[]
4840
);
4941

50-
const setHistoryEventTypesUserPreference = useCallback(
51-
(historyEventTypes: Array<WorkflowHistoryEventFilteringType>) => {
52-
setLocalStorageValue(
53-
workflowHistoryUserPreferencesConfig.historyEventTypes.key,
54-
JSON.stringify(historyEventTypes)
55-
);
56-
setHistoryEventTypesPreference(historyEventTypes);
57-
},
58-
[]
59-
);
60-
61-
const clearHistoryEventTypesUserPreference = useCallback(() => {
62-
clearLocalStorageValue(
63-
workflowHistoryUserPreferencesConfig.historyEventTypes.key
64-
);
65-
setHistoryEventTypesPreference(null);
66-
}, []);
67-
6842
return (
6943
<WorkflowHistoryContext.Provider
7044
value={{
7145
ungroupedViewUserPreference: ungroupedViewPreference,
7246
setUngroupedViewUserPreference,
73-
historyEventTypesUserPreference: historyEventTypesPreference,
74-
setHistoryEventTypesUserPreference,
75-
clearHistoryEventTypesUserPreference,
7647
}}
7748
>
7849
{children}

src/views/workflow-history/workflow-history-context-provider/workflow-history-context-provider.types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,4 @@ import { type WorkflowHistoryEventFilteringType } from '../workflow-history-filt
33
export type WorkflowHistoryContextType = {
44
ungroupedViewUserPreference: boolean | null;
55
setUngroupedViewUserPreference: (v: boolean) => void;
6-
historyEventTypesUserPreference: Array<WorkflowHistoryEventFilteringType> | null;
7-
setHistoryEventTypesUserPreference: (
8-
v: Array<WorkflowHistoryEventFilteringType>
9-
) => void;
10-
clearHistoryEventTypesUserPreference: () => void;
116
};

0 commit comments

Comments
 (0)