-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
History page - unify "Ongoing" and "Waiting" filters into "Pending" (#…
…781) * Init commit for combined filter * Add test file
- Loading branch information
1 parent
e80b69a
commit 172fb39
Showing
7 changed files
with
147 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...y/workflow-history-filters-status/helpers/__tests__/filter-events-by-event-status.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { type ActivityHistoryGroup } from '../../../workflow-history.types'; | ||
import { type WorkflowHistoryFiltersStatusValue } from '../../workflow-history-filters-status.types'; | ||
import filterEventsByEventStatus from '../filter-events-by-event-status'; | ||
|
||
const ACTIVITY_HISTORY_GROUP_COMPLETED: ActivityHistoryGroup = { | ||
label: 'Mock activity', | ||
eventsMetadata: [], | ||
status: 'COMPLETED', | ||
hasMissingEvents: false, | ||
timeMs: 123456789, | ||
timeLabel: 'Mock time label', | ||
groupType: 'Activity', | ||
events: [], | ||
}; | ||
|
||
describe(filterEventsByEventStatus.name, () => { | ||
it('should return true if historyEventStatuses is undefined', () => { | ||
const value: WorkflowHistoryFiltersStatusValue = { | ||
historyEventStatuses: undefined, | ||
}; | ||
|
||
expect( | ||
filterEventsByEventStatus(ACTIVITY_HISTORY_GROUP_COMPLETED, value) | ||
).toBe(true); | ||
}); | ||
|
||
it('should return true if group status is included in historyEventStatuses', () => { | ||
const value: WorkflowHistoryFiltersStatusValue = { | ||
historyEventStatuses: ['COMPLETED'], | ||
}; | ||
|
||
expect( | ||
filterEventsByEventStatus(ACTIVITY_HISTORY_GROUP_COMPLETED, value) | ||
).toBe(true); | ||
}); | ||
|
||
it('should return false if group status is not included in historyEventStatuses', () => { | ||
const value: WorkflowHistoryFiltersStatusValue = { | ||
historyEventStatuses: ['COMPLETED'], | ||
}; | ||
|
||
expect( | ||
filterEventsByEventStatus( | ||
{ | ||
...ACTIVITY_HISTORY_GROUP_COMPLETED, | ||
status: 'FAILED', | ||
}, | ||
value | ||
) | ||
).toBe(false); | ||
}); | ||
|
||
it('should return true if group status is ONGOING or WAITING when historyEventStatuses includes PENDING', () => { | ||
const value: WorkflowHistoryFiltersStatusValue = { | ||
historyEventStatuses: ['PENDING'], | ||
}; | ||
|
||
expect( | ||
filterEventsByEventStatus( | ||
{ | ||
...ACTIVITY_HISTORY_GROUP_COMPLETED, | ||
status: 'ONGOING', | ||
}, | ||
value | ||
) | ||
).toBe(true); | ||
expect( | ||
filterEventsByEventStatus( | ||
{ | ||
...ACTIVITY_HISTORY_GROUP_COMPLETED, | ||
status: 'WAITING', | ||
}, | ||
value | ||
) | ||
).toBe(true); | ||
}); | ||
|
||
it('should return false if group status is not ONGOING or WAITING when historyEventStatuses includes PENDING', () => { | ||
const value: WorkflowHistoryFiltersStatusValue = { | ||
historyEventStatuses: ['PENDING'], | ||
}; | ||
|
||
expect( | ||
filterEventsByEventStatus(ACTIVITY_HISTORY_GROUP_COMPLETED, value) | ||
).toBe(false); | ||
}); | ||
}); |
24 changes: 20 additions & 4 deletions
24
...workflow-history/workflow-history-filters-status/helpers/filter-events-by-event-status.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
import { type WorkflowEventStatus } from '../../workflow-history-event-status-badge/workflow-history-event-status-badge.types'; | ||
import { type HistoryEventsGroup } from '../../workflow-history.types'; | ||
import { type WorkflowHistoryFiltersStatusValue } from '../workflow-history-filters-status.types'; | ||
import { | ||
type HistoryEventFilterStatus, | ||
type WorkflowHistoryFiltersStatusValue, | ||
} from '../workflow-history-filters-status.types'; | ||
|
||
export default function filterEventsByEventStatus( | ||
group: HistoryEventsGroup, | ||
value: WorkflowHistoryFiltersStatusValue | ||
) { | ||
const selectedGroupStatuses = value.historyEventStatuses; | ||
if (!selectedGroupStatuses) return true; | ||
const historyFiltersStatuses = value.historyEventStatuses; | ||
if (!historyFiltersStatuses) return true; | ||
|
||
return selectedGroupStatuses.includes(group.status); | ||
const workflowEventStatuses = historyFiltersStatuses.reduce( | ||
(acc: WorkflowEventStatus[], currentValue: HistoryEventFilterStatus) => { | ||
if (currentValue === 'PENDING') { | ||
acc.push('ONGOING', 'WAITING'); | ||
} else { | ||
acc.push(currentValue); | ||
} | ||
return acc; | ||
}, | ||
[] | ||
); | ||
|
||
return workflowEventStatuses.includes(group.status); | ||
} |
23 changes: 14 additions & 9 deletions
23
...flow-history/workflow-history-filters-status/workflow-history-filters-status.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import { WORKFLOW_EVENT_STATUS } from '../workflow-history-event-status-badge/workflow-history-event-status-badge.constants'; | ||
import { type WorkflowEventStatus } from '../workflow-history-event-status-badge/workflow-history-event-status-badge.types'; | ||
import { type HistoryEventFilterStatus } from './workflow-history-filters-status.types'; | ||
|
||
export const WORKFLOW_HISTORY_EVENT_FILTERING_STATUS_LABELS_MAP = { | ||
[WORKFLOW_EVENT_STATUS.ONGOING]: 'On Going', | ||
[WORKFLOW_EVENT_STATUS.WAITING]: 'Waiting', | ||
[WORKFLOW_EVENT_STATUS.CANCELED]: 'Canceled', | ||
[WORKFLOW_EVENT_STATUS.FAILED]: 'Failed', | ||
[WORKFLOW_EVENT_STATUS.COMPLETED]: 'Completed', | ||
} as const satisfies Record<WorkflowEventStatus, string>; | ||
export const HISTORY_EVENT_FILTER_STATUSES = { | ||
PENDING: 'PENDING', | ||
CANCELED: 'CANCELED', | ||
FAILED: 'FAILED', | ||
COMPLETED: 'COMPLETED', | ||
} as const satisfies Record<HistoryEventFilterStatus, string>; | ||
|
||
export const HISTORY_EVENT_FILTER_STATUS_LABELS_MAP = { | ||
PENDING: 'Pending', | ||
CANCELED: 'Canceled', | ||
FAILED: 'Failed', | ||
COMPLETED: 'Completed', | ||
} as const satisfies Record<HistoryEventFilterStatus, string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
...workflow-history/workflow-history-filters-status/workflow-history-filters-status.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { type WorkflowEventStatus } from '../workflow-history-event-status-badge/workflow-history-event-status-badge.types'; | ||
export type HistoryEventFilterStatus = | ||
| 'COMPLETED' | ||
| 'FAILED' | ||
| 'CANCELED' | ||
| 'PENDING'; | ||
|
||
export type WorkflowHistoryFiltersStatusValue = { | ||
historyEventStatuses: WorkflowEventStatus[] | undefined; | ||
historyEventStatuses: HistoryEventFilterStatus[] | undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters