From 2612c3ffb95140e4faea4ba1194f69a915802bc6 Mon Sep 17 00:00:00 2001 From: Benjamin Hohenwarter Date: Thu, 22 Aug 2024 09:06:24 +0200 Subject: [PATCH] Reduce forwarded props to selection-props --- .../products/future/ProductsGrid.cometGen.ts | 1 - .../future/SelectProductsGrid.cometGen.ts | 18 ++++++++++++++++++ .../products/future/generated/ProductsGrid.tsx | 7 +++---- .../src/generator/future/generateGrid.ts | 14 +++++++++----- .../src/generator/future/generator.ts | 2 +- 5 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 demo/admin/src/products/future/SelectProductsGrid.cometGen.ts diff --git a/demo/admin/src/products/future/ProductsGrid.cometGen.ts b/demo/admin/src/products/future/ProductsGrid.cometGen.ts index f1ee555a28..d5e39bcd0b 100644 --- a/demo/admin/src/products/future/ProductsGrid.cometGen.ts +++ b/demo/admin/src/products/future/ProductsGrid.cometGen.ts @@ -8,7 +8,6 @@ export const ProductsGrid: GridConfig = { filterProp: true, toolbarActionProp: true, rowActionProp: true, - dataGridPropsProp: true, columns: [ { type: "boolean", name: "inStock", headerName: "In stock", width: 90 }, { type: "text", name: "title", headerName: "Titel", minWidth: 200, maxWidth: 250 }, diff --git a/demo/admin/src/products/future/SelectProductsGrid.cometGen.ts b/demo/admin/src/products/future/SelectProductsGrid.cometGen.ts new file mode 100644 index 0000000000..a7e5934f60 --- /dev/null +++ b/demo/admin/src/products/future/SelectProductsGrid.cometGen.ts @@ -0,0 +1,18 @@ +import { future_GridConfig as GridConfig } from "@comet/cms-admin"; +import { GQLProduct } from "@src/graphql.generated"; + +export const SelectProductsGrid: GridConfig = { + type: "grid", + gqlType: "Product", + fragmentName: "SelectProductsGridFuture", + readOnly: true, + selectionProps: true, + columns: [ + { type: "text", name: "title", headerName: "Titel", minWidth: 200, maxWidth: 250 }, + { type: "text", name: "description", headerName: "Description" }, + { type: "number", name: "price", headerName: "Price", maxWidth: 150 }, + { type: "staticSelect", name: "type", maxWidth: 150, values: [{ value: "Cap", label: "great Cap" }, "Shirt", "Tie"] }, + { type: "date", name: "availableSince", width: 140 }, + { type: "dateTime", name: "createdAt", width: 170 }, + ], +}; diff --git a/demo/admin/src/products/future/generated/ProductsGrid.tsx b/demo/admin/src/products/future/generated/ProductsGrid.tsx index c7677983b9..65b4c2df7e 100644 --- a/demo/admin/src/products/future/generated/ProductsGrid.tsx +++ b/demo/admin/src/products/future/generated/ProductsGrid.tsx @@ -17,7 +17,7 @@ import { usePersistentColumnState, } from "@comet/admin"; import { DamImageBlock } from "@comet/cms-admin"; -import { DataGridPro, DataGridProProps, GridRenderCellParams, GridToolbarQuickFilter } from "@mui/x-data-grid-pro"; +import { DataGridPro, GridRenderCellParams, GridToolbarQuickFilter } from "@mui/x-data-grid-pro"; import { GQLProductFilter } from "@src/graphql.generated"; import * as React from "react"; import { useIntl } from "react-intl"; @@ -91,13 +91,12 @@ type Props = { toolbarAction?: React.ReactNode; // eslint-disable-next-line @typescript-eslint/no-explicit-any rowAction?: (params: GridRenderCellParams) => React.ReactNode; - dataGridProps?: DataGridProProps; }; -export function ProductsGrid({ filter, toolbarAction, rowAction, dataGridProps: forwardedDataGridProps }: Props): React.ReactElement { +export function ProductsGrid({ filter, toolbarAction, rowAction }: Props): React.ReactElement { const client = useApolloClient(); const intl = useIntl(); - const dataGridProps = { ...useDataGridRemote(), ...usePersistentColumnState("ProductsGrid"), ...forwardedDataGridProps }; + const dataGridProps = { ...useDataGridRemote(), ...usePersistentColumnState("ProductsGrid") }; const columns: GridColDef[] = [ { field: "inStock", headerName: intl.formatMessage({ id: "product.inStock", defaultMessage: "In stock" }), type: "boolean", width: 90 }, diff --git a/packages/admin/cms-admin/src/generator/future/generateGrid.ts b/packages/admin/cms-admin/src/generator/future/generateGrid.ts index d1c25f55c0..590019ddde 100644 --- a/packages/admin/cms-admin/src/generator/future/generateGrid.ts +++ b/packages/admin/cms-admin/src/generator/future/generateGrid.ts @@ -328,12 +328,16 @@ export function generateGrid( }); } - if (config.dataGridPropsProp) { + if (config.selectionProps) { imports.push({ name: "DataGridProProps", importPath: "@mui/x-data-grid-pro" }); props.push({ - name: "dataGridProps", - destructionAlias: "forwardedDataGridProps", - type: `DataGridProProps`, + name: "selectionProps", + type: `{ + checkboxSelection: boolean; + keepNonExistentRowsSelected: boolean; + selectionModel: DataGridProProps["selectionModel"]; + onSelectionModelChange: DataGridProProps["onSelectionModelChange"]; + }`, optional: true, }); } @@ -490,7 +494,7 @@ export function generateGrid( ${allowCopyPaste || allowDeleting ? "const client = useApolloClient();" : ""} const intl = useIntl(); const dataGridProps = { ...useDataGridRemote(), ...usePersistentColumnState("${gqlTypePlural}Grid")${ - config.dataGridPropsProp ? `, ...forwardedDataGridProps` : `` + config.selectionProps ? `, ...selectionProps` : `` } }; ${hasScope ? `const { scope } = useContentScope();` : ""} diff --git a/packages/admin/cms-admin/src/generator/future/generator.ts b/packages/admin/cms-admin/src/generator/future/generator.ts index bf5e4b9c8e..a8e2eae03f 100644 --- a/packages/admin/cms-admin/src/generator/future/generator.ts +++ b/packages/admin/cms-admin/src/generator/future/generator.ts @@ -81,7 +81,7 @@ export type GridConfig = { toolbar?: boolean; toolbarActionProp?: boolean; rowActionProp?: boolean; - dataGridPropsProp?: boolean; + selectionProps?: boolean; }; // eslint-disable-next-line @typescript-eslint/no-explicit-any