Skip to content

Commit b2c47cd

Browse files
Merge branch 'master' into history-single-line-summary
2 parents e08dedc + a2a722f commit b2c47cd

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(
@@ -266,6 +278,48 @@ describe(WorkflowHistoryV2.name, () => {
266278
ungroupedHistoryViewEnabled: 'false',
267279
});
268280
});
281+
282+
it('should calculate activeFiltersCount as 0 when both filter arrays are empty', async () => {
283+
await setup({
284+
pageQueryParamsValues: {
285+
historyEventStatuses: [],
286+
historyEventTypes: [],
287+
},
288+
});
289+
290+
const activeFiltersCountElement = await screen.findByTestId(
291+
'active-filters-count'
292+
);
293+
expect(activeFiltersCountElement).toHaveTextContent('0');
294+
});
295+
296+
it('should calculate activeFiltersCount as 0 when both filter arrays are undefined', async () => {
297+
await setup({
298+
pageQueryParamsValues: {
299+
historyEventStatuses: undefined,
300+
historyEventTypes: undefined,
301+
},
302+
});
303+
304+
const activeFiltersCountElement = await screen.findByTestId(
305+
'active-filters-count'
306+
);
307+
expect(activeFiltersCountElement).toHaveTextContent('0');
308+
});
309+
310+
it('should calculate activeFiltersCount as sum of both filter arrays', async () => {
311+
await setup({
312+
pageQueryParamsValues: {
313+
historyEventStatuses: ['COMPLETED', 'FAILED'],
314+
historyEventTypes: ['DECISION', 'ACTIVITY', 'SIGNAL'],
315+
},
316+
});
317+
318+
const activeFiltersCountElement = await screen.findByTestId(
319+
'active-filters-count'
320+
);
321+
expect(activeFiltersCountElement).toHaveTextContent('5');
322+
});
269323
});
270324

271325
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
@@ -53,7 +53,7 @@ export default function WorkflowHistoryV2({ params }: Props) {
5353
};
5454

5555
const {
56-
activeFiltersCount,
56+
activeFiltersCount: _unusedActiveFiltersCount,
5757
queryParams,
5858
setQueryParams,
5959
...pageFiltersRest
@@ -62,6 +62,13 @@ export default function WorkflowHistoryV2({ params }: Props) {
6262
pageFiltersConfig: workflowHistoryFiltersConfig,
6363
});
6464

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

0 commit comments

Comments
 (0)