Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data view, stack, and table #2267

Merged
merged 15 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@
},
"version": "0.6.0",
"packageManager": "[email protected]"
}
}
55 changes: 31 additions & 24 deletions packages/odyssey-react-mui/src/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
useOdysseyDesignTokens,
} from "./OdysseyDesignTokensContext";
import { Heading5, Paragraph, Support } from "./Typography";
import { Box } from "./Box";

export const CARD_IMAGE_HEIGHT = "64px";

Expand Down Expand Up @@ -91,30 +92,36 @@ const Card = ({

const cardContent = useMemo(
() => (
<>
{image && (
<ImageContainer
odysseyDesignTokens={odysseyDesignTokens}
hasMenuButtonChildren={Boolean(menuButtonChildren)}
>
{image}
</ImageContainer>
)}

{overline && <Support component="div">{overline}</Support>}
{title && <Heading5 component="div">{title}</Heading5>}
{description && (
<Paragraph color="textSecondary">{description}</Paragraph>
)}

{button && (
<MuiCardActions>
<ButtonContext.Provider value={buttonProviderValue}>
{button}
</ButtonContext.Provider>
</MuiCardActions>
)}
</>
<Box
sx={{
display: "flex",
}}
>
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved
<Box>
{image && (
<ImageContainer
odysseyDesignTokens={odysseyDesignTokens}
hasMenuButtonChildren={Boolean(menuButtonChildren)}
>
{image}
</ImageContainer>
)}

{overline && <Support component="div">{overline}</Support>}
{title && <Heading5 component="div">{title}</Heading5>}
{description && (
<Paragraph color="textSecondary">{description}</Paragraph>
)}

{button && (
<MuiCardActions>
<ButtonContext.Provider value={buttonProviderValue}>
{button}
</ButtonContext.Provider>
</MuiCardActions>
)}
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved
</Box>
</Box>
),
[
button,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DataTableProps } from "./DataTable";
import { Trans, useTranslation } from "react-i18next";

export type DataTableRowActionsProps = {
row: MRT_Row<MRT_RowData>;
row: MRT_Row<MRT_RowData> | MRT_RowData;
rowIndex: number;
rowActionButtons?: (
row: MRT_RowData,
Expand Down
13 changes: 10 additions & 3 deletions packages/odyssey-react-mui/src/OdysseyCacheProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import { CacheProvider } from "@emotion/react";

export type OdysseyCacheProviderProps = {
children: ReactNode;
nonce?: string;
/**
* Emotion caches styles into the style element.
* When enabling this prop, Emotion caches the styles at this element, rather than in <head>.
*/
emotionRoot?: HTMLStyleElement;
nonce?: string;
/**
* Emotion renders into this HTML element.
* When enabling this prop, Emotion renders at the top of this component rather than the bottom like it does in the HTML `<head>`.
Expand All @@ -41,6 +41,7 @@ const OdysseyCacheProvider = ({
children,
emotionRoot,
nonce,
shadowDomElement,
stylisPlugins,
}: OdysseyCacheProviderProps) => {
const uniqueAlphabeticalId = useUniqueAlphabeticalId();
Expand All @@ -51,10 +52,16 @@ 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
speedy: shadowDomElement ? false : true, // <-- Needs to be set to false when shadow-dom is used!! https://github.com/emotion-js/emotion/issues/2053#issuecomment-713429122
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved
...(stylisPlugins && { stylisPlugins }),
});
}, [emotionRoot, nonce, stylisPlugins, uniqueAlphabeticalId]);
}, [
emotionRoot,
nonce,
shadowDomElement,
stylisPlugins,
uniqueAlphabeticalId,
]);

return <CacheProvider value={emotionCache}>{children}</CacheProvider>;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*!
* 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 { MRT_RowData, MRT_RowSelectionState } from "material-react-table";
import styled from "@emotion/styled";
import { useTranslation } from "react-i18next";

import { Box } from "../../Box";
import { Button } from "../../Button";
import { ChevronDownIcon } from "../../icons.generated";
import { MenuButton } from "../../MenuButton";
import { UniversalProps } from "./componentTypes";
import {
DesignTokens,
useOdysseyDesignTokens,
} from "../../OdysseyDesignTokensContext";

export type BulkActionsMenuProps = {
data: MRT_RowData[];
menuItems: UniversalProps["bulkActionMenuItems"];
rowSelection: MRT_RowSelectionState;
setRowSelection: Dispatch<SetStateAction<MRT_RowSelectionState>>;
};

const BulkActionsContainer = styled("div", {
shouldForwardProp: (prop) => prop !== "odysseyDesignTokens",
})<{
odysseyDesignTokens: DesignTokens;
}>(({ odysseyDesignTokens }) => ({
display: "flex",
gap: odysseyDesignTokens.Spacing2,
}));

const BulkActionMenu = ({
data,
menuItems,
rowSelection,
setRowSelection,
}: BulkActionsMenuProps) => {
const odysseyDesignTokens = useOdysseyDesignTokens();
const { t } = useTranslation();

const selectedRowCount = Object.values(rowSelection).filter(
(value) => value === true,
).length;
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved

const handleSelectAll = useCallback(() => {
const rows = Object.fromEntries(data.map((row) => [row.id, true]));
setRowSelection(rows);
}, [data, setRowSelection]);
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved

const handleSelectNone = useCallback(() => {
setRowSelection({});
}, [setRowSelection]);

return (
<BulkActionsContainer odysseyDesignTokens={odysseyDesignTokens}>
{selectedRowCount > 0 && (
<MenuButton
ariaLabel="More actions"
buttonLabel={t("table.actions.selectsome", { selectedRowCount })}
buttonVariant="primary"
endIcon={<ChevronDownIcon />}
>
{menuItems?.(rowSelection)}
</MenuButton>
)}
<Box>
<Button
isDisabled={selectedRowCount === 20}
label={t("table.actions.selectall")}
onClick={handleSelectAll}
variant="secondary"
/>
<Button
isDisabled={selectedRowCount === 0}
label={t("table.actions.selectnone")}
onClick={handleSelectNone}
variant="secondary"
/>
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved
</Box>
</BulkActionsContainer>
);
};

const MemoizedBulkActionMenu = memo(BulkActionMenu);
MemoizedBulkActionMenu.displayName = "BulkActionMenu";

export { MemoizedBulkActionMenu as BulkActionMenu };
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*!
* 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 } from "react";

import { availableStackLayouts } from "./constants";
import {
AvailableStackLayouts,
StackProps,
UniversalProps,
} from "./componentTypes";
import { DataView } from "./DataView";

export type DataStackProps = UniversalProps &
StackProps & {
initialLayout?: (typeof availableStackLayouts)[number];
availableLayouts?: AvailableStackLayouts;
};

const DataStack = ({
availableLayouts,
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved
bulkActionMenuItems,
cardProps,
currentPage,
emptyPlaceholder,
errorMessage,
filters,
getData,
hasFilters,
hasPagination,
hasRowReordering,
hasRowSelection,
hasSearch,
hasSearchSubmitButton,
isEmpty,
isLoading,
isNoResults,
isRowReorderingDisabled,
maxGridColumns,
noResultsPlaceholder,
onChangeRowSelection,
paginationType,
resultsPerPage,
rowActionMenuItems,
searchDelayTime,
totalRows,
}: DataStackProps) => {
return (
<DataView
availableLayouts={availableLayouts}
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved
bulkActionMenuItems={bulkActionMenuItems}
currentPage={currentPage}
emptyPlaceholder={emptyPlaceholder}
errorMessage={errorMessage}
filters={filters}
getData={getData}
hasFilters={hasFilters}
hasPagination={hasPagination}
hasRowReordering={hasRowReordering}
hasSearch={hasSearch}
hasSearchSubmitButton={hasSearchSubmitButton}
hasRowSelection={hasRowSelection}
isEmpty={isEmpty}
isLoading={isLoading}
isNoResults={isNoResults}
isRowReorderingDisabled={isRowReorderingDisabled}
noResultsPlaceholder={noResultsPlaceholder}
onChangeRowSelection={onChangeRowSelection}
paginationType={paginationType}
resultsPerPage={resultsPerPage}
searchDelayTime={searchDelayTime}
stackOptions={{
cardProps,
maxGridColumns,
rowActionMenuItems,
}}
jordankoschei-okta marked this conversation as resolved.
Show resolved Hide resolved
totalRows={totalRows}
/>
);
};

const MemoizedDataStack = memo(DataStack);
MemoizedDataStack.displayName = "DataStack";

export { MemoizedDataStack as DataStack };
Loading
Loading