feat(scaffolder): load data from catalog api
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
"dependencies": {
|
||||
"@backstage/core": "^0.1.1-alpha.12",
|
||||
"@backstage/theme": "^0.1.1-alpha.12",
|
||||
"@backstage/catalog-model": "^0.1.1-alpha.12",
|
||||
"@backstage/plugin-catalog": "^0.1.1-alpha.12",
|
||||
"@material-ui/core": "^4.9.1",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"@material-ui/lab": "4.0.0-alpha.45",
|
||||
|
||||
@@ -23,33 +23,38 @@ import {
|
||||
SupportButton,
|
||||
Page,
|
||||
pageTheme,
|
||||
useApi,
|
||||
} from '@backstage/core';
|
||||
import { Button, Grid, Link, Typography } from '@material-ui/core';
|
||||
import { catalogApiRef } from '@backstage/plugin-catalog';
|
||||
import {
|
||||
Typography,
|
||||
Link,
|
||||
Button,
|
||||
Grid,
|
||||
LinearProgress,
|
||||
} from '@material-ui/core';
|
||||
import { Link as RouterLink } from 'react-router-dom';
|
||||
import TemplateCard from '../TemplateCard';
|
||||
import { useAsync } from 'react-use';
|
||||
import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
|
||||
|
||||
// TODO(blam): Connect to backend
|
||||
const STATIC_DATA = [
|
||||
{
|
||||
id: 'springboot-template',
|
||||
type: 'service',
|
||||
name: 'Spring Boot Service',
|
||||
tags: ['Recommended', 'Java'],
|
||||
description:
|
||||
'Standard Spring Boot (Java) microservice with recommended configuration.',
|
||||
ownerId: 'spotify',
|
||||
},
|
||||
{
|
||||
id: 'react-ssr-template',
|
||||
type: 'website',
|
||||
name: 'SSR React Website',
|
||||
tags: ['Recommended', 'React'],
|
||||
description:
|
||||
'Next.js application skeleton for creating isomorphic web applications.',
|
||||
ownerId: 'spotify',
|
||||
},
|
||||
];
|
||||
const ScaffolderPage: React.FC<{}> = () => {
|
||||
const catalogApi = useApi(catalogApiRef);
|
||||
|
||||
const { value, loading } = useAsync(async () => {
|
||||
const entities = await catalogApi.getEntities({ kind: 'Template' });
|
||||
return (entities as TemplateEntityV1alpha1[]).map(template => ({
|
||||
id: template.metadata.uid,
|
||||
type: template.spec.type,
|
||||
name: template.metadata.name,
|
||||
// TODO(shmidt-i): decide on tags
|
||||
tags: ['not-implemented'],
|
||||
description: template.metadata.description ?? '-',
|
||||
// TODO(shmidt-i): decide on owner
|
||||
ownerId: '-',
|
||||
}));
|
||||
});
|
||||
|
||||
return (
|
||||
<Page theme={pageTheme.home}>
|
||||
<Header
|
||||
@@ -84,19 +89,23 @@ const ScaffolderPage: React.FC<{}> = () => {
|
||||
</Link>
|
||||
.
|
||||
</Typography>
|
||||
<Grid container>
|
||||
{STATIC_DATA.map(item => {
|
||||
return (
|
||||
<TemplateCard
|
||||
key={item.id}
|
||||
title={item.name}
|
||||
type={item.type}
|
||||
description={item.description}
|
||||
tags={item.tags}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Grid>
|
||||
{loading ? (
|
||||
<LinearProgress />
|
||||
) : (
|
||||
<Grid container>
|
||||
{value!.map(item => {
|
||||
return (
|
||||
<TemplateCard
|
||||
key={item.id}
|
||||
title={item.name}
|
||||
type={item.type}
|
||||
description={item.description}
|
||||
tags={item.tags}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Grid>
|
||||
)}
|
||||
</Content>
|
||||
</Page>
|
||||
);
|
||||
|
||||
@@ -67,7 +67,7 @@ const TemplateCard: FC<TemplateCardProps> = ({
|
||||
</div>
|
||||
<div className={classes.content}>
|
||||
{tags?.map(tag => (
|
||||
<Chip label={tag} />
|
||||
<Chip label={tag} key={tag} />
|
||||
))}
|
||||
<Typography variant="body2" paragraph className={classes.description}>
|
||||
{description}
|
||||
|
||||
Reference in New Issue
Block a user