@abgov/jsonforms-components 1.26.2 → 1.27.1
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/README.md
CHANGED
|
@@ -11,241 +11,62 @@ Run `nx test jsonforms-components` to execute the unit tests via [Jest](https://
|
|
|
11
11
|
```
|
|
12
12
|
- src
|
|
13
13
|
- lib
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
- Additional
|
|
15
|
+
- Cells
|
|
16
|
+
- common
|
|
17
|
+
- Components
|
|
18
|
+
- Controls
|
|
19
|
+
- Context
|
|
20
|
+
- ErrorHandling
|
|
21
|
+
- layouts
|
|
22
|
+
- util
|
|
22
23
|
|
|
23
|
-
[UI Schema](https://jsonforms.io/docs/uischema) in the JSON Forms defines the general layout of the forms generated. @abgov/jsonforms-components lib integrates the [GoA UI components](https://github.com/GovAlta/ui-components) form components by extending the "options" attribute in the UI Schema. Take GoAInput UI Schema as example:
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
{
|
|
27
|
-
"type": "Control",
|
|
28
|
-
"scope": "#/properties/name",
|
|
29
|
-
"options": {
|
|
30
|
-
"GoAInput": {
|
|
31
|
-
"name": "Name",
|
|
32
|
-
"label": "Name",
|
|
33
|
-
"testId": ""
|
|
34
|
-
...
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
24
|
```
|
|
39
25
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# JsonFormContextInstance
|
|
43
|
-
|
|
44
|
-
To use the package, and the context surrounding it, it's best to import JsonFormContextInstance attach data to it
|
|
45
|
-
|
|
46
|
-
Here are some sample api endpoints that work currently.
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
import { JsonFormContextInstance } from '@abgov/jsonforms-components';
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
JsonFormContextInstance.addDataByUrl('dog-list', 'https://dog.ceo/api/breeds/list/all', processDogs);
|
|
55
|
-
JsonFormContextInstance.addDataByUrl(
|
|
56
|
-
'basketball-players',
|
|
57
|
-
'https://www.balldontlie.io/api/v1/players',
|
|
58
|
-
processPlayers
|
|
59
|
-
);
|
|
60
|
-
JsonFormContextInstance.addDataByUrl(
|
|
61
|
-
'car-brands',
|
|
62
|
-
'https://parallelum.com.br/fipe/api/v1/carros/marcas',
|
|
63
|
-
processCarBrands
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
JsonFormContextInstance.addFormContextData(
|
|
67
|
-
'countries',
|
|
68
|
-
Countries.map((country) => country.country)
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
}, []);
|
|
72
|
-
|
|
73
|
-
function processDogs(rawData): string[] {
|
|
74
|
-
return Object.keys(rawData.message);
|
|
75
|
-
}
|
|
76
|
-
function processPlayers(rawData): string[] {
|
|
77
|
-
return rawData.data.map((player) => `${player.first_name} ${player.last_name}`);
|
|
78
|
-
}
|
|
79
|
-
function processCarBrands(rawData): string[] {
|
|
80
|
-
return rawData.map((brand) => brand.nome);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Once you add them, you can add the following to any UI Schema control to create a dropdown that displays them
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
"type": "Control",
|
|
89
|
-
"scope": "#/properties/carBrands",
|
|
90
|
-
"options": {
|
|
91
|
-
"enumContext": {
|
|
92
|
-
"key": "car-brands",
|
|
93
|
-
```
|
|
26
|
+
# Embedding ADSP Form service UI components in your application
|
|
94
27
|
|
|
95
|
-
You
|
|
28
|
+
To use ADSP Forms service UI components add in JSON Forms into your application. You will have to include the following JSX markup and imports into your React components as an example.
|
|
96
29
|
|
|
97
30
|
```
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
]
|
|
103
|
-
}
|
|
31
|
+
import { JsonForms } from '@jsonforms/react';
|
|
32
|
+
import {
|
|
33
|
+
GoARenderers,
|
|
34
|
+
} from '@abgov/jsonforms-components';
|
|
104
35
|
```
|
|
105
36
|
|
|
106
|
-
# Schemas only with no code changes
|
|
107
|
-
|
|
108
|
-
To access the apis without making any code changes to add an api,
|
|
109
|
-
|
|
110
37
|
```
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
uischema={...}
|
|
120
|
-
...
|
|
121
|
-
/>
|
|
122
|
-
/>
|
|
123
|
-
)
|
|
38
|
+
<JsonForms
|
|
39
|
+
schema={yourJSONDataSchema}
|
|
40
|
+
uischema={yourJSONUISchema}
|
|
41
|
+
data={data}
|
|
42
|
+
validationMode="ValidateAndShow"
|
|
43
|
+
renderers={GoARenderers}
|
|
44
|
+
onChange={onChange}
|
|
45
|
+
/>
|
|
124
46
|
```
|
|
125
47
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
"carBrands": {
|
|
130
|
-
"type": "string",
|
|
131
|
-
"enum": [
|
|
132
|
-
""
|
|
133
|
-
]
|
|
134
|
-
},
|
|
135
|
-
"countries": {
|
|
136
|
-
"type": "string",
|
|
137
|
-
"enum": [
|
|
138
|
-
""
|
|
139
|
-
]
|
|
140
|
-
},
|
|
141
|
-
"dogBreeds": {
|
|
142
|
-
"type": "string",
|
|
143
|
-
"enum": [
|
|
144
|
-
""
|
|
145
|
-
]
|
|
146
|
-
},
|
|
147
|
-
"basketballPlayers": {
|
|
148
|
-
"type": "string",
|
|
149
|
-
"enum": [
|
|
150
|
-
""
|
|
151
|
-
]
|
|
152
|
-
}
|
|
153
|
-
```
|
|
48
|
+
# ADSP Form service UI components UI schema
|
|
154
49
|
|
|
155
|
-
|
|
50
|
+
[UI Schema](https://jsonforms.io/docs/uischema) in the JSON Forms defines the general layout of the forms generated. @abgov/jsonforms-components lib integrates the [GoA UI components](https://github.com/GovAlta/ui-components) form components by extending the "options" attribute in the UI Schema. Take GoAInput UI Schema as example:
|
|
51
|
+
https://govalta.github.io/adsp-monorepo/tutorials/form-service/building-forms.html
|
|
156
52
|
|
|
157
53
|
```
|
|
158
|
-
{
|
|
159
|
-
"type": "HorizontalLayout",
|
|
160
|
-
"elements": [
|
|
161
54
|
{
|
|
162
55
|
"type": "Control",
|
|
163
|
-
"scope": "#/properties/
|
|
164
|
-
"options": {
|
|
165
|
-
"enumContext": {
|
|
166
|
-
"key": "car-brands",
|
|
167
|
-
"url": "https://parallelum.com.br/fipe/api/v1/carros/marcas",
|
|
168
|
-
"values": "nome"
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
"type": "Control",
|
|
174
|
-
"scope": "#/properties/dogBreeds",
|
|
175
|
-
"options": {
|
|
176
|
-
"enumContext": {
|
|
177
|
-
"key": "dog-list",
|
|
178
|
-
"url": "https://dog.ceo/api/breeds/list/all",
|
|
179
|
-
"location": "message",
|
|
180
|
-
"type": "keys"
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
"type": "Control",
|
|
186
|
-
"scope": "#/properties/basketballPlayers",
|
|
187
|
-
"options": {
|
|
188
|
-
"enumContext": {
|
|
189
|
-
"key": "basketball-players",
|
|
190
|
-
"location": "data",
|
|
191
|
-
"url": "https://www.balldontlie.io/api/v1/players",
|
|
192
|
-
"values": [
|
|
193
|
-
"first_name",
|
|
194
|
-
"last_name"
|
|
195
|
-
]
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
"type": "Control",
|
|
201
|
-
"scope": "#/properties/countries",
|
|
56
|
+
"scope": "#/properties/name",
|
|
202
57
|
"options": {
|
|
203
|
-
"
|
|
204
|
-
"
|
|
58
|
+
"GoAInput": {
|
|
59
|
+
"name": "Name",
|
|
60
|
+
"label": "Name",
|
|
61
|
+
"testId": ""
|
|
62
|
+
...
|
|
205
63
|
}
|
|
206
64
|
}
|
|
207
65
|
}
|
|
208
|
-
]
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
Countries in this example comes locally.
|
|
213
|
-
|
|
214
|
-
```
|
|
215
|
-
import Countries from './countries';
|
|
216
|
-
|
|
217
|
-
--------
|
|
218
|
-
|
|
219
|
-
export default [
|
|
220
|
-
{ country: 'Russia', land_mass_km2: 17098242 },
|
|
221
|
-
{ country: 'Canada', land_mass_km2: 9976140 },
|
|
222
|
-
...
|
|
223
|
-
]
|
|
224
66
|
```
|
|
225
67
|
|
|
226
|
-
|
|
68
|
+
The presence of the "GoAInput" indicates we are going to use the GoAInput to render the input. The attributes in the "GoAInput" will be passed to the GoAInput as component properties.
|
|
227
69
|
|
|
228
|
-
|
|
229
|
-
const animals = {
|
|
230
|
-
animals: [
|
|
231
|
-
{ name: 'Elephant', type: 'Mammal', habitat: 'Land' },
|
|
232
|
-
{ name: 'Penguin', type: 'Bird', habitat: 'Ice' },
|
|
233
|
-
{ name: 'Kangaroo', type: 'Mammal', habitat: 'Grasslands' },
|
|
234
|
-
{ name: 'Giraffe', type: 'Mammal', habitat: 'Savanna' },
|
|
235
|
-
{ name: 'Octopus', type: 'Invertebrate', habitat: 'Ocean' },
|
|
236
|
-
{ name: 'Cheetah', type: 'Mammal', habitat: 'Grasslands' },
|
|
237
|
-
{ name: 'Koala', type: 'Mammal', habitat: 'Eucalyptus Forest' },
|
|
238
|
-
{ name: 'Toucan', type: 'Bird', habitat: 'Rainforest' },
|
|
239
|
-
{ name: 'Dolphin', type: 'Mammal', habitat: 'Ocean' },
|
|
240
|
-
{ name: 'Arctic Fox', type: 'Mammal', habitat: 'Arctic Tundra' },
|
|
241
|
-
],
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
<ContextProvider data={[{ animals }]}
|
|
246
|
-
<JsonForms
|
|
247
|
-
...
|
|
248
|
-
</>
|
|
249
|
-
</ContextProvider>
|
|
70
|
+
For additional information and usage pertaining to the controls, layouts, steppers, please refer to the ADSP Form service guide which provides more in [depth information](https://govalta.github.io/adsp-monorepo/tutorials/form-service/form-service.html) on the usage.
|
|
250
71
|
|
|
251
|
-
|
|
72
|
+
Please refer to the [Cheat sheet](https://govalta.github.io/adsp-monorepo/tutorials/form-service/cheat-sheet.html) which contains schema examples for the different types of controls, steppers, layouts, etc that are currently available from ADSP Form service UI components that can used in your UI schema of your application.
|
package/index.esm.js
CHANGED
|
@@ -4496,6 +4496,9 @@ const ReviewItem = styled.div(_t$4 || (_t$4 = _$4`
|
|
|
4496
4496
|
border-radius: var(--goa-border-radius-m);
|
|
4497
4497
|
margin: var(--goa-space-2xs);
|
|
4498
4498
|
padding: var(--goa-space-xs);
|
|
4499
|
+
div:empty {
|
|
4500
|
+
display: none;
|
|
4501
|
+
}
|
|
4499
4502
|
`));
|
|
4500
4503
|
const ReviewItemSection = styled.div(_t2$2 || (_t2$2 = _$4`
|
|
4501
4504
|
background-color: #f1f1f1;
|
|
@@ -4910,6 +4913,16 @@ const mapToVisibleStep = (step, allSteps, visibleSteps) => {
|
|
|
4910
4913
|
};
|
|
4911
4914
|
|
|
4912
4915
|
const summaryLabel = 'Summary';
|
|
4916
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4917
|
+
const getProperty = (obj, propName) => {
|
|
4918
|
+
if (obj[propName] !== undefined) return obj[propName];
|
|
4919
|
+
for (const key in obj) {
|
|
4920
|
+
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
4921
|
+
const result = getProperty(obj[key], propName);
|
|
4922
|
+
if (result !== undefined) return result;
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
4925
|
+
};
|
|
4913
4926
|
const FormStepper = props => {
|
|
4914
4927
|
var _a, _b, _c, _d, _e;
|
|
4915
4928
|
const {
|
|
@@ -5086,7 +5099,20 @@ const FormStepper = props => {
|
|
|
5086
5099
|
})]
|
|
5087
5100
|
}), jsx(GoAGrid, {
|
|
5088
5101
|
minChildWidth: "600px",
|
|
5089
|
-
children: category.elements.
|
|
5102
|
+
children: category.elements.filter(field => {
|
|
5103
|
+
var _a, _b;
|
|
5104
|
+
const conditionProps = (_a = field.rule) === null || _a === void 0 ? void 0 : _a.condition;
|
|
5105
|
+
if (conditionProps && data) {
|
|
5106
|
+
const canHideControlParts = (_b = conditionProps === null || conditionProps === void 0 ? void 0 : conditionProps.scope) === null || _b === void 0 ? void 0 : _b.split('/');
|
|
5107
|
+
const canHideControl = canHideControlParts && canHideControlParts[(canHideControlParts === null || canHideControlParts === void 0 ? void 0 : canHideControlParts.length) - 1];
|
|
5108
|
+
const isHidden = getProperty(data, canHideControl);
|
|
5109
|
+
if (!isHidden) {
|
|
5110
|
+
return field;
|
|
5111
|
+
}
|
|
5112
|
+
} else {
|
|
5113
|
+
return field;
|
|
5114
|
+
}
|
|
5115
|
+
}).map((element, index) => {
|
|
5090
5116
|
return jsx("div", {
|
|
5091
5117
|
children: jsx(JsonFormsDispatch, {
|
|
5092
5118
|
"data-testid": `jsonforms-object-list-defined-elements-dispatch`,
|
|
@@ -5920,11 +5946,30 @@ const GoAArrayControlReviewRenderer = withJsonFormsArrayLayoutProps(ArrayBaseRev
|
|
|
5920
5946
|
|
|
5921
5947
|
// eslint-disable-next-line
|
|
5922
5948
|
const extractScopesFromUISchema = uischema => {
|
|
5923
|
-
var _a;
|
|
5949
|
+
var _a, _b, _c, _d, _e, _f;
|
|
5924
5950
|
const scopes = [];
|
|
5951
|
+
// eslint-disable-next-line
|
|
5952
|
+
if ((_b = (_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.detail) === null || _b === void 0 ? void 0 : _b.elements) {
|
|
5953
|
+
// eslint-disable-next-line
|
|
5954
|
+
(_e = (_d = (_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.detail) === null || _d === void 0 ? void 0 : _d.elements) === null || _e === void 0 ? void 0 : _e.forEach(element => {
|
|
5955
|
+
var _a;
|
|
5956
|
+
if (element === null || element === void 0 ? void 0 : element.elements) {
|
|
5957
|
+
// eslint-disable-next-line
|
|
5958
|
+
(_a = element === null || element === void 0 ? void 0 : element.elements) === null || _a === void 0 ? void 0 : _a.forEach(internalElement => {
|
|
5959
|
+
if (internalElement === null || internalElement === void 0 ? void 0 : internalElement.scope) {
|
|
5960
|
+
scopes.push(internalElement === null || internalElement === void 0 ? void 0 : internalElement.scope);
|
|
5961
|
+
}
|
|
5962
|
+
});
|
|
5963
|
+
} else {
|
|
5964
|
+
if (element === null || element === void 0 ? void 0 : element.scope) {
|
|
5965
|
+
scopes.push(element === null || element === void 0 ? void 0 : element.scope);
|
|
5966
|
+
}
|
|
5967
|
+
}
|
|
5968
|
+
});
|
|
5969
|
+
}
|
|
5925
5970
|
if (uischema === null || uischema === void 0 ? void 0 : uischema.elements) {
|
|
5926
5971
|
// eslint-disable-next-line
|
|
5927
|
-
(
|
|
5972
|
+
(_f = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _f === void 0 ? void 0 : _f.forEach(element => {
|
|
5928
5973
|
var _a;
|
|
5929
5974
|
if (element === null || element === void 0 ? void 0 : element.elements) {
|
|
5930
5975
|
// eslint-disable-next-line
|
|
@@ -6000,7 +6045,7 @@ const ctxToNonEmptyCellProps = (ctx, ownProps) => {
|
|
|
6000
6045
|
};
|
|
6001
6046
|
};
|
|
6002
6047
|
const NonEmptyCellComponent = /*#__PURE__*/React.memo(function NonEmptyCellComponent(props) {
|
|
6003
|
-
var _a, _b;
|
|
6048
|
+
var _a, _b, _c, _d, _e;
|
|
6004
6049
|
const {
|
|
6005
6050
|
schema,
|
|
6006
6051
|
errors,
|
|
@@ -6058,7 +6103,19 @@ const NonEmptyCellComponent = /*#__PURE__*/React.memo(function NonEmptyCellCompo
|
|
|
6058
6103
|
renderers: renderers,
|
|
6059
6104
|
cells: cells
|
|
6060
6105
|
}, rowPath);
|
|
6061
|
-
}),
|
|
6106
|
+
}),
|
|
6107
|
+
// eslint-disable-next-line
|
|
6108
|
+
(_d = (_c = (_b = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _b === void 0 ? void 0 : _b.detail) === null || _c === void 0 ? void 0 : _c.elements) === null || _d === void 0 ? void 0 : _d.map(element => {
|
|
6109
|
+
return jsx(JsonFormsDispatch, {
|
|
6110
|
+
"data-testid": `jsonforms-object-list-defined-elements-dispatch`,
|
|
6111
|
+
schema: schema,
|
|
6112
|
+
uischema: element,
|
|
6113
|
+
path: rowPath,
|
|
6114
|
+
enabled: enabled,
|
|
6115
|
+
renderers: renderers,
|
|
6116
|
+
cells: cells
|
|
6117
|
+
}, rowPath);
|
|
6118
|
+
}), ((_e = uiSchemaElementsForNotDefined === null || uiSchemaElementsForNotDefined === void 0 ? void 0 : uiSchemaElementsForNotDefined.elements) === null || _e === void 0 ? void 0 : _e.length) > 0 && jsx(JsonFormsDispatch, {
|
|
6062
6119
|
schema: schema,
|
|
6063
6120
|
uischema: uiSchemaElementsForNotDefined,
|
|
6064
6121
|
path: rowPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.27.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
|
|
6
6
|
"repository": "https://github.com/GovAlta/adsp-monorepo",
|
|
@@ -14,6 +14,7 @@ export interface FormStepperOptionProps {
|
|
|
14
14
|
previousButtonLabel?: string;
|
|
15
15
|
previousButtonType?: GoAButtonType;
|
|
16
16
|
}
|
|
17
|
+
export declare const getProperty: any;
|
|
17
18
|
export declare const FormStepper: (props: CategorizationStepperLayoutRendererProps) => JSX.Element;
|
|
18
19
|
export declare const FormStepperControl: (props: CategorizationStepperLayoutRendererProps & import("@jsonforms/core").OwnPropsOfLayout) => import("react/jsx-runtime").JSX.Element;
|
|
19
20
|
export default FormStepper;
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { ArrayLayoutProps, ControlElement, JsonSchema, JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry, ArrayTranslations, Layout } from '@jsonforms/core';
|
|
3
3
|
import { WithDeleteDialogSupport } from './DeleteDialog';
|
|
4
4
|
export type ObjectArrayControlProps = ArrayLayoutProps & WithDeleteDialogSupport;
|
|
5
|
+
export declare const extractScopesFromUISchema: (uischema: any) => string[];
|
|
5
6
|
export interface EmptyListProps {
|
|
6
7
|
numColumns: number;
|
|
7
8
|
translations: ArrayTranslations;
|