Skip to content

Commit

Permalink
Refactor settings for actions column
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesricky committed May 24, 2024
1 parent 9319d00 commit 9db27d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
6 changes: 2 additions & 4 deletions demo/admin/src/products/future/ProductsGrid.cometGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export const ProductsGrid: GridConfig<GQLProduct> = {
{ type: "date", name: "availableSince", width: 140 },
{ type: "dateTime", name: "createdAt", width: 170 },
],
actions: {
columnWidth: 116,
component: { name: "ProductsGridPreviewAction", import: "../../ProductsGridPreviewAction" },
},
actionsWidth: 116,
actionsComponent: { name: "ProductsGridPreviewAction", import: "../../ProductsGridPreviewAction" },
};
8 changes: 4 additions & 4 deletions packages/admin/cms-admin/src/generator/future/generateGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export function generateGrid(
props.push(...forwardedGqlArgsProps);

const actionsColumnProps = ['field: "actions"', 'headerName: ""', "sortable: false", "filterable: false", 'type: "actions"', 'align: "right"'];
if (typeof config.actions?.columnWidth !== "undefined") {
actionsColumnProps.push(`width: ${config.actions.columnWidth}`);
if (typeof config.actionsWidth !== "undefined") {
actionsColumnProps.push(`width: ${config.actionsWidth}`);
}

const filterArg = gridQueryType.args.find((arg) => arg.name === "filter");
Expand Down Expand Up @@ -340,7 +340,7 @@ export function generateGrid(
${Object.entries(rootBlocks)
.map(([rootBlockKey, rootBlock]) => `import { ${rootBlock.name} } from "${rootBlock.import}";`)
.join("\n")}
${config.actions?.component ? `import { ${config.actions.component.name} } from "${config.actions.component.import}";` : ""}
${config.actionsComponent ? `import { ${config.actionsComponent.name} } from "${config.actionsComponent.import}";` : ""}
const ${instanceGqlTypePlural}Fragment = gql\`
fragment ${fragmentName} on ${gqlType} {
Expand Down Expand Up @@ -497,7 +497,7 @@ export function generateGrid(
renderCell: (params) => {
return (
<>
${config.actions?.component?.name ? `<${config.actions.component.name} params={params} />` : ""}${
${config.actionsComponent?.name ? `<${config.actionsComponent.name} params={params} />` : ""}${
allowEditing
? `
<IconButton component={StackLink} pageName="edit" payload={params.row.id}>
Expand Down
6 changes: 2 additions & 4 deletions packages/admin/cms-admin/src/generator/future/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ export type GridConfig<T extends { __typename?: string }> = {
readOnly?: boolean;
filterProp?: boolean;
toolbar?: boolean;
actions?: {
columnWidth?: number;
component?: ImportReference;
};
actionsComponent?: ImportReference;
actionsWidth?: number;
};

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

0 comments on commit 9db27d1

Please sign in to comment.