From e6f2ed8ebc10731f58abd18b6aafbc1ac6ff898f Mon Sep 17 00:00:00 2001 From: reggie Date: Sat, 23 Dec 2023 11:07:21 +0200 Subject: [PATCH] preparation for resource tree changes Signed-off-by: reggie --- .../application-details.tsx | 4 ++- .../application-resource-tree.tsx | 10 ++++++-- ui/src/app/applications/components/utils.tsx | 25 ++++++++++--------- ui/src/app/shared/models.ts | 1 + .../shared/services/applications-service.ts | 17 ++++++------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/ui/src/app/applications/components/application-details/application-details.tsx b/ui/src/app/applications/components/application-details/application-details.tsx index 2575403cee653..4c685107a7839 100644 --- a/ui/src/app/applications/components/application-details/application-details.tsx +++ b/ui/src/app/applications/components/application-details/application-details.tsx @@ -956,7 +956,9 @@ export class ApplicationDetails extends React.Component { const fallbackTree = { - nodes: isApp(app) ? (app as models.Application).status.resources.map(res => ({...res, parentRefs: [], info: [], resourceVersion: '', uid: ''})) : [], + nodes: isApp(app) + ? (app as models.Application).status.resources.map(res => ({...res, parentRefs: [], info: [], resourceVersion: '', uid: ''})) + : (app as models.ApplicationSet).status.resources.map(res => ({...res, parentRefs: [], info: [], resourceVersion: '', uid: ''})), orphanedNodes: [], hosts: [] } as appModels.AbstractApplicationTree; diff --git a/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx b/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx index 3afbf2a687a7b..031d398ece5e5 100644 --- a/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx +++ b/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx @@ -30,7 +30,7 @@ import {NodeUpdateAnimation} from './node-update-animation'; import {PodGroup} from '../application-pod-view/pod-view'; import './application-resource-tree.scss'; import {ArrowConnector} from './arrow-connector'; -import {Application, ApplicationTree} from '../../../shared/models'; +import {Application, ApplicationSet, ApplicationTree} from '../../../shared/models'; function treeNodeKey(node: NodeId & {uid?: string}) { return node.uid || nodeKey(node); @@ -920,7 +920,11 @@ export const ApplicationResourceTree = (props: AbstractApplicationResourceTreePr const statusByKey = new Map(); if (isApp(props.app)) { (props.app as models.Application).status.resources.forEach(res => statusByKey.set(nodeKey(res), res)); + } else { + // Assuming AppSet. Revisit this if a third type of an AbstractApp is born. + (props.app as models.ApplicationSet).status.resources.forEach(res => statusByKey.set(nodeKey(res), res)); } + const nodeByKey = new Map(); props.tree.nodes .map(node => ({...node, orphaned: false})) @@ -1090,7 +1094,9 @@ export const ApplicationResourceTree = (props: AbstractApplicationResourceTreePr } } else { // Tree view - const managedKeys = isApp(props.app) ? new Set((props.app as Application).status.resources.map(nodeKey)) : new Set(); + const managedKeys = isApp(props.app) + ? new Set((props.app as Application).status.resources.map(nodeKey)) + : new Set((props.app as ApplicationSet).status.resources.map(nodeKey)); const orphanedKeys = isApp(props.app) ? new Set((props.tree as ApplicationTree).orphanedNodes?.map(nodeKey)) : new Set(); const orphans: ResourceTreeNode[] = []; let allChildNodes: ResourceTreeNode[] = []; diff --git a/ui/src/app/applications/components/utils.tsx b/ui/src/app/applications/components/utils.tsx index 641d730738b67..33dbe0938b8fa 100644 --- a/ui/src/app/applications/components/utils.tsx +++ b/ui/src/app/applications/components/utils.tsx @@ -13,7 +13,7 @@ import {ResourceTreeNode} from './application-resource-tree/application-resource import {CheckboxField, COLORS, ErrorNotification, Revision} from '../../shared/components'; import * as appModels from '../../shared/models'; import {services} from '../../shared/services'; -import {ApplicationSetConditionStatus, ApplicationSetStatus} from '../../shared/models'; +import {ApplicationSetConditionStatus, ApplicationSetStatus, ApplicationTree} from '../../shared/models'; import {History} from 'history'; @@ -437,8 +437,8 @@ function getResourceActionsMenuItems(resource: ResourceTreeNode, metadata: model function getActionItems( resource: ResourceTreeNode, - application: appModels.Application, - tree: appModels.ApplicationTree, + application: appModels.AbstractApplication, + tree: appModels.AbstractApplicationTree, apis: ContextApis, history: History, appChanged: BehaviorSubject, @@ -469,13 +469,14 @@ function getActionItems( action: () => apis.navigation.goto('.', {node: nodeKey(resource)}) }); } - - if (findChildPod(resource, tree)) { - items.push({ - title: 'Logs', - iconClassName: 'fa fa-fw fa-align-left', - action: () => apis.navigation.goto('.', {node: nodeKey(resource), tab: 'logs'}, {replace: true}) - }); + if (isApp(application)) { + if (findChildPod(resource, tree as ApplicationTree)) { + items.push({ + title: 'Logs', + iconClassName: 'fa fa-fw fa-align-left', + action: () => apis.navigation.goto('.', {node: nodeKey(resource), tab: 'logs'}, {replace: true}) + }); + } } if (isQuickStart) { @@ -526,8 +527,8 @@ function getActionItems( export function renderResourceMenu( resource: ResourceTreeNode, - application: appModels.Application, - tree: appModels.ApplicationTree, + application: appModels.AbstractApplication, + tree: appModels.AbstractApplicationTree, apis: ContextApis, history: History, appChanged: BehaviorSubject, diff --git a/ui/src/app/shared/models.ts b/ui/src/app/shared/models.ts index a5f039b50c640..0278eb211f7be 100644 --- a/ui/src/app/shared/models.ts +++ b/ui/src/app/shared/models.ts @@ -337,6 +337,7 @@ export interface ApplicationPreservedFields { export interface ApplicationSetStatus { conditions?: ApplicationSetCondition[]; applicationStatus: ApplicationSetApplicationStatus[]; + resources: ResourceStatus[]; } export interface ApplicationSetCondition { diff --git a/ui/src/app/shared/services/applications-service.ts b/ui/src/app/shared/services/applications-service.ts index e2e7a5388c50f..11b985f621a2e 100644 --- a/ui/src/app/shared/services/applications-service.ts +++ b/ui/src/app/shared/services/applications-service.ts @@ -95,14 +95,10 @@ export class ApplicationsService { } public resourceTree(name: string, appNamespace: string, pathname: string): Promise { - // const isFromApps = isInvokedFromAppsPath(pathname); - return ( - requests - .get(`${getRootPathByPath(pathname)}/${name}/resource-tree`) - .query({appNamespace}) - // .then(isFromApps ? res => res.body as models.ApplicationTree : res => res.body as models.ApplicationSetTree); - .then(res => res.body as models.AbstractApplicationTree) - ); + return requests + .get(`${getRootPathByPath(pathname)}/${name}/resource-tree`) + .query({appNamespace}) + .then(res => res.body as models.AbstractApplicationTree); } public watchResourceTree(name: string, appNamespace: string, pathname: string): Observable { @@ -554,7 +550,10 @@ export class ApplicationsService { data = deepMerge( { apiVersion: 'argoproj.io/v1alpha1', - kind: 'ApplicationSet' + kind: 'ApplicationSet', + status: { + resources: [] + } }, data );