|
| 1 | +import { Grid } from '@material-ui/core'; |
| 2 | +import { |
| 3 | + CatalogTable, |
| 4 | + CatalogTableColumnsFunc, |
| 5 | +} from '@backstage/plugin-catalog'; |
| 6 | +import { Content, Header, InfoCard, Page } from '@backstage/core-components'; |
| 7 | +import { |
| 8 | + catalogApiRef, |
| 9 | + EntityKindPicker, |
| 10 | + EntityListProvider, |
| 11 | +} from '@backstage/plugin-catalog-react'; |
| 12 | +import { EntityRelationsGraph } from '@backstage/plugin-catalog-graph'; |
| 13 | +import { useApi } from '@backstage/core-plugin-api'; |
| 14 | +import { useEffect, useState } from 'react'; |
| 15 | + |
| 16 | +type RootEntityNamesType = { |
| 17 | + kind: string; |
| 18 | + namespace: string; |
| 19 | + name: string; |
| 20 | +}; |
| 21 | + |
| 22 | +const functionColumns: CatalogTableColumnsFunc = entityListContext => { |
| 23 | + if (entityListContext.filters.kind?.value === 'function') { |
| 24 | + return [ |
| 25 | + CatalogTable.columns.createNameColumn({ defaultKind: 'function' }), |
| 26 | + CatalogTable.columns.createOwnerColumn(), |
| 27 | + CatalogTable.columns.createSpecTypeColumn(), |
| 28 | + ]; |
| 29 | + } |
| 30 | + |
| 31 | + return CatalogTable.defaultColumnsFunc(entityListContext); |
| 32 | +}; |
| 33 | + |
| 34 | +export const FunctionsPage = () => { |
| 35 | + const [rootEntity, setRootEntity] = useState<RootEntityNamesType[]>([]); |
| 36 | + const catalogApi = useApi(catalogApiRef); |
| 37 | + |
| 38 | + useEffect(() => { |
| 39 | + catalogApi.getEntities({ filter: { kind: 'function' } }).then(response => { |
| 40 | + const filteredResponse = response.items.filter(item => |
| 41 | + item.metadata.name === 'rootfunction' ? item : null, |
| 42 | + ); |
| 43 | + setRootEntity( |
| 44 | + filteredResponse.map(item => ({ |
| 45 | + kind: item.kind, |
| 46 | + namespace: item.metadata.namespace || 'default', |
| 47 | + name: item.metadata.name, |
| 48 | + })), |
| 49 | + ); |
| 50 | + }); |
| 51 | + }, [catalogApi]); |
| 52 | + |
| 53 | + return ( |
| 54 | + <Page themeId="functions"> |
| 55 | + <Header |
| 56 | + title="Forretningsfunksjoner i Kartverket" |
| 57 | + subtitle="Oversikt over hva Kartverket må kunne gjøre for å levere på sitt samfunnsoppdrag, og hvordan dette støttes av del-funksjoner, systemer og team." |
| 58 | + /> |
| 59 | + <Content> |
| 60 | + <EntityListProvider> |
| 61 | + <Grid container spacing={3}> |
| 62 | + <Grid item xs={12} md={6}> |
| 63 | + <EntityKindPicker initialFilter="function" hidden /> |
| 64 | + <CatalogTable |
| 65 | + title="Alle forretningsfunksjoner" |
| 66 | + columns={functionColumns} |
| 67 | + /> |
| 68 | + </Grid> |
| 69 | + <Grid item xs={12} md={6}> |
| 70 | + <InfoCard title="Funksjonshierarki"> |
| 71 | + <EntityRelationsGraph |
| 72 | + rootEntityNames={rootEntity} |
| 73 | + kinds={['function']} |
| 74 | + maxDepth={2} |
| 75 | + /> |
| 76 | + </InfoCard> |
| 77 | + </Grid> |
| 78 | + </Grid> |
| 79 | + </EntityListProvider> |
| 80 | + </Content> |
| 81 | + </Page> |
| 82 | + ); |
| 83 | +}; |
0 commit comments