@beseif-solutions/prow-core 0.3.11 → 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.
|
@@ -21,6 +21,7 @@ const commonFieldSchema = () => joi_1.default.object({
|
|
|
21
21
|
as_password: joi_1.default.bool(),
|
|
22
22
|
show: joi_1.default.bool(),
|
|
23
23
|
show_label: joi_1.default.bool().default(true),
|
|
24
|
+
t: joi_1.default.string(),
|
|
24
25
|
as_array: joi_1.default.bool(),
|
|
25
26
|
array_min: joi_1.default.when(`as_array`, {
|
|
26
27
|
is: true,
|
|
@@ -101,7 +102,7 @@ const numberInputFieldSchema = () => joi_1.default.object({
|
|
|
101
102
|
float: joi_1.default.bool(),
|
|
102
103
|
decimals: joi_1.default.when(`float`, {
|
|
103
104
|
is: true,
|
|
104
|
-
then: joi_1.default.number()
|
|
105
|
+
then: joi_1.default.number(),
|
|
105
106
|
otherwise: joi_1.default.forbidden(),
|
|
106
107
|
}),
|
|
107
108
|
})
|
|
@@ -318,12 +319,12 @@ const getSimpleFieldSchema = (field) => {
|
|
|
318
319
|
typeSchema = typeSchema.max(field.max);
|
|
319
320
|
}
|
|
320
321
|
if (typeof field.float === `boolean`) {
|
|
321
|
-
if (field.float) {
|
|
322
|
-
typeSchema = typeSchema.precision(field.decimals || 2);
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
322
|
+
if (!field.float) {
|
|
325
323
|
typeSchema = typeSchema.precision(0);
|
|
326
324
|
}
|
|
325
|
+
else if (field.decimals) {
|
|
326
|
+
typeSchema = typeSchema.precision(field.decimals);
|
|
327
|
+
}
|
|
327
328
|
}
|
|
328
329
|
break;
|
|
329
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
|
} | {
|
|
@@ -194,6 +195,7 @@ const commonFieldSchema = () =>
|
|
|
194
195
|
as_password: Joi.bool(),
|
|
195
196
|
show: Joi.bool(),
|
|
196
197
|
show_label: Joi.bool().default(true),
|
|
198
|
+
t: Joi.string(),
|
|
197
199
|
as_array: Joi.bool(),
|
|
198
200
|
array_min: Joi.when(`as_array`, {
|
|
199
201
|
is: true,
|
|
@@ -302,7 +304,7 @@ const numberInputFieldSchema = () =>
|
|
|
302
304
|
float: Joi.bool(),
|
|
303
305
|
decimals: Joi.when(`float`, {
|
|
304
306
|
is: true,
|
|
305
|
-
then: Joi.number()
|
|
307
|
+
then: Joi.number(),
|
|
306
308
|
otherwise: Joi.forbidden(),
|
|
307
309
|
}),
|
|
308
310
|
})
|
|
@@ -521,10 +523,10 @@ const getSimpleFieldSchema = (field: Field) => {
|
|
|
521
523
|
if (field.max) { typeSchema = (typeSchema as NumberSchema).max(field.max); }
|
|
522
524
|
// don't check precision if float is not set
|
|
523
525
|
if (typeof field.float === `boolean`) {
|
|
524
|
-
if (field.float) {
|
|
525
|
-
typeSchema = (typeSchema as NumberSchema).precision(field.decimals || 2);
|
|
526
|
-
} else {
|
|
526
|
+
if (!field.float) {
|
|
527
527
|
typeSchema = (typeSchema as NumberSchema).precision(0);
|
|
528
|
+
} else if (field.decimals) {
|
|
529
|
+
typeSchema = (typeSchema as NumberSchema).precision(field.decimals);
|
|
528
530
|
}
|
|
529
531
|
}
|
|
530
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
|
|