Skip to content

Commit

Permalink
preparation for resource tree changes
Browse files Browse the repository at this point in the history
Signed-off-by: reggie <[email protected]>
  • Loading branch information
reggie-k committed Dec 23, 2023
1 parent 157a845 commit e6f2ed8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,9 @@ export class ApplicationDetails extends React.Component<RouteComponentProps<{app
.pipe(
mergeMap(app => {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -920,7 +920,11 @@ export const ApplicationResourceTree = (props: AbstractApplicationResourceTreePr
const statusByKey = new Map<string, models.ResourceStatus>();
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<string, ResourceTreeNode>();
props.tree.nodes
.map(node => ({...node, orphaned: false}))
Expand Down Expand Up @@ -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[] = [];
Expand Down
25 changes: 13 additions & 12 deletions ui/src/app/applications/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<unknown>,
appChanged: BehaviorSubject<appModels.AbstractApplication>,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<unknown>,
appChanged: BehaviorSubject<appModels.AbstractApplication>,
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export interface ApplicationPreservedFields {
export interface ApplicationSetStatus {
conditions?: ApplicationSetCondition[];
applicationStatus: ApplicationSetApplicationStatus[];
resources: ResourceStatus[];
}

export interface ApplicationSetCondition {
Expand Down
17 changes: 8 additions & 9 deletions ui/src/app/shared/services/applications-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,10 @@ export class ApplicationsService {
}

public resourceTree(name: string, appNamespace: string, pathname: string): Promise<models.AbstractApplicationTree> {
// 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<models.ApplicationTree> {
Expand Down Expand Up @@ -554,7 +550,10 @@ export class ApplicationsService {
data = deepMerge(
{
apiVersion: 'argoproj.io/v1alpha1',
kind: 'ApplicationSet'
kind: 'ApplicationSet',
status: {
resources: []
}
},
data
);
Expand Down

0 comments on commit e6f2ed8

Please sign in to comment.