chore: moving the outputs around and fixing some navigation]
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import { Box, Paper } from '@material-ui/core';
|
||||
import { LinkOutputs } from './LinkOutputs';
|
||||
import { ScaffolderTaskOutput } from '../../../api';
|
||||
|
||||
/**
|
||||
* The DefaultOutputs renderer for the scaffolder task output
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export const DefaultTemplateOutputs = (props: {
|
||||
output?: ScaffolderTaskOutput;
|
||||
}) => {
|
||||
if (!props.output?.links) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box paddingBottom={2}>
|
||||
<Paper>
|
||||
<Box padding={2} justifyContent="center" display="flex" gridGap={16}>
|
||||
<LinkOutputs output={props.output} />
|
||||
</Box>
|
||||
</Paper>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { IconComponent, useApp, useRouteRef } from '@backstage/core-plugin-api';
|
||||
import { entityRouteRef } from '@backstage/plugin-catalog-react';
|
||||
import { Button, makeStyles } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import WebIcon from '@material-ui/icons/Web';
|
||||
import { parseEntityRef } from '@backstage/catalog-model';
|
||||
import { Link } from '@backstage/core-components';
|
||||
import { ScaffolderTaskOutput } from '../../../api';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
'&:hover': {
|
||||
textDecoration: 'none',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const LinkOutputs = (props: { output: ScaffolderTaskOutput }) => {
|
||||
const { links = [] } = props.output;
|
||||
const classes = useStyles();
|
||||
const app = useApp();
|
||||
const entityRoute = useRouteRef(entityRouteRef);
|
||||
|
||||
const iconResolver = (key?: string): IconComponent =>
|
||||
app.getSystemIcon(key!) ?? WebIcon;
|
||||
|
||||
return (
|
||||
<>
|
||||
{links
|
||||
.filter(({ url, entityRef }) => url || entityRef)
|
||||
.map(({ url, entityRef, title, icon }) => {
|
||||
if (entityRef) {
|
||||
const entityName = parseEntityRef(entityRef);
|
||||
const target = entityRoute(entityName);
|
||||
return { title, icon, url: target };
|
||||
}
|
||||
return { title, icon, url: url! };
|
||||
})
|
||||
.map(({ url, title, icon }, i) => {
|
||||
const Icon = iconResolver(icon);
|
||||
return (
|
||||
<Link to={url} key={i} classes={{ root: classes.root }}>
|
||||
<Button startIcon={<Icon />} component="div" color="primary">
|
||||
{title}
|
||||
</Button>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export { DefaultTemplateOutputs } from './DefaultTemplateOutputs';
|
||||
@@ -18,3 +18,4 @@ export * from './TemplateCard';
|
||||
export * from './ReviewState';
|
||||
export * from './TemplateGroup';
|
||||
export * from './Workflow';
|
||||
export * from './TemplateOutputs';
|
||||
|
||||
Reference in New Issue
Block a user