@abgov/jsonforms-components 1.19.2 → 1.19.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import React, { createContext, useContext, useReducer, useMemo, useEffect, useState, useCallback } from 'react';
|
|
3
|
-
import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputDateTime, GoAInputTime, GoADropdown, GoADropdownItem, GoARadioGroup, GoARadioItem, GoACheckbox, GoAGrid, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoADetails } from '@abgov/react-components';
|
|
3
|
+
import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputDateTime, GoAInputTime, GoADropdown, GoADropdownItem, GoARadioGroup, GoARadioItem, GoACheckbox, GoAGrid, GoADivider, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoADetails } from '@abgov/react-components';
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import get$1 from 'lodash/get';
|
|
@@ -4564,7 +4564,7 @@ const objToArray = obj => {
|
|
|
4564
4564
|
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
4565
4565
|
return [key, objToArray(value)];
|
|
4566
4566
|
}
|
|
4567
|
-
return [key, value];
|
|
4567
|
+
return [key, getValue(value)];
|
|
4568
4568
|
});
|
|
4569
4569
|
};
|
|
4570
4570
|
// test for ['name', 'fred']
|
|
@@ -4575,13 +4575,16 @@ const isNameValuePair = value => {
|
|
|
4575
4575
|
const isNestedValue = value => {
|
|
4576
4576
|
return Array.isArray(value) && value.length === 2 && typeof value[0] === 'string' && Array.isArray(value[1]);
|
|
4577
4577
|
};
|
|
4578
|
+
const isObjectArray = value => {
|
|
4579
|
+
return Array.isArray(value) && value.length > 0 && typeof value[0] === 'object';
|
|
4580
|
+
};
|
|
4578
4581
|
/*
|
|
4579
4582
|
* Convert ['name', [['first', 'fred'], ['middle', 'jolly'], ['last', 'mcguire']]]
|
|
4580
4583
|
* into [['first', 'fred'], ['middle', 'jolly'], ['last', 'mcguire']]
|
|
4581
4584
|
*/
|
|
4582
4585
|
const flatten = arr => {
|
|
4583
4586
|
return arr.reduce((acc, val) => {
|
|
4584
|
-
if (typeof val === 'string') {
|
|
4587
|
+
if (typeof val === 'string' || !val) {
|
|
4585
4588
|
return acc;
|
|
4586
4589
|
}
|
|
4587
4590
|
if (isNestedValue(val)) {
|
|
@@ -4590,7 +4593,7 @@ const flatten = arr => {
|
|
|
4590
4593
|
}
|
|
4591
4594
|
// If the current value is a string, add it to the accumulator
|
|
4592
4595
|
if (isNameValuePair(val)) {
|
|
4593
|
-
return acc.concat([val]);
|
|
4596
|
+
return acc.concat([[String(val[0]), getValue(val[1]) || '']]);
|
|
4594
4597
|
}
|
|
4595
4598
|
return acc;
|
|
4596
4599
|
}, []);
|
|
@@ -4607,14 +4610,19 @@ const flatten = arr => {
|
|
|
4607
4610
|
* page before messing with it.
|
|
4608
4611
|
*/
|
|
4609
4612
|
const getFormFieldValue = (scope, data) => {
|
|
4610
|
-
const pathArray = scope.replace('#/properties/', '').replace('properties/', '').split('/');
|
|
4611
4613
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4612
4614
|
let currentValue = data;
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4615
|
+
if (scope) {
|
|
4616
|
+
const pathArray = scope.replace('#/properties/', '').replace('properties/', '').split('/');
|
|
4617
|
+
for (const key of pathArray) {
|
|
4618
|
+
if (!currentValue) break;
|
|
4619
|
+
currentValue = currentValue[key];
|
|
4620
|
+
}
|
|
4616
4621
|
}
|
|
4617
|
-
return
|
|
4622
|
+
return isObjectArray(currentValue) ? {
|
|
4623
|
+
type: 'array',
|
|
4624
|
+
value: objToArray(currentValue)
|
|
4625
|
+
} : typeof currentValue === 'object' ? {
|
|
4618
4626
|
type: 'object',
|
|
4619
4627
|
value: flatten(objToArray(currentValue))
|
|
4620
4628
|
} : {
|
|
@@ -4663,9 +4671,26 @@ fileList, downloadFile) => {
|
|
|
4663
4671
|
return jsxs(React.Fragment, {
|
|
4664
4672
|
children: [fieldValues.type === 'primitive' && renderValue(`${label}${asterisk}: `, `${index}`, fieldValues.value, fileUploaderElement, downloadFile), fieldValues.type === 'object' && values && values.length > 0 && values.map((v, i) => {
|
|
4665
4673
|
return renderValue(`${v[0]}: `, `${index}:${i}`, v[1]);
|
|
4666
|
-
})]
|
|
4674
|
+
}), fieldValues.type === 'array' && values && values.length > 0 && renderListDetails(values)]
|
|
4667
4675
|
}, index);
|
|
4668
4676
|
};
|
|
4677
|
+
const renderListDetails = items => {
|
|
4678
|
+
return jsx(React.Fragment, {
|
|
4679
|
+
children: items.map((item, itemIndex) => {
|
|
4680
|
+
const details = Array.isArray(item) ? item : [undefined, [undefined, undefined]];
|
|
4681
|
+
return jsxs(Fragment, {
|
|
4682
|
+
children: [jsx(Grid, {
|
|
4683
|
+
children: details[1].map((detail, detailIndex) => {
|
|
4684
|
+
const safeDetail = Array.isArray(detail) ? detail : [undefined, undefined];
|
|
4685
|
+
return renderValue(`${safeDetail[0]}: `, `item-${itemIndex}-detail-${detailIndex}}`, safeDetail[1]);
|
|
4686
|
+
})
|
|
4687
|
+
}, `item-${itemIndex}`), itemIndex < items.length - 1 ? jsx(GoADivider, {
|
|
4688
|
+
mb: "m"
|
|
4689
|
+
}) : null]
|
|
4690
|
+
});
|
|
4691
|
+
})
|
|
4692
|
+
});
|
|
4693
|
+
};
|
|
4669
4694
|
|
|
4670
4695
|
const renderReviewListWithDetail = (element,
|
|
4671
4696
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.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",
|
|
@@ -2,8 +2,9 @@ import { LabelDescription } from '@jsonforms/core';
|
|
|
2
2
|
type jsonformsLabel = string | boolean | LabelDescription | undefined;
|
|
3
3
|
export declare const labelToString: (label: jsonformsLabel, scope: string) => string;
|
|
4
4
|
export interface InputValue {
|
|
5
|
-
type: 'primitive' | 'object';
|
|
6
|
-
value?: string |
|
|
5
|
+
type: 'primitive' | 'object' | 'array';
|
|
6
|
+
value?: string | NestedStringArray;
|
|
7
7
|
}
|
|
8
|
+
export type NestedStringArray = (string | undefined | NestedStringArray)[];
|
|
8
9
|
export declare const getFormFieldValue: (scope: string, data: unknown) => InputValue;
|
|
9
10
|
export {};
|