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

Supported nested fields #1621

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e2d5aed
First draft of configurable admin generator
nsams Jan 19, 2024
ded7f6f
Move admin-generator2 POC code into package
Ben-Ho Jan 25, 2024
90d0345
Supported nested fields
Ben-Ho Jan 25, 2024
1c0e328
Fix imports and export as future_*
nsams Jan 26, 2024
2a94cf5
Add future-generator command to comet-admin-generator program
nsams Jan 26, 2024
1b76f2d
Fix mistake in not-yet-implemented commented out code: correct type
nsams Jan 26, 2024
28184c7
Combine paths and leaves to enable field for object like block
Ben-Ho Jan 29, 2024
4f7c9bb
Add example using dot-notation to define form-field-name
Ben-Ho Jan 29, 2024
1f2abdf
Refactor generating gql-string
Ben-Ho Jan 29, 2024
a22af8b
Fix typescript error by providing type-hint
Ben-Ho Jan 30, 2024
722be45
Merge branch 'next' into admin-gen-configurable
nsams Jan 31, 2024
e7960e3
changeset
nsams Jan 31, 2024
fb0613f
Merge remote-tracking branch 'githubssh/admin-gen-configurable' into …
Ben-Ho Feb 4, 2024
8322077
Add more future generator features
nsams Feb 4, 2024
4e2fab6
use change-case package instead of own implementation
nsams Feb 5, 2024
d9dcc0c
Add support for date and dateTime
nsams Feb 5, 2024
b68e200
Add migration
nsams Feb 5, 2024
b0b035e
Run admin-generator to add new field
nsams Feb 5, 2024
f957997
Merge remote-tracking branch 'githubssh/admin-gen-configurable' into …
Ben-Ho Feb 5, 2024
485e727
Update .changeset/happy-fans-pump.md
nsams Feb 6, 2024
30c4cc2
Update packages/admin/cms-admin/src/generator/future/generateForm.ts
nsams Feb 6, 2024
3fc24ea
Rename gqlQueries to gqlDocuments as it also contains mutations
nsams Feb 6, 2024
a2c723f
update generated code
nsams Feb 6, 2024
f6d7906
Merge branch 'admin-gen-configurable' into benji-admin-generator
Ben-Ho Feb 9, 2024
4a7328f
Don't omit
Ben-Ho Feb 12, 2024
eb68586
Remove unused simple deep-key-of version
Ben-Ho Feb 12, 2024
c487a6f
Fix missing brackets
Ben-Ho Feb 12, 2024
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
5 changes: 5 additions & 0 deletions .changeset/happy-fans-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/cms-admin": minor
---

