Allow to set additional links to the entry description

Signed-off-by: Marek Šneberger <marek@sneberger.cz>
This commit is contained in:
Marek Šneberger
2023-01-17 16:21:49 +01:00
parent 5a95e88b4d
commit 18024a231c
9 changed files with 66 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-tech-radar': patch
---
Allow to set additional links to the entry description.
+12
View File
@@ -89,6 +89,17 @@ export interface RadarQuadrant {
name: string;
}
class RadarEntryLink {
/**
* URL of the link
*/
url: string;
/**
* Display name of the link
*/
title: string;
}
/**
* Single Entry in Tech Radar
*
@@ -127,6 +138,7 @@ export interface RadarEntry {
* Description of the Entry
*/
description?: string;
links?: Array<RadarEntryLink>;
}
/**
@@ -126,6 +126,7 @@ export function RadarComponent(props: TechRadarComponentProps) {
moved: entry.timeline[0].moved,
description: entry.description || entry.timeline[0].description,
url: entry.url,
links: entry.links,
}));
};
@@ -24,6 +24,7 @@ const minProps: Props = {
open: true,
title: 'example-title',
description: 'example-description',
links: [{ url: 'https://example.com/docs', title: 'example-link' }],
onClose: () => {},
};
@@ -34,5 +35,6 @@ describe('RadarDescription', () => {
const radarDescription = screen.getByTestId('radar-description');
expect(radarDescription).toBeInTheDocument();
expect(screen.getByText(String(minProps.description))).toBeInTheDocument();
expect(screen.getByText(String('example-link'))).toBeInTheDocument();
});
});
@@ -28,10 +28,18 @@ export type Props = {
title: string;
description: string;
url?: string;
links?: Array<{ url: string; title: string }>;
};
const RadarDescription = (props: Props): JSX.Element => {
const { open, onClose, title, description, url } = props;
function showDialogActions(
url: string | undefined,
links: Array<{ url: string; title: string }> | undefined,
): Boolean {
return isValidUrl(url) || Boolean(links && links.length > 0);
}
const { open, onClose, title, description, url, links } = props;
return (
<Dialog data-testid="radar-description" open={open} onClose={onClose}>
@@ -41,17 +49,32 @@ const RadarDescription = (props: Props): JSX.Element => {
<DialogContent dividers>
<MarkdownContent content={description} />
</DialogContent>
{isValidUrl(url) && (
{showDialogActions(url, links) && (
<DialogActions>
<Button
component={Link}
to={url}
onClick={onClose}
color="primary"
startIcon={<LinkIcon />}
>
LEARN MORE
</Button>
{links?.map(link => (
<Button
component={Link}
to={link.url}
onClick={onClose}
color="primary"
startIcon={<LinkIcon />}
key={link.url}
>
{link.title}
</Button>
))}
{isValidUrl(url) && (
<Button
component={Link}
to={url}
onClick={onClose}
color="primary"
startIcon={<LinkIcon />}
key={url}
>
LEARN MORE
</Button>
)}
</DialogActions>
)}
</Dialog>
@@ -25,6 +25,7 @@ type RadarLegendLinkProps = {
title?: string;
classes: ClassNameMap<string>;
active?: boolean;
links: Array<{ url: string; title: string }>;
};
export const RadarLegendLink = ({
@@ -33,6 +34,7 @@ export const RadarLegendLink = ({
title,
classes,
active,
links,
}: RadarLegendLinkProps) => {
const [open, setOpen] = React.useState(false);
@@ -73,6 +75,7 @@ export const RadarLegendLink = ({
title={title ? title : 'no title'}
url={url}
description={description}
links={links}
/>
)}
</>
@@ -61,6 +61,7 @@ export const RadarLegendRing = ({
title={entry.title}
description={entry.description}
active={entry.active}
links={entry.links}
/>
</li>
))}
+7 -1
View File
@@ -45,11 +45,17 @@ entries.push({
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
},
],
url: '#',
url: 'https://www.javascript.com/',
key: 'javascript',
id: 'javascript',
title: 'JavaScript',
quadrant: 'languages',
links: [
{
url: 'https://www.typescriptlang.org/',
title: 'TypeScript',
},
],
description:
'Excepteur **sint** occaecat *cupidatat* non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\n```ts\nconst x = "3";\n```\n',
});
+1
View File
@@ -61,6 +61,7 @@ export type Entry = {
title: string;
// An URL to a longer description as to why this entry is where it is
url?: string;
links?: Array<{ title: string; url: string }>;
// How this entry has recently moved; -1 for "down", +1 for "up", 0 for not moved
moved?: MovedState;
// Most recent description to display in the UI