From 8cbd88a12b232963a2bca12f959adf3b81c5b727 Mon Sep 17 00:00:00 2001 From: Frank Flitton Date: Tue, 11 Jul 2023 12:06:20 -0700 Subject: [PATCH] chore: task, workflow, launchplans Signed-off-by: Frank Flitton --- .../Breadcrumbs/async/executionContext.ts | 161 ++++++++++++++++++ .../registry/contextualDefaults.ts | 52 +++++- 2 files changed, 211 insertions(+), 2 deletions(-) diff --git a/packages/console/src/components/Breadcrumbs/async/executionContext.ts b/packages/console/src/components/Breadcrumbs/async/executionContext.ts index 64e02fc33..279a08008 100644 --- a/packages/console/src/components/Breadcrumbs/async/executionContext.ts +++ b/packages/console/src/components/Breadcrumbs/async/executionContext.ts @@ -55,6 +55,14 @@ const getExecutionValue = (location: Location) => { return executionValue; }; +const getVersionValue = (location: Location) => { + const segments = decodeURIComponent(location.pathname).split('/'); + const versionSegmentName = segments.findIndex(s => s === 'version'); + + const versionValue = segments[versionSegmentName + 1] || ''; + return versionValue; +}; + export const executonNamedEntityAsyncValue: BreadcrumbAsyncValue = async ( location, breadcrumb, @@ -140,6 +148,159 @@ export const executionTaskWorkflowVersions: BreadcrumbAsyncPopOverData = async ( return popOverData; }; +export const taskVersions: BreadcrumbAsyncPopOverData = async ( + location, + breadcrumb, +) => { + const resourceId = { + project: breadcrumb.projectId, + domain: breadcrumb.domainId, + name: breadcrumb.value, + resourceType: ResourceType.TASK, + }; + + const versionValue = getVersionValue(location); + const entityVersions = await fetchVersions(resourceId); + + const popOverData: BreadcrumbEntity[] = entityVersions.entities.map( + (entityVersion, index) => { + const title = entityVersion?.id?.version || ''; + const url = Routes.EntityVersionDetails.makeUrl( + breadcrumb.projectId, + breadcrumb.domainId, + breadcrumb.value, + 'task', + title, + ); + const createdAt = formatDateUTC( + timestampToDate(entityVersion?.closure?.createdAt), + ); + + // UI only shows last version + const active = versionValue ? versionValue === title : index === 0; + + return { + title, + url, + createdAt, + active, + }; + }, + ); + + return popOverData; +}; + +export const workflowVersions: BreadcrumbAsyncPopOverData = async ( + location, + breadcrumb, +) => { + const resourceId = { + project: breadcrumb.projectId, + domain: breadcrumb.domainId, + name: breadcrumb.value, + resourceType: ResourceType.WORKFLOW, + }; + + const versionValue = getVersionValue(location); + const entityVersions = await fetchVersions(resourceId); + + const popOverData: BreadcrumbEntity[] = entityVersions.entities.map( + (entityVersion, index) => { + const title = entityVersion?.id?.version || ''; + const url = Routes.EntityVersionDetails.makeUrl( + breadcrumb.projectId, + breadcrumb.domainId, + breadcrumb.value, + 'workflow', + title, + ); + const createdAt = formatDateUTC( + timestampToDate(entityVersion?.closure?.createdAt), + ); + + // UI only shows last version + const active = versionValue ? versionValue === title : index === 0; + + return { + title, + url, + createdAt, + active, + }; + }, + ); + + return popOverData; +}; + +export const launchPlanVersions: BreadcrumbAsyncPopOverData = async ( + location, + breadcrumb, +) => { + const resourceId = { + project: breadcrumb.projectId, + domain: breadcrumb.domainId, + name: breadcrumb.value, + resourceType: ResourceType.LAUNCH_PLAN, + }; + + const versionValue = getVersionValue(location); + const entityVersions = await fetchVersions(resourceId); + + const popOverData: BreadcrumbEntity[] = entityVersions.entities.map( + (entityVersion, index) => { + const title = entityVersion?.id?.version || ''; + const url = Routes.EntityVersionDetails.makeUrl( + breadcrumb.projectId, + breadcrumb.domainId, + breadcrumb.value, + 'launch_plan', + title, + ); + const createdAt = formatDateUTC( + timestampToDate(entityVersion?.closure?.createdAt), + ); + + // UI only shows last version + const active = versionValue ? versionValue === title : index === 0; + + return { + title, + url, + createdAt, + active, + }; + }, + ); + + return popOverData; +}; + +export const taskVersionsLink: BreadcrumbAsyncViewAllLink = async ( + location, + breadcrumb, +) => { + const data = await taskVersions(location, breadcrumb); + return data[0].url; +}; + +export const workflowVersionsLink: BreadcrumbAsyncViewAllLink = async ( + location, + breadcrumb, +) => { + const data = await workflowVersions(location, breadcrumb); + return data[0].url; +}; + +export const launchPlanVersionsLink: BreadcrumbAsyncViewAllLink = async ( + location, + breadcrumb, +) => { + const data = await launchPlanVersions(location, breadcrumb); + return data[0].url; +}; + export const executionTaskWorkflowViewAll: BreadcrumbAsyncViewAllLink = async ( location: Location, breadcrumb: BreadcrumbFormControlInterface, diff --git a/packages/console/src/components/Breadcrumbs/registry/contextualDefaults.ts b/packages/console/src/components/Breadcrumbs/registry/contextualDefaults.ts index 1c16ea5d8..bc452b2f3 100644 --- a/packages/console/src/components/Breadcrumbs/registry/contextualDefaults.ts +++ b/packages/console/src/components/Breadcrumbs/registry/contextualDefaults.ts @@ -1,6 +1,11 @@ import { Routes } from 'routes'; import { domains, namedEntities, projects } from '../async/fn'; -import { projectSelfLink } from '../selfLinks'; +import { + launchPlanSelfLink, + projectSelfLink, + taskSelfLink, + workflowSelfLink, +} from '../selfLinks'; import { Breadcrumb } from '../types'; import { makeBreadcrumb } from './utils'; import { namedEntitiesDefaultValue } from '../defaultValue'; @@ -14,6 +19,12 @@ import { executionsPeerExecutionList, executonNamedEntityAsyncValue, executonTaskWorkFlowNameAsyncValue, + launchPlanVersions, + launchPlanVersionsLink, + taskVersions, + taskVersionsLink, + workflowVersions, + workflowVersionsLink, } from '../async/executionContext'; /** @@ -46,13 +57,14 @@ export const contextualBreadcrumbRegistryList: Breadcrumb[] = [ makeBreadcrumb({ id: 'executions:named-entity', label: 'Entity Search Lists', - asyncValue: executonNamedEntityAsyncValue, + defaultValue: 'Executions', asyncData: namedEntities, valididator: executionsValidatorEmpty, }), makeBreadcrumb({ id: 'executions:task-workflow-name', label: 'Workflow', + defaultValue: 'Executions', asyncValue: executonTaskWorkFlowNameAsyncValue, asyncData: executionTaskWorkflowVersions, asyncViewAllLink: executionTaskWorkflowViewAll, @@ -63,4 +75,40 @@ export const contextualBreadcrumbRegistryList: Breadcrumb[] = [ defaultValue: 'Executions', asyncData: executionsPeerExecutionList, }), + makeBreadcrumb({ + id: 'tasks:details', + label: 'Execution', + selfLink: taskSelfLink, + asyncData: taskVersions, + asyncViewAllLink: taskVersionsLink, + }), + makeBreadcrumb({ + id: 'task:versions', + label: 'Execution', + selfLink: taskSelfLink, + }), + makeBreadcrumb({ + id: 'workflows:details', + label: 'Workflow', + selfLink: workflowSelfLink, + asyncData: workflowVersions, + asyncViewAllLink: workflowVersionsLink, + }), + makeBreadcrumb({ + id: 'workflow:versions', + label: 'Workflow', + selfLink: workflowSelfLink, + }), + makeBreadcrumb({ + id: 'launchPlans:details', + label: 'Launch Plan', + selfLink: launchPlanSelfLink, + asyncData: launchPlanVersions, + asyncViewAllLink: launchPlanVersionsLink, + }), + makeBreadcrumb({ + id: 'launch_plan:versions', + label: 'Launch Plan', + selfLink: launchPlanSelfLink, + }), ];