From fe91339d6e6c4df1844789dcf4edcbfdf1626e1b Mon Sep 17 00:00:00 2001 From: Adhitya Mamallan Date: Fri, 6 Dec 2024 12:36:18 +0530 Subject: [PATCH] Add new view for workflows in basic visibility clusters (#754) Add new view for workflows in Basic Visibility clusters Add filters for basic visibility workflows Add new type for basic visibility workflow status (which also includes all closed workflows) Add new query params for workflowId, workflowType and basic visibility workflow status --- .../config/domain-page-query-params.config.ts | 20 +++++ .../domain-workflows-basic-filters.config.ts | 39 ++++++++++ ...rkflows-basic-search-debounce-ms.config.ts | 3 + ...in-workflows-basic-filters-status.test.tsx | 74 +++++++++++++++++++ ...orkflows-basic-filters-status.constants.ts | 15 ++++ ...n-workflows-basic-filters-status.styles.ts | 18 +++++ .../domain-workflows-basic-filters-status.tsx | 41 ++++++++++ ...in-workflows-basic-filters-status.types.ts | 7 ++ ...s-workflow-status-basic-visibility.test.ts | 19 +++++ .../is-workflow-status-basic-visibility.ts | 8 ++ .../domain-workflows-basic-filters.styles.ts | 26 +++++++ .../domain-workflows-basic-filters.tsx | 59 +++++++++++++++ .../domain-workflows-basic.tsx | 14 ++++ .../domain-workflows-query-params.ts | 3 + 14 files changed, 346 insertions(+) create mode 100644 src/views/domain-workflows-basic/config/domain-workflows-basic-filters.config.ts create mode 100644 src/views/domain-workflows-basic/config/domain-workflows-basic-search-debounce-ms.config.ts create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic-filters-status/__tests__/domain-workflows-basic-filters-status.test.tsx create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.constants.ts create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.styles.ts create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.tsx create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.types.ts create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic-filters-status/helpers/__tests__/is-workflow-status-basic-visibility.test.ts create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic-filters-status/helpers/is-workflow-status-basic-visibility.ts create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic-filters/domain-workflows-basic-filters.styles.ts create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic-filters/domain-workflows-basic-filters.tsx create mode 100644 src/views/domain-workflows-basic/domain-workflows-basic.tsx diff --git a/src/views/domain-page/config/domain-page-query-params.config.ts b/src/views/domain-page/config/domain-page-query-params.config.ts index abb27a548..0e5828297 100644 --- a/src/views/domain-page/config/domain-page-query-params.config.ts +++ b/src/views/domain-page/config/domain-page-query-params.config.ts @@ -2,6 +2,8 @@ import { type PageQueryParam } from '@/hooks/use-page-query-params/use-page-quer import parseDateQueryParam from '@/utils/datetime/parse-date-query-param'; import { type SortOrder } from '@/utils/sort-by'; import { type DomainWorkflowsHeaderInputType } from '@/views/domain-workflows/domain-workflows-header/domain-workflows-header.types'; +import { type WorkflowStatusBasicVisibility } from '@/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.types'; +import isWorkflowStatusBasicVisibility from '@/views/domain-workflows-basic/domain-workflows-basic-filters-status/helpers/is-workflow-status-basic-visibility'; import isWorkflowStatus from '@/views/shared/workflow-status-tag/helpers/is-workflow-status'; import { type WorkflowStatus } from '@/views/shared/workflow-status-tag/workflow-status-tag.types'; @@ -16,6 +18,10 @@ const domainPageQueryParamsConfig: [ PageQueryParam<'sortOrder', SortOrder>, // Query input PageQueryParam<'query', string>, + // Basic Visibility inputs + PageQueryParam<'workflowId', string>, + PageQueryParam<'workflowType', string>, + PageQueryParam<'statusBasic', WorkflowStatusBasicVisibility | undefined>, ] = [ { key: 'inputType', @@ -57,6 +63,20 @@ const domainPageQueryParamsConfig: [ key: 'query', defaultValue: '', }, + { + key: 'workflowId', + defaultValue: '', + }, + { + key: 'workflowType', + defaultValue: '', + }, + { + key: 'statusBasic', + queryParamKey: 'status', + parseValue: (value: string) => + isWorkflowStatusBasicVisibility(value) ? value : undefined, + }, ] as const; export default domainPageQueryParamsConfig; diff --git a/src/views/domain-workflows-basic/config/domain-workflows-basic-filters.config.ts b/src/views/domain-workflows-basic/config/domain-workflows-basic-filters.config.ts new file mode 100644 index 000000000..1c231e956 --- /dev/null +++ b/src/views/domain-workflows-basic/config/domain-workflows-basic-filters.config.ts @@ -0,0 +1,39 @@ +import { type PageFilterConfig } from '@/components/page-filters/page-filters.types'; +import type domainPageQueryParamsConfig from '@/views/domain-page/config/domain-page-query-params.config'; +import DomainWorkflowsFiltersDates from '@/views/domain-workflows/domain-workflows-filters-dates/domain-workflows-filters-dates'; +import { type DomainWorkflowsFiltersDatesValue } from '@/views/domain-workflows/domain-workflows-filters-dates/domain-workflows-filters-dates.types'; + +import DomainWorkflowsBasicFiltersStatus from '../domain-workflows-basic-filters-status/domain-workflows-basic-filters-status'; +import { type DomainWorkflowsBasicFiltersStatusValue } from '../domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.types'; + +const domainWorkflowsBasicFiltersConfig: [ + PageFilterConfig< + typeof domainPageQueryParamsConfig, + DomainWorkflowsBasicFiltersStatusValue + >, + PageFilterConfig< + typeof domainPageQueryParamsConfig, + DomainWorkflowsFiltersDatesValue + >, +] = [ + { + id: 'status', + getValue: (v) => ({ statusBasic: v.statusBasic }), + formatValue: (v) => v, + component: DomainWorkflowsBasicFiltersStatus, + }, + { + id: 'dates', + getValue: (v) => ({ + timeRangeStart: v.timeRangeStart, + timeRangeEnd: v.timeRangeEnd, + }), + formatValue: (v) => ({ + timeRangeStart: v.timeRangeStart?.toISOString(), + timeRangeEnd: v.timeRangeEnd?.toISOString(), + }), + component: DomainWorkflowsFiltersDates, + }, +] as const; + +export default domainWorkflowsBasicFiltersConfig; diff --git a/src/views/domain-workflows-basic/config/domain-workflows-basic-search-debounce-ms.config.ts b/src/views/domain-workflows-basic/config/domain-workflows-basic-search-debounce-ms.config.ts new file mode 100644 index 000000000..4f786ece0 --- /dev/null +++ b/src/views/domain-workflows-basic/config/domain-workflows-basic-search-debounce-ms.config.ts @@ -0,0 +1,3 @@ +const DOMAIN_WORKFLOWS_BASIC_SEARCH_DEBOUNCE_MS = 250; + +export default DOMAIN_WORKFLOWS_BASIC_SEARCH_DEBOUNCE_MS; diff --git a/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/__tests__/domain-workflows-basic-filters-status.test.tsx b/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/__tests__/domain-workflows-basic-filters-status.test.tsx new file mode 100644 index 000000000..24adbe4a2 --- /dev/null +++ b/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/__tests__/domain-workflows-basic-filters-status.test.tsx @@ -0,0 +1,74 @@ +import React from 'react'; + +import { render, screen, fireEvent, act } from '@/test-utils/rtl'; + +import { mockDomainWorkflowsQueryParamsValues } from '@/views/domain-workflows/__fixtures__/domain-workflows-query-params'; + +import DomainWorkflowsBasicFiltersStatus from '../domain-workflows-basic-filters-status'; +import { WORKFLOW_STATUS_NAMES_BASIC_VISIBILITY } from '../domain-workflows-basic-filters-status.constants'; +import { type DomainWorkflowsBasicFiltersStatusValue } from '../domain-workflows-basic-filters-status.types'; + +describe(DomainWorkflowsBasicFiltersStatus.name, () => { + it('renders without errors', () => { + setup({}); + expect(screen.getByRole('combobox')).toBeInTheDocument(); + }); + + it('displays all the options in the select component', () => { + setup({}); + const selectFilter = screen.getByRole('combobox'); + act(() => { + fireEvent.click(selectFilter); + }); + Object.entries(WORKFLOW_STATUS_NAMES_BASIC_VISIBILITY).forEach( + ([_, value]) => expect(screen.getByText(value)).toBeInTheDocument() + ); + }); + + it('calls the setQueryParams function when an option is selected', () => { + const { mockSetValue } = setup({}); + const selectFilter = screen.getByRole('combobox'); + act(() => { + fireEvent.click(selectFilter); + }); + const runningOption = screen.getByText('Closed'); + act(() => { + fireEvent.click(runningOption); + }); + expect(mockSetValue).toHaveBeenCalledWith({ + statusBasic: 'ALL_CLOSED', + }); + }); + + it('calls the setQueryParams function when the filter is cleared', () => { + const { mockSetValue } = setup({ + overrides: { + statusBasic: 'WORKFLOW_EXECUTION_CLOSE_STATUS_FAILED', + }, + }); + const clearButton = screen.getByLabelText('Clear value'); + act(() => { + fireEvent.click(clearButton); + }); + expect(mockSetValue).toHaveBeenCalledWith({ statusBasic: undefined }); + }); +}); + +function setup({ + overrides, +}: { + overrides?: DomainWorkflowsBasicFiltersStatusValue; +}) { + const mockSetValue = jest.fn(); + render( + + ); + + return { mockSetValue }; +} diff --git a/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.constants.ts b/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.constants.ts new file mode 100644 index 000000000..1590b6954 --- /dev/null +++ b/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.constants.ts @@ -0,0 +1,15 @@ +import { WORKFLOW_STATUS_NAMES } from '@/views/shared/workflow-status-tag/workflow-status-tag.constants'; + +import { type WorkflowStatusBasicVisibility } from './domain-workflows-basic-filters-status.types'; + +export const WORKFLOW_STATUS_NAMES_BASIC_VISIBILITY = { + ALL_CLOSED: 'Closed', + ...WORKFLOW_STATUS_NAMES, +} as const satisfies Record; + +export const WORKFLOW_STATUS_OPTIONS_BASIC_VISIBILITY = Object.entries( + WORKFLOW_STATUS_NAMES_BASIC_VISIBILITY +).map(([key, value]) => ({ + id: key, + label: value, +})); diff --git a/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.styles.ts b/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.styles.ts new file mode 100644 index 000000000..d9a2ff7d9 --- /dev/null +++ b/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.styles.ts @@ -0,0 +1,18 @@ +import { type Theme } from 'baseui'; +import type { FormControlOverrides } from 'baseui/form-control/types'; +import { type StyleObject } from 'styletron-react'; + +export const overrides = { + selectFormControl: { + Label: { + style: ({ $theme }: { $theme: Theme }): StyleObject => ({ + ...$theme.typography.LabelXSmall, + }), + }, + ControlContainer: { + style: (): StyleObject => ({ + margin: '0px', + }), + }, + } satisfies FormControlOverrides, +}; diff --git a/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.tsx b/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.tsx new file mode 100644 index 000000000..e56e90a5d --- /dev/null +++ b/src/views/domain-workflows-basic/domain-workflows-basic-filters-status/domain-workflows-basic-filters-status.tsx @@ -0,0 +1,41 @@ +'use client'; +import React from 'react'; + +import { FormControl } from 'baseui/form-control'; +import { Select, SIZE } from 'baseui/select'; + +import { type PageFilterComponentProps } from '@/components/page-filters/page-filters.types'; +import { type WorkflowStatus } from '@/views/shared/workflow-status-tag/workflow-status-tag.types'; + +import { WORKFLOW_STATUS_OPTIONS_BASIC_VISIBILITY } from './domain-workflows-basic-filters-status.constants'; +import { overrides } from './domain-workflows-basic-filters-status.styles'; +import { type DomainWorkflowsBasicFiltersStatusValue } from './domain-workflows-basic-filters-status.types'; + +export default function DomainWorkflowsBasicFiltersStatus({ + value, + setValue, +}: PageFilterComponentProps) { + const statusOptionValue = WORKFLOW_STATUS_OPTIONS_BASIC_VISIBILITY.filter( + (option) => option.id === value.statusBasic + ); + + return ( + +