@abgov/jsonforms-components 1.21.0 → 1.21.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/index.esm.js +57 -32
- package/package.json +1 -1
- package/src/lib/Controls/FormStepper/util/GenerateFormFields.d.ts +3 -2
- package/src/lib/Controls/FormStepper/util/RenderFormReviewFields.d.ts +2 -1
- package/src/lib/Controls/FormStepper/util/renderReviewControl.d.ts +4 -2
- package/src/lib/Controls/FormStepper/util/renderReviewLIstWithDetail.d.ts +2 -2
package/index.esm.js
CHANGED
|
@@ -4,7 +4,7 @@ import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputD
|
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import get$1 from 'lodash/get';
|
|
7
|
-
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
|
|
7
|
+
import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl as isControl$1, isCategorization, isLayout as isLayout$1 } from '@jsonforms/core';
|
|
8
8
|
import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
|
|
9
9
|
import merge from 'lodash/merge';
|
|
10
10
|
import isEmpty$1 from 'lodash/isEmpty';
|
|
@@ -4595,7 +4595,6 @@ const flatten = arr => {
|
|
|
4595
4595
|
const flatter = flatten(val[1]);
|
|
4596
4596
|
return acc.concat(flatter);
|
|
4597
4597
|
}
|
|
4598
|
-
// If the current value is a string, add it to the accumulator
|
|
4599
4598
|
if (isNameValuePair(val)) {
|
|
4600
4599
|
return acc.concat([[String(val[0]), getValue(val[1]) || '']]);
|
|
4601
4600
|
}
|
|
@@ -4613,7 +4612,7 @@ const flatten = arr => {
|
|
|
4613
4612
|
* However, we need to decide how to handle these sorts of nested data in the summary
|
|
4614
4613
|
* page before messing with it.
|
|
4615
4614
|
*/
|
|
4616
|
-
const getFormFieldValue = (scope, data) => {
|
|
4615
|
+
const getFormFieldValue = (schema, scope, data) => {
|
|
4617
4616
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4618
4617
|
let currentValue = data;
|
|
4619
4618
|
if (scope) {
|
|
@@ -4660,7 +4659,7 @@ const renderFileLink = (fileUploaderElement, downloadFile) => {
|
|
|
4660
4659
|
children: fileUploaderElement === null || fileUploaderElement === void 0 ? void 0 : fileUploaderElement.filename
|
|
4661
4660
|
});
|
|
4662
4661
|
};
|
|
4663
|
-
const renderReviewControl = (data, element, requiredFields, index,
|
|
4662
|
+
const renderReviewControl = (schema, data, element, requiredFields, index,
|
|
4664
4663
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4665
4664
|
fileList, downloadFile) => {
|
|
4666
4665
|
const fieldName = element.scope.split('/').pop() || '';
|
|
@@ -4668,21 +4667,21 @@ fileList, downloadFile) => {
|
|
|
4668
4667
|
if (!fieldName || !label) return null;
|
|
4669
4668
|
const isFileUploader = element.scope.includes('fileUploader');
|
|
4670
4669
|
const fileUploaderElement = isFileUploader ? fileList && fileList[fieldName] : null;
|
|
4671
|
-
const fieldValues = getFormFieldValue(element.scope, data ? data : {});
|
|
4670
|
+
const fieldValues = getFormFieldValue(schema, element.scope, data ? data : {});
|
|
4672
4671
|
const isRequired = requiredFields.includes(fieldName);
|
|
4673
4672
|
const asterisk = isRequired ? ' *' : '';
|
|
4674
4673
|
const values = fieldValues.value;
|
|
4675
4674
|
return jsxs(React.Fragment, {
|
|
4676
4675
|
children: [fieldValues.type === 'primitive' && renderValue(`${label}${asterisk}: `, `${index}`, fieldValues.value, fileUploaderElement, downloadFile), fieldValues.type === 'object' && values && values.length > 0 && values.map((v, i) => {
|
|
4677
4676
|
return renderValue(`${v[0]}: `, `${index}:${i}`, v[1]);
|
|
4678
|
-
}), fieldValues.type === 'array' && values && values.length > 0 &&
|
|
4677
|
+
}), fieldValues.type === 'array' && values && values.length > 0 && renderList(values)]
|
|
4679
4678
|
}, index);
|
|
4680
4679
|
};
|
|
4681
|
-
const
|
|
4680
|
+
const renderList = items => {
|
|
4682
4681
|
return jsx(React.Fragment, {
|
|
4683
4682
|
children: items.map((item, itemIndex) => {
|
|
4684
4683
|
const details = Array.isArray(item) ? item : [undefined, [undefined, undefined]];
|
|
4685
|
-
return jsxs(
|
|
4684
|
+
return jsxs("div", {
|
|
4686
4685
|
children: [jsx(Grid, {
|
|
4687
4686
|
children: details[1].map((detail, detailIndex) => {
|
|
4688
4687
|
const safeDetail = Array.isArray(detail) ? detail : [undefined, undefined];
|
|
@@ -4696,32 +4695,44 @@ const renderListDetails = items => {
|
|
|
4696
4695
|
});
|
|
4697
4696
|
};
|
|
4698
4697
|
|
|
4699
|
-
const renderReviewListWithDetail = (
|
|
4698
|
+
const renderReviewListWithDetail = (schema, elements,
|
|
4700
4699
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4701
4700
|
data, field, index, requiredFields) => {
|
|
4702
4701
|
const listData = data[field];
|
|
4702
|
+
const detailData = [];
|
|
4703
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4704
|
+
listData.forEach((elementData, i) => {
|
|
4705
|
+
const itemData = [];
|
|
4706
|
+
elements.forEach((element, j) => {
|
|
4707
|
+
const fieldName = element.scope.split('/').pop() || '';
|
|
4708
|
+
const label = resolveLabelFromScope(element.scope);
|
|
4709
|
+
const value = String(elementData[fieldName]);
|
|
4710
|
+
itemData.push([label, value]);
|
|
4711
|
+
});
|
|
4712
|
+
detailData.push([`${i}`, itemData]);
|
|
4713
|
+
});
|
|
4703
4714
|
return jsxs(ListWithDetail, {
|
|
4704
4715
|
children: [jsxs(ListWithDetailHeading, {
|
|
4705
4716
|
children: [field, listData.length > 1 && 's']
|
|
4706
|
-
}),
|
|
4707
|
-
children: listData.map((childData, childIndex) => {
|
|
4708
|
-
var _a, _b;
|
|
4709
|
-
return jsx(React.Fragment, {
|
|
4710
|
-
children: jsx(RenderFormReviewFields, {
|
|
4711
|
-
elements: ((_b = (_a = element === null || element === void 0 ? void 0 : element.options) === null || _a === void 0 ? void 0 : _a.detail) === null || _b === void 0 ? void 0 : _b.elements) || [],
|
|
4712
|
-
data: childData,
|
|
4713
|
-
requiredFields: requiredFields
|
|
4714
|
-
})
|
|
4715
|
-
}, `${index}-${childIndex}`);
|
|
4716
|
-
})
|
|
4717
|
-
})]
|
|
4717
|
+
}), renderList(detailData)]
|
|
4718
4718
|
}, `${index}-${field}`);
|
|
4719
4719
|
};
|
|
4720
4720
|
|
|
4721
|
+
const isControl = type => {
|
|
4722
|
+
return type === 'Control';
|
|
4723
|
+
};
|
|
4724
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4725
|
+
const isListWithDetail$1 = (type, data, fieldName) => {
|
|
4726
|
+
return type === 'ListWithDetail' && typeof data === 'object' && data !== null && fieldName in data && Array.isArray(data[fieldName]) && data[fieldName].length > 0;
|
|
4727
|
+
};
|
|
4728
|
+
const isLayout = schema => {
|
|
4729
|
+
return typeof schema === 'object' && schema !== null && 'elements' in schema;
|
|
4730
|
+
};
|
|
4721
4731
|
const RenderFormReviewFields = ({
|
|
4722
4732
|
elements,
|
|
4723
4733
|
data,
|
|
4724
|
-
requiredFields
|
|
4734
|
+
requiredFields,
|
|
4735
|
+
schema
|
|
4725
4736
|
}) => {
|
|
4726
4737
|
var _a, _b;
|
|
4727
4738
|
const enumerators = useContext(JsonFormContext);
|
|
@@ -4736,25 +4747,38 @@ const RenderFormReviewFields = ({
|
|
|
4736
4747
|
}
|
|
4737
4748
|
};
|
|
4738
4749
|
return elements.map((element, index) => {
|
|
4739
|
-
var _a;
|
|
4750
|
+
var _a, _b, _c;
|
|
4740
4751
|
const clonedElement = JSON.parse(JSON.stringify(element));
|
|
4741
4752
|
const fieldName = (_a = clonedElement.scope) === null || _a === void 0 ? void 0 : _a.split('/').pop();
|
|
4742
|
-
if (clonedElement.type
|
|
4743
|
-
return renderReviewControl(data, clonedElement, requiredFields, index, fileList, downloadFile);
|
|
4744
|
-
} else if (clonedElement.type
|
|
4753
|
+
if (isControl(clonedElement.type)) {
|
|
4754
|
+
return renderReviewControl(schema, data, clonedElement, requiredFields, index, fileList, downloadFile);
|
|
4755
|
+
} else if (isListWithDetail$1(clonedElement.type, data, fieldName)) {
|
|
4756
|
+
const elements = removeLayouts((_c = (_b = clonedElement === null || clonedElement === void 0 ? void 0 : clonedElement.options) === null || _b === void 0 ? void 0 : _b.detail) === null || _c === void 0 ? void 0 : _c.elements) || [];
|
|
4757
|
+
return renderReviewListWithDetail(schema, elements, data, fieldName, index);
|
|
4758
|
+
} else if (isLayout(clonedElement)) {
|
|
4745
4759
|
return jsx(React.Fragment, {
|
|
4746
4760
|
children: jsx(RenderFormReviewFields, {
|
|
4747
4761
|
elements: clonedElement.elements,
|
|
4748
4762
|
data: data,
|
|
4749
|
-
requiredFields: requiredFields
|
|
4763
|
+
requiredFields: requiredFields,
|
|
4764
|
+
schema: schema
|
|
4750
4765
|
})
|
|
4751
4766
|
}, index);
|
|
4752
|
-
} else if (clonedElement.type === 'ListWithDetail' && data && data[fieldName] && data[fieldName].length > 0) {
|
|
4753
|
-
return renderReviewListWithDetail(clonedElement, data, fieldName, index, requiredFields);
|
|
4754
4767
|
}
|
|
4755
4768
|
return null;
|
|
4756
4769
|
});
|
|
4757
4770
|
};
|
|
4771
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4772
|
+
const removeLayouts = elements => {
|
|
4773
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4774
|
+
return elements.reduce((acc, item) => {
|
|
4775
|
+
if (isLayout(item)) {
|
|
4776
|
+
return acc.concat(removeLayouts(item.elements));
|
|
4777
|
+
} else {
|
|
4778
|
+
return acc.concat(item);
|
|
4779
|
+
}
|
|
4780
|
+
}, []);
|
|
4781
|
+
};
|
|
4758
4782
|
|
|
4759
4783
|
const RenderStepElements = props => {
|
|
4760
4784
|
return (
|
|
@@ -5001,7 +5025,8 @@ const FormStepper = props => {
|
|
|
5001
5025
|
children: jsx(RenderFormReviewFields, {
|
|
5002
5026
|
elements: category === null || category === void 0 ? void 0 : category.elements,
|
|
5003
5027
|
data: data,
|
|
5004
|
-
requiredFields: requiredFields
|
|
5028
|
+
requiredFields: requiredFields,
|
|
5029
|
+
schema: schema
|
|
5005
5030
|
})
|
|
5006
5031
|
})]
|
|
5007
5032
|
}, index);
|
|
@@ -6046,7 +6071,7 @@ const getUISchemaErrors = (uiSchema, schema) => {
|
|
|
6046
6071
|
return '';
|
|
6047
6072
|
}
|
|
6048
6073
|
// Check control elements
|
|
6049
|
-
if (isControl(uiSchema) && hasType(uiSchema, 'Control')) {
|
|
6074
|
+
if (isControl$1(uiSchema) && hasType(uiSchema, 'Control')) {
|
|
6050
6075
|
if (!isScopedPrefixed(uiSchema.scope)) {
|
|
6051
6076
|
return errMalformedScope(uiSchema.scope);
|
|
6052
6077
|
}
|
|
@@ -6080,7 +6105,7 @@ const getUISchemaErrors = (uiSchema, schema) => {
|
|
|
6080
6105
|
}
|
|
6081
6106
|
// ensure each element has type Category, and that each category
|
|
6082
6107
|
// has elements
|
|
6083
|
-
if (isLayout(uiSchema)) {
|
|
6108
|
+
if (isLayout$1(uiSchema)) {
|
|
6084
6109
|
const invalidCategorizations = [];
|
|
6085
6110
|
const invalidCategories = [];
|
|
6086
6111
|
uiSchema.elements.forEach(e => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abgov/jsonforms-components",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.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",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { LabelDescription } from '@jsonforms/core';
|
|
1
|
+
import { JsonSchema, LabelDescription } from '@jsonforms/core';
|
|
2
2
|
type jsonformsLabel = string | boolean | LabelDescription | undefined;
|
|
3
3
|
export declare const labelToString: (label: jsonformsLabel, scope: string) => string;
|
|
4
|
+
export declare const resolveLabelFromScope: (scope: string) => string;
|
|
4
5
|
export interface InputValue {
|
|
5
6
|
type: 'primitive' | 'object' | 'array';
|
|
6
7
|
value?: string | NestedStringArray;
|
|
7
8
|
}
|
|
8
9
|
export type NestedStringArray = (string | undefined | NestedStringArray)[];
|
|
9
|
-
export declare const getFormFieldValue: (scope: string, data: unknown) => InputValue;
|
|
10
|
+
export declare const getFormFieldValue: (schema: JsonSchema, scope: string, data: unknown) => InputValue;
|
|
10
11
|
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Categorization, Category, UISchemaElement } from '@jsonforms/core';
|
|
2
|
+
import { Categorization, Category, JsonSchema, UISchemaElement } from '@jsonforms/core';
|
|
3
3
|
interface RenderFormReviewFieldsProps {
|
|
4
4
|
elements: UISchemaElement[] | (Category | Categorization)[];
|
|
5
5
|
data: any;
|
|
6
6
|
requiredFields: string[];
|
|
7
|
+
schema: JsonSchema;
|
|
7
8
|
}
|
|
8
9
|
export declare const RenderFormReviewFields: React.FC<RenderFormReviewFieldsProps>;
|
|
9
10
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ControlElement } from '@jsonforms/core';
|
|
1
|
+
import { ControlElement, JsonSchema } from '@jsonforms/core';
|
|
2
|
+
import { NestedStringArray } from './GenerateFormFields';
|
|
2
3
|
export interface FileElement extends File {
|
|
3
4
|
filename: string;
|
|
4
5
|
propertyId: string;
|
|
5
6
|
}
|
|
6
|
-
export declare const renderReviewControl: (data: unknown, element: ControlElement, requiredFields: string[], index: number, fileList: Record<string, any>, downloadFile: (file: File, propertyId: string) => void) => JSX.Element | null;
|
|
7
|
+
export declare const renderReviewControl: (schema: JsonSchema, data: unknown, element: ControlElement, requiredFields: string[], index: number, fileList: Record<string, any>, downloadFile: (file: File, propertyId: string) => void) => JSX.Element | null;
|
|
8
|
+
export declare const renderList: (items: NestedStringArray) => JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ControlElement } from '@jsonforms/core';
|
|
2
|
-
export declare const renderReviewListWithDetail: (
|
|
1
|
+
import { ControlElement, JsonSchema } from '@jsonforms/core';
|
|
2
|
+
export declare const renderReviewListWithDetail: (schema: JsonSchema, elements: ControlElement[], data: any, field: string, index: number, requiredFields: string[]) => JSX.Element;
|