@comet/admin-generator 8.17.1 → 9.0.0-beta.0

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.
Files changed (87) hide show
  1. package/bin/admin-generator.mjs +3 -0
  2. package/dist/adminGenerator.d.mts +1 -0
  3. package/dist/adminGenerator.mjs +4441 -0
  4. package/dist/index.d.mts +344 -0
  5. package/dist/index.mjs +4440 -0
  6. package/package.json +31 -21
  7. package/bin/admin-generator.js +0 -8
  8. package/lib/adminGenerator.d.ts +0 -1
  9. package/lib/adminGenerator.js +0 -8
  10. package/lib/commands/generate/config/parseConfig.d.ts +0 -1
  11. package/lib/commands/generate/config/parseConfig.js +0 -72
  12. package/lib/commands/generate/config/transformConfig.d.ts +0 -7
  13. package/lib/commands/generate/config/transformConfig.js +0 -264
  14. package/lib/commands/generate/generate-command.d.ts +0 -340
  15. package/lib/commands/generate/generate-command.js +0 -112
  16. package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.d.ts +0 -26
  17. package/lib/commands/generate/generateForm/asyncSelect/generateAsyncSelect.js +0 -364
  18. package/lib/commands/generate/generateForm/extractErrorEnums.d.ts +0 -16
  19. package/lib/commands/generate/generateForm/extractErrorEnums.js +0 -100
  20. package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.d.ts +0 -2
  21. package/lib/commands/generate/generateForm/flatFormFieldsFromFormConfig.js +0 -22
  22. package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.d.ts +0 -6
  23. package/lib/commands/generate/generateForm/formField/findIntrospectionFieldType.js +0 -22
  24. package/lib/commands/generate/generateForm/formField/options.d.ts +0 -24
  25. package/lib/commands/generate/generateForm/formField/options.js +0 -85
  26. package/lib/commands/generate/generateForm/generateComponentFormField.d.ts +0 -5
  27. package/lib/commands/generate/generateForm/generateComponentFormField.js +0 -22
  28. package/lib/commands/generate/generateForm/generateErrorHandling.d.ts +0 -8
  29. package/lib/commands/generate/generateForm/generateErrorHandling.js +0 -24
  30. package/lib/commands/generate/generateForm/generateErrorMessages.d.ts +0 -11
  31. package/lib/commands/generate/generateForm/generateErrorMessages.js +0 -28
  32. package/lib/commands/generate/generateForm/generateFields.d.ts +0 -42
  33. package/lib/commands/generate/generateForm/generateFields.js +0 -87
  34. package/lib/commands/generate/generateForm/generateForm.d.ts +0 -14
  35. package/lib/commands/generate/generateForm/generateForm.js +0 -565
  36. package/lib/commands/generate/generateForm/generateFormField.d.ts +0 -12
  37. package/lib/commands/generate/generateForm/generateFormField.js +0 -368
  38. package/lib/commands/generate/generateForm/generateFormLayout.d.ts +0 -12
  39. package/lib/commands/generate/generateForm/generateFormLayout.js +0 -154
  40. package/lib/commands/generate/generateForm/generateFormValues.d.ts +0 -40
  41. package/lib/commands/generate/generateForm/generateFormValues.js +0 -219
  42. package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.d.ts +0 -11
  43. package/lib/commands/generate/generateForm/generateFragmentByFormFragmentFields.js +0 -29
  44. package/lib/commands/generate/generateForm/getForwardedGqlArgs.d.ts +0 -18
  45. package/lib/commands/generate/generateForm/getForwardedGqlArgs.js +0 -79
  46. package/lib/commands/generate/generateGrid/detectMuiXVersion.d.ts +0 -5
  47. package/lib/commands/generate/generateGrid/detectMuiXVersion.js +0 -32
  48. package/lib/commands/generate/generateGrid/findInputObjectType.d.ts +0 -2
  49. package/lib/commands/generate/generateGrid/findInputObjectType.js +0 -15
  50. package/lib/commands/generate/generateGrid/generateGqlFieldList.d.ts +0 -6
  51. package/lib/commands/generate/generateGrid/generateGqlFieldList.js +0 -56
  52. package/lib/commands/generate/generateGrid/generateGrid.d.ts +0 -16
  53. package/lib/commands/generate/generateGrid/generateGrid.js +0 -1017
  54. package/lib/commands/generate/generateGrid/generateGridToolbar.d.ts +0 -15
  55. package/lib/commands/generate/generateGrid/generateGridToolbar.js +0 -90
  56. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.d.ts +0 -13
  57. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.js +0 -59
  58. package/lib/commands/generate/generateGrid/getPropsForFilterProp.d.ts +0 -14
  59. package/lib/commands/generate/generateGrid/getPropsForFilterProp.js +0 -13
  60. package/lib/commands/generate/generateGrid/usableFields.d.ts +0 -14
  61. package/lib/commands/generate/generateGrid/usableFields.js +0 -3
  62. package/lib/commands/generate/utils/camelCaseToHumanReadable.d.ts +0 -1
  63. package/lib/commands/generate/utils/camelCaseToHumanReadable.js +0 -7
  64. package/lib/commands/generate/utils/columnVisibility.d.ts +0 -6
  65. package/lib/commands/generate/utils/columnVisibility.js +0 -2
  66. package/lib/commands/generate/utils/convertConfigImport.d.ts +0 -6
  67. package/lib/commands/generate/utils/convertConfigImport.js +0 -14
  68. package/lib/commands/generate/utils/findMutationType.d.ts +0 -3
  69. package/lib/commands/generate/utils/findMutationType.js +0 -18
  70. package/lib/commands/generate/utils/findQueryType.d.ts +0 -2
  71. package/lib/commands/generate/utils/findQueryType.js +0 -18
  72. package/lib/commands/generate/utils/findRootBlocks.d.ts +0 -8
  73. package/lib/commands/generate/utils/findRootBlocks.js +0 -66
  74. package/lib/commands/generate/utils/generateGqlOperation.d.ts +0 -12
  75. package/lib/commands/generate/utils/generateGqlOperation.js +0 -87
  76. package/lib/commands/generate/utils/generateImportsCode.d.ts +0 -6
  77. package/lib/commands/generate/utils/generateImportsCode.js +0 -31
  78. package/lib/commands/generate/utils/intl.d.ts +0 -20
  79. package/lib/commands/generate/utils/intl.js +0 -44
  80. package/lib/commands/generate/utils/isFieldOptional.d.ts +0 -7
  81. package/lib/commands/generate/utils/isFieldOptional.js +0 -21
  82. package/lib/commands/generate/utils/runtimeTypeGuards.d.ts +0 -20
  83. package/lib/commands/generate/utils/runtimeTypeGuards.js +0 -22
  84. package/lib/commands/generate/utils/writeGenerated.d.ts +0 -1
  85. package/lib/commands/generate/utils/writeGenerated.js +0 -123
  86. package/lib/index.d.ts +0 -2
  87. package/lib/index.js +0 -6
