@comet/admin-generator 8.0.0-beta.0 → 8.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/generate/generate-command.d.ts +25 -17
- package/lib/commands/generate/generate-command.js +12 -37
- package/lib/commands/generate/generateForm/generateComponentFormField.js +7 -3
- package/lib/commands/generate/generateForm/generateFields.js +2 -3
- package/lib/commands/generate/generateForm/generateForm.js +6 -6
- package/lib/commands/generate/generateForm/generateFormField.js +12 -16
- package/lib/commands/generate/generateForm/generateFormLayout.js +1 -2
- package/lib/commands/generate/generateForm/getForwardedGqlArgs.js +1 -2
- package/lib/commands/generate/generateGrid/findInputObjectType.js +1 -2
- package/lib/commands/generate/generateGrid/generateGqlFieldList.d.ts +2 -3
- package/lib/commands/generate/generateGrid/generateGqlFieldList.js +5 -6
- package/lib/commands/generate/generateGrid/generateGrid.js +42 -35
- package/lib/commands/generate/generateGrid/getForwardedGqlArgs.js +1 -2
- package/lib/commands/generate/generateGrid/getPropsForFilterProp.js +1 -2
- package/lib/commands/generate/utils/camelCaseToHumanReadable.js +1 -2
- package/lib/commands/generate/utils/convertConfigImport.d.ts +5 -0
- package/lib/commands/generate/utils/convertConfigImport.js +14 -0
- package/lib/commands/generate/utils/findMutationType.js +2 -3
- package/lib/commands/generate/utils/findQueryType.js +1 -2
- package/lib/commands/generate/utils/findRootBlocks.js +1 -2
- package/lib/commands/generate/utils/generateImportsCode.js +1 -2
- package/lib/commands/generate/utils/runtimeTypeGuards.d.ts +20 -0
- package/lib/commands/generate/utils/runtimeTypeGuards.js +22 -0
- package/lib/commands/generate/utils/tsMorphHelper.d.ts +4 -0
- package/lib/commands/generate/utils/tsMorphHelper.js +199 -0
- package/lib/commands/generate/utils/writeGenerated.js +38 -11
- package/package.json +19 -13
- package/lib/commands/generate/generateGrid/combinationColumn.d.ts +0 -43
- package/lib/commands/generate/generateGrid/combinationColumn.js +0 -151
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { type GridColDef } from "@comet/admin";
|
|
2
2
|
import { type IconName } from "@comet/admin-icons";
|
|
3
|
-
import { type FinalFormFileUploadProps } from "@comet/cms-admin";
|
|
3
|
+
import { type BlockInterface, type FinalFormFileUploadProps } from "@comet/cms-admin";
|
|
4
4
|
import { type IconProps } from "@mui/material";
|
|
5
|
-
import { type GridFilterItem, type GridSortDirection } from "@mui/x-data-grid";
|
|
5
|
+
import { type GridCellParams, type GridFilterItem, type GridFilterOperator, type GridRenderCellParams, type GridSortDirection, type GridValidRowModel } from "@mui/x-data-grid";
|
|
6
6
|
import { Command } from "commander";
|
|
7
|
-
import { type
|
|
7
|
+
import { type FieldValidator } from "final-form";
|
|
8
|
+
import { type ComponentType } from "react";
|
|
8
9
|
import { type UsableFields } from "./generateGrid/usableFields";
|
|
9
10
|
import { type ColumnVisibleOption } from "./utils/columnVisibility";
|
|
10
|
-
export type ImportReference = {
|
|
11
|
-
name: string;
|
|
12
|
-
import: string;
|
|
13
|
-
};
|
|
14
11
|
type IconObject = Pick<IconProps, "color" | "fontSize"> & {
|
|
15
12
|
name: IconName;
|
|
16
13
|
};
|
|
17
|
-
type Icon = IconName | IconObject |
|
|
14
|
+
type Icon = IconName | IconObject | ComponentType;
|
|
18
15
|
export type Adornment = string | {
|
|
19
16
|
icon: Icon;
|
|
20
17
|
};
|
|
@@ -36,7 +33,7 @@ type InputBaseFieldConfig = {
|
|
|
36
33
|
};
|
|
37
34
|
export type ComponentFormFieldConfig = {
|
|
38
35
|
type: "component";
|
|
39
|
-
component:
|
|
36
|
+
component: ComponentType;
|
|
40
37
|
};
|
|
41
38
|
export type FormFieldConfig<T> = (({
|
|
42
39
|
type: "text";
|
|
@@ -71,13 +68,13 @@ export type FormFieldConfig<T> = (({
|
|
|
71
68
|
};
|
|
72
69
|
} & Omit<InputBaseFieldConfig, "endAdornment">) | {
|
|
73
70
|
type: "block";
|
|
74
|
-
block:
|
|
71
|
+
block: BlockInterface;
|
|
75
72
|
} | SingleFileFormFieldConfig | MultiFileFormFieldConfig) & {
|
|
76
73
|
name: keyof T;
|
|
77
74
|
label?: string;
|
|
78
75
|
required?: boolean;
|
|
79
76
|
virtual?: boolean;
|
|
80
|
-
validate?:
|
|
77
|
+
validate?: FieldValidator<unknown>;
|
|
81
78
|
helperText?: string;
|
|
82
79
|
readOnly?: boolean;
|
|
83
80
|
};
|
|
@@ -115,7 +112,7 @@ type TabsConfig = {
|
|
|
115
112
|
content: GeneratorConfig;
|
|
116
113
|
}[];
|
|
117
114
|
};
|
|
118
|
-
|
|
115
|
+
type BaseColumnConfig = Pick<GridColDef, "headerName" | "width" | "minWidth" | "maxWidth" | "flex" | "pinned" | "disableExport"> & {
|
|
119
116
|
headerInfoTooltip?: string;
|
|
120
117
|
visible?: ColumnVisibleOption;
|
|
121
118
|
fieldName?: string;
|
|
@@ -125,16 +122,21 @@ export type StaticSelectLabelCellContent = {
|
|
|
125
122
|
secondaryText?: string;
|
|
126
123
|
icon?: Icon;
|
|
127
124
|
};
|
|
128
|
-
export type GridColumnConfig<T> = ({
|
|
125
|
+
export type GridColumnConfig<T extends GridValidRowModel> = ({
|
|
129
126
|
type: "text";
|
|
127
|
+
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
130
128
|
} | {
|
|
131
129
|
type: "number";
|
|
130
|
+
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
132
131
|
} | {
|
|
133
132
|
type: "boolean";
|
|
133
|
+
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
134
134
|
} | {
|
|
135
135
|
type: "date";
|
|
136
|
+
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
136
137
|
} | {
|
|
137
138
|
type: "dateTime";
|
|
139
|
+
renderCell?: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
138
140
|
} | {
|
|
139
141
|
type: "staticSelect";
|
|
140
142
|
values?: Array<{
|
|
@@ -143,15 +145,21 @@ export type GridColumnConfig<T> = ({
|
|
|
143
145
|
} | string>;
|
|
144
146
|
} | {
|
|
145
147
|
type: "block";
|
|
146
|
-
block:
|
|
148
|
+
block: BlockInterface;
|
|
147
149
|
}) & {
|
|
148
150
|
name: UsableFields<T>;
|
|
149
|
-
filterOperators?:
|
|
151
|
+
filterOperators?: GridFilterOperator[];
|
|
150
152
|
} & BaseColumnConfig;
|
|
151
153
|
export type ActionsGridColumnConfig = {
|
|
152
154
|
type: "actions";
|
|
153
|
-
component?:
|
|
155
|
+
component?: ComponentType<GridCellParams>;
|
|
154
156
|
} & BaseColumnConfig;
|
|
157
|
+
export type VirtualGridColumnConfig<T extends GridValidRowModel> = {
|
|
158
|
+
type: "virtual";
|
|
159
|
+
name: string;
|
|
160
|
+
queryFields?: UsableFields<T>[];
|
|
161
|
+
renderCell: (params: GridRenderCellParams<T, any, any>) => JSX.Element;
|
|
162
|
+
} & Pick<GridColDef, "sortBy"> & BaseColumnConfig;
|
|
155
163
|
type InitialFilterConfig = {
|
|
156
164
|
items: GridFilterItem[];
|
|
157
165
|
linkOperator?: "and" | "or";
|
|
@@ -164,7 +172,7 @@ export type GridConfig<T extends {
|
|
|
164
172
|
fragmentName?: string;
|
|
165
173
|
query?: string;
|
|
166
174
|
queryParamsPrefix?: string;
|
|
167
|
-
columns: Array<GridColumnConfig<T> |
|
|
175
|
+
columns: Array<GridColumnConfig<T> | ActionsGridColumnConfig | VirtualGridColumnConfig<T>>;
|
|
168
176
|
excelExport?: boolean;
|
|
169
177
|
add?: boolean;
|
|
170
178
|
edit?: boolean;
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -32,7 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
9
|
});
|
|
33
10
|
};
|
|
34
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.generateCommand =
|
|
12
|
+
exports.generateCommand = void 0;
|
|
13
|
+
exports.isFormFieldConfig = isFormFieldConfig;
|
|
14
|
+
exports.isFormLayoutConfig = isFormLayoutConfig;
|
|
36
15
|
const graphql_file_loader_1 = require("@graphql-tools/graphql-file-loader");
|
|
37
16
|
const load_1 = require("@graphql-tools/load");
|
|
38
17
|
const commander_1 = require("commander");
|
|
@@ -42,23 +21,19 @@ const graphql_1 = require("graphql");
|
|
|
42
21
|
const path_1 = require("path");
|
|
43
22
|
const generateForm_1 = require("./generateForm/generateForm");
|
|
44
23
|
const generateGrid_1 = require("./generateGrid/generateGrid");
|
|
24
|
+
const tsMorphHelper_1 = require("./utils/tsMorphHelper");
|
|
45
25
|
const writeGenerated_1 = require("./utils/writeGenerated");
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
26
|
function isFormFieldConfig(arg) {
|
|
48
27
|
return !isFormLayoutConfig(arg);
|
|
49
28
|
}
|
|
50
|
-
exports.isFormFieldConfig = isFormFieldConfig;
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
29
|
function isFormLayoutConfig(arg) {
|
|
53
30
|
return arg.type !== undefined && ["fieldSet", "optionalNestedFields"].includes(arg.type);
|
|
54
31
|
}
|
|
55
|
-
exports.isFormLayoutConfig = isFormLayoutConfig;
|
|
56
32
|
/**
|
|
57
33
|
* @experimental
|
|
58
34
|
*/
|
|
59
|
-
function runGenerate(
|
|
60
|
-
return __awaiter(this,
|
|
61
|
-
var _a;
|
|
35
|
+
function runGenerate() {
|
|
36
|
+
return __awaiter(this, arguments, void 0, function* (filePattern = "src/**/*.cometGen.{ts,tsx}") {
|
|
62
37
|
const schema = yield (0, load_1.loadSchema)("./schema.gql", {
|
|
63
38
|
loaders: [new graphql_file_loader_1.GraphQLFileLoader()],
|
|
64
39
|
});
|
|
@@ -68,10 +43,10 @@ function runGenerate(filePattern = "src/**/*.cometGen.ts") {
|
|
|
68
43
|
let outputCode = "";
|
|
69
44
|
let gqlDocumentsOutputCode = "";
|
|
70
45
|
const targetDirectory = `${(0, path_1.dirname)(file)}/generated`;
|
|
71
|
-
const baseOutputFilename = (0, path_1.basename)(file).replace(/\.cometGen\.
|
|
72
|
-
const configs =
|
|
73
|
-
//const configs = await import(`${process.cwd()}/${file}`);
|
|
74
|
-
const codeOuputFilename = `${targetDirectory}/${(0, path_1.basename)(file.replace(/\.cometGen\.
|
|
46
|
+
const baseOutputFilename = (0, path_1.basename)(file).replace(/\.cometGen\.tsx?$/, "");
|
|
47
|
+
const configs = (0, tsMorphHelper_1.configsFromSourceFile)((0, tsMorphHelper_1.morphTsSource)(file));
|
|
48
|
+
//const configs = await import(`${process.cwd()}/${file.replace(/\.ts$/, "")}`);
|
|
49
|
+
const codeOuputFilename = `${targetDirectory}/${(0, path_1.basename)(file.replace(/\.cometGen\.tsx?$/, ""))}.tsx`;
|
|
75
50
|
yield fs_1.promises.rm(codeOuputFilename, { force: true });
|
|
76
51
|
console.log(`generating ${file}`);
|
|
77
52
|
for (const exportName in configs) {
|
|
@@ -94,7 +69,7 @@ function runGenerate(filePattern = "src/**/*.cometGen.ts") {
|
|
|
94
69
|
}
|
|
95
70
|
yield (0, writeGenerated_1.writeGenerated)(codeOuputFilename, outputCode);
|
|
96
71
|
if (gqlDocumentsOutputCode != "") {
|
|
97
|
-
const gqlDocumentsOuputFilename = `${targetDirectory}/${(0, path_1.basename)(file.replace(/\.cometGen\.
|
|
72
|
+
const gqlDocumentsOuputFilename = `${targetDirectory}/${(0, path_1.basename)(file.replace(/\.cometGen\.tsx?$/, ""))}.gql.tsx`;
|
|
98
73
|
yield fs_1.promises.rm(gqlDocumentsOuputFilename, { force: true });
|
|
99
74
|
gqlDocumentsOutputCode = `import { gql } from "@apollo/client";
|
|
100
75
|
import { finalFormFileUploadFragment, finalFormFileUploadDownloadableFragment } from "@comet/cms-admin";
|
|
@@ -108,7 +83,7 @@ function runGenerate(filePattern = "src/**/*.cometGen.ts") {
|
|
|
108
83
|
}
|
|
109
84
|
exports.generateCommand = new commander_1.Command("generate")
|
|
110
85
|
.option("-f, --file <file>", "path to config file or glob pattern to generate specific files")
|
|
111
|
-
.action((
|
|
86
|
+
.action((_a) => __awaiter(void 0, [_a], void 0, function* ({ file: filePattern }) {
|
|
112
87
|
console.log("️️️⚠️️️⚠️️️⚠️️️ Admin Generator is still experimental and in beta phase. ⚠️️️⚠️️️⚠️️️\n\n");
|
|
113
88
|
yield runGenerate(filePattern);
|
|
114
89
|
}));
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateComponentFormField =
|
|
3
|
+
exports.generateComponentFormField = generateComponentFormField;
|
|
4
|
+
const convertConfigImport_1 = require("../utils/convertConfigImport");
|
|
5
|
+
const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
|
|
4
6
|
function generateComponentFormField({ config }) {
|
|
5
|
-
|
|
7
|
+
if (!(0, runtimeTypeGuards_1.isGeneratorConfigImport)(config.component)) {
|
|
8
|
+
throw new Error("config.component must be a GeneratorConfigImport");
|
|
9
|
+
}
|
|
10
|
+
const imports = [(0, convertConfigImport_1.convertConfigImport)(config.component)];
|
|
6
11
|
const code = `<${config.component.name} />`;
|
|
7
12
|
return {
|
|
8
13
|
imports,
|
|
@@ -15,4 +20,3 @@ function generateComponentFormField({ config }) {
|
|
|
15
20
|
gqlDocuments: {},
|
|
16
21
|
};
|
|
17
22
|
}
|
|
18
|
-
exports.generateComponentFormField = generateComponentFormField;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.findFieldByName = findFieldByName;
|
|
4
|
+
exports.generateFields = generateFields;
|
|
4
5
|
const generate_command_1 = require("../generate-command");
|
|
5
6
|
const generateComponentFormField_1 = require("./generateComponentFormField");
|
|
6
7
|
const generateFormField_1 = require("./generateFormField");
|
|
@@ -18,7 +19,6 @@ function findFieldByName(name, fields) {
|
|
|
18
19
|
: undefined;
|
|
19
20
|
}, undefined);
|
|
20
21
|
}
|
|
21
|
-
exports.findFieldByName = findFieldByName;
|
|
22
22
|
function generateFields({ gqlIntrospection, baseOutputFilename, fields, formFragmentName, formConfig, gqlType, namePrefix, }) {
|
|
23
23
|
const gqlDocuments = {};
|
|
24
24
|
let hooksCode = "";
|
|
@@ -85,4 +85,3 @@ function generateFields({ gqlIntrospection, baseOutputFilename, fields, formFrag
|
|
|
85
85
|
finalFormConfig,
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
exports.generateFields = generateFields;
|
|
@@ -11,10 +11,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.generateForm =
|
|
14
|
+
exports.generateForm = generateForm;
|
|
15
15
|
const generate_command_1 = require("../generate-command");
|
|
16
|
+
const convertConfigImport_1 = require("../utils/convertConfigImport");
|
|
16
17
|
const findMutationType_1 = require("../utils/findMutationType");
|
|
17
18
|
const generateImportsCode_1 = require("../utils/generateImportsCode");
|
|
19
|
+
const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
|
|
18
20
|
const generateFields_1 = require("./generateFields");
|
|
19
21
|
const getForwardedGqlArgs_1 = require("./getForwardedGqlArgs");
|
|
20
22
|
function generateFormPropsCode(props) {
|
|
@@ -96,10 +98,9 @@ config) {
|
|
|
96
98
|
return field;
|
|
97
99
|
});
|
|
98
100
|
rootBlockFields.forEach((field) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
101
|
+
if ((0, runtimeTypeGuards_1.isGeneratorConfigImport)(field.block)) {
|
|
102
|
+
imports.push((0, convertConfigImport_1.convertConfigImport)(field.block));
|
|
103
|
+
}
|
|
103
104
|
});
|
|
104
105
|
const readOnlyFields = formFields.filter((field) => field.readOnly);
|
|
105
106
|
const fileFields = formFields.filter((field) => field.type == "fileUpload");
|
|
@@ -440,7 +441,6 @@ config) {
|
|
|
440
441
|
gqlDocuments,
|
|
441
442
|
};
|
|
442
443
|
}
|
|
443
|
-
exports.generateForm = generateForm;
|
|
444
444
|
/**
|
|
445
445
|
* Checks if the provided form config is valid.
|
|
446
446
|
*
|
|
@@ -11,11 +11,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.generateFormField =
|
|
14
|
+
exports.generateFormField = generateFormField;
|
|
15
15
|
const generate_command_1 = require("../generate-command");
|
|
16
16
|
const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
|
|
17
|
+
const convertConfigImport_1 = require("../utils/convertConfigImport");
|
|
17
18
|
const findQueryType_1 = require("../utils/findQueryType");
|
|
18
19
|
const isFieldOptional_1 = require("../utils/isFieldOptional");
|
|
20
|
+
const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
|
|
19
21
|
const generateFields_1 = require("./generateFields");
|
|
20
22
|
const getAdornmentData = ({ adornmentData }) => {
|
|
21
23
|
let adornmentString = "";
|
|
@@ -31,12 +33,9 @@ const getAdornmentData = ({ adornmentData }) => {
|
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
else if (typeof adornmentData.icon === "object") {
|
|
34
|
-
if (
|
|
36
|
+
if ((0, runtimeTypeGuards_1.isGeneratorConfigImport)(adornmentData.icon)) {
|
|
35
37
|
adornmentString = `<${adornmentData.icon.name} />`;
|
|
36
|
-
adornmentImport =
|
|
37
|
-
name: `${adornmentData.icon.name}`,
|
|
38
|
-
importPath: `${adornmentData.icon.import}`,
|
|
39
|
-
};
|
|
38
|
+
adornmentImport = (0, convertConfigImport_1.convertConfigImport)(adornmentData.icon);
|
|
40
39
|
}
|
|
41
40
|
else {
|
|
42
41
|
const _a = adornmentData.icon, { name } = _a, iconProps = __rest(_a, ["name"]);
|
|
@@ -109,16 +108,14 @@ function generateFormField({ gqlIntrospection, baseOutputFilename, config, formC
|
|
|
109
108
|
let finalFormConfig;
|
|
110
109
|
let validateCode = "";
|
|
111
110
|
if (config.validate) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
if ((0, runtimeTypeGuards_1.isGeneratorConfigImport)(config.validate)) {
|
|
112
|
+
imports.push((0, convertConfigImport_1.convertConfigImport)(config.validate));
|
|
113
|
+
validateCode = `validate={${config.validate.name}}`;
|
|
114
|
+
}
|
|
115
|
+
else if ((0, runtimeTypeGuards_1.isGeneratorConfigCode)(config.validate)) {
|
|
116
|
+
validateCode = `validate={${config.validate.code}}`;
|
|
117
|
+
imports.push(...config.validate.imports.map((imprt) => (0, convertConfigImport_1.convertConfigImport)(imprt)));
|
|
116
118
|
}
|
|
117
|
-
imports.push({
|
|
118
|
-
name: config.validate.name,
|
|
119
|
-
importPath,
|
|
120
|
-
});
|
|
121
|
-
validateCode = `validate={${config.validate.name}}`;
|
|
122
119
|
}
|
|
123
120
|
const fieldLabel = `<FormattedMessage id="${formattedMessageRootId}.${name}" defaultMessage="${label}" />`;
|
|
124
121
|
let startAdornment = { adornmentString: "" };
|
|
@@ -522,4 +519,3 @@ function generateFormField({ gqlIntrospection, baseOutputFilename, config, formC
|
|
|
522
519
|
finalFormConfig,
|
|
523
520
|
};
|
|
524
521
|
}
|
|
525
|
-
exports.generateFormField = generateFormField;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateFormLayout =
|
|
3
|
+
exports.generateFormLayout = generateFormLayout;
|
|
4
4
|
const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
|
|
5
5
|
const generateFields_1 = require("./generateFields");
|
|
6
6
|
function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, formFragmentName, formConfig, gqlType, namePrefix, }) {
|
|
@@ -161,4 +161,3 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
|
|
|
161
161
|
finalFormConfig,
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
|
-
exports.generateFormLayout = generateFormLayout;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getForwardedGqlArgs =
|
|
3
|
+
exports.getForwardedGqlArgs = getForwardedGqlArgs;
|
|
4
4
|
function getForwardedGqlArgs({ fields, gqlOperation, gqlIntrospection, }) {
|
|
5
5
|
const imports = [];
|
|
6
6
|
const props = [];
|
|
@@ -33,7 +33,6 @@ function getForwardedGqlArgs({ fields, gqlOperation, gqlIntrospection, }) {
|
|
|
33
33
|
gqlArgs,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
exports.getForwardedGqlArgs = getForwardedGqlArgs;
|
|
37
36
|
function getArgsIncludingInputArgSubfields(gqlOperation, gqlIntrospection) {
|
|
38
37
|
const nativeScalars = ["ID", "String", "Boolean", "Int", "Float", "DateTime", "JSONObject"];
|
|
39
38
|
// reducer is not created inline to reuse it to look into "input" arg
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findInputObjectType =
|
|
3
|
+
exports.findInputObjectType = findInputObjectType;
|
|
4
4
|
function findInputObjectType(input, schema) {
|
|
5
5
|
let type = input.type;
|
|
6
6
|
if (type.kind == "NON_NULL") {
|
|
@@ -13,4 +13,3 @@ function findInputObjectType(input, schema) {
|
|
|
13
13
|
const filterType = schema.__schema.types.find((type) => type.kind === "INPUT_OBJECT" && type.name === typeName);
|
|
14
14
|
return filterType;
|
|
15
15
|
}
|
|
16
|
-
exports.findInputObjectType = findInputObjectType;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type ActionsGridColumnConfig, type GridColumnConfig } from "../generate-command";
|
|
2
|
-
import { type GridCombinationColumnConfig } from "./combinationColumn";
|
|
1
|
+
import { type ActionsGridColumnConfig, type GridColumnConfig, type VirtualGridColumnConfig } from "../generate-command";
|
|
3
2
|
export declare function generateGqlFieldList({ columns, }: {
|
|
4
|
-
columns: Array<GridColumnConfig<any> |
|
|
3
|
+
columns: Array<GridColumnConfig<any> | ActionsGridColumnConfig | VirtualGridColumnConfig<any>>;
|
|
5
4
|
}): string;
|
|
@@ -3,9 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateGqlFieldList =
|
|
6
|
+
exports.generateGqlFieldList = generateGqlFieldList;
|
|
7
7
|
const object_path_1 = __importDefault(require("object-path"));
|
|
8
|
-
const combinationColumn_1 = require("./combinationColumn");
|
|
9
8
|
const recursiveStringify = (obj) => {
|
|
10
9
|
let ret = "";
|
|
11
10
|
let prefixField = "";
|
|
@@ -26,10 +25,11 @@ const recursiveStringify = (obj) => {
|
|
|
26
25
|
};
|
|
27
26
|
function generateGqlFieldList({ columns, }) {
|
|
28
27
|
const fieldsObject = columns.reduce((acc, field) => {
|
|
28
|
+
var _a;
|
|
29
29
|
if (field.type !== "actions") {
|
|
30
|
-
if (field.type === "
|
|
31
|
-
(
|
|
32
|
-
object_path_1.default.set(acc,
|
|
30
|
+
if (field.type === "virtual") {
|
|
31
|
+
(_a = field.queryFields) === null || _a === void 0 ? void 0 : _a.map((queryField) => {
|
|
32
|
+
object_path_1.default.set(acc, queryField, true);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
@@ -40,4 +40,3 @@ function generateGqlFieldList({ columns, }) {
|
|
|
40
40
|
}, {});
|
|
41
41
|
return recursiveStringify(fieldsObject);
|
|
42
42
|
}
|
|
43
|
-
exports.generateGqlFieldList = generateGqlFieldList;
|
|
@@ -11,14 +11,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.generateGrid =
|
|
14
|
+
exports.generateGrid = generateGrid;
|
|
15
15
|
const pluralize_1 = require("pluralize");
|
|
16
16
|
const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
|
|
17
|
+
const convertConfigImport_1 = require("../utils/convertConfigImport");
|
|
17
18
|
const findMutationType_1 = require("../utils/findMutationType");
|
|
18
19
|
const findQueryType_1 = require("../utils/findQueryType");
|
|
19
20
|
const findRootBlocks_1 = require("../utils/findRootBlocks");
|
|
20
21
|
const generateImportsCode_1 = require("../utils/generateImportsCode");
|
|
21
|
-
const
|
|
22
|
+
const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
|
|
22
23
|
const findInputObjectType_1 = require("./findInputObjectType");
|
|
23
24
|
const generateGqlFieldList_1 = require("./generateGqlFieldList");
|
|
24
25
|
const generateGridToolbar_1 = require("./generateGridToolbar");
|
|
@@ -113,9 +114,7 @@ const getValueOptionsLabelData = (messageId, label) => {
|
|
|
113
114
|
gridCellContent,
|
|
114
115
|
};
|
|
115
116
|
};
|
|
116
|
-
function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntrospection, },
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
-
config) {
|
|
117
|
+
function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntrospection, }, config) {
|
|
119
118
|
var _a, _b;
|
|
120
119
|
const gqlType = config.gqlType;
|
|
121
120
|
const gqlTypePlural = (0, pluralize_1.plural)(gqlType);
|
|
@@ -148,15 +147,17 @@ config) {
|
|
|
148
147
|
rootBlockColumns.forEach((field) => {
|
|
149
148
|
if (rootBlocks[String(field.name)]) {
|
|
150
149
|
// update rootBlocks if they are also used in columns
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
const block = field.block;
|
|
151
|
+
if ((0, runtimeTypeGuards_1.isGeneratorConfigImport)(block)) {
|
|
152
|
+
rootBlocks[String(field.name)].import = block.import;
|
|
153
|
+
rootBlocks[String(field.name)].name = block.name;
|
|
154
|
+
}
|
|
153
155
|
}
|
|
154
156
|
});
|
|
155
157
|
Object.values(rootBlocks).forEach((block) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
});
|
|
158
|
+
if ((0, runtimeTypeGuards_1.isGeneratorConfigImport)(block)) {
|
|
159
|
+
imports.push((0, convertConfigImport_1.convertConfigImport)(block));
|
|
160
|
+
}
|
|
160
161
|
});
|
|
161
162
|
const gridQueryType = (0, findQueryType_1.findQueryTypeOrThrow)(gridQuery, gqlIntrospection);
|
|
162
163
|
const createMutationType = (0, findMutationType_1.findMutationType)(`create${gqlType}`, gqlIntrospection);
|
|
@@ -247,6 +248,12 @@ config) {
|
|
|
247
248
|
});
|
|
248
249
|
const actionsColumnConfig = config.columns.find((column) => column.type === "actions");
|
|
249
250
|
const _c = actionsColumnConfig !== null && actionsColumnConfig !== void 0 ? actionsColumnConfig : {}, { component: actionsColumnComponent, type: actionsColumnType, headerName: actionsColumnHeaderName, pinned: actionsColumnPinned = "right", width: actionsColumnWidth = defaultActionsColumnWidth, visible: actionsColumnVisible = undefined } = _c, restActionsColumnConfig = __rest(_c, ["component", "type", "headerName", "pinned", "width", "visible"]);
|
|
251
|
+
if (actionsColumnComponent) {
|
|
252
|
+
if (!(0, runtimeTypeGuards_1.isGeneratorConfigImport)(actionsColumnComponent)) {
|
|
253
|
+
throw new Error("Unsupported actionsColumnComponent, only imports are supported");
|
|
254
|
+
}
|
|
255
|
+
imports.push((0, convertConfigImport_1.convertConfigImport)(actionsColumnComponent));
|
|
256
|
+
}
|
|
250
257
|
const gridNeedsTheme = config.columns.some((column) => typeof column.visible === "string");
|
|
251
258
|
const gridColumnFields = config.columns.filter((column) => column.type !== "actions").map((column) => {
|
|
252
259
|
var _a;
|
|
@@ -257,17 +264,14 @@ config) {
|
|
|
257
264
|
let valueFormatter = undefined;
|
|
258
265
|
let gridType;
|
|
259
266
|
let filterOperators;
|
|
260
|
-
if (column.filterOperators) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
267
|
+
if (column.type != "virtual" && column.filterOperators) {
|
|
268
|
+
if ((0, runtimeTypeGuards_1.isGeneratorConfigImport)(column.filterOperators)) {
|
|
269
|
+
imports.push((0, convertConfigImport_1.convertConfigImport)(column.filterOperators));
|
|
270
|
+
filterOperators = column.filterOperators.name;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
throw new Error("Unsupported filterOperators, only imports are supported for now");
|
|
265
274
|
}
|
|
266
|
-
imports.push({
|
|
267
|
-
name: column.filterOperators.name,
|
|
268
|
-
importPath,
|
|
269
|
-
});
|
|
270
|
-
filterOperators = column.filterOperators.name;
|
|
271
275
|
}
|
|
272
276
|
if (type == "dateTime") {
|
|
273
277
|
gridColumnType = "...dataGridDateTimeColumn,";
|
|
@@ -301,11 +305,8 @@ config) {
|
|
|
301
305
|
iconsToImport.push(value.label.icon);
|
|
302
306
|
}
|
|
303
307
|
else if (typeof ((_a = value.label.icon) === null || _a === void 0 ? void 0 : _a.name) === "string") {
|
|
304
|
-
if (
|
|
305
|
-
imports.push(
|
|
306
|
-
name: value.label.icon.name,
|
|
307
|
-
importPath: value.label.icon.import,
|
|
308
|
-
});
|
|
308
|
+
if ((0, runtimeTypeGuards_1.isGeneratorConfigImport)(value.label.icon)) {
|
|
309
|
+
imports.push((0, convertConfigImport_1.convertConfigImport)(value.label.icon));
|
|
309
310
|
}
|
|
310
311
|
else {
|
|
311
312
|
iconsToImport.push(value.label.icon.name);
|
|
@@ -364,8 +365,20 @@ config) {
|
|
|
364
365
|
disableExport: column.disableExport,
|
|
365
366
|
};
|
|
366
367
|
}
|
|
367
|
-
|
|
368
|
-
|
|
368
|
+
if ((column.type == "text" ||
|
|
369
|
+
column.type == "number" ||
|
|
370
|
+
column.type == "boolean" ||
|
|
371
|
+
column.type == "date" ||
|
|
372
|
+
column.type == "dateTime" ||
|
|
373
|
+
column.type == "virtual") &&
|
|
374
|
+
column.renderCell) {
|
|
375
|
+
if ((0, runtimeTypeGuards_1.isGeneratorConfigCode)(column.renderCell)) {
|
|
376
|
+
renderCell = column.renderCell.code;
|
|
377
|
+
imports.push(...column.renderCell.imports.map((imprt) => (0, convertConfigImport_1.convertConfigImport)(imprt)));
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
throw new Error(`Unsupported renderCell for column '${name}', only arrow functions are supported`);
|
|
381
|
+
}
|
|
369
382
|
}
|
|
370
383
|
//TODO support n:1 relation with singleSelect
|
|
371
384
|
return {
|
|
@@ -501,11 +514,6 @@ config) {
|
|
|
501
514
|
import { FormattedMessage, FormattedNumber, useIntl } from "react-intl";
|
|
502
515
|
${(0, generateImportsCode_1.generateImportsCode)(imports)}
|
|
503
516
|
|
|
504
|
-
${Object.entries(rootBlocks)
|
|
505
|
-
.map(([rootBlockKey, rootBlock]) => `import { ${rootBlock.name} } from "${rootBlock.import}";`)
|
|
506
|
-
.join("\n")}
|
|
507
|
-
${actionsColumnComponent ? `import { ${actionsColumnComponent.name} } from "${actionsColumnComponent.import}";` : ""}
|
|
508
|
-
|
|
509
517
|
const ${instanceGqlTypePlural}Fragment = gql\`
|
|
510
518
|
fragment ${fragmentName} on ${gqlType} {
|
|
511
519
|
id
|
|
@@ -615,7 +623,7 @@ config) {
|
|
|
615
623
|
}
|
|
616
624
|
}
|
|
617
625
|
const columnDefinition = {
|
|
618
|
-
field: column.fieldName ? `"${column.fieldName}"` : `"${column.name.replace(/\./g, "_")}"`,
|
|
626
|
+
field: column.fieldName ? `"${column.fieldName}"` : `"${column.name.replace(/\./g, "_")}"`, // field-name is used for api-filter, and api nests with underscore
|
|
619
627
|
renderHeader: column.headerInfoTooltip
|
|
620
628
|
? `() => (
|
|
621
629
|
<>
|
|
@@ -783,7 +791,6 @@ config) {
|
|
|
783
791
|
gqlDocuments,
|
|
784
792
|
};
|
|
785
793
|
}
|
|
786
|
-
exports.generateGrid = generateGrid;
|
|
787
794
|
const getDefaultActionsColumnWidth = (showCrudContextMenu, showEdit) => {
|
|
788
795
|
let numberOfActions = 0;
|
|
789
796
|
if (showCrudContextMenu) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getForwardedGqlArgs =
|
|
3
|
+
exports.getForwardedGqlArgs = getForwardedGqlArgs;
|
|
4
4
|
function getForwardedGqlArgs(gqlFields) {
|
|
5
5
|
const supportedGqlArgs = ["offset", "limit", "sort", "search", "filter", "scope", "input"]; // this arguments need to be handled differently or are already handled somewhere else
|
|
6
6
|
const imports = [];
|
|
@@ -31,7 +31,6 @@ function getForwardedGqlArgs(gqlFields) {
|
|
|
31
31
|
gqlArgs,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
exports.getForwardedGqlArgs = getForwardedGqlArgs;
|
|
35
34
|
function getArgs(gqlFields, skipGqlArgs) {
|
|
36
35
|
return gqlFields.reduce((acc, gqlField) => {
|
|
37
36
|
gqlField.args.forEach((gqlArg) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPropsForFilterProp =
|
|
3
|
+
exports.getPropsForFilterProp = getPropsForFilterProp;
|
|
4
4
|
function getPropsForFilterProp({ config, filterType, }) {
|
|
5
5
|
if (!config.filterProp)
|
|
6
6
|
return { hasFilterProp: false, imports: [], props: [] };
|
|
@@ -11,4 +11,3 @@ function getPropsForFilterProp({ config, filterType, }) {
|
|
|
11
11
|
props: [{ name: "filter", optional: true, type: filterTypeName }],
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
exports.getPropsForFilterProp = getPropsForFilterProp;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.camelCaseToHumanReadable =
|
|
3
|
+
exports.camelCaseToHumanReadable = camelCaseToHumanReadable;
|
|
4
4
|
const change_case_1 = require("change-case");
|
|
5
5
|
function camelCaseToHumanReadable(s) {
|
|
6
6
|
return (0, change_case_1.capitalCase)(s);
|
|
7
7
|
}
|
|
8
|
-
exports.camelCaseToHumanReadable = camelCaseToHumanReadable;
|