@abgov/jsonforms-components 1.26.1 → 1.27.0

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
- - GoARenders
15
- - <GoAComponent A Reducer>
16
- ...
17
- - <GoAComponent B Reducer>
18
- ...
19
- ```
20
-
21
- # GoA UI component JSON Forms UI Schema
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
- 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.
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 also need to add the following to the data schema
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
- "carBrands": {
99
- "type": "string",
100
- "enum": [
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
- import { JsonFormContextInstance } from '@abgov/jsonforms-components';
112
-
113
- const { jsonFormContext, baseEnumerator } = JsonFormContextInstance;
114
-
115
- return(
116
- <jsonFormContext.Provider value={baseEnumerator}>
117
- <JsonForms
118
- schema={...}
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
- Data Schema
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
- Ui Schema
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/carBrands",
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
- "enumContext": {
204
- "key": "countries"
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
- Another way to add data to ContextProvider (optional)
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
@@ -4075,13 +4075,17 @@ const EnumSelect = props => {
4075
4075
  return Object.assign({}, d);
4076
4076
  }
4077
4077
  })];
4078
+ const hasNonEmptyOptions = newOptions.some(option => option.value !== '');
4079
+ if (!hasNonEmptyOptions && newOptions.length === 1 && newOptions[0].value === '') {
4080
+ return newOptions;
4081
+ }
4078
4082
  if (newOptions && newOptions.length === 0) {
4079
4083
  newOptions.push({
4080
4084
  label: '',
4081
4085
  value: ''
4082
4086
  });
4083
4087
  }
4084
- return newOptions;
4088
+ return newOptions.filter(option => option.value !== '');
4085
4089
  }, [registerData, options]);
4086
4090
  useEffect(() => {
4087
4091
  if (registerConfig) {
@@ -5916,11 +5920,30 @@ const GoAArrayControlReviewRenderer = withJsonFormsArrayLayoutProps(ArrayBaseRev
5916
5920
 
5917
5921
  // eslint-disable-next-line
5918
5922
  const extractScopesFromUISchema = uischema => {
5919
- var _a;
5923
+ var _a, _b, _c, _d, _e, _f;
5920
5924
  const scopes = [];
5925
+ // eslint-disable-next-line
5926
+ 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) {
5927
+ // eslint-disable-next-line
5928
+ (_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 => {
5929
+ var _a;
5930
+ if (element === null || element === void 0 ? void 0 : element.elements) {
5931
+ // eslint-disable-next-line
5932
+ (_a = element === null || element === void 0 ? void 0 : element.elements) === null || _a === void 0 ? void 0 : _a.forEach(internalElement => {
5933
+ if (internalElement === null || internalElement === void 0 ? void 0 : internalElement.scope) {
5934
+ scopes.push(internalElement === null || internalElement === void 0 ? void 0 : internalElement.scope);
5935
+ }
5936
+ });
5937
+ } else {
5938
+ if (element === null || element === void 0 ? void 0 : element.scope) {
5939
+ scopes.push(element === null || element === void 0 ? void 0 : element.scope);
5940
+ }
5941
+ }
5942
+ });
5943
+ }
5921
5944
  if (uischema === null || uischema === void 0 ? void 0 : uischema.elements) {
5922
5945
  // eslint-disable-next-line
5923
- (_a = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _a === void 0 ? void 0 : _a.forEach(element => {
5946
+ (_f = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _f === void 0 ? void 0 : _f.forEach(element => {
5924
5947
  var _a;
5925
5948
  if (element === null || element === void 0 ? void 0 : element.elements) {
5926
5949
  // eslint-disable-next-line
@@ -5996,7 +6019,7 @@ const ctxToNonEmptyCellProps = (ctx, ownProps) => {
5996
6019
  };
5997
6020
  };
5998
6021
  const NonEmptyCellComponent = /*#__PURE__*/React.memo(function NonEmptyCellComponent(props) {
5999
- var _a, _b;
6022
+ var _a, _b, _c, _d, _e;
6000
6023
  const {
6001
6024
  schema,
6002
6025
  errors,
@@ -6054,7 +6077,19 @@ const NonEmptyCellComponent = /*#__PURE__*/React.memo(function NonEmptyCellCompo
6054
6077
  renderers: renderers,
6055
6078
  cells: cells
6056
6079
  }, rowPath);
6057
- }), ((_b = uiSchemaElementsForNotDefined === null || uiSchemaElementsForNotDefined === void 0 ? void 0 : uiSchemaElementsForNotDefined.elements) === null || _b === void 0 ? void 0 : _b.length) > 0 && jsx(JsonFormsDispatch, {
6080
+ }),
6081
+ // eslint-disable-next-line
6082
+ (_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 => {
6083
+ return jsx(JsonFormsDispatch, {
6084
+ "data-testid": `jsonforms-object-list-defined-elements-dispatch`,
6085
+ schema: schema,
6086
+ uischema: element,
6087
+ path: rowPath,
6088
+ enabled: enabled,
6089
+ renderers: renderers,
6090
+ cells: cells
6091
+ }, rowPath);
6092
+ }), ((_e = uiSchemaElementsForNotDefined === null || uiSchemaElementsForNotDefined === void 0 ? void 0 : uiSchemaElementsForNotDefined.elements) === null || _e === void 0 ? void 0 : _e.length) > 0 && jsx(JsonFormsDispatch, {
6058
6093
  schema: schema,
6059
6094
  uischema: uiSchemaElementsForNotDefined,
6060
6095
  path: rowPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.26.1",
3
+ "version": "1.27.0",
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",
@@ -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;