@comet/admin-generator 8.11.0-canary-20251211122101 → 8.11.0-canary-20251211150434
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/config/transformConfig.js +34 -0
- package/lib/commands/generate/generate-command.d.ts +14 -11
- package/lib/commands/generate/generateForm/formField/options.js +7 -3
- package/lib/commands/generate/generateForm/generateFormField.js +6 -3
- package/lib/commands/generate/generateForm/generateFormLayout.js +17 -8
- package/lib/commands/generate/generateGrid/generateGrid.js +72 -25
- package/lib/commands/generate/generateGrid/generateGridToolbar.d.ts +2 -1
- package/lib/commands/generate/generateGrid/generateGridToolbar.js +6 -1
- package/lib/commands/generate/utils/intl.d.ts +17 -1
- package/lib/commands/generate/utils/intl.js +27 -4
- package/lib/commands/generate/utils/runtimeTypeGuards.d.ts +8 -0
- package/lib/commands/generate/utils/runtimeTypeGuards.js +10 -0
- package/package.json +5 -5
|
@@ -52,6 +52,20 @@ const supportedInlineCodePaths = [
|
|
|
52
52
|
//support in up to 5 levels of nested fields (eg. fieldSet)
|
|
53
53
|
...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.validate`),
|
|
54
54
|
];
|
|
55
|
+
const supportedFormattedMessagePaths = [
|
|
56
|
+
"[type=grid].newEntryText",
|
|
57
|
+
"[type=grid].columns.headerName",
|
|
58
|
+
"[type=grid].columns.headerInfoTooltip",
|
|
59
|
+
//staticSelect
|
|
60
|
+
"[type=grid].columns.values.label",
|
|
61
|
+
"[type=grid].columns.values.label.primaryText",
|
|
62
|
+
"[type=grid].columns.values.label.secondaryText",
|
|
63
|
+
//support in up to 5 levels of nested fields (eg. fieldSet)
|
|
64
|
+
...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.label`),
|
|
65
|
+
...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.helperText`),
|
|
66
|
+
...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.checkboxLabel`),
|
|
67
|
+
...Array.from(Array(5).keys()).map((i) => `[type=form]${".fields".repeat(i + 1)}.title`), // fieldSet title
|
|
68
|
+
];
|
|
55
69
|
// transform the config file to replace all imports and inline code with a { code, imports } object
|
|
56
70
|
// this is needed to be able to execute the config file in a node environment
|
|
57
71
|
function transformConfigFile(fileName, sourceText) {
|
|
@@ -112,6 +126,26 @@ function transformConfigFile(fileName, sourceText) {
|
|
|
112
126
|
}
|
|
113
127
|
}
|
|
114
128
|
}
|
|
129
|
+
else if (ts.isJsxSelfClosingElement(node)) {
|
|
130
|
+
if (node.tagName.getText() == "FormattedMessage") {
|
|
131
|
+
if (!supportedFormattedMessagePaths.includes(path)) {
|
|
132
|
+
throw new Error(`FormattedMessage is not supported in this context: ${path}`);
|
|
133
|
+
}
|
|
134
|
+
return ts.factory.createObjectLiteralExpression(node.attributes.properties.map((attr) => {
|
|
135
|
+
var _a;
|
|
136
|
+
if (!ts.isJsxAttribute(attr)) {
|
|
137
|
+
throw new Error(`Only JsxAttributes are supported in FormattedMessage in this context: ${path}`);
|
|
138
|
+
}
|
|
139
|
+
let name = (_a = attr.name) === null || _a === void 0 ? void 0 : _a.getText();
|
|
140
|
+
if (name === "id")
|
|
141
|
+
name = "formattedMessageId"; // rename to identify as formattedMessage
|
|
142
|
+
if (!attr.initializer || !ts.isStringLiteral(attr.initializer)) {
|
|
143
|
+
throw new Error(`Only string literals are supported in FormattedMessage in this context: ${path}.${name}`);
|
|
144
|
+
}
|
|
145
|
+
return ts.factory.createPropertyAssignment(name, ts.factory.createStringLiteral(attr.initializer.text));
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
115
149
|
const transformKinds = [
|
|
116
150
|
ts.SyntaxKind.Identifier,
|
|
117
151
|
ts.SyntaxKind.ArrayLiteralExpression,
|
|
@@ -6,9 +6,11 @@ import { type IconProps } from "@mui/material";
|
|
|
6
6
|
import { type GridCellParams, type GridFilterItem, type GridFilterOperator, type GridRenderCellParams, type GridSortDirection, type GridValidRowModel } from "@mui/x-data-grid";
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
import { type FieldValidator, type FormApi } from "final-form";
|
|
9
|
-
import {
|
|
9
|
+
import type { ComponentType, ReactElement } from "react";
|
|
10
|
+
import type { FormattedMessage, MessageDescriptor } from "react-intl";
|
|
10
11
|
import { type UsableFields, type UsableFormFields } from "./generateGrid/usableFields";
|
|
11
12
|
import { type ColumnVisibleOption } from "./utils/columnVisibility";
|
|
13
|
+
export type FormattedMessageElement = ReactElement<MessageDescriptor, typeof FormattedMessage>;
|
|
12
14
|
type IconObject = Pick<IconProps, "color" | "fontSize"> & {
|
|
13
15
|
name: IconName;
|
|
14
16
|
};
|
|
@@ -143,23 +145,23 @@ export type FormFieldConfig<T> = (({
|
|
|
143
145
|
maxFiles?: number;
|
|
144
146
|
download?: boolean;
|
|
145
147
|
} & Pick<Partial<FinalFormFileUploadProps<true>>, "maxFileSize" | "readOnly" | "layout" | "accept">)) & {
|
|
146
|
-
label?: string;
|
|
148
|
+
label?: string | FormattedMessageElement;
|
|
147
149
|
required?: boolean;
|
|
148
150
|
validate?: FieldValidator<unknown>;
|
|
149
|
-
helperText?: string;
|
|
151
|
+
helperText?: string | FormattedMessageElement;
|
|
150
152
|
readOnly?: boolean;
|
|
151
153
|
};
|
|
152
154
|
export declare function isFormFieldConfig<T>(arg: any): arg is FormFieldConfig<T>;
|
|
153
155
|
type OptionalNestedFieldsConfig<T> = {
|
|
154
156
|
type: "optionalNestedFields";
|
|
155
157
|
name: UsableFormFields<T>;
|
|
156
|
-
checkboxLabel?: string;
|
|
158
|
+
checkboxLabel?: string | FormattedMessageElement;
|
|
157
159
|
fields: FormFieldConfig<any>[];
|
|
158
160
|
};
|
|
159
161
|
export type FormLayoutConfig<T> = {
|
|
160
162
|
type: "fieldSet";
|
|
161
163
|
name: string;
|
|
162
|
-
title?: string;
|
|
164
|
+
title?: string | FormattedMessageElement;
|
|
163
165
|
supportText?: string;
|
|
164
166
|
collapsible?: boolean;
|
|
165
167
|
initiallyExpanded?: boolean;
|
|
@@ -194,19 +196,20 @@ export type InjectedFormVariables = {
|
|
|
194
196
|
scope: ContentScope;
|
|
195
197
|
};
|
|
196
198
|
export declare function injectFormVariables<T>(fn: (injectedVariables: InjectedFormVariables) => T): T;
|
|
197
|
-
type BaseColumnConfig = Pick<GridColDef, "
|
|
198
|
-
|
|
199
|
+
type BaseColumnConfig = Pick<GridColDef, "width" | "minWidth" | "maxWidth" | "flex" | "pinned" | "disableExport"> & {
|
|
200
|
+
headerName?: string | FormattedMessageElement;
|
|
201
|
+
headerInfoTooltip?: string | FormattedMessageElement;
|
|
199
202
|
visible?: ColumnVisibleOption;
|
|
200
203
|
fieldName?: string;
|
|
201
204
|
};
|
|
202
205
|
export type GridColumnStaticSelectLabelCellContent = {
|
|
203
|
-
primaryText?: string;
|
|
204
|
-
secondaryText?: string;
|
|
206
|
+
primaryText?: string | FormattedMessageElement;
|
|
207
|
+
secondaryText?: string | FormattedMessageElement;
|
|
205
208
|
icon?: Icon;
|
|
206
209
|
};
|
|
207
210
|
export type GridColumnStaticSelectValue = StaticSelectValue | {
|
|
208
211
|
value: string | number | boolean;
|
|
209
|
-
label: string | GridColumnStaticSelectLabelCellContent;
|
|
212
|
+
label: string | FormattedMessageElement | GridColumnStaticSelectLabelCellContent;
|
|
210
213
|
} | number | boolean;
|
|
211
214
|
export type GridColumnConfig<T extends GridValidRowModel> = ({
|
|
212
215
|
type: "text";
|
|
@@ -294,7 +297,7 @@ export type GridConfig<T extends {
|
|
|
294
297
|
filterProp?: boolean;
|
|
295
298
|
toolbar?: boolean;
|
|
296
299
|
toolbarActionProp?: boolean;
|
|
297
|
-
newEntryText?: string;
|
|
300
|
+
newEntryText?: string | FormattedMessageElement;
|
|
298
301
|
rowActionProp?: boolean;
|
|
299
302
|
selectionProps?: "multiSelect" | "singleSelect";
|
|
300
303
|
rowReordering?: {
|
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.buildFormFieldOptions = buildFormFieldOptions;
|
|
15
15
|
const camelCaseToHumanReadable_1 = require("../../utils/camelCaseToHumanReadable");
|
|
16
16
|
const convertConfigImport_1 = require("../../utils/convertConfigImport");
|
|
17
|
+
const intl_1 = require("../../utils/intl");
|
|
17
18
|
const runtimeTypeGuards_1 = require("../../utils/runtimeTypeGuards");
|
|
18
19
|
const buildAdornmentData = ({ adornmentData }) => {
|
|
19
20
|
let adornmentString = "";
|
|
@@ -52,12 +53,15 @@ const buildAdornmentData = ({ adornmentData }) => {
|
|
|
52
53
|
* Helper function that builds various options needed for generating form fields.
|
|
53
54
|
*/
|
|
54
55
|
function buildFormFieldOptions({ config, formConfig, }) {
|
|
55
|
-
var _a;
|
|
56
56
|
const rootGqlType = formConfig.gqlType;
|
|
57
57
|
const name = String(config.name);
|
|
58
|
-
const label = (_a = config.label) !== null && _a !== void 0 ? _a : (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(name);
|
|
59
58
|
const formattedMessageRootId = rootGqlType[0].toLowerCase() + rootGqlType.substring(1);
|
|
60
|
-
const fieldLabel =
|
|
59
|
+
const fieldLabel = (0, intl_1.generateFormattedMessage)({
|
|
60
|
+
config: config.label,
|
|
61
|
+
id: `${formattedMessageRootId}.${name}`,
|
|
62
|
+
defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(name),
|
|
63
|
+
type: "jsx",
|
|
64
|
+
});
|
|
61
65
|
const imports = [];
|
|
62
66
|
let startAdornment = { adornmentString: "" };
|
|
63
67
|
let endAdornment = { adornmentString: "" };
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateFormField = generateFormField;
|
|
4
4
|
const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
|
|
5
5
|
const convertConfigImport_1 = require("../utils/convertConfigImport");
|
|
6
|
+
const intl_1 = require("../utils/intl");
|
|
6
7
|
const isFieldOptional_1 = require("../utils/isFieldOptional");
|
|
7
8
|
const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
|
|
8
9
|
const generateAsyncSelect_1 = require("./asyncSelect/generateAsyncSelect");
|
|
@@ -57,9 +58,11 @@ function generateFormField({ gqlIntrospection, baseOutputFilename, config, formC
|
|
|
57
58
|
${config.startAdornment ? `startAdornment={<InputAdornment position="start">${startAdornment.adornmentString}</InputAdornment>}` : ""}
|
|
58
59
|
${config.endAdornment ? `endAdornment={<InputAdornment position="end">${endAdornment.adornmentString}</InputAdornment>}` : ""}
|
|
59
60
|
${config.helperText
|
|
60
|
-
? `helperText={
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
? `helperText={${(0, intl_1.generateFormattedMessage)({
|
|
62
|
+
config: config.helperText,
|
|
63
|
+
id: `${formattedMessageRootId}.${name}.helperText`,
|
|
64
|
+
type: "jsx",
|
|
65
|
+
})}}`
|
|
63
66
|
: ""}
|
|
64
67
|
${validateCode}
|
|
65
68
|
/>`;
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateFormLayout = generateFormLayout;
|
|
4
4
|
const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
|
|
5
|
+
const intl_1 = require("../utils/intl");
|
|
5
6
|
const findIntrospectionFieldType_1 = require("./formField/findIntrospectionFieldType");
|
|
6
7
|
const generateFields_1 = require("./generateFields");
|
|
7
8
|
function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, formFragmentName, formConfig, gqlType, namePrefix, }) {
|
|
8
|
-
var _a, _b, _c
|
|
9
|
+
var _a, _b, _c;
|
|
9
10
|
const rootGqlType = formConfig.gqlType;
|
|
10
11
|
const formattedMessageRootId = rootGqlType[0].toLowerCase() + rootGqlType.substring(1);
|
|
11
12
|
const dataRootName = rootGqlType[0].toLowerCase() + rootGqlType.substring(1); // TODO should probably be deteced via query
|
|
@@ -18,7 +19,6 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
|
|
|
18
19
|
const formValuesConfig = [];
|
|
19
20
|
const finalFormConfig = { subscription: {}, renderProps: {} };
|
|
20
21
|
if (config.type === "fieldSet") {
|
|
21
|
-
const title = (_a = config.title) !== null && _a !== void 0 ? _a : (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(config.name);
|
|
22
22
|
const generatedFields = (0, generateFields_1.generateFields)({
|
|
23
23
|
gqlIntrospection,
|
|
24
24
|
baseOutputFilename,
|
|
@@ -36,10 +36,10 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
|
|
|
36
36
|
imports.push(...generatedFields.imports);
|
|
37
37
|
formProps.push(...generatedFields.formProps);
|
|
38
38
|
formValuesConfig.push(...generatedFields.formValuesConfig);
|
|
39
|
-
finalFormConfig.subscription = Object.assign(Object.assign({}, finalFormConfig.subscription), (
|
|
40
|
-
finalFormConfig.renderProps = Object.assign(Object.assign({}, finalFormConfig.renderProps), (
|
|
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
41
|
imports.push({ name: "FieldSet", importPath: "@comet/admin" });
|
|
42
|
-
const supportPlaceholder = (
|
|
42
|
+
const supportPlaceholder = (_c = config.supportText) === null || _c === void 0 ? void 0 : _c.includes("{");
|
|
43
43
|
if (supportPlaceholder) {
|
|
44
44
|
imports.push({ name: "FormSpy", importPath: "react-final-form" });
|
|
45
45
|
}
|
|
@@ -47,7 +47,12 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
|
|
|
47
47
|
<FieldSet
|
|
48
48
|
${config.collapsible === undefined || config.collapsible ? `collapsible` : ``}
|
|
49
49
|
${config.initiallyExpanded != null ? `initiallyExpanded={${config.initiallyExpanded}}` : ``}
|
|
50
|
-
title={
|
|
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
|
+
})}}
|
|
51
56
|
${config.supportText
|
|
52
57
|
? `supportText={
|
|
53
58
|
${supportPlaceholder ? `mode === "edit" && (<FormSpy subscription={{ values: true }}>{({ values }) => (` : ``}
|
|
@@ -70,7 +75,6 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
|
|
|
70
75
|
throw new Error(`field ${name} in gql introspection type ${gqlType} not found`);
|
|
71
76
|
if (introspectionFieldType.kind !== "OBJECT")
|
|
72
77
|
throw new Error(`field ${name} in gql introspection type ${gqlType} has to be OBJECT`);
|
|
73
|
-
const checkboxLabel = (_e = config.checkboxLabel) !== null && _e !== void 0 ? _e : `Enable ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(String(config.name))}`;
|
|
74
78
|
const generatedFields = (0, generateFields_1.generateFields)({
|
|
75
79
|
gqlIntrospection,
|
|
76
80
|
baseOutputFilename,
|
|
@@ -110,7 +114,12 @@ function generateFormLayout({ gqlIntrospection, baseOutputFilename, config, form
|
|
|
110
114
|
fullWidth
|
|
111
115
|
name="${String(config.name)}Enabled"
|
|
112
116
|
type="checkbox"
|
|
113
|
-
label={
|
|
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
|
+
})}}
|
|
114
123
|
>
|
|
115
124
|
{(props) => (
|
|
116
125
|
<FormControlLabel
|
|
@@ -20,6 +20,7 @@ const findQueryType_1 = require("../utils/findQueryType");
|
|
|
20
20
|
const findRootBlocks_1 = require("../utils/findRootBlocks");
|
|
21
21
|
const generateGqlOperation_1 = require("../utils/generateGqlOperation");
|
|
22
22
|
const generateImportsCode_1 = require("../utils/generateImportsCode");
|
|
23
|
+
const intl_1 = require("../utils/intl");
|
|
23
24
|
const runtimeTypeGuards_1 = require("../utils/runtimeTypeGuards");
|
|
24
25
|
const detectMuiXVersion_1 = require("./detectMuiXVersion");
|
|
25
26
|
const findInputObjectType_1 = require("./findInputObjectType");
|
|
@@ -73,37 +74,59 @@ const getSortByValue = (sortBy) => {
|
|
|
73
74
|
return sortBy;
|
|
74
75
|
};
|
|
75
76
|
const getValueOptionsLabelData = (messageId, label) => {
|
|
76
|
-
if (typeof label === "string") {
|
|
77
|
+
if (typeof label === "string" || (0, runtimeTypeGuards_1.isGeneratorConfigFormattedMessage)(label)) {
|
|
77
78
|
return {
|
|
78
|
-
textLabel:
|
|
79
|
+
textLabel: (0, intl_1.generateFormattedMessage)({
|
|
80
|
+
config: label,
|
|
81
|
+
id: messageId,
|
|
82
|
+
type: "intlCall",
|
|
83
|
+
}),
|
|
79
84
|
};
|
|
80
85
|
}
|
|
81
86
|
const textLabelParts = [];
|
|
82
87
|
const gridCellContentProps = {};
|
|
83
|
-
if (label.primaryText) {
|
|
88
|
+
if ("primaryText" in label && label.primaryText) {
|
|
84
89
|
const primaryMessageId = `${messageId}.primary`;
|
|
85
|
-
textLabelParts.push(
|
|
86
|
-
|
|
90
|
+
textLabelParts.push((0, intl_1.generateFormattedMessage)({
|
|
91
|
+
config: label.primaryText,
|
|
92
|
+
id: primaryMessageId,
|
|
93
|
+
type: "intlCall",
|
|
94
|
+
}));
|
|
95
|
+
gridCellContentProps.primaryText = (0, intl_1.generateFormattedMessage)({
|
|
96
|
+
config: label.primaryText,
|
|
97
|
+
id: primaryMessageId,
|
|
98
|
+
type: "jsx",
|
|
99
|
+
});
|
|
87
100
|
}
|
|
88
|
-
if (label.secondaryText) {
|
|
101
|
+
if ("secondaryText" in label && label.secondaryText) {
|
|
89
102
|
const secondaryMessageId = `${messageId}.secondary`;
|
|
90
|
-
textLabelParts.push(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
textLabelParts.push((0, intl_1.generateFormattedMessage)({
|
|
104
|
+
config: label.secondaryText,
|
|
105
|
+
id: secondaryMessageId,
|
|
106
|
+
type: "intlCall",
|
|
107
|
+
}));
|
|
108
|
+
gridCellContentProps.secondaryText = (0, intl_1.generateFormattedMessage)({
|
|
109
|
+
config: label.secondaryText,
|
|
110
|
+
id: secondaryMessageId,
|
|
111
|
+
type: "jsx",
|
|
112
|
+
});
|
|
95
113
|
}
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
gridCellContentProps.icon = `<${label.icon
|
|
114
|
+
if ("icon" in label) {
|
|
115
|
+
if (typeof label.icon === "string") {
|
|
116
|
+
gridCellContentProps.icon = `<${label.icon}Icon />`;
|
|
99
117
|
}
|
|
100
|
-
else {
|
|
101
|
-
|
|
102
|
-
|
|
118
|
+
else if (typeof label.icon === "object") {
|
|
119
|
+
if ("import" in label.icon) {
|
|
120
|
+
gridCellContentProps.icon = `<${label.icon.name} />`;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const _a = label.icon, { name } = _a, iconProps = __rest(_a, ["name"]);
|
|
124
|
+
gridCellContentProps.icon = `<${name}Icon
|
|
103
125
|
${Object.entries(iconProps)
|
|
104
|
-
|
|
105
|
-
|
|
126
|
+
.map(([key, value]) => `${key}="${value}"`)
|
|
127
|
+
.join("\n")}
|
|
106
128
|
/>`;
|
|
129
|
+
}
|
|
107
130
|
}
|
|
108
131
|
}
|
|
109
132
|
const gridCellContent = `<GridCellContent
|
|
@@ -380,7 +403,7 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
380
403
|
const enumType = gqlIntrospection.__schema.types.find((t) => t.kind === "ENUM" && t.name === introspectionFieldType.name);
|
|
381
404
|
(_a = column.values) === null || _a === void 0 ? void 0 : _a.forEach((value) => {
|
|
382
405
|
var _a;
|
|
383
|
-
if (typeof value === "object" && typeof value.label === "object" &&
|
|
406
|
+
if (typeof value === "object" && typeof value.label === "object" && "icon" in value.label) {
|
|
384
407
|
if (typeof value.label.icon === "string") {
|
|
385
408
|
iconsToImport.push(value.label.icon);
|
|
386
409
|
}
|
|
@@ -677,10 +700,19 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
677
700
|
renderHeader: column.headerInfoTooltip
|
|
678
701
|
? `() => (
|
|
679
702
|
<>
|
|
680
|
-
<GridColumnHeaderTitle label={
|
|
703
|
+
<GridColumnHeaderTitle label={${(0, intl_1.generateFormattedMessage)({
|
|
704
|
+
config: column.headerName,
|
|
705
|
+
id: `${instanceGqlType}.${column.name}`,
|
|
706
|
+
defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(column.name),
|
|
707
|
+
type: "intlCall",
|
|
708
|
+
})}} columnWidth= {${tooltipColumnWidth}}
|
|
681
709
|
/>
|
|
682
710
|
<Tooltip
|
|
683
|
-
title={
|
|
711
|
+
title={${(0, intl_1.generateFormattedMessage)({
|
|
712
|
+
config: column.headerInfoTooltip,
|
|
713
|
+
id: `${instanceGqlType}.${column.name}.tooltip`,
|
|
714
|
+
type: "jsx",
|
|
715
|
+
})}}
|
|
684
716
|
>
|
|
685
717
|
<InfoIcon sx={{ marginLeft: 1 }} />
|
|
686
718
|
</Tooltip>
|
|
@@ -689,7 +721,12 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
689
721
|
: undefined,
|
|
690
722
|
headerName: column.headerName === ""
|
|
691
723
|
? `""`
|
|
692
|
-
:
|
|
724
|
+
: (0, intl_1.generateFormattedMessage)({
|
|
725
|
+
config: column.headerName,
|
|
726
|
+
id: `${instanceGqlType}.${column.name}`,
|
|
727
|
+
defaultMessage: (0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(column.name),
|
|
728
|
+
type: "intlCall",
|
|
729
|
+
}),
|
|
693
730
|
type: column.gridType ? `"${column.gridType}"` : undefined,
|
|
694
731
|
filterable: (!column.filterOperators && !filterFields.includes(column.name)) || allowRowReordering ? `false` : undefined,
|
|
695
732
|
sortable: (!sortFields.includes(column.name) || allowRowReordering) && !column.sortBy ? `false` : undefined,
|
|
@@ -717,8 +754,18 @@ function generateGrid({ exportName, baseOutputFilename, targetDirectory, gqlIntr
|
|
|
717
754
|
.join(",\n")},
|
|
718
755
|
${showActionsColumn
|
|
719
756
|
? tsCodeRecordToString(Object.assign(Object.assign({ field: '"actions"', headerName: actionsColumnHeaderName
|
|
720
|
-
?
|
|
721
|
-
|
|
757
|
+
? (0, intl_1.generateFormattedMessage)({
|
|
758
|
+
config: actionsColumnHeaderName,
|
|
759
|
+
id: `${instanceGqlType}.actions`,
|
|
760
|
+
type: "intlCall",
|
|
761
|
+
})
|
|
762
|
+
: `""`, sortable: "false", filterable: "false", type: '"actions"', align: '"right"', pinned: `"${actionsColumnPinned}"`, width: forwardRowAction ? "actionsColumnWidth" : actionsColumnWidth, visible: actionsColumnVisible && `theme.breakpoints.${actionsColumnVisible}` }, restActionsColumnConfig), { headerInfoTooltip: restActionsColumnConfig.headerInfoTooltip
|
|
763
|
+
? (0, intl_1.generateFormattedMessage)({
|
|
764
|
+
config: restActionsColumnConfig.headerInfoTooltip,
|
|
765
|
+
id: `${instanceGqlType}.actions`,
|
|
766
|
+
type: "intlCall",
|
|
767
|
+
})
|
|
768
|
+
: undefined, disableExport: config.excelExport ? "true" : undefined, renderCell: `(params) => {
|
|
722
769
|
return (
|
|
723
770
|
<>
|
|
724
771
|
${(actionsColumnComponent === null || actionsColumnComponent === void 0 ? void 0 : actionsColumnComponent.name) ? `<${actionsColumnComponent.name} {...params} />` : ""}${allowEditing
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type FormattedMessageElement } from "../generate-command";
|
|
1
2
|
type Options = {
|
|
2
3
|
componentName: string;
|
|
3
4
|
forwardToolbarAction: boolean | undefined;
|
|
@@ -7,7 +8,7 @@ type Options = {
|
|
|
7
8
|
allowAdding: boolean;
|
|
8
9
|
instanceGqlType: string;
|
|
9
10
|
gqlType: string;
|
|
10
|
-
newEntryText: string | undefined;
|
|
11
|
+
newEntryText: string | FormattedMessageElement | undefined;
|
|
11
12
|
fragmentName: string;
|
|
12
13
|
};
|
|
13
14
|
export declare const generateGridToolbar: ({ componentName, forwardToolbarAction, hasSearch, hasFilter, excelExport, allowAdding, instanceGqlType, gqlType, newEntryText, fragmentName, }: Options) => string;
|
|
@@ -14,7 +14,12 @@ const generateGridToolbar = ({ componentName, forwardToolbarAction, hasSearch, h
|
|
|
14
14
|
<FillSpace />
|
|
15
15
|
${renderToolbarActions({
|
|
16
16
|
forwardToolbarAction,
|
|
17
|
-
addItemText: (0, intl_1.
|
|
17
|
+
addItemText: (0, intl_1.generateFormattedMessage)({
|
|
18
|
+
config: newEntryText,
|
|
19
|
+
id: `${instanceGqlType}.${(0, change_case_1.camelCase)(fragmentName)}.newEntry`,
|
|
20
|
+
defaultMessage: `New ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(gqlType)}`,
|
|
21
|
+
type: "jsx",
|
|
22
|
+
}),
|
|
18
23
|
excelExport,
|
|
19
24
|
allowAdding,
|
|
20
25
|
})}
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { type FormattedMessageElement } from "../generate-command";
|
|
2
|
+
type GenerateFormattedMessageOptions = ({
|
|
3
|
+
config: string | FormattedMessageElement | undefined;
|
|
4
|
+
defaultMessage: string;
|
|
5
|
+
} | {
|
|
6
|
+
config: string | FormattedMessageElement;
|
|
7
|
+
}) & {
|
|
8
|
+
id: string;
|
|
9
|
+
type: "jsx" | "intlCall";
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Generates a <FormattedMessage> JSX element or an intl.formatMessage call string supporting <FormattedMessage> config objects.
|
|
13
|
+
*
|
|
14
|
+
* either config or defaultMessage is required
|
|
15
|
+
*/
|
|
16
|
+
export declare const generateFormattedMessage: (options: GenerateFormattedMessageOptions) => string;
|
|
17
|
+
export {};
|
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
exports.generateFormattedMessage = void 0;
|
|
4
|
+
const runtimeTypeGuards_1 = require("./runtimeTypeGuards");
|
|
5
|
+
/**
|
|
6
|
+
* Generates a <FormattedMessage> JSX element or an intl.formatMessage call string supporting <FormattedMessage> config objects.
|
|
7
|
+
*
|
|
8
|
+
* either config or defaultMessage is required
|
|
9
|
+
*/
|
|
10
|
+
const generateFormattedMessage = (options) => {
|
|
11
|
+
let id = options.id;
|
|
12
|
+
let defaultMessage = "";
|
|
13
|
+
if ("defaultMessage" in options) {
|
|
14
|
+
defaultMessage = options.defaultMessage;
|
|
15
|
+
}
|
|
16
|
+
if ((0, runtimeTypeGuards_1.isGeneratorConfigFormattedMessage)(options.config)) {
|
|
17
|
+
id = options.config.formattedMessageId;
|
|
18
|
+
defaultMessage = options.config.defaultMessage;
|
|
19
|
+
}
|
|
20
|
+
else if (typeof options.config === "string") {
|
|
21
|
+
defaultMessage = options.config;
|
|
22
|
+
}
|
|
23
|
+
if (options.type === "jsx") {
|
|
24
|
+
return `<FormattedMessage id=${JSON.stringify(id)} defaultMessage=${JSON.stringify(defaultMessage)} />`;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return `intl.formatMessage({ id: ${JSON.stringify(id)}, defaultMessage: ${JSON.stringify(defaultMessage)} })`;
|
|
28
|
+
}
|
|
6
29
|
};
|
|
7
|
-
exports.
|
|
30
|
+
exports.generateFormattedMessage = generateFormattedMessage;
|
|
@@ -17,4 +17,12 @@ type GeneratorConfigCode = {
|
|
|
17
17
|
* Type Guard used by generator runtime for places where runtime vs. configtime types mismatch
|
|
18
18
|
*/
|
|
19
19
|
export declare function isGeneratorConfigCode(value: unknown): value is GeneratorConfigCode;
|
|
20
|
+
type GeneratorConfigFormattedMessage = {
|
|
21
|
+
formattedMessageId: string;
|
|
22
|
+
defaultMessage: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Type Guard used by generator runtime for places where runtime vs. configtime types mismatch
|
|
26
|
+
*/
|
|
27
|
+
export declare function isGeneratorConfigFormattedMessage(value: unknown): value is GeneratorConfigFormattedMessage;
|
|
20
28
|
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isGeneratorConfigImport = isGeneratorConfigImport;
|
|
4
4
|
exports.isGeneratorConfigCode = isGeneratorConfigCode;
|
|
5
|
+
exports.isGeneratorConfigFormattedMessage = isGeneratorConfigFormattedMessage;
|
|
5
6
|
/**
|
|
6
7
|
* Type Guard used by generator runtime for places where runtime vs. configtime types mismatch
|
|
7
8
|
*/
|
|
@@ -20,3 +21,12 @@ function isGeneratorConfigCode(value) {
|
|
|
20
21
|
}
|
|
21
22
|
return false;
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Type Guard used by generator runtime for places where runtime vs. configtime types mismatch
|
|
26
|
+
*/
|
|
27
|
+
function isGeneratorConfigFormattedMessage(value) {
|
|
28
|
+
if (value && typeof value === "object" && "formattedMessageId" in value) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/admin-generator",
|
|
3
|
-
"version": "8.11.0-canary-
|
|
3
|
+
"version": "8.11.0-canary-20251211150434",
|
|
4
4
|
"description": "Comet Admin Generator CLI tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/admin/admin-generator",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"rimraf": "^6.1.2",
|
|
49
49
|
"ts-jest": "^29.4.0",
|
|
50
50
|
"typescript": "5.9.3",
|
|
51
|
-
"@comet/admin": "8.11.0-canary-
|
|
52
|
-
"@comet/admin-icons": "8.11.0-canary-
|
|
53
|
-
"@comet/cms-admin": "8.11.0-canary-
|
|
54
|
-
"@comet/eslint-config": "8.11.0-canary-
|
|
51
|
+
"@comet/admin": "8.11.0-canary-20251211150434",
|
|
52
|
+
"@comet/admin-icons": "8.11.0-canary-20251211150434",
|
|
53
|
+
"@comet/cms-admin": "8.11.0-canary-20251211150434",
|
|
54
|
+
"@comet/eslint-config": "8.11.0-canary-20251211150434"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=22.0.0"
|