@abgov/jsonforms-components 1.14.1 → 1.14.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/index.esm.js CHANGED
@@ -3263,6 +3263,48 @@ $({ target: 'String', proto: true, forced: !correctIsRegExpLogic('includes') },
3263
3263
  }
3264
3264
  });
3265
3265
 
3266
+ /******************************************************************************
3267
+ Copyright (c) Microsoft Corporation.
3268
+
3269
+ Permission to use, copy, modify, and/or distribute this software for any
3270
+ purpose with or without fee is hereby granted.
3271
+
3272
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3273
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3274
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3275
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3276
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3277
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3278
+ PERFORMANCE OF THIS SOFTWARE.
3279
+ ***************************************************************************** */
3280
+
3281
+ function __rest(s, e) {
3282
+ var t = {};
3283
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3284
+ t[p] = s[p];
3285
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3286
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3287
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3288
+ t[p[i]] = s[p[i]];
3289
+ }
3290
+ return t;
3291
+ }
3292
+
3293
+ function __awaiter(thisArg, _arguments, P, generator) {
3294
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3295
+ return new (P || (P = Promise))(function (resolve, reject) {
3296
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3297
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3298
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3299
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
3300
+ });
3301
+ }
3302
+
3303
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
3304
+ var e = new Error(message);
3305
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3306
+ };
3307
+
3266
3308
  const getAxiosInterceptorConfig = axios => {
3267
3309
  const requestId = axios.interceptors.request.use(req => {
3268
3310
  if (req.data === undefined) {
@@ -3272,7 +3314,7 @@ const getAxiosInterceptorConfig = axios => {
3272
3314
  });
3273
3315
  return [requestId, axios];
3274
3316
  };
3275
- function addDataByUrl(key, url, processDataFunction, token) {
3317
+ const addDataByUrl = (key, url, processDataFunction, token) => __awaiter(void 0, void 0, void 0, function* () {
3276
3318
  let header = {};
3277
3319
  const [requestId, axiosWithConfig] = getAxiosInterceptorConfig(axios);
3278
3320
  if (token) {
@@ -3280,7 +3322,7 @@ function addDataByUrl(key, url, processDataFunction, token) {
3280
3322
  Authorization: `Bearer ${token}`
3281
3323
  });
3282
3324
  }
3283
- axiosWithConfig.get(url, header).then(response => {
3325
+ yield axiosWithConfig.get(url, header).then(response => {
3284
3326
  const processedData = processDataFunction(response.data);
3285
3327
  enumValues.set(key, () => processedData);
3286
3328
  }).catch(err => {
@@ -3291,14 +3333,15 @@ function addDataByUrl(key, url, processDataFunction, token) {
3291
3333
  }
3292
3334
  });
3293
3335
  axiosWithConfig.interceptors.request.eject(requestId);
3294
- }
3295
- function addDataByOptions(key, url, location, type, values) {
3336
+ });
3337
+ function addDataByOptions(key, url, location, type, values = ['']) {
3296
3338
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3297
3339
  const dataFunction = data => {
3298
3340
  let dataLink = data;
3299
3341
  let returnData = [''];
3300
- const locationArray = location && !Array.isArray(location) ? [location] : location;
3301
- locationArray === null || locationArray === void 0 ? void 0 : locationArray.forEach(attribute => {
3342
+ const locationArray = location && Array.isArray(location) ? location : [location];
3343
+ const locationArrayTyped = locationArray;
3344
+ locationArrayTyped === null || locationArrayTyped === void 0 ? void 0 : locationArrayTyped.forEach(attribute => {
3302
3345
  dataLink = dataLink[attribute];
3303
3346
  });
3304
3347
  const valuesArray = Array.isArray(values) ? values : [values];
@@ -3341,20 +3384,16 @@ function ContextProvider(props) {
3341
3384
  downloadFile,
3342
3385
  deleteFile
3343
3386
  } = props.fileManagement;
3344
- /* eslint-disable @typescript-eslint/no-empty-function */
3345
- const uploadFileFunction = uploadFile ? uploadFile : () => {};
3346
- const downloadFileFunction = downloadFile ? downloadFile : () => {};
3347
- const deleteFileFunction = deleteFile ? deleteFile : () => {};
3348
3387
  enumValues.set('file-list', () => fileList);
3349
- enumFunctions.set('upload-file', () => uploadFileFunction);
3350
- enumFunctions.set('download-file', () => downloadFileFunction);
3351
- enumFunctions.set('delete-file', () => deleteFileFunction);
3388
+ enumFunctions.set('upload-file', () => uploadFile);
3389
+ enumFunctions.set('download-file', () => downloadFile);
3390
+ enumFunctions.set('delete-file', () => deleteFile);
3352
3391
  }
3353
3392
  if (props.submit) {
3354
3393
  const {
3355
3394
  submitForm
3356
3395
  } = props.submit;
3357
- const submitFunction = submitForm ? submitForm : () => {};
3396
+ const submitFunction = submitForm;
3358
3397
  enumSubmitFunctions.set('submit-form', () => submitFunction);
3359
3398
  }
3360
3399
  if (props.data) {
@@ -3936,46 +3975,82 @@ const getFormFieldValue = (scope, data) => {
3936
3975
  return '';
3937
3976
  }
3938
3977
  };
3939
- const renderFormFields = (elements, data,
3940
- // eslint-disable-line @typescript-eslint/no-explicit-any
3941
- requiredFields) => elements.map((element, index) => {
3942
- var _a;
3943
- const clonedElement = JSON.parse(JSON.stringify(element));
3944
- const lastSegment = (_a = clonedElement.scope) === null || _a === void 0 ? void 0 : _a.split('/').pop();
3945
- if (clonedElement.type === 'Control' && clonedElement.scope) {
3946
- const label = clonedElement.label ? clonedElement.label : resolveLabelFromScope(clonedElement.scope);
3947
- if (!label) return null;
3948
- const value = getFormFieldValue(clonedElement.scope, data ? data : {}).toString();
3949
- const asterisk = requiredFields.indexOf(lastSegment) !== -1 ? ' *' : '';
3950
- return jsxs(GridItem, {
3951
- md: 6,
3952
- vSpacing: 1,
3953
- hSpacing: 0.5,
3954
- children: [jsxs("strong", {
3955
- children: [label, " ", asterisk + ':']
3956
- }), ' ', value]
3957
- }, index);
3958
- } else if (clonedElement.type !== 'ListWithDetail' && (clonedElement === null || clonedElement === void 0 ? void 0 : clonedElement.elements)) {
3959
- return jsx(React.Fragment, {
3960
- children: renderFormFields(clonedElement.elements, data, requiredFields)
3961
- }, index);
3962
- } else if (clonedElement.type === 'ListWithDetail' && data && data[lastSegment] && data[lastSegment].length > 0) {
3963
- const listData = data[lastSegment];
3964
- return jsxs(ListWithDetail, {
3965
- children: [jsxs(ListWithDetailHeading, {
3966
- children: [lastSegment, listData.length > 1 && 's']
3967
- }), jsx(Grid, {
3968
- children: listData.map((childData,
3969
- // eslint-disable-line @typescript-eslint/no-explicit-any
3970
- childIndex // eslint-disable-line @typescript-eslint/no-explicit-any
3971
- ) => jsx(React.Fragment, {
3972
- children: renderFormFields(clonedElement.elements, childData, requiredFields)
3973
- }, `${index}-${childIndex}`))
3974
- })]
3975
- });
3976
- }
3977
- return null;
3978
- });
3978
+ const RenderFormFields = ({
3979
+ elements,
3980
+ data,
3981
+ requiredFields
3982
+ }) => {
3983
+ var _a, _b;
3984
+ const enumerators = useContext(JsonFormContext);
3985
+ const downloadTriggerFunction = (_a = enumerators === null || enumerators === void 0 ? void 0 : enumerators.functions) === null || _a === void 0 ? void 0 : _a.get('download-file');
3986
+ const downloadTrigger = downloadTriggerFunction && downloadTriggerFunction();
3987
+ const fileListValue = (_b = enumerators === null || enumerators === void 0 ? void 0 : enumerators.data) === null || _b === void 0 ? void 0 : _b.get('file-list');
3988
+ // eslint-disable-next-line
3989
+ const fileList = fileListValue && fileListValue();
3990
+ const toCamelCase = input => {
3991
+ const words = input.split(' ');
3992
+ const firstWord = words[0].toLowerCase();
3993
+ const capitalizedWords = words.slice(1).map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase());
3994
+ return [firstWord, ...capitalizedWords].join('');
3995
+ };
3996
+ const downloadFile = (file, propertyId) => {
3997
+ if (downloadTrigger) {
3998
+ downloadTrigger(file, propertyId);
3999
+ }
4000
+ };
4001
+ return elements.map((element, index) => {
4002
+ var _a;
4003
+ const clonedElement = JSON.parse(JSON.stringify(element));
4004
+ const lastSegment = (_a = clonedElement.scope) === null || _a === void 0 ? void 0 : _a.split('/').pop();
4005
+ if (clonedElement.type === 'Control' && clonedElement.scope) {
4006
+ const label = clonedElement.label ? clonedElement.label : resolveLabelFromScope(clonedElement.scope);
4007
+ if (!label) return null;
4008
+ const isFileUploader = label.toLowerCase().includes('file uploader');
4009
+ const fileUploaderElement = isFileUploader ? fileList && fileList[toCamelCase(label)] : null;
4010
+ const value = getFormFieldValue(clonedElement.scope, data ? data : {}).toString();
4011
+ const isRequired = requiredFields.includes(lastSegment);
4012
+ const asterisk = isRequired ? ' *' : '';
4013
+ return jsxs(GridItem, {
4014
+ md: 6,
4015
+ vSpacing: 1,
4016
+ hSpacing: 0.5,
4017
+ children: [jsxs("strong", {
4018
+ children: [label, " ", asterisk + ': ']
4019
+ }), fileUploaderElement ? jsx("a", {
4020
+ onClick: () => downloadFile(fileUploaderElement, fileUploaderElement === null || fileUploaderElement === void 0 ? void 0 : fileUploaderElement.propertyId),
4021
+ children: fileUploaderElement === null || fileUploaderElement === void 0 ? void 0 : fileUploaderElement.filename
4022
+ }) : value]
4023
+ }, index);
4024
+ } else if (clonedElement.type !== 'ListWithDetail' && (clonedElement === null || clonedElement === void 0 ? void 0 : clonedElement.elements)) {
4025
+ return jsx(React.Fragment, {
4026
+ children: jsx(RenderFormFields, {
4027
+ elements: clonedElement.elements,
4028
+ data: data,
4029
+ requiredFields: requiredFields
4030
+ })
4031
+ }, index);
4032
+ } else if (clonedElement.type === 'ListWithDetail' && data && data[lastSegment] && data[lastSegment].length > 0) {
4033
+ const listData = data[lastSegment];
4034
+ return jsxs(ListWithDetail, {
4035
+ children: [jsxs(ListWithDetailHeading, {
4036
+ children: [lastSegment, listData.length > 1 && 's']
4037
+ }), jsx(Grid, {
4038
+ children: listData.map((childData,
4039
+ // eslint-disable-line @typescript-eslint/no-explicit-any
4040
+ childIndex // eslint-disable-line @typescript-eslint/no-explicit-any
4041
+ ) => jsx(React.Fragment, {
4042
+ children: jsx(RenderFormFields, {
4043
+ elements: clonedElement.elements,
4044
+ data: childData,
4045
+ requiredFields: requiredFields
4046
+ })
4047
+ }, `${index}-${childIndex}`))
4048
+ })]
4049
+ });
4050
+ }
4051
+ return null;
4052
+ });
4053
+ };
3979
4054
 
3980
4055
  const RenderStepElements = props => {
3981
4056
  return (
@@ -4017,6 +4092,30 @@ const validateData = (jsonSchema, data, ajv) => {
4017
4092
  }
4018
4093
  };
4019
4094
 
4095
+ /**
4096
+ * Steps can be hidden:
4097
+ * When the user clicks on a step in the stepper function, it returns
4098
+ * a step number relative to all steps. Map to the step number relative
4099
+ * to the visible steps.
4100
+ */
4101
+ const mapToVisibleStep = (step, allSteps, visibleSteps) => {
4102
+ if (visibleSteps.length < 1) return 0;
4103
+ if (step < 1) return 1;
4104
+ if (allSteps.length !== visibleSteps.length) {
4105
+ const stepIndex = step - 1;
4106
+ if (step > 1 && step <= allSteps.length) {
4107
+ // Check to see if the the step is visible
4108
+ const selectedLabel = allSteps[stepIndex];
4109
+ const selectedIndex = visibleSteps.indexOf(selectedLabel);
4110
+ step = selectedIndex !== -1 ? selectedIndex + 1 : 1;
4111
+ }
4112
+ if (step > allSteps.length) {
4113
+ step = visibleSteps.length;
4114
+ }
4115
+ }
4116
+ return step;
4117
+ };
4118
+
4020
4119
  const FormStepper = props => {
4021
4120
  var _a, _b, _c, _d;
4022
4121
  const {
@@ -4098,26 +4197,10 @@ const FormStepper = props => {
4098
4197
  }
4099
4198
  setPage(page);
4100
4199
  }
4101
- const getNextStep = step => {
4102
- const rawCategoryLabels = rawCategories.elements.map(category => category.label);
4103
- if (rawCategoryLabels.length !== CategoryLabels.length) {
4104
- if (step > 1 && step <= rawCategoryLabels.length) {
4105
- const selectedTabLabel = rawCategoryLabels[step - 1];
4106
- const selectedTab = CategoryLabels.indexOf(selectedTabLabel);
4107
- const newStep = selectedTab !== -1 ? selectedTab + 1 : step;
4108
- return newStep;
4109
- }
4110
- if (step > rawCategoryLabels.length) {
4111
- return step - 1;
4112
- }
4113
- }
4114
- return step;
4115
- };
4116
4200
  function setTab(page) {
4117
- page = getNextStep(page);
4118
- setStep(page);
4119
- if (page < 1 || page > categories.length + 1) return;
4120
- setShowNextBtn(categories.length + 1 !== page);
4201
+ const rawCategoryLabels = rawCategories.elements.map(category => category.label);
4202
+ page = mapToVisibleStep(page, rawCategoryLabels, CategoryLabels);
4203
+ setPage(page);
4121
4204
  }
4122
4205
  function setPage(page) {
4123
4206
  setStep(page);
@@ -4207,7 +4290,11 @@ const FormStepper = props => {
4207
4290
  children: readOnly ? 'View' : 'Edit'
4208
4291
  })]
4209
4292
  }), jsx(Grid, {
4210
- children: renderFormFields(category.elements, data, requiredFields)
4293
+ children: jsx(RenderFormFields, {
4294
+ elements: category.elements,
4295
+ data: data,
4296
+ requiredFields: requiredFields
4297
+ })
4211
4298
  })]
4212
4299
  }, index);
4213
4300
  })