Add future Admin Generator that works with configuration files
2 changes: 1 addition & 1 deletion demo/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": true,
"scripts": {
"admin-generator": "rimraf 'src/*/generated' && comet-admin-generator generate crud-generator-config.ts",
"admin-generator": "rimraf 'src/*/generated' && comet-admin-generator generate crud-generator-config.ts && comet-admin-generator future-generate",
"build": "run-s intl:compile && run-p gql:types generate-block-types && cross-env BABEL_ENV=production webpack --config ./webpack.config.ts --env production --mode production --progress",
"generate-block-types": "comet generate-block-types --inputs",
"generate-block-types:watch": "chokidar -s \"**/block-meta.json\" -c \"npm run generate-block-types\"",
Expand Down
8 changes: 8 additions & 0 deletions demo/admin/src/common/MasterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Page } from "@src/pages/Page";
import { categoryToUrlParam, pageTreeCategories, urlParamToCategory } from "@src/pageTree/pageTreeCategories";
import { PredefinedPage } from "@src/predefinedPage/PredefinedPage";
import ProductCategoriesPage from "@src/products/categories/ProductCategoriesPage";
import { ProductsPage as FutureProductsPage } from "@src/products/future/ProductsPage";
import { ProductsPage } from "@src/products/generated/ProductsPage";
import ProductsHandmadePage from "@src/products/ProductsPage";
import ProductTagsPage from "@src/products/tags/ProductTagsPage";
Expand Down Expand Up @@ -164,6 +165,13 @@ export const masterMenuData: MasterMenuData = [
primary: <FormattedMessage id="menu.products" defaultMessage="Products" />,
icon: <Snips />,
submenu: [
{
primary: <FormattedMessage id="menu.productsFuture" defaultMessage="Products Future" />,
route: {
path: "/products-future",
component: FutureProductsPage,
},
},
{
primary: <FormattedMessage id="menu.products" defaultMessage="Products" />,
route: {
Expand Down
56 changes: 56 additions & 0 deletions demo/admin/src/products/future/ProductForm.cometGen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { future_FormConfig as FormConfig } from "@comet/cms-admin";
import { GQLProduct } from "@src/graphql.generated";

export const ProductForm: FormConfig<GQLProduct> = {
type: "form",
gqlType: "Product",
fragmentName: "ProductFormDetails", // configurable as it must be unique across project
fields: [
{
type: "text",
name: "title",
label: "Titel", // default is generated from name (camelCaseToHumanReadable)
required: true, // default is inferred from gql schema
},
{ type: "text", name: "packageDimensions.height", label: "Height" },
{ type: "text", name: "slug" },
{ type: "text", name: "description", label: "Description", multiline: true },
{ type: "staticSelect", name: "type", label: "Type" /*, values: from gql schema (TODO overridable)*/ },
//TODO { type: "asyncSelect", name: "category", label: "Category" /*, endpoint: from gql schema (overridable)*/ },
{ type: "number", name: "price" },
{ type: "boolean", name: "inStock" },
{ type: "date", name: "availableSince" },
{ type: "block", name: "image", label: "Image", block: { name: "PixelImageBlock", import: "@comet/cms-admin" } },
],
};

/*
TODO
export const tabsConfig: TabsConfig = {
type: "tabs",
tabs: [{ name: "form", content: formConfig }],
};

//alternative syntax for the above
export const tabsConfig2: TabsConfig = {
type: "tabs",
tabs: [
{
name: "form",
content: {
type: "form",
gqlType: "Product",
fields: [
{ type: "text", name: "title", label: "Titel" },
{ type: "text", name: "slug", label: "Slug" },
{ type: "text", name: "description", label: "Description", multiline: true },
{ type: "staticSelect", name: "type", label: "Type" / *, values: from gql schema (overridable)* / },
{ type: "asyncSelect", name: "type", label: "Type" / *, endpoint: from gql schema (overridable)* / },
{ type: "block", name: "image", label: "Image", block: PixelImageBlock },
],
} satisfies FormConfig<GQLProduct>,
},
],
};

*/
16 changes: 16 additions & 0 deletions demo/admin/src/products/future/ProductsGrid.cometGen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { future_GridConfig as GridConfig } from "@comet/cms-admin";
import { GQLProduct } from "@src/graphql.generated";

export const ProductsGrid: GridConfig<GQLProduct> = {
type: "grid",
gqlType: "Product",
fragmentName: "ProductsGridFuture", // configurable as it must be unique across project
columns: [
{ type: "text", name: "title", headerName: "Titel", width: 150 },
{ type: "text", name: "description", headerName: "Description", width: 150 },
{ type: "number", name: "price", headerName: "Price", width: 150 },
{ type: "staticSelect", name: "type" /*, values: from gql schema (TODO overridable)*/ },
{ type: "date", name: "availableSince" },
{ type: "dateTime", name: "createdAt" },
],
};
25 changes: 25 additions & 0 deletions demo/admin/src/products/future/ProductsPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Stack, StackPage, StackSwitch } from "@comet/admin";
import * as React from "react";
import { useIntl } from "react-intl";

import { ProductForm } from "./generated/ProductForm";
import { ProductsGrid } from "./generated/ProductsGrid";

export function ProductsPage(): React.ReactElement {
const intl = useIntl();
return (
<Stack topLevelTitle={intl.formatMessage({ id: "products.products", defaultMessage: "Products" })}>
<StackSwitch>
<StackPage name="grid">
<ProductsGrid />
</StackPage>
<StackPage name="edit" title={intl.formatMessage({ id: "products.editProduct", defaultMessage: "Edit Product" })}>
{(selectedId) => <ProductForm id={selectedId} />}
</StackPage>
<StackPage name="add" title={intl.formatMessage({ id: "products.addProduct", defaultMessage: "Add Product" })}>
<ProductForm />
</StackPage>
</StackSwitch>
</Stack>
);
}
49 changes: 49 additions & 0 deletions demo/admin/src/products/future/generated/ProductForm.gql.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// This file has been generated by comet admin-generator.
// You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
import { gql } from "@apollo/client";

export const productFormFragment = gql`
fragment ProductFormDetails on Product {
title
packageDimensions {
height
}
slug
description
type
price
inStock
availableSince
image
}
`;
export const productQuery = gql`
query Product($id: ID!) {
product(id: $id) {
id
updatedAt
...ProductFormDetails
}
}
${productFormFragment}
`;
export const createProductMutation = gql`
mutation CreateProduct($input: ProductInput!) {
createProduct(input: $input) {
id
updatedAt
...ProductFormDetails
}
}
${productFormFragment}
`;
export const updateProductMutation = gql`
mutation UpdateProduct($id: ID!, $input: ProductUpdateInput!, $lastUpdatedAt: DateTime) {
updateProduct(id: $id, input: $input, lastUpdatedAt: $lastUpdatedAt) {
id
updatedAt
...ProductFormDetails
}
}
${productFormFragment}
`;
Loading