|
| 1 | +import React, { Fragment } from "react"; |
| 2 | + |
| 3 | +import { Content, PageSection, Tab, TabContent, Tabs, TabTitleText } from "@patternfly/react-core"; |
| 4 | +import { ExternalLinkAltIcon } from "@patternfly/react-icons"; |
| 5 | + |
| 6 | +import { LoadingWrapper } from "@app/components/LoadingWrapper"; |
| 7 | +import { useFetchTrustRootMetadataInfo } from "@app/queries/trust"; |
| 8 | + |
| 9 | +import { Certificates } from "./components/Certificates"; |
| 10 | +import { RootDetails } from "./components/RootDetails"; |
| 11 | + |
| 12 | +export const TrustRoots: React.FC = () => { |
| 13 | + const { rootMetadataList, isFetching, fetchError } = useFetchTrustRootMetadataInfo(); |
| 14 | + |
| 15 | + // Tab refs |
| 16 | + const certificatesTabRef = React.createRef<HTMLElement>(); |
| 17 | + const rootDetailsTabRef = React.createRef<HTMLElement>(); |
| 18 | + |
| 19 | + const [activeTabKey, setActiveTabKey] = React.useState<string | number>(0); |
| 20 | + |
| 21 | + const handleTabClick = (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent, tabIndex: string | number) => { |
| 22 | + setActiveTabKey(tabIndex); |
| 23 | + }; |
| 24 | + |
| 25 | + return ( |
| 26 | + <Fragment> |
| 27 | + <PageSection variant="default"> |
| 28 | + <Content> |
| 29 | + <h1>Trust Root</h1> |
| 30 | + <p>This information represents the update framework.</p> |
| 31 | + <p> |
| 32 | + <a href={rootMetadataList?.["repo-url"]} target="_blank" rel="noreferrer"> |
| 33 | + {rootMetadataList?.["repo-url"]} <ExternalLinkAltIcon /> |
| 34 | + </a> |
| 35 | + </p> |
| 36 | + </Content> |
| 37 | + </PageSection> |
| 38 | + <PageSection variant="default"> |
| 39 | + <Tabs |
| 40 | + mountOnEnter |
| 41 | + activeKey={activeTabKey} |
| 42 | + onSelect={handleTabClick} |
| 43 | + aria-label="Tabs that contain the SBOM information" |
| 44 | + role="region" |
| 45 | + > |
| 46 | + <Tab |
| 47 | + eventKey={0} |
| 48 | + title={<TabTitleText>Certificates</TabTitleText>} |
| 49 | + tabContentId="certificatesTabSection" |
| 50 | + tabContentRef={certificatesTabRef} |
| 51 | + /> |
| 52 | + <Tab |
| 53 | + eventKey={1} |
| 54 | + title={<TabTitleText>Root details</TabTitleText>} |
| 55 | + tabContentId="rootDetailsTabSection" |
| 56 | + tabContentRef={rootDetailsTabRef} |
| 57 | + /> |
| 58 | + </Tabs> |
| 59 | + </PageSection> |
| 60 | + <PageSection> |
| 61 | + <TabContent eventKey={0} id="certificatesTabSection" ref={certificatesTabRef} aria-label="Certificates"> |
| 62 | + <Certificates /> |
| 63 | + </TabContent> |
| 64 | + <TabContent eventKey={1} id="rootDetailsTabSection" ref={rootDetailsTabRef} aria-label="Root details" hidden> |
| 65 | + <LoadingWrapper isFetching={isFetching} fetchError={fetchError}> |
| 66 | + {rootMetadataList && <RootDetails rootMetadataList={rootMetadataList} />} |
| 67 | + </LoadingWrapper> |
| 68 | + </TabContent> |
| 69 | + </PageSection> |
| 70 | + </Fragment> |
| 71 | + ); |
| 72 | +}; |
0 commit comments