|
| 1 | +import * as React from 'react'; |
| 2 | +import { RouteComponentProps } from 'react-router'; |
| 3 | + |
| 4 | +import { ResourceLink, useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk'; |
| 5 | +import { Badge, DescriptionList, Flex, FlexItem, PageSection, Title } from '@patternfly/react-core'; |
| 6 | + |
| 7 | +import { ApplicationKind, ApplicationModel } from '../../models/ApplicationModel'; |
| 8 | +import { ApplicationSetKind, ApplicationSetModel } from '../../models/ApplicationSetModel'; |
| 9 | +import HealthStatus from '../../Statuses/HealthStatus'; |
| 10 | +import { Conditions } from '../../utils/components/Conditions/Conditions'; |
| 11 | +import { getAppSetGeneratorCount, getAppSetStatus } from '../../utils/gitops'; |
| 12 | +import BaseDetailsSummary, { |
| 13 | + DetailsDescriptionGroup, |
| 14 | +} from '../shared/BaseDetailsSummary/BaseDetailsSummary'; |
| 15 | + |
| 16 | +import './AppSetDetailsTab.scss'; |
| 17 | + |
| 18 | +type AppSetDetailsTabProps = RouteComponentProps<{ ns: string; name: string }> & { |
| 19 | + obj?: ApplicationSetKind; |
| 20 | +}; |
| 21 | + |
| 22 | +const AppSetDetailsTab: React.FC<AppSetDetailsTabProps> = ({ obj }) => { |
| 23 | + const namespace = obj?.metadata?.namespace; |
| 24 | + |
| 25 | + // Get applications to count generated apps |
| 26 | + const [applications] = useK8sWatchResource<ApplicationKind[]>({ |
| 27 | + groupVersionKind: { |
| 28 | + group: ApplicationModel.apiGroup, |
| 29 | + version: ApplicationModel.apiVersion, |
| 30 | + kind: ApplicationModel.kind, |
| 31 | + }, |
| 32 | + namespace: namespace || obj?.metadata?.namespace, |
| 33 | + isList: true, |
| 34 | + }); |
| 35 | + |
| 36 | + if (!obj) return null; |
| 37 | + |
| 38 | + const status = obj.status || {}; |
| 39 | + const spec = obj.spec || {}; |
| 40 | + const totalGenerators = getAppSetGeneratorCount(obj); |
| 41 | + const appSetStatus = getAppSetStatus(obj); |
| 42 | + |
| 43 | + // Count applications owned by this ApplicationSet |
| 44 | + const generatedAppsCount = |
| 45 | + applications?.filter((app) => |
| 46 | + app.metadata?.ownerReferences?.some( |
| 47 | + (owner) => owner.kind === obj.kind && owner.name === obj.metadata?.name, |
| 48 | + ), |
| 49 | + ).length || 0; |
| 50 | + |
| 51 | + return ( |
| 52 | + <> |
| 53 | + <PageSection> |
| 54 | + <Title headingLevel="h2" className="co-section-heading"> |
| 55 | + Argo CD ApplicationSet details |
| 56 | + </Title> |
| 57 | + <Flex |
| 58 | + justifyContent={{ default: 'justifyContentSpaceEvenly' }} |
| 59 | + direction={{ default: 'column', lg: 'row' }} |
| 60 | + > |
| 61 | + <Flex flex={{ default: 'flex_2' }}> |
| 62 | + <FlexItem> |
| 63 | + <BaseDetailsSummary obj={obj} model={ApplicationSetModel} /> |
| 64 | + </FlexItem> |
| 65 | + </Flex> |
| 66 | + <Flex flex={{ default: 'flex_2' }} direction={{ default: 'column' }}> |
| 67 | + <FlexItem> |
| 68 | + <DescriptionList className="pf-c-description-list"> |
| 69 | + <DetailsDescriptionGroup |
| 70 | + title="Status" |
| 71 | + help="Current health status of the ApplicationSet." |
| 72 | + > |
| 73 | + <HealthStatus status={appSetStatus} /> |
| 74 | + </DetailsDescriptionGroup> |
| 75 | + |
| 76 | + <DetailsDescriptionGroup |
| 77 | + title="Generated Apps" |
| 78 | + help="Number of applications generated by this ApplicationSet." |
| 79 | + > |
| 80 | + <Badge isRead color="blue"> |
| 81 | + {generatedAppsCount} application{generatedAppsCount !== 1 ? 's' : ''} |
| 82 | + </Badge> |
| 83 | + </DetailsDescriptionGroup> |
| 84 | + |
| 85 | + <DetailsDescriptionGroup |
| 86 | + title="Generators" |
| 87 | + help="Number of generators configured in this ApplicationSet." |
| 88 | + > |
| 89 | + <Badge isRead color="grey"> |
| 90 | + {totalGenerators} generator{totalGenerators !== 1 ? 's' : ''} |
| 91 | + </Badge> |
| 92 | + </DetailsDescriptionGroup> |
| 93 | + |
| 94 | + <DetailsDescriptionGroup |
| 95 | + title="App Project" |
| 96 | + help="Argo CD project that this ApplicationSet belongs to." |
| 97 | + > |
| 98 | + <ResourceLink |
| 99 | + namespace={obj?.metadata?.namespace} |
| 100 | + groupVersionKind={{ |
| 101 | + group: 'argoproj.io', |
| 102 | + version: 'v1alpha1', |
| 103 | + kind: 'AppProject', |
| 104 | + }} |
| 105 | + name={spec.template?.spec?.project || 'default'} |
| 106 | + /> |
| 107 | + </DetailsDescriptionGroup> |
| 108 | + |
| 109 | + {spec.template?.spec?.source?.repoURL && ( |
| 110 | + <DetailsDescriptionGroup |
| 111 | + title="Repository" |
| 112 | + help="Git repository URL where the ApplicationSet configuration is stored." |
| 113 | + > |
| 114 | + <a |
| 115 | + href={spec.template.spec.source.repoURL} |
| 116 | + target="_blank" |
| 117 | + rel="noopener noreferrer" |
| 118 | + > |
| 119 | + {spec.template.spec.source.repoURL} |
| 120 | + </a> |
| 121 | + </DetailsDescriptionGroup> |
| 122 | + )} |
| 123 | + </DescriptionList> |
| 124 | + </FlexItem> |
| 125 | + </Flex> |
| 126 | + </Flex> |
| 127 | + </PageSection> |
| 128 | + |
| 129 | + <PageSection> |
| 130 | + <Title headingLevel="h2" className="co-section-heading"> |
| 131 | + Conditions |
| 132 | + </Title> |
| 133 | + <Conditions conditions={status.conditions} /> |
| 134 | + </PageSection> |
| 135 | + </> |
| 136 | + ); |
| 137 | +}; |
| 138 | + |
| 139 | +export default AppSetDetailsTab; |
0 commit comments