diff --git a/packages/oss-console/src/components/Entities/EntitySchedules.tsx b/packages/oss-console/src/components/Entities/EntitySchedules.tsx index cc15befa9..6ba0569ff 100644 --- a/packages/oss-console/src/components/Entities/EntitySchedules.tsx +++ b/packages/oss-console/src/components/Entities/EntitySchedules.tsx @@ -153,6 +153,16 @@ export const EntitySchedules: React.FC<{ operation: FilterOperationName.EQ, value: id.name, }, + { + key: 'workflow.project', + operation: FilterOperationName.EQ, + value: id.project, + }, + { + key: 'workflow.domain', + operation: FilterOperationName.EQ, + value: id.domain, + }, ], }); diff --git a/packages/oss-console/src/components/Entities/test/EntitySchedules.test.tsx b/packages/oss-console/src/components/Entities/test/EntitySchedules.test.tsx new file mode 100644 index 000000000..06ef6c56f --- /dev/null +++ b/packages/oss-console/src/components/Entities/test/EntitySchedules.test.tsx @@ -0,0 +1,66 @@ +import React from 'react'; +import { render, waitFor } from '@testing-library/react'; +import { QueryClientProvider } from 'react-query'; +import { FilterOperationName } from '@clients/common/types/adminEntityTypes'; +import { ResourceIdentifier, ResourceType } from '../../../models/Common/types'; +import * as launchPlanApi from '../../../models/Launch/api'; +import { CREATED_AT_DESCENDING_SORT } from '../../../models/Launch/constants'; +import { LaunchPlanState } from '../../../models/Launch/types'; +import { createTestQueryClient } from '../../../test/utils'; +import { EntitySchedules } from '../EntitySchedules'; + +it('scopes active launch plans to the workflow project, domain and name', async () => { + const id: ResourceIdentifier = { + resourceType: ResourceType.WORKFLOW, + project: 'flytesnacks', + domain: 'development', + name: 'scheduled-workflow', + }; + const client = createTestQueryClient(); + const listLaunchPlans = jest.spyOn(launchPlanApi, 'listLaunchPlans').mockResolvedValue({ + entities: [], + }); + + try { + render( + + + , + ); + + await waitFor(() => + expect(listLaunchPlans).toHaveBeenCalledWith( + { project: id.project, domain: id.domain, name: undefined }, + { + limit: 5, + sort: CREATED_AT_DESCENDING_SORT, + filter: [ + { + key: 'state', + operation: FilterOperationName.EQ, + value: LaunchPlanState.ACTIVE, + }, + { + key: 'workflow.name', + operation: FilterOperationName.EQ, + value: id.name, + }, + { + key: 'workflow.project', + operation: FilterOperationName.EQ, + value: id.project, + }, + { + key: 'workflow.domain', + operation: FilterOperationName.EQ, + value: id.domain, + }, + ], + }, + ), + ); + } finally { + listLaunchPlans.mockRestore(); + client.clear(); + } +}); diff --git a/packages/oss-console/src/components/Launch/LaunchForm/test/LaunchWorkflowForm.test.tsx b/packages/oss-console/src/components/Launch/LaunchForm/test/LaunchWorkflowForm.test.tsx index dfbdc2f4e..30beef1d3 100644 --- a/packages/oss-console/src/components/Launch/LaunchForm/test/LaunchWorkflowForm.test.tsx +++ b/packages/oss-console/src/components/Launch/LaunchForm/test/LaunchWorkflowForm.test.tsx @@ -12,7 +12,7 @@ import { QueryClientProviderProps, } from 'react-query'; import Long from 'long'; -import { RequestConfig } from '@clients/common/types/adminEntityTypes'; +import { FilterOperationName, RequestConfig } from '@clients/common/types/adminEntityTypes'; import { APIContext } from '../../../data/apiContext'; import { mockAPIContextValue } from '../../../data/__mocks__/apiContext'; import { @@ -255,6 +255,50 @@ describe('LaunchForm: Workflow', () => { }); }); + it('should scope launch plans to the selected workflow identifier', async () => { + const selectedWorkflow = { + ...mockWorkflowVersions[0].id, + project: 'other-project', + domain: 'production', + }; + mockWorkflowVersions[0].id = selectedWorkflow; + renderForm(); + + await waitFor(() => + expect(mockListLaunchPlans).toHaveBeenCalledWith( + { + project: selectedWorkflow.project, + domain: selectedWorkflow.domain, + }, + { + limit: 50, + filter: [ + { + key: 'workflow.name', + operation: FilterOperationName.EQ, + value: selectedWorkflow.name, + }, + { + key: 'workflow.version', + operation: FilterOperationName.EQ, + value: selectedWorkflow.version, + }, + { + key: 'workflow.project', + operation: FilterOperationName.EQ, + value: selectedWorkflow.project, + }, + { + key: 'workflow.domain', + operation: FilterOperationName.EQ, + value: selectedWorkflow.domain, + }, + ], + }, + ), + ); + }); + it('should select the launch plan matching the workflow name by default', async () => { const { container } = renderForm(); await waitFor(() => { diff --git a/packages/oss-console/src/components/Launch/LaunchForm/useLaunchWorkflowFormState.ts b/packages/oss-console/src/components/Launch/LaunchForm/useLaunchWorkflowFormState.ts index bfbd56c2c..93a640116 100644 --- a/packages/oss-console/src/components/Launch/LaunchForm/useLaunchWorkflowFormState.ts +++ b/packages/oss-console/src/components/Launch/LaunchForm/useLaunchWorkflowFormState.ts @@ -76,6 +76,16 @@ async function loadLaunchPlans( operation: FilterOperationName.EQ, value: version, }, + { + key: 'workflow.project', + operation: FilterOperationName.EQ, + value: project, + }, + { + key: 'workflow.domain', + operation: FilterOperationName.EQ, + value: domain, + }, ], limit: 50, },