@@ -4283,38 +4370,6 @@ const categoriesAreValid = uischema => {
4283
4370
  };
4284
4371
  const CategorizationRendererTester = rankWith(2, and(uiTypeIs('Categorization'), categoriesAreValid, optionIs('variant', 'stepper')));
4285
4372
 
4286
- /******************************************************************************
4287
- Copyright (c) Microsoft Corporation.
4288
-
4289
- Permission to use, copy, modify, and/or distribute this software for any
4290
- purpose with or without fee is hereby granted.
4291
-
4292
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
4293
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4294
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
4295
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4296
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4297
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4298
- PERFORMANCE OF THIS SOFTWARE.
4299
- ***************************************************************************** */
4300
-
4301
- function __rest(s, e) {
4302
- var t = {};
4303
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4304
- t[p] = s[p];
4305
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
4306
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
4307
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
4308
- t[p[i]] = s[p[i]];
4309
- }
4310
- return t;
4311
- }
4312
-
4313
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
4314
- var e = new Error(message);
4315
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
4316
- };
4317
-
4318
4373
  let _$3 = t => t,
4319
4374
  _t$3;
4320
4375
  const GoAContextMenuIcon = props => {
@@ -5432,4 +5487,4 @@ const GoARenderers = [...GoABaseRenderers, {
5432
5487
  }];
5433
5488
  const GoACells = [...InputCells];
5434
5489
 
5435
- export { ContextProvider, GoABaseRenderers, GoACells, GoARenderers, JsonFormContext, addData, addDataByOptions, addDataByUrl, ajv, getAllData, getData };
5490
+ export { ContextProvider, GoABaseRenderers, GoACells, GoARenderers, JsonFormContext, addData, addDataByOptions, addDataByUrl, ajv, getAllData, getAxiosInterceptorConfig, getData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.14.1",
3
+ "version": "1.14.3",
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",
@@ -1,9 +1,11 @@
1
1
  import React from 'react';
2
+ import { AxiosStatic } from 'axios';
2
3
  export interface AllData {
3
4
  [x: string]: any;
4
5
  }
5
- export declare function addDataByUrl(key: string, url: string, processDataFunction: (url: string) => string[], token?: string): void;
6
- export declare function addDataByOptions(key: string, url: string, location: string[], type: string, values: string[]): void;
6
+ export declare const getAxiosInterceptorConfig: (axios: AxiosStatic) => [number, AxiosStatic];
7
+ export declare const addDataByUrl: (key: string, url: string, processDataFunction: (data: object) => string[], token?: string) => Promise<void>;
8
+ export declare function addDataByOptions(key: string, url: string, location: string[] | string, type: string, values?: string[] | string): void;
7
9
  interface FileManagement {
8
10
  fileList?: any;
9
11
  uploadFile?: (file: File, propertyId: string) => void;
@@ -20,16 +22,16 @@ type Props = {
20
22
  data?: any;
21
23
  };
22
24
  export declare const JsonFormContext: React.Context<{
23
- data: Map<string, () => Record<string, any> | string[]>;
24
- functions: Map<string, () => (file: File, propertyId: string) => void>;
25
- submitFunction: Map<string, () => (data: any) => void>;
25
+ data: Map<string, () => Record<string, any>>;
26
+ functions: Map<string, () => ((file: File, propertyId: string) => void) | undefined>;
27
+ submitFunction: Map<string, () => ((data: any) => void) | undefined>;
26
28
  }>;
27
29
  export declare function ContextProvider(props: Props): JSX.Element | null;
28
30
  /**
29
31
  * Grabs data stored under a given key
30
32
  *
31
33
  */
32
- export declare function getData(key: string): string[] | Record<string, any> | undefined;
34
+ export declare function getData(key: string): Record<string, any> | undefined;
33
35
  /**
34
36
  * Grabs all data
35
37
  *
@@ -1,4 +1,11 @@
1
1
  import { UISchemaElement, Category, Categorization } from '@jsonforms/core';
2
+ import React from 'react';
3
+ interface RenderFormFieldsProps {
4
+ elements: UISchemaElement[] | (Category | Categorization)[];
5
+ data: any;
6
+ requiredFields: string[];
7
+ }
2
8
  export declare const resolveLabelFromScope: (scope: string) => string | null;
3
9
  export declare const getFormFieldValue: (scope: string, data: object) => any;
4
- export declare const renderFormFields: (elements: UISchemaElement[] | (Category | Categorization)[], data: any, requiredFields: string[]) => (import("react/jsx-runtime").JSX.Element | null)[];
10
+ export declare const RenderFormFields: React.FC<RenderFormFieldsProps>;
11
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Steps can be hidden:
3
+ * When the user clicks on a step in the stepper function, it returns
4
+ * a step number relative to all steps. Map to the step number relative
5
+ * to the visible steps.
6
+ */
7
+ export declare const mapToVisibleStep: (step: number, allSteps: string[], visibleSteps: (string | undefined)[]) => number;