Skip to content

Commit 6323148

Browse files
committed
Improve vanilla ArrayControl
The vanilla ArrayControl was wrapping the `addItem` in a function, whereas the `addItem` function is already wrapped. So the `onClick` can directly be bound to `addItem`. The wrong binding lead to the add functionality not working. Increase rank of the ArrayControl so that it behaves the same as for the react material renderers. Add example to demonstrate different selections of renderers based on the existince of a const property in the schema. Fixes #1948
1 parent 413b976 commit 6323148

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
The MIT License
3+
4+
Copyright (c) 2022 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 { registerExamples } from '../register';
26+
import { UISchemaElement } from '@jsonforms/core';
27+
28+
export const schema = {
29+
type: 'object',
30+
definitions: {
31+
import: {
32+
title: 'Import',
33+
type: 'object',
34+
properties: {
35+
eClass: {
36+
const: "http://my_schema/1.0.0#//Import"
37+
},
38+
document: {
39+
type: 'string'
40+
},
41+
package: {
42+
type: 'string'
43+
},
44+
prefix: {
45+
type: 'string'
46+
}
47+
}
48+
},
49+
},
50+
properties: {
51+
import: {
52+
type: 'array',
53+
items: {
54+
$ref: '#/definitions/import'
55+
}
56+
}
57+
}
58+
};
59+
60+
export const uischema: UISchemaElement = undefined;
61+
62+
export const data = {
63+
import: [{
64+
document: "Document1",
65+
package: "Package1",
66+
prefix: "Prefix"
67+
}]
68+
};
69+
70+
registerExamples([
71+
{
72+
name: '1948',
73+
label: 'Issue 1948 with schema',
74+
data,
75+
schema,
76+
uischema
77+
}
78+
]);
79+
80+
registerExamples([
81+
{
82+
name: '1948without',
83+
label: 'Issue 1948 w/o schema',
84+
data,
85+
schema:undefined,
86+
uischema
87+
}
88+
]);

packages/examples/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import * as listWithDetail from './examples/list-with-detail';
5959
import * as listWithDetailRegistered from './examples/list-with-detail-registered';
6060
import * as object from './examples/object';
6161
import * as i18n from './examples/i18n';
62+
import * as issue_1948 from './examples/1948';
6263
import * as issue_1169 from './examples/1169';
6364
import * as issue_1220 from './examples/1220';
6465
import * as issue_1253 from './examples/1253';
@@ -83,6 +84,7 @@ export * from './example';
8384
import * as ifThenElse from './examples/if_then_else';
8485

8586
export {
87+
issue_1948,
8688
defaultExample,
8789
allOf,
8890
anyOf,

packages/vanilla/src/complex/array/ArrayControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const ArrayControl = ({
5050
<legend>
5151
<button
5252
className={classNames.button}
53-
onClick={() => addItem(path, createDefaultValue(schema))}
53+
onClick={addItem(path, createDefaultValue(schema))}
5454
>
5555
+
5656
</button>

packages/vanilla/src/complex/array/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { ArrayControl } from './ArrayControl';
3333
export { ArrayControl, ArrayControlRenderer };
3434

3535
export const arrayControlTester: RankedTester = rankWith(
36-
2,
36+
4,
3737
isObjectArrayWithNesting
3838
);
3939

0 commit comments

Comments
 (0)