Skip to content

Commit

Permalink
Reduce forwarded props to selection-props
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Ho committed Aug 22, 2024
1 parent 3173e7d commit 2612c3f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 0 additions & 1 deletion demo/admin/src/products/future/ProductsGrid.cometGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const ProductsGrid: GridConfig<GQLProduct> = {
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 },
Expand Down
18 changes: 18 additions & 0 deletions demo/admin/src/products/future/SelectProductsGrid.cometGen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { future_GridConfig as GridConfig } from "@comet/cms-admin";
import { GQLProduct } from "@src/graphql.generated";

export const SelectProductsGrid: GridConfig<GQLProduct> = {
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 },
],
};
7 changes: 3 additions & 4 deletions demo/admin/src/products/future/generated/ProductsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -91,13 +91,12 @@ type Props = {
toolbarAction?: React.ReactNode;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
rowAction?: (params: GridRenderCellParams<any, GQLProductsGridFutureFragment, any>) => 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<GQLProductsGridFutureFragment>[] = [
{ field: "inStock", headerName: intl.formatMessage({ id: "product.inStock", defaultMessage: "In stock" }), type: "boolean", width: 90 },
Expand Down
14 changes: 9 additions & 5 deletions packages/admin/cms-admin/src/generator/future/generateGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down Expand Up @@ -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();` : ""}
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/cms-admin/src/generator/future/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export type GridConfig<T extends { __typename?: string }> = {
toolbar?: boolean;
toolbarActionProp?: boolean;
rowActionProp?: boolean;
dataGridPropsProp?: boolean;
selectionProps?: boolean;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 2612c3f

Please sign in to comment.