@@ -1,368 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateFormField = generateFormField;
4
- const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
5
- const convertConfigImport_1 = require("../utils/convertConfigImport");
6
- const intl_1 = require("../utils/intl");
7
- const isFieldOptional_1 = require("../utils/isFieldOptional");
8
- const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
9
- const generateAsyncSelect_1 = require("./asyncSelect/generateAsyncSelect");
10
- const findIntrospectionFieldType_1 = require("./formField/findIntrospectionFieldType");
11
- const options_1 = require("./formField/options");
12
- function generateFormField({ gqlIntrospection, baseOutputFilename, config, formConfig, gqlType, namePrefix, }) {
13
- if (config.type == "asyncSelect" || config.type == "asyncSelectFilter") {
14
- return (0, generateAsyncSelect_1.generateAsyncSelect)({ gqlIntrospection, baseOutputFilename, config, formConfig, gqlType, namePrefix });
15
- }
16
- const imports = [];
17
- const formProps = [];
18
- const { name, formattedMessageRootId, fieldLabel, startAdornment, endAdornment, imports: optionsImports, } = (0, options_1.buildFormFieldOptions)({ config, formConfig });
19
- imports.push(...optionsImports);
20
- let introspectionFieldType = (0, findIntrospectionFieldType_1.findIntrospectionFieldType)({ name, gqlIntrospection, gqlType });
21
- const nameWithPrefix = `${namePrefix ? `${namePrefix}.` : ``}${name}`;
22
- const rootGqlType = formConfig.gqlType;
23
- const dataRootName = rootGqlType[0].toLowerCase() + rootGqlType.substring(1); // TODO should probably be deteced via query
24
- const required = !(0, isFieldOptional_1.isFieldOptional)({ config, gqlIntrospection, gqlType });
25
- //TODO verify introspectionField.type is compatbile with config.type
26
- const endAdornmentWithLockIconProp = `endAdornment={<InputAdornment position="end"><Lock /></InputAdornment>}`;
27
- const readOnlyProps = `readOnly disabled`;
28
- const readOnlyPropsWithLock = `${readOnlyProps} ${endAdornmentWithLockIconProp}`;
29
- const formValueConfig = {
30
- fieldName: nameWithPrefix,
31
- };
32
- const gqlDocuments = {};
33
- const hooksCode = "";
34
- let finalFormConfig;
35
- let validateCode = "";
36
- if (config.validate) {
37
- if ((0, runtimeTypeGuards_1.isGeneratorConfigImport)(config.validate)) {
38
- imports.push((0, convertConfigImport_1.convertConfigImport)(config.validate));
39
- validateCode = `validate={${config.validate.name}}`;
40
- }
41
- else if ((0, runtimeTypeGuards_1.isGeneratorConfigCode)(config.validate)) {
42
- validateCode = `validate={${config.validate.code}}`;
43
- imports.push(...config.validate.imports.map((imprt) => (0, convertConfigImport_1.convertConfigImport)(imprt)));
44
- }
45
- }
46
- let code = "";
47
- let formFragmentFields = [name];
48
- if (config.type == "text") {
49
- const TextInputComponent = config.multiline ? "TextAreaField" : "TextField";
50
- code = `
51
- <${TextInputComponent}
52
- ${required ? "required" : ""}
53
- ${config.readOnly ? readOnlyPropsWithLock : ""}
54
- variant="horizontal"
55
- fullWidth
56
- name="${nameWithPrefix}"
57
- label={${fieldLabel}}
58
- ${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
59
- ${config.endAdornment ? `endAdornment={<InputAdornment position="end">${endAdornment.adornmentString}</InputAdornment>}` : ""}
60
- ${config.helperText
61
- ? `helperText={${(0, intl_1.generateFormattedMessage)({
62
- config: config.helperText,
63
- id: `${formattedMessageRootId}.${name}.helperText`,
64
- type: "jsx",
65
- })}}`
66
- : ""}
67
- ${validateCode}
68
- />`;
69
- if (!required && !config.readOnly) {
70
- formValueConfig.formValueToGqlInputCode = `$fieldName ?? null`;
71
- }
72
- if (config.initialValue !== undefined) {
73
- formValueConfig.defaultInitializationCode = JSON.stringify(config.initialValue);
74
- }
75
- }
76
- else if (config.type == "number") {
77
- code = `
78
- <NumberField
79
- ${required ? "required" : ""}
80
- ${config.readOnly ? readOnlyPropsWithLock : ""}
81
- variant="horizontal"
82
- fullWidth
83
- name="${nameWithPrefix}"
84
- label={${fieldLabel}}
85
- ${config.decimals ? `decimals={${config.decimals}}` : ""}
86
- ${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
87
- ${config.endAdornment ? `endAdornment={<InputAdornment position="end">${endAdornment.adornmentString}</InputAdornment>}` : ""}
88
- ${config.helperText
89
- ? `helperText={<FormattedMessage id=` +
90
- `"${formattedMessageRootId}.${name}.helperText" ` +
91
- `defaultMessage="${config.helperText}" />}`
92
- : ""}
93
- ${validateCode}
94
- />`;
95
- if (!required && !config.readOnly) {
96
- formValueConfig.formValueToGqlInputCode = `$fieldName ?? null`;
97
- }
98
- if (config.initialValue !== undefined) {
99
- formValueConfig.defaultInitializationCode = JSON.stringify(config.initialValue);
100
- }
101
- }
102
- else if (config.type === "numberRange") {
103
- code = `
104
- <Field
105
- ${required ? "required" : ""}
106
- ${config.readOnly ? readOnlyPropsWithLock : ""}
107
- variant="horizontal"
108
- fullWidth
109
- name="${nameWithPrefix}"
110
- component={FinalFormRangeInput}
111
- label={${fieldLabel}}
112
- min={${config.minValue}}
113
- max={${config.maxValue}}
114
- ${config.disableSlider ? "disableSlider" : ""}
115
- ${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
116
- ${config.endAdornment ? `endAdornment={<InputAdornment position="end">${endAdornment.adornmentString}</InputAdornment>}` : ""}
117
- ${config.helperText
118
- ? `helperText={<FormattedMessage id=` +
119
- `"${formattedMessageRootId}.${name}.helperText" ` +
120
- `defaultMessage="${config.helperText}" />}`
121
- : ""}
122
- ${validateCode}
123
- />`;
124
- formFragmentFields = [`${name}.min`, `${name}.max`];
125
- if (config.initialValue !== undefined) {
126
- formValueConfig.defaultInitializationCode = JSON.stringify(config.initialValue);
127
- }
128
- }
129
- else if (config.type == "boolean") {
130
- const checkboxLabel = config.checkboxLabel
131
- ? (0, intl_1.generateFormattedMessage)({
132
- config: config.checkboxLabel,
133
- id: `${formattedMessageRootId}.${name}.checkboxLabel`,
134
- type: "jsx",
135
- })
136
- : "";
137
- code = `<CheckboxField
138
- fieldLabel={${fieldLabel}}
139
- ${config.checkboxLabel ? `label={${checkboxLabel}}` : ""}
140
- name="${nameWithPrefix}"
141
- fullWidth
142
- variant="horizontal"
143
- ${config.readOnly ? readOnlyProps : ""}
144
- ${config.helperText
145
- ? `helperText={<FormattedMessage id=` +
146
- `"${formattedMessageRootId}.${name}.helperText" ` +
147
- `defaultMessage="${config.helperText}" />}`
148
- : ""}
149
- ${validateCode}
150
- />`;
151
- formValueConfig.defaultInitializationCode = config.initialValue ? "true" : "false";
152
- }
153
- else if (config.type == "date") {
154
- imports.push({
155
- name: "Future_DatePickerField",
156
- importPath: "@comet/admin",
157
- });
158
- code = `
159
- <Future_DatePickerField
160
- ${required ? "required" : ""}
161
- ${config.readOnly ? readOnlyPropsWithLock : ""}
162
- variant="horizontal"
163
- fullWidth
164
- name="${nameWithPrefix}"
165
- label={${fieldLabel}}
166
- ${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
167
- ${config.endAdornment ? `endAdornment={<InputAdornment position="end">${endAdornment.adornmentString}</InputAdornment>}` : ""}
168
- ${config.helperText
169
- ? `helperText={<FormattedMessage id=` +
170
- `"${formattedMessageRootId}.${name}.helperText" ` +
171
- `defaultMessage="${config.helperText}" />}`
172
- : ""}
173
- ${validateCode}
174
- />`;
175
- if (!required && !config.readOnly) {
176
- formValueConfig.formValueToGqlInputCode = `$fieldName ?? null`;
177
- }
178
- if (config.initialValue !== undefined) {
179
- formValueConfig.defaultInitializationCode = JSON.stringify(config.initialValue);
180
- }
181
- }
182
- else if (config.type == "dateTime") {
183
- imports.push({
184
- name: "Future_DateTimePickerField as DateTimePickerField",
185
- importPath: "@comet/admin",
186
- });
187
- code = `<DateTimePickerField
188
- ${required ? "required" : ""}
189
- ${config.readOnly ? readOnlyPropsWithLock : ""}
190
- variant="horizontal"
191
- fullWidth
192
- name="${nameWithPrefix}"
193
- label={${fieldLabel}}
194
- ${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
195
- ${config.endAdornment ? `endAdornment={<InputAdornment position="end">${endAdornment.adornmentString}</InputAdornment>}` : ""}
196
- ${config.helperText
197
- ? `helperText={<FormattedMessage id=` +
198
- `"${formattedMessageRootId}.${name}.helperText" ` +
199
- `defaultMessage="${config.helperText}" />}`
200
- : ""}
201
- ${validateCode}
202
- />`;
203
- formValueConfig.initializationCode = `data.${dataRootName}.${nameWithPrefix} ? new Date(data.${dataRootName}.${nameWithPrefix}) : undefined`;
204
- formValueConfig.omitFromFragmentType = true;
205
- formValueConfig.typeCode = {
206
- nullable: !required,
207
- type: `Date${!required ? " | null" : ""}`,
208
- };
209
- if (!config.readOnly) {
210
- formValueConfig.formValueToGqlInputCode = required ? `$fieldName.toISOString()` : `$fieldName ? $fieldName.toISOString() : null`;
211
- }
212
- if (config.initialValue !== undefined) {
213
- formValueConfig.defaultInitializationCode = `new Date("${config.initialValue.toISOString()}")`;
214
- }
215
- }
216
- else if (config.type == "block") {
217
- code = `<Field name="${nameWithPrefix}" isEqual={isEqual} label={${fieldLabel}} variant="horizontal" fullWidth>
218
- {createFinalFormBlock(rootBlocks.${String(config.name)})}
219
- </Field>`;
220
- formValueConfig.formValueToGqlInputCode = `rootBlocks.${name}.state2Output($fieldName)`;
221
- formValueConfig.omitFromFragmentType = true;
222
- formValueConfig.typeCode = { nullable: false, type: `BlockState<typeof rootBlocks.${name}>` };
223
- formValueConfig.initializationCode = `rootBlocks.${name}.input2State(data.${dataRootName}.${nameWithPrefix})`;
224
- formValueConfig.defaultInitializationCode = `rootBlocks.${name}.defaultValues()`;
225
- }
226
- else if (config.type === "fileUpload") {
227
- const multiple = config.multiple || (typeof config.maxFiles === "number" && config.maxFiles > 1);
228
- code = `<FileUploadField name="${name}" label={${fieldLabel}}
229
- variant="horizontal"
230
- ${config.multiple ? "multiple" : ""}
231
- ${config.maxFiles ? `maxFiles={${config.maxFiles}}` : ""}
232
- ${config.maxFileSize ? `maxFileSize={${config.maxFileSize}}` : ""}
233
- ${config.readOnly ? `readOnly` : ""}
234
- ${config.layout ? `layout="${config.layout}"` : ""}
235
- ${config.accept ? `accept="${config.accept}"` : ""}
236
- />`;
237
- if (multiple) {
238
- formValueConfig.formValueToGqlInputCode = `$fieldName?.map(({ id }) => id)`;
239
- }
240
- else {
241
- formValueConfig.formValueToGqlInputCode = `$fieldName ? $fieldName.id : null`;
242
- }
243
- formFragmentFields = [`${name}...${config.download ? "FinalFormFileUploadDownloadable" : "FinalFormFileUpload"}`];
244
- }
245
- else if (config.type == "staticSelect") {
246
- const multiple = (introspectionFieldType === null || introspectionFieldType === void 0 ? void 0 : introspectionFieldType.kind) === "LIST";
247
- if ((introspectionFieldType === null || introspectionFieldType === void 0 ? void 0 : introspectionFieldType.kind) === "LIST") {
248
- introspectionFieldType =
249
- introspectionFieldType.ofType.kind === "NON_NULL" ? introspectionFieldType.ofType.ofType : introspectionFieldType.ofType;
250
- }
251
- const enumType = gqlIntrospection.__schema.types.find((t) => t.kind === "ENUM" && t.name === introspectionFieldType.name);
252
- if (!enumType)
253
- throw new Error(`Enum type ${introspectionFieldType.name} not found for field ${name}`);
254
- const values = (config.values ? config.values : enumType.enumValues.map((i) => i.name)).map((value) => {
255
- if (typeof value === "string") {
256
- const messageId = `${formattedMessageRootId}.${name}.${value.charAt(0).toLowerCase() + value.slice(1)}`;
257
- const valueLabel = (0, intl_1.generateFormattedMessage)({
258
- config: undefined,
259
- defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(value),
260
- id: messageId,
261
- type: "jsx",
262
- });
263
- return {
264
- value,
265
- labelCode: valueLabel,
266
- };
267
- }
268
- else {
269
- const messageId = `${formattedMessageRootId}.${name}.${value.value.charAt(0).toLowerCase() + value.value.slice(1)}`;
270
- const valueLabel = (0, intl_1.generateFormattedMessage)({
271
- config: value.label,
272
- id: messageId,
273
- type: "jsx",
274
- });
275
- return {
276
- value: value.value,
277
- labelCode: valueLabel,
278
- };
279
- }
280
- });
281
- let inputType = config.inputType;
282
- if (!inputType) {
283
- if (!required || multiple) {
284
- // radio is not clearable, render always as select if not required
285
- // radio doesn't support multiple
286
- inputType = "select";
287
- }
288
- else {
289
- // auto select/radio based on number of values
290
- if (values.length <= 5) {
291
- inputType = "radio";
292
- }
293
- else {
294
- inputType = "select";
295
- }
296
- }
297
- }
298
- if (inputType === "radio" && multiple) {
299
- throw new Error(`${name}: inputType=radio doesn't support multiple`);
300
- }
301
- if (inputType === "radio" && !required) {
302
- throw new Error(`${name}: inputType=radio must be required as it doesn't support clearable`);
303
- }
304
- const renderAsRadio = inputType === "radio";
305
- if (renderAsRadio) {
306
- code = `<RadioGroupField
307
- ${required ? "required" : ""}
308
- variant="horizontal"
309
- fullWidth
310
- name="${nameWithPrefix}"
311
- label={${fieldLabel}}
312
- options={[
313
- ${values
314
- .map((value) => {
315
- return `{
316
- label: ${value.labelCode},
317
- value: "${value.value}",
318
- }`;
319
- })
320
- .join(",")}
321
- ]}/>`;
322
- }
323
- else {
324
- imports.push({
325
- name: "SelectField",
326
- importPath: "@comet/admin",
327
- });
328
- code = `<SelectField
329
- ${required ? "required" : ""}
330
- fullWidth
331
- variant={"horizontal"}
332
- name="${nameWithPrefix}"
333
- label={${fieldLabel}}
334
- ${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
335
- ${config.helperText
336
- ? `helperText={<FormattedMessage id=` +
337
- `"${formattedMessageRootId}.${name}.helperText" ` +
338
- `defaultMessage="${config.helperText}" />}`
339
- : ""}
340
- ${validateCode}
341
- ${config.readOnly ? readOnlyPropsWithLock : ""}
342
- ${multiple ? "multiple" : ""}
343
- options={[${values.map((value) => {
344
- return `{
345
- value: "${value.value}",
346
- label: ${value.labelCode}
347
- }`;
348
- })}]}
349
- />`;
350
- }
351
- if (config.initialValue !== undefined) {
352
- formValueConfig.defaultInitializationCode = JSON.stringify(config.initialValue);
353
- }
354
- }
355
- else {
356
- throw new Error(`Unsupported type`);
357
- }
358
- return {
359
- code,
360
- hooksCode,
361
- formFragmentFields,
362
- gqlDocuments,
363
- imports,
364
- formProps,
365
- formValuesConfig: [formValueConfig],
366
- finalFormConfig,
367
- };
368
- }
@@ -1,12 +0,0 @@
1
- import { type IntrospectionQuery } from "graphql";
2
- import { type FormConfig, type FormLayoutConfig } from "../generate-command";
3
- import { type GenerateFieldsReturn } from "./generateFields";
4
- export declare function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, formFragmentName, formConfig, gqlType, namePrefix, }: {
5
- gqlIntrospection: IntrospectionQuery;
6
- baseOutputFilename: string;
7
- config: FormLayoutConfig<any>;
8
- formFragmentName: string;
9
- formConfig: FormConfig<any>;
10
- gqlType: string;
11
- namePrefix?: string;
12
- }): GenerateFieldsReturn;
@@ -1,154 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateFormLayout = generateFormLayout;
4
- const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
5
- const intl_1 = require("../utils/intl");
6
- const findIntrospectionFieldType_1 = require("./formField/findIntrospectionFieldType");
7
- const generateFields_1 = require("./generateFields");
8
- function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, formFragmentName, formConfig, gqlType, namePrefix, }) {
9
- var _a, _b, _c;
10
- const rootGqlType = formConfig.gqlType;
11
- const formattedMessageRootId = rootGqlType[0].toLowerCase() + rootGqlType.substring(1);
12
- const dataRootName = rootGqlType[0].toLowerCase() + rootGqlType.substring(1); // TODO should probably be deteced via query
13
- let code = "";
14
- let hooksCode = "";
15
- const formFragmentFields = [];
16
- const gqlDocuments = {};
17
- const imports = [];
18
- const formProps = [];
19
- const formValuesConfig = [];
20
- const finalFormConfig = { subscription: {}, renderProps: {} };
21
- if (config.type === "fieldSet") {
22
- const generatedFields = (0, generateFields_1.generateFields)({
23
- gqlIntrospection,
24
- baseOutputFilename,
25
- fields: config.fields,
26
- formFragmentName,
27
- formConfig,
28
- gqlType,
29
- namePrefix,
30
- });
31
- hooksCode += generatedFields.hooksCode;
32
- formFragmentFields.push(...generatedFields.formFragmentFields);
33
- for (const name in generatedFields.gqlDocuments) {
34
- gqlDocuments[name] = generatedFields.gqlDocuments[name];
35
- }
36
- imports.push(...generatedFields.imports);
37
- formProps.push(...generatedFields.formProps);
38
- formValuesConfig.push(...generatedFields.formValuesConfig);
39
- finalFormConfig.subscription = Object.assign(Object.assign({}, finalFormConfig.subscription), (_a = generatedFields.finalFormConfig) === null || _a === void 0 ? void 0 : _a.subscription);
40
- finalFormConfig.renderProps = Object.assign(Object.assign({}, finalFormConfig.renderProps), (_b = generatedFields.finalFormConfig) === null || _b === void 0 ? void 0 : _b.renderProps);
41
- imports.push({ name: "FieldSet", importPath: "@comet/admin" });
42
- const supportPlaceholder = (_c = config.supportText) === null || _c === void 0 ? void 0 : _c.includes("{");
43
- if (supportPlaceholder) {
44
- imports.push({ name: "FormSpy", importPath: "react-final-form" });
45
- }
46
- code = `
47
- <FieldSet
48
- ${config.collapsible === undefined || config.collapsible ? `collapsible` : ``}
49
- ${config.initiallyExpanded != null ? `initiallyExpanded={${config.initiallyExpanded}}` : ``}
50
- title={${(0, intl_1.generateFormattedMessage)({
51
- config: config.title,
52
- id: `${formattedMessageRootId}.${config.name}.title`,
53
- defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(config.name),
54
- type: "jsx",
55
- })}}
56
- ${config.supportText
57
- ? `supportText={
58
- ${supportPlaceholder ? `mode === "edit" && (<FormSpy subscription={{ values: true }}>{({ values }) => (` : ``}
59
- <FormattedMessage
60
- id="${formattedMessageRootId}.${config.name}.supportText"
61
- defaultMessage="${config.supportText}"
62
- ${supportPlaceholder ? `values={{ ...values }}` : ``}
63
- />
64
- ${supportPlaceholder ? `)}</FormSpy>)` : ``}
65
- }`
66
- : ``}
67
- >
68
- ${generatedFields.code}
69
- </FieldSet>`;
70
- }
71
- else if (config.type === "optionalNestedFields") {
72
- const name = String(config.name);
73
- const introspectionFieldType = (0, findIntrospectionFieldType_1.findIntrospectionFieldType)({ name, gqlType, gqlIntrospection });
74
- if (!introspectionFieldType)
75
- throw new Error(`field ${name} in gql introspection type ${gqlType} not found`);
76
- if (introspectionFieldType.kind !== "OBJECT")
77
- throw new Error(`field ${name} in gql introspection type ${gqlType} has to be OBJECT`);
78
- const generatedFields = (0, generateFields_1.generateFields)({
79
- gqlIntrospection,
80
- baseOutputFilename,
81
- fields: config.fields,
82
- formFragmentName,
83
- formConfig,
84
- gqlType: introspectionFieldType.name,
85
- namePrefix: name,
86
- });
87
- hooksCode += generatedFields.hooksCode;
88
- formFragmentFields.push(...generatedFields.formFragmentFields.map((field) => `${name}.${field}`));
89
- for (const name in generatedFields.gqlDocuments) {
90
- gqlDocuments[name] = generatedFields.gqlDocuments[name];
91
- }
92
- imports.push(...generatedFields.imports);
93
- formValuesConfig.push(...generatedFields.formValuesConfig);
94
- // first field is the "enabled" checkbox
95
- formValuesConfig.push({
96
- fieldName: `${name}Enabled`,
97
- omitFromFragmentType: false,
98
- destructFromFormValues: true,
99
- typeCode: {
100
- nullable: false,
101
- type: "boolean",
102
- },
103
- initializationCode: `!!data.${dataRootName}.${name}`,
104
- });
105
- // second field is the nested object, which is not a final-form field itself
106
- formValuesConfig.push({
107
- fieldName: `${name}`,
108
- wrapFormValueToGqlInputCode: `${name.split(".").pop()}Enabled && $fieldName ? $inner : null`,
109
- });
110
- imports.push({ name: "FinalFormSwitch", importPath: "@comet/admin" });
111
- imports.push({ name: "messages", importPath: "@comet/admin" });
112
- imports.push({ name: "FormControlLabel", importPath: "@mui/material" });
113
- code = `<Field
114
- fullWidth
115
- name="${String(config.name)}Enabled"
116
- type="checkbox"
117
- label={${(0, intl_1.generateFormattedMessage)({
118
- config: config.checkboxLabel,
119
- id: `${formattedMessageRootId}.${String(config.name)}.${String(config.name)}Enabled`,
120
- defaultMessage: `Enable ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(String(config.name))}`,
121
- type: "jsx",
122
- })}}
123
- >
124
- {(props) => (
125
- <FormControlLabel
126
- control={<FinalFormSwitch {...props} />}
127
- label={props.input.checked ? <FormattedMessage {...messages.yes} /> : <FormattedMessage {...messages.no} />}
128
- />
129
- )}
130
- </Field>
131
- <Field name="${String(config.name)}Enabled" fullWidth subscription={{ value: true }}>
132
- {({ input: { value } }) =>
133
- value ? (
134
- <>
135
- ${generatedFields.code}
136
- </>
137
- ) : null
138
- }
139
- </Field>`;
140
- }
141
- else {
142
- throw new Error(`Unsupported type`);
143
- }
144
- return {
145
- code,
146
- hooksCode,
147
- formFragmentFields,
148
- gqlDocuments,
149
- imports,
150
- formProps,
151
- formValuesConfig,
152
- finalFormConfig,
153
- };
154
- }
@@ -1,40 +0,0 @@
1
- import { type IntrospectionQuery } from "graphql";
2
- import { type GenerateFieldsReturn } from "./generateFields";
3
- type FormValuesConfigTreeNode = {
4
- config?: GenerateFieldsReturn["formValuesConfig"][0];
5
- nullable?: boolean;
6
- children: FormValuesConfigTree;
7
- };
8
- type FormValuesConfigTree = {
9
- [key: string]: FormValuesConfigTreeNode;
10
- };
11
- export declare function formValuesConfigToTree({ formValuesConfig, gqlIntrospection, gqlType, }: {
12
- formValuesConfig: GenerateFieldsReturn["formValuesConfig"];
13
- gqlIntrospection: IntrospectionQuery;
14
- gqlType: string;
15
- }): FormValuesConfigTree;
16
- export declare function generateFormValuesType({ formValuesConfig, filterByFragmentType, gqlIntrospection, gqlType, }: {
17
- formValuesConfig: GenerateFieldsReturn["formValuesConfig"];
18
- filterByFragmentType: string;
19
- gqlIntrospection: IntrospectionQuery;
20
- gqlType: string;
21
- }): string;
22
- export declare function generateInitialValues({ mode, formValuesConfig, filterByFragmentType, gqlIntrospection, gqlType, initialValuesAsProp, }: {
23
- mode: "all" | "edit" | "add";
24
- formValuesConfig: GenerateFieldsReturn["formValuesConfig"];
25
- filterByFragmentType: string;
26
- gqlIntrospection: IntrospectionQuery;
27
- gqlType: string;
28
- initialValuesAsProp: boolean;
29
- }): string;
30
- export declare function generateDestructFormValueForInput({ formValuesConfig, gqlIntrospection, gqlType, }: {
31
- formValuesConfig: GenerateFieldsReturn["formValuesConfig"];
32
- gqlIntrospection: IntrospectionQuery;
33
- gqlType: string;
34
- }): string;
35
- export declare function generateFormValuesToGqlInput({ formValuesConfig, gqlIntrospection, gqlType, }: {
36
- formValuesConfig: GenerateFieldsReturn["formValuesConfig"];
37
- gqlIntrospection: IntrospectionQuery;
38
- gqlType: string;
39
- }): string;
40
- export {};