Skip to content

Commit

Permalink
OS-7761. Restore the 'Expand' button to the side modal header
Browse files Browse the repository at this point in the history
  • Loading branch information
ek-hystax authored Aug 26, 2024
1 parent 755b5a2 commit b0e7921
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
23 changes: 20 additions & 3 deletions ngui/ui/src/components/SideModal/SideModal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import { useState } from "react";
import { ReactNode, SyntheticEvent, useState } from "react";
import Drawer from "@mui/material/Drawer";
import SideModalHeader from "components/SideModalHeader";
import { SideModalHeaderProps } from "components/SideModalHeader/SideModalHeader";
import useStyles from "./SideModal.styles";

const DrawerContent = ({ headerProps, handleClose, children }) => {
type DrawerContentProps = {
headerProps: SideModalHeaderProps;
handleClose: (event: SyntheticEvent) => void;
children: ReactNode;
};

type SideModalProps = {
isOpen: boolean;
closeHandler: (isOpen: boolean) => void;
dataTestId: string;
headerProps: SideModalHeaderProps;
onClose?: (event: SyntheticEvent) => void;
children: ReactNode;
};

const DrawerContent = ({ headerProps, handleClose, children }: DrawerContentProps) => {
const { showExpand, ...sideModalHeaderProps } = headerProps;

const [isExpanded, setIsExpanded] = useState(showExpand);
Expand All @@ -14,6 +30,7 @@ const DrawerContent = ({ headerProps, handleClose, children }) => {
<div className={cx(classes.sideModal, isExpanded && classes.sideModalExpanded)}>
<SideModalHeader
{...sideModalHeaderProps}
showExpand={showExpand}
onClose={handleClose}
isExpanded={isExpanded}
onExpandChange={() => setIsExpanded(!isExpanded)}
Expand All @@ -23,7 +40,7 @@ const DrawerContent = ({ headerProps, handleClose, children }) => {
);
};

const SideModal = ({ isOpen, closeHandler, dataTestId, headerProps = {}, onClose, children }) => {
const SideModal = ({ isOpen, closeHandler, dataTestId, headerProps, onClose, children }: SideModalProps) => {
const handleClose = (event) => {
if (event.type === "keydown" && (event.key === "Tab" || event.key === "Shift")) {
return;
Expand Down
23 changes: 21 additions & 2 deletions ngui/ui/src/components/SideModalHeader/SideModalHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ReactNode, SyntheticEvent } from "react";
import CloseIcon from "@mui/icons-material/Close";
import WidthNormalIcon from "@mui/icons-material/WidthNormal";
import WidthWideIcon from "@mui/icons-material/WidthWide";
Expand All @@ -10,6 +11,23 @@ import SideModalTitle from "components/SideModalTitle";
import { capitalize } from "utils/strings";
import useStyles from "./SideModalHeader.styles";

type Title =
| { text: string; messageId?: never; formattedMessageValues?: never }
| { text?: never; messageId: string; formattedMessageValues?: Record<string, ReactNode> };

export type SideModalHeaderProps = Title & {
onClose: (event: SyntheticEvent) => void;
showExpand?: boolean;
onExpandChange?: () => void;
isExpanded?: boolean;
dataTestIds?: {
title?: string;
closeButton?: string;
expandButton?: string;
};
color?: "primary" | "success" | "info" | "error";
};

const SideModalHeader = ({
text,
messageId,
Expand All @@ -20,7 +38,7 @@ const SideModalHeader = ({
formattedMessageValues,
dataTestIds,
color = "primary"
}) => {
}: SideModalHeaderProps) => {
const { classes, cx } = useStyles();

const {
Expand All @@ -29,7 +47,8 @@ const SideModalHeader = ({
expandButton: expandButtonDataTestId
} = dataTestIds || {};

const headerClasses = cx(classes["header".concat(capitalize(color))]);
const headerColorClassName = `header${capitalize(color)}` as const;
const headerClasses = cx(classes[headerColorClassName]);

return (
<Box mb={2}>
Expand Down
9 changes: 7 additions & 2 deletions ngui/ui/src/components/SideModalTitle/SideModalTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Typography from "@mui/material/Typography";
import Typography, { TypographyProps } from "@mui/material/Typography";

const SideModalTitle = ({ children, dataProductTourId, dataTestId, ...rest }) => (
type SideModalTitleProps = {
dataProductTourId?: string;
dataTestId?: string;
} & TypographyProps;

const SideModalTitle = ({ children, dataProductTourId, dataTestId, ...rest }: SideModalTitleProps) => (
<Typography component="h2" variant="h6" data-product-tour-id={dataProductTourId} data-test-id={dataTestId} {...rest}>
{children}
</Typography>
Expand Down
3 changes: 2 additions & 1 deletion ngui/ui/src/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const getHash = (s) => {
return h;
};

export const capitalize = (s) => (isString(s) ? s.charAt(0).toUpperCase() + s.slice(1) : "");
export const capitalize = <T extends string>(s: T): Capitalize<T> =>
(isString(s) ? s.charAt(0).toUpperCase() + s.slice(1) : "") as Capitalize<T>;

export const concatenate = (array, pre, separator) => {
const string = array.join(separator);
Expand Down

0 comments on commit b0e7921

Please sign in to comment.