Skip to content

Commit

Permalink
Use in WorkflowLayout as a container in Route element prop
Browse files Browse the repository at this point in the history
  • Loading branch information
septum committed Oct 17, 2024
1 parent edf9ba1 commit 272c29b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
32 changes: 22 additions & 10 deletions frontend/packages/core/src/AppProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Landing from "../landing";
import type { ClutchError } from "../Network/errors";
import NotFound from "../not-found";
import type { AppConfiguration } from "../Types";
import WorkflowLayout, { LayoutProps } from "../WorkflowLayout";

import { registeredWorkflows } from "./registrar";
import ShortLinkProxy, { ShortLinkBaseRoute } from "./short-link-proxy";
Expand Down Expand Up @@ -214,21 +215,32 @@ const ClutchApp = ({
const heading = route.displayName
? `${workflow.displayName}: ${route.displayName}`
: workflow.displayName;

// We define these props in order to avoid UI changes before refactoring
const workflowLayoutProps: LayoutProps = {
variant: "custom",
showHeader: false,
heading: route.layoutProps?.heading || heading,
...route.layoutProps,
};
return (
<Route
key={workflow.path}
path={`${route.path.replace(/^\/+/, "").replace(/\/+$/, "")}`}
element={
<AppNotification
type="layout"
workflow={workflow?.displayName}
banners={appConfiguration?.banners}
>
{React.cloneElement(<route.component />, {
...route.componentProps,
heading,
})}
</AppNotification>
<WorkflowLayout {...workflowLayoutProps}>
<AppNotification
type="layout"
workflow={workflow?.displayName}
banners={appConfiguration?.banners}
>
{React.cloneElement(<route.component />, {
...route.componentProps,
// This is going to be removed to be used in the WorkflowLayout only
heading,
})}
</AppNotification>
</WorkflowLayout>
}
/>
);
Expand Down
3 changes: 3 additions & 0 deletions frontend/packages/core/src/AppProvider/workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Alert, Grid, IconButton } from "@mui/material";

import { Dialog, DialogContent } from "../dialog";
import Code from "../text";
import type { LayoutProps } from "../WorkflowLayout";

import type { WorkflowIcon } from "./index";

Expand Down Expand Up @@ -90,6 +91,8 @@ export interface Route {
* If this is not set the route will always be registered.
*/
featureFlag?: string;

layoutProps?: LayoutProps;
}

export interface ConfiguredRoute extends Route {
Expand Down
10 changes: 6 additions & 4 deletions frontend/packages/core/src/WorkflowLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type { CSSObject, Theme } from "@mui/material";
import styled from "../styled";
import { Typography } from "../typography";

type LayoutVariant = "standard" | "wizard";
export type LayoutVariant = "standard" | "wizard" | "custom";

type LayoutProps = {
variant: LayoutVariant;
export type LayoutProps = {
variant?: LayoutVariant;
heading?: string | React.ReactElement;
showHeader?: boolean;
};
Expand Down Expand Up @@ -36,6 +36,8 @@ const getContainerVariantStyles = (variant: LayoutVariant, theme: Theme) => {
padding: theme.spacing(theme.clutch.spacing.lg, theme.clutch.spacing.none),
margin: theme.spacing(theme.clutch.spacing.none, "auto"),
},
// No styles
custom: {},
};
return layoutVariantStylesMap[variant];
};
Expand All @@ -58,7 +60,7 @@ const HeaderTitle = styled(Typography)({
});

const WorkflowLayout = ({
variant,
variant = "custom",
showHeader,
heading,
children,
Expand Down

0 comments on commit 272c29b

Please sign in to comment.