From d53ca0d289978fed6eb0b79062c76722f68a15c4 Mon Sep 17 00:00:00 2001 From: Soham Parekh Date: Fri, 17 Feb 2023 00:25:39 +0530 Subject: [PATCH 1/8] feat: add domain settings for project dashboard Signed-off-by: 4nalog <4nalog@protonmail.com> --- .../components/Project/ProjectDashboard.tsx | 38 +++++++++++++++---- .../console/src/models/Common/constants.ts | 1 + packages/console/src/models/Project/api.ts | 21 +++++++++- packages/console/src/models/Project/utils.ts | 3 +- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/packages/console/src/components/Project/ProjectDashboard.tsx b/packages/console/src/components/Project/ProjectDashboard.tsx index 7ce1886f1..e4e017809 100644 --- a/packages/console/src/components/Project/ProjectDashboard.tsx +++ b/packages/console/src/components/Project/ProjectDashboard.tsx @@ -32,8 +32,11 @@ import { useOnlyMyExecutionsFilterState } from 'components/Executions/filters/us import { WaitForData } from 'components/common/WaitForData'; import { history } from 'routes/history'; import { Routes } from 'routes/routes'; -import { compact } from 'lodash'; -import { getProjectDomainAttributes } from 'models/Project/api'; +import _, { compact } from 'lodash'; +import { + getProjectAttributes, + getProjectDomainAttributes, +} from 'models/Project/api'; import t from './strings'; import { failedToLoadExecutionsString } from './constants'; @@ -150,6 +153,23 @@ export const ProjectDashboard: React.FC = ({ const queryClient = useQueryClient(); + const projectAttributesQuery = useQuery< + Admin.ProjectAttributesGetResponse, + Error + >({ + queryKey: ['projectAttributes', project], + queryFn: async () => { + const projectAtributes = await getProjectAttributes({ + project, + }); + queryClient.setQueryData( + ['projectAttributes', project], + projectAtributes, + ); + return projectAtributes; + }, + }); + const projectDomainAttributesQuery = useQuery< Admin.ProjectDomainAttributesGetResponse, Error @@ -166,7 +186,7 @@ export const ProjectDashboard: React.FC = ({ ); return projectDomainAtributes; }, - staleTime: Infinity, + enabled: !!projectAttributesQuery.data, }); const content = executionsQuery.isLoadingError ? ( @@ -191,8 +211,12 @@ export const ProjectDashboard: React.FC = ({ ); const configData = - projectDomainAttributesQuery.data?.attributes?.matchingAttributes - ?.workflowExecutionConfig ?? undefined; + _.merge( + projectAttributesQuery.data?.attributes?.matchingAttributes + ?.workflowExecutionConfig, + projectDomainAttributesQuery.data?.attributes?.matchingAttributes + ?.workflowExecutionConfig, + ) ?? undefined; const renderDomainSettingsSection = () => ( @@ -206,9 +230,7 @@ export const ProjectDashboard: React.FC = ({ {t('tasksTotal', numberOfTasks)} - - {renderDomainSettingsSection} - + {renderDomainSettingsSection()}
diff --git a/packages/console/src/models/Common/constants.ts b/packages/console/src/models/Common/constants.ts index 4350c97d2..198e7a59b 100644 --- a/packages/console/src/models/Common/constants.ts +++ b/packages/console/src/models/Common/constants.ts @@ -7,6 +7,7 @@ export const endpointPrefixes = { nodeExecution: '/node_executions', dynamicWorkflowExecution: '/data/node_executions', project: '/projects', + projectAttributes: '/project_attributes', projectDomainAtributes: '/project_domain_attributes', relaunchExecution: '/executions/relaunch', recoverExecution: '/executions/recover', diff --git a/packages/console/src/models/Project/api.ts b/packages/console/src/models/Project/api.ts index c57dd077c..7b7664f7c 100644 --- a/packages/console/src/models/Project/api.ts +++ b/packages/console/src/models/Project/api.ts @@ -18,6 +18,25 @@ export const listProjects = () => sortBy(projects, project => `${project.name}`.toLowerCase()) as Project[], }); +export const getProjectAttributes = (scope: IdentifierScope) => + getAdminEntity< + Admin.ProjectAttributesGetResponse, + Admin.ProjectAttributesGetResponse + >( + { + path: makeProjectDomainAttributesPath( + endpointPrefixes.projectAttributes, + scope, + ), + messageType: Admin.ProjectAttributesGetResponse, + }, + { + params: { + resource_type: Admin.MatchableResource.WORKFLOW_EXECUTION_CONFIG, + }, + }, + ); + export const getProjectDomainAttributes = (scope: IdentifierScope) => getAdminEntity< Admin.ProjectDomainAttributesGetResponse, @@ -32,7 +51,7 @@ export const getProjectDomainAttributes = (scope: IdentifierScope) => }, { params: { - resource_type: 'WORKFLOW_EXECUTION_CONFIG', + resource_type: Admin.MatchableResource.WORKFLOW_EXECUTION_CONFIG, }, }, ); diff --git a/packages/console/src/models/Project/utils.ts b/packages/console/src/models/Project/utils.ts index 8856402ba..ddb3a02d0 100644 --- a/packages/console/src/models/Project/utils.ts +++ b/packages/console/src/models/Project/utils.ts @@ -1,3 +1,4 @@ +import _ from 'lodash'; import { Identifier } from 'models/Common/types'; import { Project } from './types'; @@ -15,5 +16,5 @@ export function makeProjectDomainAttributesPath( prefix: string, { project, domain }: Partial, ) { - return [prefix, project, domain].join('/'); + return _.compact([prefix, project, domain]).join('/'); } From dd134ac8989297f8b221e164e8891d63dfc1bcfb Mon Sep 17 00:00:00 2001 From: 4nalog <4nalog@protonmail.com> Date: Fri, 17 Feb 2023 01:41:14 +0530 Subject: [PATCH 2/8] fix: dependency between queries Signed-off-by: 4nalog <4nalog@protonmail.com> --- .../components/Project/ProjectDashboard.tsx | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/console/src/components/Project/ProjectDashboard.tsx b/packages/console/src/components/Project/ProjectDashboard.tsx index e4e017809..6422895f4 100644 --- a/packages/console/src/components/Project/ProjectDashboard.tsx +++ b/packages/console/src/components/Project/ProjectDashboard.tsx @@ -153,40 +153,40 @@ export const ProjectDashboard: React.FC = ({ const queryClient = useQueryClient(); - const projectAttributesQuery = useQuery< - Admin.ProjectAttributesGetResponse, + const projectDomainAttributesQuery = useQuery< + Admin.ProjectDomainAttributesGetResponse, Error >({ - queryKey: ['projectAttributes', project], + queryKey: ['projectDomainAttributes', project, domain], queryFn: async () => { - const projectAtributes = await getProjectAttributes({ + const projectDomainAtributes = await getProjectDomainAttributes({ + domain, project, }); queryClient.setQueryData( - ['projectAttributes', project], - projectAtributes, + ['projectDomainAttributes', project, domain], + projectDomainAtributes, ); - return projectAtributes; + return projectDomainAtributes; }, }); - const projectDomainAttributesQuery = useQuery< - Admin.ProjectDomainAttributesGetResponse, + const projectAttributesQuery = useQuery< + Admin.ProjectAttributesGetResponse, Error >({ - queryKey: ['projectDomainAttributes', project, domain], + queryKey: ['projectAttributes', project], queryFn: async () => { - const projectDomainAtributes = await getProjectDomainAttributes({ - domain, + const projectAtributes = await getProjectAttributes({ project, }); queryClient.setQueryData( - ['projectDomainAttributes', project, domain], - projectDomainAtributes, + ['projectAttributes', project], + projectAtributes, ); - return projectDomainAtributes; + return projectAtributes; }, - enabled: !!projectAttributesQuery.data, + enabled: !projectDomainAttributesQuery.isFetching, }); const content = executionsQuery.isLoadingError ? ( @@ -230,7 +230,9 @@ export const ProjectDashboard: React.FC = ({ {t('tasksTotal', numberOfTasks)}
- {renderDomainSettingsSection()} + + {renderDomainSettingsSection} +
From b3c8a5f5e659b8d1744cbd7aa06497c9c8ce51dc Mon Sep 17 00:00:00 2001 From: 4nalog <4nalog@protonmail.com> Date: Fri, 17 Feb 2023 01:49:41 +0530 Subject: [PATCH 3/8] refactor: use exact imports from lodash Signed-off-by: 4nalog <4nalog@protonmail.com> --- packages/console/src/components/Project/ProjectDashboard.tsx | 4 ++-- packages/console/src/models/Project/utils.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/console/src/components/Project/ProjectDashboard.tsx b/packages/console/src/components/Project/ProjectDashboard.tsx index 6422895f4..0f29b22c4 100644 --- a/packages/console/src/components/Project/ProjectDashboard.tsx +++ b/packages/console/src/components/Project/ProjectDashboard.tsx @@ -32,7 +32,7 @@ import { useOnlyMyExecutionsFilterState } from 'components/Executions/filters/us import { WaitForData } from 'components/common/WaitForData'; import { history } from 'routes/history'; import { Routes } from 'routes/routes'; -import _, { compact } from 'lodash'; +import { compact, merge } from 'lodash'; import { getProjectAttributes, getProjectDomainAttributes, @@ -211,7 +211,7 @@ export const ProjectDashboard: React.FC = ({ ); const configData = - _.merge( + merge( projectAttributesQuery.data?.attributes?.matchingAttributes ?.workflowExecutionConfig, projectDomainAttributesQuery.data?.attributes?.matchingAttributes diff --git a/packages/console/src/models/Project/utils.ts b/packages/console/src/models/Project/utils.ts index ddb3a02d0..50ae585b6 100644 --- a/packages/console/src/models/Project/utils.ts +++ b/packages/console/src/models/Project/utils.ts @@ -1,4 +1,4 @@ -import _ from 'lodash'; +import { compact } from 'lodash'; import { Identifier } from 'models/Common/types'; import { Project } from './types'; @@ -16,5 +16,5 @@ export function makeProjectDomainAttributesPath( prefix: string, { project, domain }: Partial, ) { - return _.compact([prefix, project, domain]).join('/'); + return compact([prefix, project, domain]).join('/'); } From 8bee9cbe818cb0b063a4e51e91556d2d810c947f Mon Sep 17 00:00:00 2001 From: 4nalog <4nalog@protonmail.com> Date: Fri, 17 Feb 2023 21:23:20 +0530 Subject: [PATCH 4/8] refactor: tests for domain settings Signed-off-by: 4nalog <4nalog@protonmail.com> --- .../Project/test/ProjectDashboard.test.tsx | 41 +++++++++++++++++-- .../common/DomainSettingsSection.tsx | 12 +++--- .../console/src/components/common/strings.ts | 1 + .../test/DomainSettingsSection.test.tsx | 10 ++--- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/packages/console/src/components/Project/test/ProjectDashboard.test.tsx b/packages/console/src/components/Project/test/ProjectDashboard.test.tsx index eee1ae7c0..ecc9c299f 100644 --- a/packages/console/src/components/Project/test/ProjectDashboard.test.tsx +++ b/packages/console/src/components/Project/test/ProjectDashboard.test.tsx @@ -20,7 +20,10 @@ import { import { useUserProfile } from 'components/hooks/useUserProfile'; import { FetchableData } from 'components/hooks/types'; import { loadedFetchable } from 'components/hooks/__mocks__/fetchableData'; -import { getProjectDomainAttributes } from 'models/Project/api'; +import { + getProjectAttributes, + getProjectDomainAttributes, +} from 'models/Project/api'; import { Admin } from '@flyteorg/flyteidl-types'; import * as LocalCache from 'basics/LocalCache'; import { ProjectDashboard } from '../ProjectDashboard'; @@ -33,6 +36,31 @@ jest.mock('notistack', () => ({ })); jest.mock('models/Project/api', () => ({ + getProjectAttributes: jest.fn().mockResolvedValue(() => { + const projectAttributesMock: Admin.ProjectAttributesGetResponse = { + attributes: { + matchingAttributes: { + workflowExecutionConfig: { + maxParallelism: 1, + securityContext: { runAs: { k8sServiceAccount: 'default' } }, + rawOutputDataConfig: { + outputLocationPrefix: + 'cliOutputLocationPrefixFromProjectAttributes', + }, + annotations: { + values: { + cliAnnotationKey: 'cliAnnotationValueFromProjectAttributes', + }, + }, + labels: { + values: { cliLabelKey: 'cliLabelValueFromProjectAttributes' }, + }, + }, + }, + }, + }; + return projectAttributesMock; + }), getProjectDomainAttributes: jest.fn().mockResolvedValue(() => { const projectDomainAttributesMock: Admin.ProjectDomainAttributesDeleteResponse = { @@ -41,9 +69,6 @@ jest.mock('models/Project/api', () => ({ workflowExecutionConfig: { maxParallelism: 5, securityContext: { runAs: { k8sServiceAccount: 'default' } }, - rawOutputDataConfig: { - outputLocationPrefix: 'cliOutputLocationPrefix', - }, annotations: { values: { cliAnnotationKey: 'cliAnnotationValue' }, }, @@ -123,9 +148,17 @@ describe('ProjectDashboard', () => { it('should display domain attributes section when config was provided', async () => { const { getByText } = renderView(); + expect(getProjectAttributes).toHaveBeenCalled(); expect(getProjectDomainAttributes).toHaveBeenCalled(); await waitFor(() => { expect(getByText('Domain Settings')).toBeInTheDocument(); + expect( + getByText('cliOutputLocationPrefixFromProjectAttributes'), + ).toBeInTheDocument(); + expect(getByText('cliAnnotationKey')).toBeInTheDocument(); + expect( + getByText('cliAnnotationValueFromProjectAttributes'), + ).not.toBeInTheDocument(); }); }); diff --git a/packages/console/src/components/common/DomainSettingsSection.tsx b/packages/console/src/components/common/DomainSettingsSection.tsx index 3b11c362c..b156ae126 100644 --- a/packages/console/src/components/common/DomainSettingsSection.tsx +++ b/packages/console/src/components/common/DomainSettingsSection.tsx @@ -55,11 +55,11 @@ export const DomainSettingsSection = ({ return null; } - const role = configData.securityContext?.runAs?.iamRole || t('inherited'); + const role = configData.securityContext?.runAs?.iamRole || t('noValue'); const serviceAccount = - configData.securityContext?.runAs?.k8sServiceAccount || t('inherited'); + configData.securityContext?.runAs?.k8sServiceAccount || t('noValue'); const rawData = - configData.rawOutputDataConfig?.outputLocationPrefix || t('inherited'); + configData.rawOutputDataConfig?.outputLocationPrefix || t('noValue'); const maxParallelism = configData.maxParallelism || undefined; return ( @@ -101,7 +101,7 @@ export const DomainSettingsSection = ({ {configData.labels?.values ? ( ) : ( - t('inherited') + t('noValue') )}
@@ -109,7 +109,7 @@ export const DomainSettingsSection = ({ {configData.annotations?.values ? ( ) : ( - t('inherited') + t('noValue') )}
@@ -122,7 +122,7 @@ export const DomainSettingsSection = ({ {t('maxParallelismHeader')}

- {maxParallelism ?? t('inherited')} + {maxParallelism ?? t('noValue')}
diff --git a/packages/console/src/components/common/strings.ts b/packages/console/src/components/common/strings.ts index 3e8e84cce..ae784c9d1 100644 --- a/packages/console/src/components/common/strings.ts +++ b/packages/console/src/components/common/strings.ts @@ -12,6 +12,7 @@ const str = { securityContextHeader: 'Security Context', serviceAccountHeader: 'Service Account', noMatchingResults: 'No matching results', + noValue: '-', missingUnionListOfSubType: 'Unexpected missing type for union', missingMapSubType: 'Unexpected missing subtype for map', mapMissingMapProperty: 'Map literal missing `map` property', diff --git a/packages/console/src/components/common/test/DomainSettingsSection.test.tsx b/packages/console/src/components/common/test/DomainSettingsSection.test.tsx index 16f9efe31..ca6ae8dde 100644 --- a/packages/console/src/components/common/test/DomainSettingsSection.test.tsx +++ b/packages/console/src/components/common/test/DomainSettingsSection.test.tsx @@ -55,7 +55,7 @@ describe('DomainSettingsSection', () => { const tables = queryAllByRole('table'); expect(tables).toHaveLength(2); // should display a placeholder text, as role was not passed - const emptyRole = queryByText('Inherits from project level values'); + const emptyRole = queryByText('-'); expect(emptyRole).toBeInTheDocument(); }); @@ -76,9 +76,7 @@ describe('DomainSettingsSection', () => { const tables = queryAllByRole('table'); expect(tables).toHaveLength(1); // should display two placeholder text, as role and labels were not passed - const inheritedPlaceholders = queryAllByText( - 'Inherits from project level values', - ); + const inheritedPlaceholders = queryAllByText('-'); expect(inheritedPlaceholders).toHaveLength(2); }); @@ -101,9 +99,7 @@ describe('DomainSettingsSection', () => { const tables = queryByRole('table'); expect(tables).not.toBeInTheDocument(); // should display three placeholder text, as role, labels, annotations were not passed - const inheritedPlaceholders = queryAllByText( - 'Inherits from project level values', - ); + const inheritedPlaceholders = queryAllByText('-'); expect(inheritedPlaceholders).toHaveLength(3); }); }); From 51f0193533dc822092f29310688092ff2960bc96 Mon Sep 17 00:00:00 2001 From: 4nalog <4nalog@protonmail.com> Date: Sat, 18 Feb 2023 00:03:22 +0530 Subject: [PATCH 5/8] chore: bump minor version Signed-off-by: 4nalog <4nalog@protonmail.com> --- packages/console/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/console/package.json b/packages/console/package.json index 004303cbe..251821a93 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -1,6 +1,6 @@ { "name": "@flyteorg/console", - "version": "0.0.8", + "version": "0.0.9", "description": "Flyteconsole main app module", "main": "./dist/index.js", "module": "./lib/index.js", From fe37cffa046cc86e18f5920d0bfb9516956f57dd Mon Sep 17 00:00:00 2001 From: 4nalog <4nalog@protonmail.com> Date: Sat, 18 Feb 2023 00:24:33 +0530 Subject: [PATCH 6/8] refactor: minor version bump test Signed-off-by: 4nalog <4nalog@protonmail.com> --- packages/console/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/console/package.json b/packages/console/package.json index 251821a93..f79cf69e2 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -1,6 +1,6 @@ { "name": "@flyteorg/console", - "version": "0.0.9", + "version": "0.0.9-test", "description": "Flyteconsole main app module", "main": "./dist/index.js", "module": "./lib/index.js", From 44a8930dcd342091124e2241311b0ec28bc737e2 Mon Sep 17 00:00:00 2001 From: 4nalog <4nalog@protonmail.com> Date: Mon, 20 Feb 2023 23:44:15 +0530 Subject: [PATCH 7/8] chore: bump minor version Signed-off-by: 4nalog <4nalog@protonmail.com> --- packages/console/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/console/package.json b/packages/console/package.json index f79cf69e2..251821a93 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -1,6 +1,6 @@ { "name": "@flyteorg/console", - "version": "0.0.9-test", + "version": "0.0.9", "description": "Flyteconsole main app module", "main": "./dist/index.js", "module": "./lib/index.js", From c2bf77aa2c1f0184bfd3537ca2107ba4e0292da5 Mon Sep 17 00:00:00 2001 From: 4nalog <88684372+4nalog@users.noreply.github.com> Date: Wed, 22 Feb 2023 21:18:01 +0530 Subject: [PATCH 8/8] Update package.json Signed-off-by: 4nalog <4nalog@protonmail.com> --- packages/console/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/console/package.json b/packages/console/package.json index 251821a93..741447e1c 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -1,6 +1,6 @@ { "name": "@flyteorg/console", - "version": "0.0.9", + "version": "0.0.10", "description": "Flyteconsole main app module", "main": "./dist/index.js", "module": "./lib/index.js",