From db8ff82cb89a288c95492bc5f9b72a4c2bb9e01a Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Wed, 5 Mar 2025 16:06:12 +0100 Subject: [PATCH] refactor: apply review suggestions Co-authored-by: Patrik Oldsberg Signed-off-by: Camila Belo --- packages/core-components/report.api.md | 1 - .../HorizontalScrollGrid.tsx | 5 +- .../src/alpha/DefaultEntityContentLayout.tsx | 142 ++++++++++-------- 3 files changed, 83 insertions(+), 65 deletions(-) diff --git a/packages/core-components/report.api.md b/packages/core-components/report.api.md index 77262e5360..c706eef2bb 100644 --- a/packages/core-components/report.api.md +++ b/packages/core-components/report.api.md @@ -20,7 +20,6 @@ import { default as CSS_2 } from 'csstype'; import { CSSProperties } from 'react'; import { ElementType } from 'react'; import { ErrorInfo } from 'react'; -import { GridSpacing } from '@material-ui/core/Grid'; import IconButton from '@material-ui/core/IconButton'; import { IconComponent } from '@backstage/core-plugin-api'; import { Icons } from '@material-table/core'; diff --git a/packages/core-components/src/components/HorizontalScrollGrid/HorizontalScrollGrid.tsx b/packages/core-components/src/components/HorizontalScrollGrid/HorizontalScrollGrid.tsx index 72a596415d..e89b7896dd 100644 --- a/packages/core-components/src/components/HorizontalScrollGrid/HorizontalScrollGrid.tsx +++ b/packages/core-components/src/components/HorizontalScrollGrid/HorizontalScrollGrid.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ import Box from '@material-ui/core/Box'; -import Grid, { GridSpacing } from '@material-ui/core/Grid'; +import Grid from '@material-ui/core/Grid'; import IconButton from '@material-ui/core/IconButton'; import { makeStyles } from '@material-ui/core/styles'; import ChevronLeftIcon from '@material-ui/icons/ChevronLeft'; @@ -54,7 +54,6 @@ type Props = { scrollStep?: number; scrollSpeed?: number; // lower is faster minScrollDistance?: number; // limits how small steps the scroll can take in px - spacing?: GridSpacing; }; /** @public */ @@ -210,7 +209,6 @@ export function HorizontalScrollGrid(props: PropsWithChildren) { scrollStep = 100, scrollSpeed = 50, minScrollDistance = 5, - spacing, children, ...otherProps } = props; @@ -236,7 +234,6 @@ export function HorizontalScrollGrid(props: PropsWithChildren) { wrap="nowrap" className={classes.container} ref={ref as any} - spacing={spacing} > {children} diff --git a/plugins/catalog/src/alpha/DefaultEntityContentLayout.tsx b/plugins/catalog/src/alpha/DefaultEntityContentLayout.tsx index 708f9bdb5f..7a73f991bc 100644 --- a/plugins/catalog/src/alpha/DefaultEntityContentLayout.tsx +++ b/plugins/catalog/src/alpha/DefaultEntityContentLayout.tsx @@ -16,7 +16,7 @@ import React from 'react'; import Grid from '@material-ui/core/Grid'; -import { makeStyles } from '@material-ui/core/styles'; +import { makeStyles, Theme } from '@material-ui/core/styles'; import { EntityContentLayoutProps } from '@backstage/plugin-catalog-react/alpha'; import { EntitySwitch } from '../components/EntitySwitch'; import { @@ -33,23 +33,61 @@ import { } from '../components/EntityProcessingErrorsPanel'; import { HorizontalScrollGrid } from '@backstage/core-components'; -const useStyles = makeStyles(theme => ({ +const useStyles = makeStyles< + Theme, + { infoCards: boolean; peekCards: boolean; fullCards: boolean } +>(theme => ({ + root: { + display: 'flex', + flexFlow: 'column nowrap', + gap: theme.spacing(3), + }, + fullArea: { + display: 'flex', + flexFlow: 'column', + gap: theme.spacing(3), + alignItems: 'stretch', + minWidth: 0, + }, + infoArea: { + display: 'flex', + flexFlow: 'column nowrap', + alignItems: 'stretch', + gap: theme.spacing(3), + minWidth: 0, + }, + peekArea: { + margin: theme.spacing(1.5), // To counteract MUI negative grid margin + }, peekCard: { flex: '0 0 auto', - }, - [theme.breakpoints.up('sm')]: { - infoArea: { - order: 1, - position: 'sticky', - top: -16, - alignSelf: 'flex-start', + '& + &': { + marginLeft: theme.spacing(3), }, - card: { - alignSelf: 'stretch', - '& > *': { - height: '100%', - minHeight: 400, - }, + }, + [theme.breakpoints.up('md')]: { + root: { + display: 'grid', + gap: 0, + gridTemplateAreas: ({ peekCards }) => ` + "${peekCards ? 'peek' : 'full'} info" + "full info" + `, + gridTemplateColumns: ({ infoCards }) => (infoCards ? '2fr 1fr' : '1fr'), + alignItems: 'start', + }, + infoArea: { + gridArea: 'info', + position: 'sticky', + top: theme.spacing(3), + marginLeft: theme.spacing(3), + }, + fullArea: { + gridArea: 'full', + }, + peekArea: { + gridArea: 'peek', + marginBottom: theme.spacing(3), }, }, })); @@ -84,57 +122,41 @@ const entityWarningContent = ( export function DefaultEntityContentLayout(props: EntityContentLayoutProps) { const { cards } = props; - const classes = useStyles(); const infoCards = cards.filter(card => card.type === 'info'); const peekCards = cards.filter(card => card.type === 'peek'); const fullCards = cards.filter(card => !card.type || card.type === 'full'); + + const classes = useStyles({ + infoCards: !!infoCards.length, + peekCards: !!peekCards.length, + fullCards: !!fullCards.length, + }); + return ( - + <> {entityWarningContent} - {infoCards.length > 0 ? ( - - - {infoCards.map((card, index) => ( - - {card.element} - - ))} - - - ) : null} - {peekCards.length > 0 || fullCards.length > 0 ? ( - - {peekCards.length > 0 ? ( - - - - {peekCards.map((card, index) => ( - - {card.element} - - ))} - - - - ) : null} - {fullCards.length > 0 ? ( - - {fullCards.map((card, index) => ( - - {card.element} - +
+ {infoCards.length > 0 ? ( +
+ {infoCards.map(card => card.element)} +
+ ) : null} + {peekCards.length > 0 ? ( +
+ + {peekCards.map(card => ( +
{card.element}
))} - - ) : null} - - ) : null} - +
+
+ ) : null} + {fullCards.length > 0 ? ( +
+ {fullCards.map(card => card.element)} +
+ ) : null} +
+ ); }