|
| 1 | +import * as React from 'react'; |
| 2 | +import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk'; |
| 3 | +import { ApplicationSetKind, ApplicationSetModel } from '../../models/ApplicationSetModel'; |
| 4 | +import { |
| 5 | + Spinner, |
| 6 | + Bullseye, |
| 7 | + Tabs, |
| 8 | + Tab, |
| 9 | + TabTitleText, |
| 10 | +} from '@patternfly/react-core'; |
| 11 | +import { useApplicationSetActionsProvider } from '../../hooks/useApplicationSetActionsProvider'; |
| 12 | +import ResourceDetailsTitle from '../../utils/components/DetailsPageTitle/ResourceDetailsTitle'; |
| 13 | +import AppSetDetailsTab from './AppSetDetailsTab'; |
| 14 | +import GeneratorsTab from './GeneratorsTab'; |
| 15 | +import AppsTab from './AppsTab'; |
| 16 | +import EventsTab from './EventsTab'; |
| 17 | +import YAMLTab from './YAMLTab'; |
| 18 | +import './AppSetNavPage.scss'; |
| 19 | + |
| 20 | +type AppSetPageProps = { |
| 21 | + name: string; |
| 22 | + namespace: string; |
| 23 | + kind: string; |
| 24 | +}; |
| 25 | + |
| 26 | +const AppSetNavPage: React.FC<AppSetPageProps> = ({ name, namespace, kind }) => { |
| 27 | + const [activeTabKey, setActiveTabKey] = React.useState<string | number>(0); |
| 28 | + |
| 29 | + const [appSet, loaded, loadError] = useK8sWatchResource<ApplicationSetKind>({ |
| 30 | + groupVersionKind: { |
| 31 | + group: 'argoproj.io', |
| 32 | + version: 'v1alpha1', |
| 33 | + kind: 'ApplicationSet', |
| 34 | + }, |
| 35 | + name, |
| 36 | + namespace, |
| 37 | + }); |
| 38 | + |
| 39 | + const [actions] = useApplicationSetActionsProvider(appSet); |
| 40 | + |
| 41 | + if (loadError) return <div>Error loading ApplicationSet details.</div>; |
| 42 | + if (!loaded || !appSet) return ( |
| 43 | + <Bullseye> |
| 44 | + <Spinner size="xl" /> |
| 45 | + </Bullseye> |
| 46 | + ); |
| 47 | + |
| 48 | + const handleTabClick = (event: React.MouseEvent<HTMLElement, MouseEvent>, tabIndex: string | number) => { |
| 49 | + setActiveTabKey(tabIndex); |
| 50 | + }; |
| 51 | + |
| 52 | + return ( |
| 53 | + <div className="application-set-details-page__main-section"> |
| 54 | + <ResourceDetailsTitle |
| 55 | + obj={appSet} |
| 56 | + model={ApplicationSetModel} |
| 57 | + name={name} |
| 58 | + namespace={namespace} |
| 59 | + actions={actions} |
| 60 | + iconText="AS" |
| 61 | + iconTitle="Argo CD ApplicationSet" |
| 62 | + resourcePrefix="Argo CD" |
| 63 | + /> |
| 64 | + |
| 65 | + <div className="application-set-details-page__body"> |
| 66 | + <div className="application-set-details-page__pane-body"> |
| 67 | + <Tabs activeKey={activeTabKey} onSelect={handleTabClick} className="pf-v6-c-tabs"> |
| 68 | + <Tab eventKey={0} title={<TabTitleText>Details</TabTitleText>} className="pf-v6-c-tab-content"> |
| 69 | + <AppSetDetailsTab obj={appSet} namespace={namespace} name={name} /> |
| 70 | + </Tab> |
| 71 | + <Tab eventKey={1} title={<TabTitleText>YAML</TabTitleText>} className="pf-v6-c-tab-content"> |
| 72 | + <YAMLTab obj={appSet} namespace={namespace} name={name} /> |
| 73 | + </Tab> |
| 74 | + <Tab eventKey={2} title={<TabTitleText>Generators</TabTitleText>} className="pf-v6-c-tab-content"> |
| 75 | + <GeneratorsTab obj={appSet} namespace={namespace} name={name} /> |
| 76 | + </Tab> |
| 77 | + <Tab eventKey={3} title={<TabTitleText>Applications</TabTitleText>} className="pf-v6-c-tab-content"> |
| 78 | + <AppsTab obj={appSet} namespace={namespace} name={name} /> |
| 79 | + </Tab> |
| 80 | + <Tab eventKey={4} title={<TabTitleText>Events</TabTitleText>} className="pf-v6-c-tab-content"> |
| 81 | + <EventsTab obj={appSet} namespace={namespace} name={name} /> |
| 82 | + </Tab> |
| 83 | + </Tabs> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + ); |
| 88 | +}; |
| 89 | + |
| 90 | +export default AppSetNavPage; |
0 commit comments