Skip to content

Commit 5c8c2b2

Browse files
Merge branch 'master' into history-ungrouped-table
2 parents dfd235a + a2a722f commit 5c8c2b2

File tree

4 files changed

+102
-36
lines changed

4 files changed

+102
-36
lines changed

src/components/tag-filter/__tests__/tag-filter.test.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ describe(TagFilter.name, () => {
5555
expect(mockOnChangeValues).toHaveBeenCalledWith(['opt2']);
5656
});
5757

58-
it('selects all tags when "Show all" is clicked and no values are currently selected', async () => {
58+
it('clears all selections when "Show all" is clicked and no values are currently selected', async () => {
5959
const { user, mockOnChangeValues } = setup({
6060
values: [],
6161
});
6262

6363
const showAllTag = screen.getByText('Show all');
6464
await user.click(showAllTag);
6565

66-
expect(mockOnChangeValues).toHaveBeenCalledWith(['opt1', 'opt2', 'opt3']);
66+
expect(mockOnChangeValues).toHaveBeenCalledWith([]);
6767
});
6868

69-
it('deselects all tags when "Show all" is clicked and all values are currently selected', async () => {
69+
it('clears all selections when "Show all" is clicked and all values are currently selected', async () => {
7070
const { user, mockOnChangeValues } = setup({
7171
values: ['opt1', 'opt2', 'opt3'],
7272
});
@@ -77,15 +77,26 @@ describe(TagFilter.name, () => {
7777
expect(mockOnChangeValues).toHaveBeenCalledWith([]);
7878
});
7979

80-
it('selects all tags when "Show all" is clicked and only some values are currently selected', async () => {
80+
it('clears all selections when "Show all" is clicked and only some values are currently selected', async () => {
8181
const { user, mockOnChangeValues } = setup({
8282
values: ['opt1'],
8383
});
8484

8585
const showAllTag = screen.getByText('Show all');
8686
await user.click(showAllTag);
8787

88-
expect(mockOnChangeValues).toHaveBeenCalledWith(['opt1', 'opt2', 'opt3']);
88+
expect(mockOnChangeValues).toHaveBeenCalledWith([]);
89+
});
90+
91+
it('automatically toggles to "show all" (empty array) when the last tag is clicked and all tags become selected', async () => {
92+
const { user, mockOnChangeValues } = setup({
93+
values: ['opt1', 'opt2'],
94+
});
95+
96+
// Click the last tag to select all tags - should auto-toggle to empty array
97+
await user.click(screen.getByText('Option 3'));
98+
99+
expect(mockOnChangeValues).toHaveBeenCalledWith([]);
89100
});
90101

91102
it('does not render "Show all" tag when hideShowAll is true', () => {

src/components/tag-filter/tag-filter.tsx

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,29 @@ export default function TagFilter<T extends string>({
2121
[optionsConfig]
2222
);
2323

24-
const areAllValuesSet = useMemo(
25-
() => tagKeys.every((key) => values.includes(key)),
26-
[tagKeys, values]
27-
);
28-
29-
const toggleAllValues = useCallback(
30-
() => onChangeValues(areAllValuesSet ? [] : tagKeys),
31-
[tagKeys, areAllValuesSet, onChangeValues]
32-
);
24+
const isShowAll = useMemo(() => values.length === 0, [values]);
3325

3426
const onChangeSingleValue = useCallback(
35-
(value: T) =>
36-
onChangeValues(
37-
values.includes(value)
38-
? values.filter((v) => v !== value)
39-
: [...values, value]
40-
),
41-
[values, onChangeValues]
27+
(value: T) => {
28+
const newValues = values.includes(value)
29+
? values.filter((v) => v !== value)
30+
: [...values, value];
31+
32+
// If all tags are selected, automatically toggle to "show all" (empty array)
33+
const areAllTagsSelected = tagKeys.every((key) =>
34+
newValues.includes(key)
35+
);
36+
onChangeValues(areAllTagsSelected ? [] : newValues);
37+
},
38+
[values, onChangeValues, tagKeys]
4239
);
4340

4441
return (
4542
<styled.FormControlContainer>
4643
<FormControl label={label} overrides={overrides.formControl}>
4744
<styled.TagsContainer>
4845
{!hideShowAll && (
49-
<SelectableTag
50-
value={areAllValuesSet}
51-
onClick={() => toggleAllValues()}
52-
>
46+
<SelectableTag value={isShowAll} onClick={() => onChangeValues([])}>
5347
Show all
5448
</SelectableTag>
5549
)}

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

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,29 @@ jest.mock(
5353
);
5454

5555
jest.mock('../workflow-history-header/workflow-history-header', () =>
56-
jest.fn(({ isUngroupedHistoryViewEnabled, onClickGroupModeToggle }) => (
57-
<div data-testid="workflow-history-header">
58-
<div>Workflow history Header</div>
59-
<div data-testid="is-ungrouped-enabled">
60-
{String(isUngroupedHistoryViewEnabled)}
56+
jest.fn(
57+
({
58+
isUngroupedHistoryViewEnabled,
59+
onClickGroupModeToggle,
60+
pageFiltersProps,
61+
}) => (
62+
<div data-testid="workflow-history-header">
63+
<div>Workflow history Header</div>
64+
<div data-testid="is-ungrouped-enabled">
65+
{String(isUngroupedHistoryViewEnabled)}
66+
</div>
67+
<div data-testid="active-filters-count">
68+
{pageFiltersProps.activeFiltersCount}
69+
</div>
70+
<button
71+
data-testid="toggle-group-mode"
72+
onClick={onClickGroupModeToggle}
73+
>
74+
Toggle Group Mode
75+
</button>
6176
</div>
62-
<button data-testid="toggle-group-mode" onClick={onClickGroupModeToggle}>
63-
Toggle Group Mode
64-
</button>
65-
</div>
66-
))
77+
)
78+
)
6779
);
6880

6981
jest.mock(
@@ -288,6 +300,48 @@ describe(WorkflowHistoryV2.name, () => {
288300
ungroupedHistoryViewEnabled: 'false',
289301
});
290302
});
303+
304+
it('should calculate activeFiltersCount as 0 when both filter arrays are empty', async () => {
305+
await setup({
306+
pageQueryParamsValues: {
307+
historyEventStatuses: [],
308+
historyEventTypes: [],
309+
},
310+
});
311+
312+
const activeFiltersCountElement = await screen.findByTestId(
313+
'active-filters-count'
314+
);
315+
expect(activeFiltersCountElement).toHaveTextContent('0');
316+
});
317+
318+
it('should calculate activeFiltersCount as 0 when both filter arrays are undefined', async () => {
319+
await setup({
320+
pageQueryParamsValues: {
321+
historyEventStatuses: undefined,
322+
historyEventTypes: undefined,
323+
},
324+
});
325+
326+
const activeFiltersCountElement = await screen.findByTestId(
327+
'active-filters-count'
328+
);
329+
expect(activeFiltersCountElement).toHaveTextContent('0');
330+
});
331+
332+
it('should calculate activeFiltersCount as sum of both filter arrays', async () => {
333+
await setup({
334+
pageQueryParamsValues: {
335+
historyEventStatuses: ['COMPLETED', 'FAILED'],
336+
historyEventTypes: ['DECISION', 'ACTIVITY', 'SIGNAL'],
337+
},
338+
});
339+
340+
const activeFiltersCountElement = await screen.findByTestId(
341+
'active-filters-count'
342+
);
343+
expect(activeFiltersCountElement).toHaveTextContent('5');
344+
});
291345
});
292346

293347
async function setup({

src/views/workflow-history-v2/workflow-history-v2.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default function WorkflowHistoryV2({ params }: Props) {
5454
};
5555

5656
const {
57-
activeFiltersCount,
57+
activeFiltersCount: _unusedActiveFiltersCount,
5858
queryParams,
5959
setQueryParams,
6060
...pageFiltersRest
@@ -63,6 +63,13 @@ export default function WorkflowHistoryV2({ params }: Props) {
6363
pageFiltersConfig: workflowHistoryFiltersConfig,
6464
});
6565

66+
const activeFiltersCount = useMemo(
67+
() =>
68+
(queryParams.historyEventStatuses?.length ?? 0) +
69+
(queryParams.historyEventTypes?.length ?? 0),
70+
[queryParams.historyEventStatuses, queryParams.historyEventTypes]
71+
);
72+
6673
const {
6774
eventGroups,
6875
updateEvents: updateGrouperEvents,

0 commit comments

Comments
 (0)