@beseif-solutions/prow-core 0.3.12 → 0.3.13
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.
|
@@ -12,6 +12,7 @@ type Common = {
|
|
|
12
12
|
as_password?: boolean;
|
|
13
13
|
show?: boolean;
|
|
14
14
|
show_label?: boolean;
|
|
15
|
+
t?: string;
|
|
15
16
|
} & ({
|
|
16
17
|
as_array?: false;
|
|
17
18
|
} | {
|
|
@@ -102,10 +103,8 @@ export type SelectFieldChoice<Values = string | number | boolean | File, Extend
|
|
|
102
103
|
key: string;
|
|
103
104
|
value: Values;
|
|
104
105
|
} & Extend;
|
|
105
|
-
declare const RICH_TEXT_PROPS: readonly ["bold", "italic", "underline", "strike", "code", "heading", "blockquote", "codeBlock", "bulletList", "orderedList", "horizontalRule", "hardBreak"];
|
|
106
106
|
type CustomDisplayTextField = {
|
|
107
107
|
format: `textarea` | `rich-text` | `markdown`;
|
|
108
|
-
props?: typeof RICH_TEXT_PROPS[number][];
|
|
109
108
|
};
|
|
110
109
|
type IDETextField = {
|
|
111
110
|
format: `code`;
|
|
@@ -9,20 +9,6 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
9
9
|
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
10
10
|
const context_1 = __importDefault(require("./context"));
|
|
11
11
|
const where_1 = require("./where");
|
|
12
|
-
const RICH_TEXT_PROPS = [
|
|
13
|
-
`bold`,
|
|
14
|
-
`italic`,
|
|
15
|
-
`underline`,
|
|
16
|
-
`strike`,
|
|
17
|
-
`code`,
|
|
18
|
-
`heading`,
|
|
19
|
-
`blockquote`,
|
|
20
|
-
`codeBlock`,
|
|
21
|
-
`bulletList`,
|
|
22
|
-
`orderedList`,
|
|
23
|
-
`horizontalRule`,
|
|
24
|
-
`hardBreak`,
|
|
25
|
-
];
|
|
26
12
|
const conditionSchema = () => joi_1.default.object({
|
|
27
13
|
condition: joi_1.default.object().required(),
|
|
28
14
|
overrides: joi_1.default.object().required(),
|
|
@@ -35,6 +21,7 @@ const commonFieldSchema = () => joi_1.default.object({
|
|
|
35
21
|
as_password: joi_1.default.bool(),
|
|
36
22
|
show: joi_1.default.bool(),
|
|
37
23
|
show_label: joi_1.default.bool().default(true),
|
|
24
|
+
t: joi_1.default.string(),
|
|
38
25
|
as_array: joi_1.default.bool(),
|
|
39
26
|
array_min: joi_1.default.when(`as_array`, {
|
|
40
27
|
is: true,
|
|
@@ -107,11 +94,6 @@ const stringInputFieldSchema = () => joi_1.default.object({
|
|
|
107
94
|
then: joi_1.default.string(),
|
|
108
95
|
otherwise: joi_1.default.forbidden(),
|
|
109
96
|
}),
|
|
110
|
-
props: joi_1.default.when(`format`, {
|
|
111
|
-
is: joi_1.default.valid(`textarea`, `markdown`, `rich-text`),
|
|
112
|
-
then: joi_1.default.array().items(joi_1.default.string().valid(...RICH_TEXT_PROPS)),
|
|
113
|
-
otherwise: joi_1.default.forbidden(),
|
|
114
|
-
}),
|
|
115
97
|
}));
|
|
116
98
|
const numberInputFieldSchema = () => joi_1.default.object({
|
|
117
99
|
default: defaultSchema(joi_1.default.number()),
|
|
@@ -120,7 +102,7 @@ const numberInputFieldSchema = () => joi_1.default.object({
|
|
|
120
102
|
float: joi_1.default.bool(),
|
|
121
103
|
decimals: joi_1.default.when(`float`, {
|
|
122
104
|
is: true,
|
|
123
|
-
then: joi_1.default.number()
|
|
105
|
+
then: joi_1.default.number(),
|
|
124
106
|
otherwise: joi_1.default.forbidden(),
|
|
125
107
|
}),
|
|
126
108
|
})
|
|
@@ -337,12 +319,12 @@ const getSimpleFieldSchema = (field) => {
|
|
|
337
319
|
typeSchema = typeSchema.max(field.max);
|
|
338
320
|
}
|
|
339
321
|
if (typeof field.float === `boolean`) {
|
|
340
|
-
if (field.float) {
|
|
341
|
-
typeSchema = typeSchema.precision(field.decimals || 2);
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
322
|
+
if (!field.float) {
|
|
344
323
|
typeSchema = typeSchema.precision(0);
|
|
345
324
|
}
|
|
325
|
+
else if (field.decimals) {
|
|
326
|
+
typeSchema = typeSchema.precision(field.decimals);
|
|
327
|
+
}
|
|
346
328
|
}
|
|
347
329
|
break;
|
|
348
330
|
case `dict`:
|
|
@@ -93,18 +93,19 @@ const i18n = (options) => {
|
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
exports.i18n = i18n;
|
|
96
|
-
const localizeField = (t, element, field,
|
|
97
|
-
const key = lodash_1.default.compact([parent, field.key]).join(`.`);
|
|
98
|
-
field.
|
|
99
|
-
field.
|
|
96
|
+
const localizeField = (t, element, field, recursive = {}) => {
|
|
97
|
+
const key = lodash_1.default.compact([recursive.parent, field.key]).join(`.`);
|
|
98
|
+
const root = field.t || recursive.t || `${element}.fields`;
|
|
99
|
+
field.label = t(`${root}.${key}.label`, { fallback: true });
|
|
100
|
+
field.help = t(`${root}.${key}.help`);
|
|
100
101
|
if (field.type === `dict` && field.items) {
|
|
101
|
-
field.items = field.items.map((f) => localizeField(t, element, f, `${key}.items
|
|
102
|
+
field.items = field.items.map((f) => localizeField(t, element, f, { parent: `${key}.items`, t: field.t }));
|
|
102
103
|
}
|
|
103
104
|
else if (`format` in field && field.format === `select` && lodash_1.default.isArray(field.choices)) {
|
|
104
105
|
field.choices = field.choices.map((fc) => ({
|
|
105
106
|
...fc,
|
|
106
|
-
label: t(`${
|
|
107
|
-
help: t(`${
|
|
107
|
+
label: t(`${root}.${key}.choices.${fc.key}.label`, { fallback: true }),
|
|
108
|
+
help: t(`${root}.${key}.choices.${fc.key}.help`),
|
|
108
109
|
}));
|
|
109
110
|
}
|
|
110
111
|
return field;
|
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ type Common = {
|
|
|
17
17
|
as_password?: boolean,
|
|
18
18
|
show?: boolean,
|
|
19
19
|
show_label?: boolean,
|
|
20
|
+
t?: string,
|
|
20
21
|
} & ({
|
|
21
22
|
as_array?: false,
|
|
22
23
|
} | {
|
|
@@ -156,24 +157,8 @@ export type SelectFieldChoice<Values = string | number | boolean | File, Extend
|
|
|
156
157
|
} & Extend;
|
|
157
158
|
|
|
158
159
|
/* custom display configuration */
|
|
159
|
-
const RICH_TEXT_PROPS = [
|
|
160
|
-
`bold`,
|
|
161
|
-
`italic`,
|
|
162
|
-
`underline`,
|
|
163
|
-
`strike`,
|
|
164
|
-
`code`,
|
|
165
|
-
`heading`,
|
|
166
|
-
`blockquote`,
|
|
167
|
-
`codeBlock`,
|
|
168
|
-
`bulletList`,
|
|
169
|
-
`orderedList`,
|
|
170
|
-
`horizontalRule`,
|
|
171
|
-
`hardBreak`,
|
|
172
|
-
] as const;
|
|
173
|
-
|
|
174
160
|
type CustomDisplayTextField = {
|
|
175
161
|
format: `textarea` | `rich-text` | `markdown`,
|
|
176
|
-
props?: typeof RICH_TEXT_PROPS[number][];
|
|
177
162
|
};
|
|
178
163
|
|
|
179
164
|
type IDETextField = {
|
|
@@ -210,6 +195,7 @@ const commonFieldSchema = () =>
|
|
|
210
195
|
as_password: Joi.bool(),
|
|
211
196
|
show: Joi.bool(),
|
|
212
197
|
show_label: Joi.bool().default(true),
|
|
198
|
+
t: Joi.string(),
|
|
213
199
|
as_array: Joi.bool(),
|
|
214
200
|
array_min: Joi.when(`as_array`, {
|
|
215
201
|
is: true,
|
|
@@ -307,13 +293,6 @@ const stringInputFieldSchema = () =>
|
|
|
307
293
|
then: Joi.string(),
|
|
308
294
|
otherwise: Joi.forbidden(),
|
|
309
295
|
}),
|
|
310
|
-
props: Joi.when(`format`, {
|
|
311
|
-
is: Joi.valid(`textarea`, `markdown`, `rich-text`),
|
|
312
|
-
then: Joi.array().items(
|
|
313
|
-
Joi.string().valid(...RICH_TEXT_PROPS)
|
|
314
|
-
),
|
|
315
|
-
otherwise: Joi.forbidden(),
|
|
316
|
-
}),
|
|
317
296
|
})
|
|
318
297
|
);
|
|
319
298
|
|
|
@@ -325,7 +304,7 @@ const numberInputFieldSchema = () =>
|
|
|
325
304
|
float: Joi.bool(),
|
|
326
305
|
decimals: Joi.when(`float`, {
|
|
327
306
|
is: true,
|
|
328
|
-
then: Joi.number()
|
|
307
|
+
then: Joi.number(),
|
|
329
308
|
otherwise: Joi.forbidden(),
|
|
330
309
|
}),
|
|
331
310
|
})
|
|
@@ -544,10 +523,10 @@ const getSimpleFieldSchema = (field: Field) => {
|
|
|
544
523
|
if (field.max) { typeSchema = (typeSchema as NumberSchema).max(field.max); }
|
|
545
524
|
// don't check precision if float is not set
|
|
546
525
|
if (typeof field.float === `boolean`) {
|
|
547
|
-
if (field.float) {
|
|
548
|
-
typeSchema = (typeSchema as NumberSchema).precision(field.decimals || 2);
|
|
549
|
-
} else {
|
|
526
|
+
if (!field.float) {
|
|
550
527
|
typeSchema = (typeSchema as NumberSchema).precision(0);
|
|
528
|
+
} else if (field.decimals) {
|
|
529
|
+
typeSchema = (typeSchema as NumberSchema).precision(field.decimals);
|
|
551
530
|
}
|
|
552
531
|
}
|
|
553
532
|
|
|
@@ -134,19 +134,22 @@ const localizeField = (
|
|
|
134
134
|
t: ReturnType<typeof i18n>[`t`],
|
|
135
135
|
element: string,
|
|
136
136
|
field: Field<LocalizedField>,
|
|
137
|
-
parent =
|
|
137
|
+
recursive: { parent?: string, t?: string } = {},
|
|
138
138
|
): Field<LocalizedField> => {
|
|
139
|
-
const key = _.compact([parent, field.key]).join(`.`);
|
|
140
|
-
|
|
141
|
-
field.
|
|
139
|
+
const key = _.compact([recursive.parent, field.key]).join(`.`);
|
|
140
|
+
|
|
141
|
+
const root = field.t || recursive.t || `${element}.fields`;
|
|
142
|
+
|
|
143
|
+
field.label = t(`${root}.${key}.label`, { fallback: true });
|
|
144
|
+
field.help = t(`${root}.${key}.help`);
|
|
142
145
|
|
|
143
146
|
if (field.type === `dict` && field.items) {
|
|
144
|
-
field.items = field.items.map((f) => localizeField(t, element, f, `${key}.items
|
|
147
|
+
field.items = field.items.map((f) => localizeField(t, element, f, { parent: `${key}.items`, t: field.t }));
|
|
145
148
|
} else if (`format` in field && field.format === `select` && _.isArray(field.choices)) {
|
|
146
149
|
field.choices = field.choices.map((fc: SelectFieldChoice<any, LocalizedField>) => ({
|
|
147
150
|
...fc,
|
|
148
|
-
label: t(`${
|
|
149
|
-
help: t(`${
|
|
151
|
+
label: t(`${root}.${key}.choices.${fc.key}.label`, { fallback: true }),
|
|
152
|
+
help: t(`${root}.${key}.choices.${fc.key}.help`),
|
|
150
153
|
}));
|
|
151
154
|
}
|
|
152
155
|
|