Skip to content

Commit

Permalink
Make styling of groups tab in the explore page use the Backstage theme
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
  • Loading branch information
Fox32 committed Sep 8, 2021
1 parent 96f2392 commit db6d278
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .changeset/ten-dolls-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@backstage/plugin-explore': patch
---

Make styling of groups tab in the explore page use the Backstage theme instead
of hard coded colors. Change the layout to be full screen.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
getEntityRelations,
formatEntityRefTitle,
} from '@backstage/plugin-catalog-react';
import { makeStyles, Typography } from '@material-ui/core';
import { makeStyles, Typography, useTheme } from '@material-ui/core';
import ZoomOutMap from '@material-ui/icons/ZoomOutMap';
import React from 'react';
import { useAsync } from 'react-use';
Expand All @@ -42,23 +42,28 @@ import {
import { useApi, useRouteRef, configApiRef } from '@backstage/core-plugin-api';

const useStyles = makeStyles((theme: BackstageTheme) => ({
graph: {
flex: 1,
minHeight: 0,
},
organizationNode: {
fill: 'coral',
stroke: theme.palette.border,
fill: theme.palette.background.paper,
stroke: theme.palette.primary.main,
},
groupNode: {
fill: 'yellowgreen',
fill: theme.palette.background.paper,
stroke: theme.palette.border,
},
centeredContent: {
padding: '10px',
padding: theme.spacing(1),
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
color: 'black',
},
textWrapper: {
color: theme.palette.textContrast,
display: '-webkit-box',
WebkitBoxOrient: 'vertical',
WebkitLineClamp: 2,
Expand All @@ -70,31 +75,24 @@ const useStyles = makeStyles((theme: BackstageTheme) => ({
},
}));

const dimensions = {
nodeWidth: 180,
nodeHeight: 90,
nodeCornerRadius: 20,
nodeAligmentShift: 5,
};

function RenderNode(props: DependencyGraphTypes.RenderNodeProps<any>) {
const nodeWidth = 180;
const nodeHeight = 80;
const theme = useTheme();
const classes = useStyles();
const catalogEntityRoute = useRouteRef(entityRouteRef);

if (props.node.id === 'root') {
return (
<g>
<rect
width={dimensions.nodeWidth}
height={dimensions.nodeHeight}
rx={dimensions.nodeCornerRadius}
width={nodeWidth}
height={nodeHeight}
rx={theme.shape.borderRadius}
className={classes.organizationNode}
/>
<title>{props.node.name}</title>
<foreignObject
width={dimensions.nodeWidth}
height={dimensions.nodeHeight}
>
<foreignObject width={nodeWidth} height={nodeHeight}>
<div className={classes.centeredContent}>
<div className={classes.textWrapper}>{props.node.name}</div>
</div>
Expand All @@ -108,9 +106,9 @@ function RenderNode(props: DependencyGraphTypes.RenderNodeProps<any>) {
return (
<g>
<rect
width={dimensions.nodeWidth}
height={dimensions.nodeHeight}
rx={dimensions.nodeCornerRadius}
width={nodeWidth}
height={nodeHeight}
rx={theme.shape.borderRadius}
className={classes.groupNode}
/>
<title>{props.node.name}</title>
Expand All @@ -122,10 +120,7 @@ function RenderNode(props: DependencyGraphTypes.RenderNodeProps<any>) {
name: ref.name,
})}
>
<foreignObject
width={dimensions.nodeWidth}
height={dimensions.nodeHeight}
>
<foreignObject width={nodeWidth} height={nodeHeight}>
<div className={classes.centeredContent}>
<div className={classes.textWrapper}>{props.node.name}</div>
</div>
Expand All @@ -146,6 +141,7 @@ export function GroupsDiagram() {
}>();
const edges = new Array<{ from: string; to: string; label: string }>();

const classes = useStyles();
const configApi = useApi(configApiRef);
const catalogApi = useApi(catalogApiRef);
const organizationName =
Expand Down Expand Up @@ -218,6 +214,7 @@ export function GroupsDiagram() {
nodeMargin={10}
direction={DependencyGraphTypes.Direction.RIGHT_LEFT}
renderNode={RenderNode}
className={classes.graph}
/>
<Typography
variant="caption"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import {
ContentHeader,
SupportButton,
} from '@backstage/core-components';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles({
root: {
height: '100%',
maxHeight: '100%',
minHeight: 0,
},
});

type GroupsExplorerContentProps = {
title?: string;
Expand All @@ -29,8 +38,10 @@ type GroupsExplorerContentProps = {
export const GroupsExplorerContent = ({
title,
}: GroupsExplorerContentProps) => {
const classes = useStyles();

return (
<Content noPadding>
<Content noPadding stretch className={classes.root}>
<ContentHeader title={title ?? 'Groups'}>
<SupportButton>Explore your groups.</SupportButton>
</ContentHeader>
Expand Down

0 comments on commit db6d278

Please sign in to comment.