From 8d2301d9d5826870cba8b1c224ec493b4c540851 Mon Sep 17 00:00:00 2001 From: Jordan Koschei Date: Mon, 17 Jun 2024 21:05:21 -0400 Subject: [PATCH 01/15] feat: add DataComponent work --- packages/odyssey-react-mui/src/Card.tsx | 55 +-- .../src/DataTable/DataTableRowActions.tsx | 2 +- .../src/OdysseyCacheProvider.tsx | 4 +- .../labs/DataComponents/BulkActionsMenu.tsx | 85 ++++ .../src/labs/DataComponents/DataStack.tsx | 93 +++++ .../src/labs/DataComponents/DataTable.tsx | 95 +++++ .../src/labs/DataComponents/DataView.tsx | 388 ++++++++++++++++++ .../labs/DataComponents/LayoutSwitcher.tsx | 65 +++ .../src/labs/DataComponents/RowActions.tsx | 119 ++++++ .../src/labs/DataComponents/StackCard.tsx | 194 +++++++++ .../src/labs/DataComponents/StackContent.tsx | 238 +++++++++++ .../src/labs/DataComponents/TableContent.tsx | 361 ++++++++++++++++ .../src/labs/DataComponents/TableSettings.tsx | 137 +++++++ .../src/labs/DataComponents/componentTypes.ts | 118 ++++++ .../src/labs/DataComponents/constants.tsx | 20 + .../src/labs/DataComponents/dataTypes.ts | 72 ++++ .../src/labs/DataComponents/fetchData.ts | 49 +++ .../src/labs/DataComponents/index.tsx | 19 + .../labs/DataComponents/tableConstants.tsx | 156 +++++++ .../DataComponents/useFilterConversion.ts | 91 ++++ packages/odyssey-react-mui/src/labs/index.ts | 2 + .../src/theme/components.tsx | 5 +- .../odyssey-mui/Card/Card.stories.tsx | 27 +- .../DataTable/DataTable.stories.tsx | 14 +- 24 files changed, 2367 insertions(+), 42 deletions(-) create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/BulkActionsMenu.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/DataStack.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/DataTable.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/DataView.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/LayoutSwitcher.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/RowActions.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/StackCard.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/StackContent.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/TableContent.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/TableSettings.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/componentTypes.ts create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/constants.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/dataTypes.ts create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/fetchData.ts create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/index.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/tableConstants.tsx create mode 100644 packages/odyssey-react-mui/src/labs/DataComponents/useFilterConversion.ts diff --git a/packages/odyssey-react-mui/src/Card.tsx b/packages/odyssey-react-mui/src/Card.tsx index 41c540ec05..7549944d7f 100644 --- a/packages/odyssey-react-mui/src/Card.tsx +++ b/packages/odyssey-react-mui/src/Card.tsx @@ -33,6 +33,7 @@ import { useOdysseyDesignTokens, } from "./OdysseyDesignTokensContext"; import { Heading5, Paragraph, Support } from "./Typography"; +import { Box } from "./Box"; export const CARD_IMAGE_HEIGHT = "64px"; @@ -91,30 +92,36 @@ const Card = ({ const cardContent = useMemo( () => ( - <> - {image && ( - - {image} - - )} - - {overline && {overline}} - {title && {title}} - {description && ( - {description} - )} - - {button && ( - - - {button} - - - )} - + + + {image && ( + + {image} + + )} + + {overline && {overline}} + {title && {title}} + {description && ( + {description} + )} + + {button && ( + + + {button} + + + )} + + ), [ button, diff --git a/packages/odyssey-react-mui/src/DataTable/DataTableRowActions.tsx b/packages/odyssey-react-mui/src/DataTable/DataTableRowActions.tsx index 773aed4882..2e80e6407f 100644 --- a/packages/odyssey-react-mui/src/DataTable/DataTableRowActions.tsx +++ b/packages/odyssey-react-mui/src/DataTable/DataTableRowActions.tsx @@ -27,7 +27,7 @@ import { DataTableProps } from "./DataTable"; import { Trans, useTranslation } from "react-i18next"; export type DataTableRowActionsProps = { - row: MRT_Row; + row: MRT_Row | MRT_RowData; rowIndex: number; rowActionButtons?: ( row: MRT_RowData, diff --git a/packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx b/packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx index 43742f4491..6132920bc5 100644 --- a/packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx +++ b/packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx @@ -51,7 +51,9 @@ const OdysseyCacheProvider = ({ key: uniqueAlphabeticalId, nonce: nonce ?? window.cspNonce, prepend: true, - speedy: false, // <-- Needs to be set to false when shadow-dom is used!! https://github.com/emotion-js/emotion/issues/2053#issuecomment-713429122 + // TODO: Change this back!! + speedy: true, + // speedy: false, // <-- Needs to be set to false when shadow-dom is used!! https://github.com/emotion-js/emotion/issues/2053#issuecomment-713429122 ...(stylisPlugins && { stylisPlugins }), }); }, [emotionRoot, nonce, stylisPlugins, uniqueAlphabeticalId]); diff --git a/packages/odyssey-react-mui/src/labs/DataComponents/BulkActionsMenu.tsx b/packages/odyssey-react-mui/src/labs/DataComponents/BulkActionsMenu.tsx new file mode 100644 index 0000000000..cbe327bf4b --- /dev/null +++ b/packages/odyssey-react-mui/src/labs/DataComponents/BulkActionsMenu.tsx @@ -0,0 +1,85 @@ +/*! + * Copyright (c) 2024-present, Okta, Inc. and/or its affiliates. All rights reserved. + * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and limitations under the License. + */ + +import { memo, useCallback, Dispatch, SetStateAction } from "react"; +import { UniversalProps } from "./componentTypes"; +import { MenuButton } from "../../MenuButton"; +import { Button } from "../../Button"; +import { Box } from "../../Box"; +import { ChevronDownIcon } from "../../icons.generated"; +import { MRT_RowData, MRT_RowSelectionState } from "material-react-table"; + +export type BulkActionMenuProps = { + data: MRT_RowData[]; + menuItems: UniversalProps["bulkActionMenuItems"]; + rowSelection: MRT_RowSelectionState; + setRowSelection: Dispatch>; +}; + +const BulkActionMenu = ({ + data, + menuItems, + rowSelection, + setRowSelection, +}: BulkActionMenuProps) => { + const selectedRowCount = Object.values(rowSelection).filter( + (value) => value === true, + ).length; + + const handleSelectAll = useCallback(() => { + const rows = Object.fromEntries(data.map((row) => [row.id, true])); + setRowSelection(rows); + }, [data, setRowSelection]); + + const handleSelectNone = useCallback(() => { + setRowSelection({}); + }, [setRowSelection]); + + return ( + + {selectedRowCount > 0 && ( + } + buttonLabel={`${selectedRowCount} selected`} + ariaLabel="More actions" + > + {menuItems?.(rowSelection)} + + )} + +