@jsonforms/core 3.0.0-alpha.2 → 3.0.0-alpha.3
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/docs/assets/js/search.json +1 -1
- package/docs/globals.html +159 -57
- package/docs/index.html +9 -0
- package/docs/interfaces/arraycontrolprops.html +21 -21
- package/docs/interfaces/arraylayoutprops.html +21 -21
- package/docs/interfaces/cellprops.html +12 -12
- package/docs/interfaces/combinatorrendererprops.html +13 -13
- package/docs/interfaces/controlprops.html +16 -16
- package/docs/interfaces/controlstate.html +2 -2
- package/docs/interfaces/controlwithdetailprops.html +17 -17
- package/docs/interfaces/dispatchcellprops.html +10 -10
- package/docs/interfaces/dispatchcellstateprops.html +10 -10
- package/docs/interfaces/dispatchpropsofarraycontrol.html +4 -4
- package/docs/interfaces/dispatchpropsofcontrol.html +1 -1
- package/docs/interfaces/dispatchpropsofmultienumcontrol.html +2 -2
- package/docs/interfaces/enumcellprops.html +13 -13
- package/docs/interfaces/enumoption.html +2 -2
- package/docs/interfaces/jsonformsprops.html +9 -9
- package/docs/interfaces/layoutprops.html +10 -10
- package/docs/interfaces/ownpropsofcell.html +9 -9
- package/docs/interfaces/ownpropsofcontrol.html +9 -9
- package/docs/interfaces/ownpropsofenum.html +1 -1
- package/docs/interfaces/ownpropsofenumcell.html +10 -10
- package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
- package/docs/interfaces/ownpropsoflayout.html +9 -9
- package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
- package/docs/interfaces/ownpropsofrenderer.html +8 -8
- package/docs/interfaces/rendererprops.html +9 -9
- package/docs/interfaces/statepropsofarraycontrol.html +17 -17
- package/docs/interfaces/statepropsofarraylayout.html +17 -17
- package/docs/interfaces/statepropsofcell.html +11 -11
- package/docs/interfaces/statepropsofcombinator.html +12 -12
- package/docs/interfaces/statepropsofcontrol.html +15 -15
- package/docs/interfaces/statepropsofcontrolwithdetail.html +16 -16
- package/docs/interfaces/statepropsofenumcell.html +12 -12
- package/docs/interfaces/statepropsofjsonformsrenderer.html +9 -9
- package/docs/interfaces/statepropsoflayout.html +10 -10
- package/docs/interfaces/statepropsofmasteritem.html +7 -7
- package/docs/interfaces/statepropsofrenderer.html +9 -9
- package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
- package/docs/interfaces/withclassname.html +1 -1
- package/lib/i18n/i18nUtil.d.ts +10 -3
- package/lib/i18n/i18nUtil.js +29 -16
- package/lib/i18n/i18nUtil.js.map +1 -1
- package/lib/jsonforms-core.js +5 -5
- package/lib/jsonforms-core.js.map +1 -1
- package/lib/reducers/reducers.d.ts +2 -10
- package/lib/reducers/reducers.js +1 -10
- package/lib/reducers/reducers.js.map +1 -1
- package/lib/util/cell.js +5 -6
- package/lib/util/cell.js.map +1 -1
- package/lib/util/renderer.d.ts +3 -2
- package/lib/util/renderer.js +20 -22
- package/lib/util/renderer.js.map +1 -1
- package/package.json +2 -2
- package/src/i18n/i18nUtil.ts +43 -14
- package/src/reducers/reducers.ts +0 -20
- package/src/util/cell.ts +4 -4
- package/src/util/renderer.ts +14 -15
- package/test/i18n/i18nUtil.test.ts +48 -0
- package/test/reducers/core.test.ts +2 -3
- package/test/util/renderer.test.ts +72 -40
package/src/util/renderer.ts
CHANGED
|
@@ -55,9 +55,7 @@ import { isVisible } from './runtime';
|
|
|
55
55
|
import { CoreActions, update } from '../actions';
|
|
56
56
|
import { ErrorObject } from 'ajv';
|
|
57
57
|
import { JsonFormsState } from '../store';
|
|
58
|
-
import { getCombinedErrorMessage, getI18nKey,
|
|
59
|
-
|
|
60
|
-
export { JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry };
|
|
58
|
+
import { getCombinedErrorMessage, getI18nKey, getI18nKeyPrefix, Translator } from '../i18n';
|
|
61
59
|
|
|
62
60
|
const isRequired = (
|
|
63
61
|
schema: JsonSchema,
|
|
@@ -195,7 +193,7 @@ export const enumToEnumOptionMapper = (
|
|
|
195
193
|
export const oneOfToEnumOptionMapper = (
|
|
196
194
|
e: any,
|
|
197
195
|
t?: Translator,
|
|
198
|
-
|
|
196
|
+
fallbackI18nKey?: string
|
|
199
197
|
): EnumOption => {
|
|
200
198
|
let label =
|
|
201
199
|
e.title ??
|
|
@@ -204,8 +202,8 @@ export const oneOfToEnumOptionMapper = (
|
|
|
204
202
|
// prefer schema keys as they can be more specialized
|
|
205
203
|
if (e.i18n) {
|
|
206
204
|
label = t(e.i18n, label);
|
|
207
|
-
} else if (
|
|
208
|
-
label = t(`${
|
|
205
|
+
} else if (fallbackI18nKey) {
|
|
206
|
+
label = t(`${fallbackI18nKey}.${label}`, label);
|
|
209
207
|
} else {
|
|
210
208
|
label = t(label, label);
|
|
211
209
|
}
|
|
@@ -464,9 +462,9 @@ export const mapStateToControlProps = (
|
|
|
464
462
|
const schema = resolvedSchema ?? rootSchema;
|
|
465
463
|
const t = getTranslator()(state);
|
|
466
464
|
const te = getErrorTranslator()(state);
|
|
467
|
-
const i18nLabel = t(getI18nKey(schema, uischema, 'label')
|
|
468
|
-
const i18nDescription = t(getI18nKey(schema, uischema, 'description')
|
|
469
|
-
const i18nErrorMessage = getCombinedErrorMessage(errors, te, t, schema, uischema);
|
|
465
|
+
const i18nLabel = t(getI18nKey(schema, uischema, path, 'label'), label);
|
|
466
|
+
const i18nDescription = t(getI18nKey(schema, uischema, path, 'description'), description);
|
|
467
|
+
const i18nErrorMessage = getCombinedErrorMessage(errors, te, t, schema, uischema, path);
|
|
470
468
|
|
|
471
469
|
return {
|
|
472
470
|
data,
|
|
@@ -518,14 +516,14 @@ export const mapStateToEnumControlProps = (
|
|
|
518
516
|
enumToEnumOptionMapper(
|
|
519
517
|
e,
|
|
520
518
|
getTranslator()(state),
|
|
521
|
-
props.uischema
|
|
519
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
522
520
|
)
|
|
523
521
|
) ||
|
|
524
522
|
(props.schema.const && [
|
|
525
523
|
enumToEnumOptionMapper(
|
|
526
524
|
props.schema.const,
|
|
527
525
|
getTranslator()(state),
|
|
528
|
-
props.uischema
|
|
526
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
529
527
|
)
|
|
530
528
|
]);
|
|
531
529
|
return {
|
|
@@ -551,7 +549,7 @@ export const mapStateToOneOfEnumControlProps = (
|
|
|
551
549
|
oneOfToEnumOptionMapper(
|
|
552
550
|
oneOfSubSchema,
|
|
553
551
|
getTranslator()(state),
|
|
554
|
-
props.uischema
|
|
552
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
555
553
|
)
|
|
556
554
|
);
|
|
557
555
|
return {
|
|
@@ -579,14 +577,14 @@ export const mapStateToMultiEnumControlProps = (
|
|
|
579
577
|
oneOfToEnumOptionMapper(
|
|
580
578
|
oneOfSubSchema,
|
|
581
579
|
state.jsonforms.i18n?.translate,
|
|
582
|
-
props.uischema
|
|
580
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
583
581
|
)
|
|
584
582
|
)) ||
|
|
585
583
|
items?.enum?.map(e =>
|
|
586
584
|
enumToEnumOptionMapper(
|
|
587
585
|
e,
|
|
588
586
|
state.jsonforms.i18n?.translate,
|
|
589
|
-
props.uischema
|
|
587
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
590
588
|
)
|
|
591
589
|
);
|
|
592
590
|
return {
|
|
@@ -923,7 +921,7 @@ export interface StatePropsOfCombinator extends OwnPropsOfControl {
|
|
|
923
921
|
data: any;
|
|
924
922
|
}
|
|
925
923
|
|
|
926
|
-
const mapStateToCombinatorRendererProps = (
|
|
924
|
+
export const mapStateToCombinatorRendererProps = (
|
|
927
925
|
state: JsonFormsState,
|
|
928
926
|
ownProps: OwnPropsOfControl,
|
|
929
927
|
keyword: CombinatorKeyword
|
|
@@ -1052,6 +1050,7 @@ export const mapStateToArrayLayoutProps = (
|
|
|
1052
1050
|
getErrorTranslator()(state),
|
|
1053
1051
|
getTranslator()(state),
|
|
1054
1052
|
undefined,
|
|
1053
|
+
undefined,
|
|
1055
1054
|
undefined
|
|
1056
1055
|
);
|
|
1057
1056
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
The MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2017-2021 EclipseSource Munich
|
|
5
|
+
https://github.com/eclipsesource/jsonforms
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
import test from 'ava';
|
|
26
|
+
|
|
27
|
+
import { transformPathToI18nPrefix } from '../../src';
|
|
28
|
+
|
|
29
|
+
test('transformPathToI18nPrefix returns root when empty', t => {
|
|
30
|
+
t.is(transformPathToI18nPrefix(''), 'root');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('transformPathToI18nPrefix does not modify non-array paths', t => {
|
|
34
|
+
t.is(transformPathToI18nPrefix('foo'), 'foo');
|
|
35
|
+
t.is(transformPathToI18nPrefix('foo.bar'), 'foo.bar');
|
|
36
|
+
t.is(transformPathToI18nPrefix('bar3.foo2'), 'bar3.foo2');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('transformPathToI18nPrefix removes array indices', t => {
|
|
40
|
+
t.is(transformPathToI18nPrefix('foo.2.bar'), 'foo.bar');
|
|
41
|
+
t.is(transformPathToI18nPrefix('foo.234324234.bar'), 'foo.bar');
|
|
42
|
+
t.is(transformPathToI18nPrefix('foo.0.bar'), 'foo.bar');
|
|
43
|
+
t.is(transformPathToI18nPrefix('foo.0.bar.1.foobar'), 'foo.bar.foobar');
|
|
44
|
+
t.is(transformPathToI18nPrefix('3.foobar'), 'foobar');
|
|
45
|
+
t.is(transformPathToI18nPrefix('foobar.3'), 'foobar');
|
|
46
|
+
t.is(transformPathToI18nPrefix('foo1.23.b2ar3.1.5.foo'), 'foo1.b2ar3.foo');
|
|
47
|
+
t.is(transformPathToI18nPrefix('3'), 'root');
|
|
48
|
+
});
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import test from 'ava';
|
|
26
26
|
import Ajv from 'ajv';
|
|
27
27
|
import { coreReducer } from '../../src/reducers';
|
|
28
|
-
import { init, update, updateErrors } from '../../src/actions';
|
|
28
|
+
import { init, setSchema, setValidationMode, update, updateCore, updateErrors } from '../../src/actions';
|
|
29
29
|
import { JsonSchema } from '../../src/models/jsonSchema';
|
|
30
30
|
import {
|
|
31
31
|
errorAt,
|
|
@@ -34,9 +34,8 @@ import {
|
|
|
34
34
|
subErrorsAt
|
|
35
35
|
} from '../../src/reducers/core';
|
|
36
36
|
|
|
37
|
-
import { createAjv, updateCore } from '../../src';
|
|
38
|
-
import { setSchema, setValidationMode } from '../../lib';
|
|
39
37
|
import { cloneDeep } from 'lodash';
|
|
38
|
+
import { createAjv } from '../../src/util/validator';
|
|
40
39
|
|
|
41
40
|
test('core reducer should support v7', t => {
|
|
42
41
|
const schema: JsonSchema = {
|
|
@@ -23,47 +23,25 @@
|
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
import * as _ from 'lodash';
|
|
26
|
-
import { init, update, UPDATE_DATA, UpdateAction } from '../../src/actions';
|
|
27
26
|
import * as Redux from 'redux';
|
|
28
|
-
import {
|
|
29
|
-
clearAllIds,
|
|
30
|
-
computeLabel,
|
|
31
|
-
createAjv,
|
|
32
|
-
createDefaultValue,
|
|
33
|
-
mapDispatchToArrayControlProps,
|
|
34
|
-
mapDispatchToControlProps,
|
|
35
|
-
mapStateToArrayLayoutProps,
|
|
36
|
-
mapStateToControlProps,
|
|
37
|
-
mapStateToJsonFormsRendererProps,
|
|
38
|
-
mapStateToLayoutProps,
|
|
39
|
-
mapStateToOneOfProps,
|
|
40
|
-
mapStateToMultiEnumControlProps,
|
|
41
|
-
mapDispatchToMultiEnumProps
|
|
42
|
-
} from '../../src/util';
|
|
43
27
|
import configureStore from 'redux-mock-store';
|
|
44
28
|
import test from 'ava';
|
|
45
|
-
|
|
46
|
-
import {
|
|
47
|
-
ControlElement,
|
|
48
|
-
CoreActions,
|
|
49
|
-
coreReducer,
|
|
50
|
-
Dispatch,
|
|
51
|
-
JsonFormsCore,
|
|
52
|
-
JsonFormsState,
|
|
53
|
-
JsonSchema,
|
|
54
|
-
JsonSchema7,
|
|
55
|
-
mapStateToAnyOfProps,
|
|
56
|
-
OwnPropsOfControl,
|
|
57
|
-
rankWith,
|
|
58
|
-
RuleEffect,
|
|
59
|
-
UISchemaElement,
|
|
60
|
-
setValidationMode,
|
|
61
|
-
defaultJsonFormsI18nState,
|
|
62
|
-
i18nJsonSchema,
|
|
63
|
-
mapStateToEnumControlProps,
|
|
64
|
-
mapStateToOneOfEnumControlProps
|
|
65
|
-
} from '../../src';
|
|
29
|
+
|
|
66
30
|
import { ErrorObject } from 'ajv';
|
|
31
|
+
import { JsonFormsState } from '../../src/store';
|
|
32
|
+
import { coreReducer, JsonFormsCore } from '../../src/reducers/core';
|
|
33
|
+
import { Dispatch } from '../../src/util/type';
|
|
34
|
+
import { CoreActions, init, setValidationMode, update, UpdateAction, UPDATE_DATA } from '../../src/actions/actions';
|
|
35
|
+
import { ControlElement, RuleEffect, UISchemaElement } from '../../src/models/uischema';
|
|
36
|
+
import { computeLabel, createDefaultValue, mapDispatchToArrayControlProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAnyOfProps, mapStateToArrayLayoutProps, mapStateToControlProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLayoutProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, OwnPropsOfControl } from '../../src/util/renderer';
|
|
37
|
+
import { clearAllIds } from '../../src/util/ids';
|
|
38
|
+
import { generateDefaultUISchema } from '../../src/generators/uischema';
|
|
39
|
+
import { JsonSchema } from '../../src/models/jsonSchema';
|
|
40
|
+
import { rankWith } from '../../src/testers/testers';
|
|
41
|
+
import { createAjv } from '../../src/util/validator';
|
|
42
|
+
import { JsonSchema7 } from '../../src/models/jsonSchema7';
|
|
43
|
+
import { defaultJsonFormsI18nState } from '../../src/reducers/i18n';
|
|
44
|
+
import { i18nJsonSchema } from '../../src/i18n/i18nTypes';
|
|
67
45
|
|
|
68
46
|
const middlewares: Redux.Middleware[] = [];
|
|
69
47
|
const mockStore = configureStore<JsonFormsState>(middlewares);
|
|
@@ -1304,7 +1282,7 @@ test('mapStateToControlProps - i18n - default translation has no effect', t => {
|
|
|
1304
1282
|
t.is(props.description, undefined);
|
|
1305
1283
|
});
|
|
1306
1284
|
|
|
1307
|
-
test('mapStateToControlProps - i18n - translation via
|
|
1285
|
+
test('mapStateToControlProps - i18n - translation via path key', t => {
|
|
1308
1286
|
const ownProps = {
|
|
1309
1287
|
uischema: coreUISchema
|
|
1310
1288
|
};
|
|
@@ -1312,6 +1290,24 @@ test('mapStateToControlProps - i18n - translation via label key', t => {
|
|
|
1312
1290
|
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1313
1291
|
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1314
1292
|
switch(key){
|
|
1293
|
+
case 'firstName.label': return 'my translation';
|
|
1294
|
+
default: return defaultMessage;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1299
|
+
t.is(props.label, 'my translation');
|
|
1300
|
+
t.is(props.description, undefined);
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1303
|
+
test('mapStateToControlProps - i18n - translation via default message', t => {
|
|
1304
|
+
const ownProps = {
|
|
1305
|
+
uischema: coreUISchema
|
|
1306
|
+
};
|
|
1307
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1308
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1309
|
+
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1310
|
+
switch(defaultMessage){
|
|
1315
1311
|
case 'First Name': return 'my translation';
|
|
1316
1312
|
default: return defaultMessage;
|
|
1317
1313
|
}
|
|
@@ -1601,7 +1597,7 @@ test('mapStateToEnumControlProps - i18n - default translation has no effect', t
|
|
|
1601
1597
|
t.is(props.options[0].label, 'a');
|
|
1602
1598
|
});
|
|
1603
1599
|
|
|
1604
|
-
test('mapStateToEnumControlProps - i18n - label translation', t => {
|
|
1600
|
+
test('mapStateToEnumControlProps - i18n - path label translation', t => {
|
|
1605
1601
|
const ownProps = {
|
|
1606
1602
|
uischema: coreUISchema
|
|
1607
1603
|
};
|
|
@@ -1610,6 +1606,24 @@ test('mapStateToEnumControlProps - i18n - label translation', t => {
|
|
|
1610
1606
|
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1611
1607
|
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1612
1608
|
switch(key){
|
|
1609
|
+
case 'firstName.a': return 'my message';
|
|
1610
|
+
default: return defaultMessage;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
const props = mapStateToEnumControlProps(state, ownProps);
|
|
1615
|
+
t.is(props.options[0].label, 'my message');
|
|
1616
|
+
});
|
|
1617
|
+
|
|
1618
|
+
test('mapStateToEnumControlProps - i18n - defaultMessage translation', t => {
|
|
1619
|
+
const ownProps = {
|
|
1620
|
+
uischema: coreUISchema
|
|
1621
|
+
};
|
|
1622
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1623
|
+
state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
|
|
1624
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1625
|
+
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1626
|
+
switch(defaultMessage){
|
|
1613
1627
|
case 'a': return 'my message';
|
|
1614
1628
|
default: return defaultMessage;
|
|
1615
1629
|
}
|
|
@@ -1662,7 +1676,7 @@ test('mapStateToOneOfEnumControlProps- i18n - default translation has no effect'
|
|
|
1662
1676
|
t.is(props.options[0].label, 'foo');
|
|
1663
1677
|
});
|
|
1664
1678
|
|
|
1665
|
-
test('mapStateToOneOfEnumControlProps - i18n - label translation', t => {
|
|
1679
|
+
test('mapStateToOneOfEnumControlProps - i18n - path label translation', t => {
|
|
1666
1680
|
const ownProps = {
|
|
1667
1681
|
uischema: coreUISchema
|
|
1668
1682
|
};
|
|
@@ -1671,6 +1685,24 @@ test('mapStateToOneOfEnumControlProps - i18n - label translation', t => {
|
|
|
1671
1685
|
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1672
1686
|
state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
|
|
1673
1687
|
switch(key){
|
|
1688
|
+
case 'firstName.foo': return 'my message';
|
|
1689
|
+
default: return defaultMessage;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
const props = mapStateToOneOfEnumControlProps(state, ownProps);
|
|
1694
|
+
t.is(props.options[0].label, 'my message');
|
|
1695
|
+
});
|
|
1696
|
+
|
|
1697
|
+
test('mapStateToOneOfEnumControlProps - i18n - default message translation', t => {
|
|
1698
|
+
const ownProps = {
|
|
1699
|
+
uischema: coreUISchema
|
|
1700
|
+
};
|
|
1701
|
+
const state: JsonFormsState = createState(coreUISchema);
|
|
1702
|
+
state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
|
|
1703
|
+
state.jsonforms.i18n = defaultJsonFormsI18nState;
|
|
1704
|
+
state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
|
|
1705
|
+
switch(defaultMessage){
|
|
1674
1706
|
case 'foo': return 'my message';
|
|
1675
1707
|
default: return defaultMessage;
|
|
1676
1708
|
}
|