@abgov/jsonforms-components 0.0.1 → 1.1.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.
Files changed (123) hide show
  1. package/index.esm.d.ts +1 -0
  2. package/index.esm.js +4752 -0
  3. package/package.json +5 -2
  4. package/src/index.d.ts +5 -0
  5. package/src/lib/Additional/HelpContent.d.ts +21 -0
  6. package/src/lib/Additional/styled-components.d.ts +1 -0
  7. package/src/lib/Cells/DateCell.d.ts +6 -0
  8. package/src/lib/Cells/IntegerCell.d.ts +6 -0
  9. package/src/lib/Cells/NumberCell.d.ts +6 -0
  10. package/src/lib/Cells/TextCell.d.ts +6 -0
  11. package/src/lib/Cells/TimeCell.d.ts +6 -0
  12. package/src/lib/Cells/index.d.ts +2 -0
  13. package/src/lib/Context/index.d.ts +39 -0
  14. package/src/lib/Controls/FileUploader/ContextMenu.d.ts +18 -0
  15. package/src/lib/Controls/FileUploader/FileUploaderControl.d.ts +4 -0
  16. package/src/lib/Controls/FileUploader/FileUploaderTester.d.ts +2 -0
  17. package/src/lib/Controls/FileUploader/styled-components.d.ts +1 -0
  18. package/src/lib/Controls/FormStepper/FormStepperControl.d.ts +10 -0
  19. package/src/lib/Controls/FormStepper/FormStepperTester.d.ts +2 -0
  20. package/src/lib/Controls/FormStepper/styled-components.d.ts +3 -0
  21. package/src/lib/Controls/Inputs/InputBaseControl.d.ts +7 -0
  22. package/src/lib/Controls/Inputs/InputBooleanControl.d.ts +6 -0
  23. package/src/lib/Controls/Inputs/InputBooleanRadioControl.d.ts +6 -0
  24. package/src/lib/Controls/Inputs/InputDateControl.d.ts +9 -0
  25. package/src/lib/Controls/Inputs/InputDateTimeControl.d.ts +9 -0
  26. package/src/lib/Controls/Inputs/InputEnum.d.ts +12 -0
  27. package/src/lib/Controls/Inputs/InputEnumAutoComplete.d.ts +10 -0
  28. package/src/lib/Controls/Inputs/InputEnumRadios.d.ts +12 -0
  29. package/src/lib/Controls/Inputs/InputIntegerControl.d.ts +9 -0
  30. package/src/lib/Controls/Inputs/InputMultiLineTextControl.d.ts +9 -0
  31. package/src/lib/Controls/Inputs/InputNumberControl.d.ts +9 -0
  32. package/src/lib/Controls/Inputs/InputTextControl.d.ts +9 -0
  33. package/src/lib/Controls/Inputs/InputTimeControl.d.ts +9 -0
  34. package/src/lib/Controls/Inputs/{type.ts → type.d.ts} +1 -1
  35. package/src/lib/Controls/ObjectArray/DeleteDialog.d.ts +12 -0
  36. package/src/lib/Controls/ObjectArray/ObjectArray.d.ts +6 -0
  37. package/src/lib/Controls/ObjectArray/ObjectArrayToolBar.d.ts +16 -0
  38. package/src/lib/Controls/ObjectArray/ObjectListControl.d.ts +24 -0
  39. package/src/lib/Controls/ObjectArray/styled-components.d.ts +3 -0
  40. package/src/lib/ErrorHandling/GoAErrorControl.d.ts +15 -0
  41. package/src/lib/ErrorHandling/{MessageControl.tsx → MessageControl.d.ts} +1 -8
  42. package/src/lib/ErrorHandling/errorCheck.d.ts +14 -0
  43. package/src/lib/ErrorHandling/schemaValidation.d.ts +11 -0
  44. package/src/lib/common/Grid.d.ts +11 -0
  45. package/src/lib/jsonforms-components.d.ts +4 -0
  46. package/src/lib/layouts/GroupControl.d.ts +5 -0
  47. package/src/lib/layouts/HorizontalLayoutControl.d.ts +5 -0
  48. package/src/lib/layouts/VerticalLayoutControl.d.ts +4 -0
  49. package/src/lib/util/layout.d.ts +8 -0
  50. package/src/lib/util/schemaUtils.d.ts +1 -0
  51. package/src/lib/util/stringUtils.d.ts +33 -0
  52. package/src/lib/util/style-component.d.ts +1 -0
  53. package/.babelrc +0 -12
  54. package/.eslintrc.json +0 -36
  55. package/.releaserc.json +0 -25
  56. package/jest.config.ts +0 -11
  57. package/project.json +0 -55
  58. package/rollup.config.js +0 -14
  59. package/src/index.ts +0 -166
  60. package/src/lib/Additional/HelpContent.tsx +0 -95
  61. package/src/lib/Additional/styled-components.ts +0 -27
  62. package/src/lib/Cells/DateCell.tsx +0 -10
  63. package/src/lib/Cells/IntegerCell.tsx +0 -10
  64. package/src/lib/Cells/NumberCell.tsx +0 -10
  65. package/src/lib/Cells/TextCell.tsx +0 -10
  66. package/src/lib/Cells/TimeCell.tsx +0 -10
  67. package/src/lib/Cells/index.tsx +0 -14
  68. package/src/lib/Context/index.tsx +0 -172
  69. package/src/lib/Controls/FileUploader/ContextMenu.tsx +0 -50
  70. package/src/lib/Controls/FileUploader/FileUploaderControl.tsx +0 -131
  71. package/src/lib/Controls/FileUploader/FileUploaderTester.tsx +0 -3
  72. package/src/lib/Controls/FileUploader/styled-components.tsx +0 -10
  73. package/src/lib/Controls/FormStepper/FormStepperControl.tsx +0 -269
  74. package/src/lib/Controls/FormStepper/FormStepperTester.tsx +0 -22
  75. package/src/lib/Controls/FormStepper/styled-components.tsx +0 -17
  76. package/src/lib/Controls/Inputs/InputBaseControl.tsx +0 -52
  77. package/src/lib/Controls/Inputs/InputBooleanControl.tsx +0 -67
  78. package/src/lib/Controls/Inputs/InputBooleanRadioControl.tsx +0 -74
  79. package/src/lib/Controls/Inputs/InputDateControl.tsx +0 -90
  80. package/src/lib/Controls/Inputs/InputDateTimeControl.tsx +0 -46
  81. package/src/lib/Controls/Inputs/InputEnum.tsx +0 -74
  82. package/src/lib/Controls/Inputs/InputEnumAutoComplete.tsx +0 -73
  83. package/src/lib/Controls/Inputs/InputEnumRadios.tsx +0 -43
  84. package/src/lib/Controls/Inputs/InputIntegerControl.tsx +0 -63
  85. package/src/lib/Controls/Inputs/InputMultiLineTextControl.tsx +0 -63
  86. package/src/lib/Controls/Inputs/InputNumberControl.tsx +0 -63
  87. package/src/lib/Controls/Inputs/InputTextControl.tsx +0 -62
  88. package/src/lib/Controls/Inputs/InputTimeControl.tsx +0 -46
  89. package/src/lib/Controls/Inputs/inputControl.spec.ts +0 -84
  90. package/src/lib/Controls/ObjectArray/DeleteDialog.tsx +0 -49
  91. package/src/lib/Controls/ObjectArray/ObjectArray.tsx +0 -59
  92. package/src/lib/Controls/ObjectArray/ObjectArrayToolBar.tsx +0 -51
  93. package/src/lib/Controls/ObjectArray/ObjectListControl.tsx +0 -368
  94. package/src/lib/Controls/ObjectArray/styled-components.tsx +0 -13
  95. package/src/lib/ErrorHandling/GoAErrorControl.tsx +0 -53
  96. package/src/lib/ErrorHandling/categorizationValidation.spec.ts +0 -98
  97. package/src/lib/ErrorHandling/controlValildation.spec.ts +0 -57
  98. package/src/lib/ErrorHandling/errorCheck.spec.ts +0 -185
  99. package/src/lib/ErrorHandling/errorCheck.tsx +0 -86
  100. package/src/lib/ErrorHandling/layoutValildation.spec.ts +0 -47
  101. package/src/lib/ErrorHandling/otherValildation.spec.ts +0 -74
  102. package/src/lib/ErrorHandling/schemaValidation.ts +0 -115
  103. package/src/lib/common/Grid.tsx +0 -55
  104. package/src/lib/jsonforms-components.module.scss +0 -7
  105. package/src/lib/jsonforms-components.spec.tsx +0 -10
  106. package/src/lib/jsonforms-components.tsx +0 -14
  107. package/src/lib/layouts/GroupControl.tsx +0 -25
  108. package/src/lib/layouts/HorizontalLayoutControl.tsx +0 -30
  109. package/src/lib/layouts/VerticalLayoutControl.tsx +0 -28
  110. package/src/lib/util/layout.tsx +0 -68
  111. package/src/lib/util/schemaUtils.ts +0 -9
  112. package/src/lib/util/stringUtils.ts +0 -98
  113. package/src/lib/util/style-component.ts +0 -8
  114. package/tsconfig.json +0 -20
  115. package/tsconfig.lib.json +0 -19
  116. package/tsconfig.spec.json +0 -20
  117. /package/src/lib/Additional/{index.ts → index.d.ts} +0 -0
  118. /package/src/lib/Controls/FileUploader/{index.tsx → index.d.ts} +0 -0
  119. /package/src/lib/Controls/FormStepper/{index.tsx → index.d.ts} +0 -0
  120. /package/src/lib/Controls/Inputs/{index.tsx → index.d.ts} +0 -0
  121. /package/src/lib/Controls/ObjectArray/{index.tsx → index.d.ts} +0 -0
  122. /package/src/lib/Controls/{index.tsx → index.d.ts} +0 -0
  123. /package/src/lib/layouts/{index.ts → index.d.ts} +0 -0
@@ -1,50 +0,0 @@
1
- import React, { FC } from 'react';
2
- import { GoAButton, GoAIconButton, GoAIconType } from '@abgov/react-components-new';
3
- import styled from 'styled-components';
4
-
5
- interface ContextMenuIconProps {
6
- type: GoAIconType;
7
- testId?: string;
8
- title?: string;
9
- onClick?: () => void;
10
- disabled?: boolean;
11
- }
12
-
13
- interface ContextMenuTextProps {
14
- type?: GoAIconType;
15
- testId?: string;
16
- onClick?: () => void;
17
- }
18
-
19
- export const GoAContextMenuIcon: FC<ContextMenuIconProps> = (props) => {
20
- return (
21
- <GoAIconButton
22
- icon={props.type}
23
- onClick={props.onClick}
24
- title={props.title}
25
- testId={props.testId}
26
- size="small"
27
- disabled={props.disabled}
28
- />
29
- );
30
- };
31
-
32
- export const GoAContextMenuText: FC<ContextMenuTextProps> = (props) => {
33
- return <GoAButton type="tertiary" onClick={props.onClick} testId={props.testId} size="compact" />;
34
- };
35
-
36
- export const GoAContextMenu = styled.div`
37
- display: flex;
38
- align-items: center;
39
- background-color: #fff;
40
- gap: 0.25rem;
41
-
42
- > .goa-icon-button {
43
- cursor: pointer;
44
- border-radius: 0.25rem;
45
- padding: 0.25rem;
46
- }
47
- > .goa-icon-button + .goa-icon-button {
48
- margin-left: 0rem;
49
- }
50
- `;
@@ -1,131 +0,0 @@
1
- import React, { useContext, useEffect } from 'react';
2
- import { GoAFileUploadInput, GoAFormItem, GoACircularProgress, GoAModal } from '@abgov/react-components-new';
3
- import { WithClassname, ControlProps } from '@jsonforms/core';
4
-
5
- import styled from 'styled-components';
6
- import { JsonFormContext } from '../../Context';
7
-
8
- import { GoAContextMenu, GoAContextMenuIcon } from './ContextMenu';
9
-
10
- type FileUploaderLayoutRendererProps = ControlProps & WithClassname;
11
-
12
- export const FileUploader = ({ data, path, handleChange, uischema, ...props }: FileUploaderLayoutRendererProps) => {
13
- const enumerators = useContext(JsonFormContext);
14
- const uploadTriggerFunction = enumerators.functions.get('upload-file');
15
- const uploadTrigger = uploadTriggerFunction && uploadTriggerFunction();
16
- const downloadTriggerFunction = enumerators.functions.get('download-file');
17
- const downloadTrigger = downloadTriggerFunction && downloadTriggerFunction();
18
- const deleteTriggerFunction = enumerators.functions.get('delete-file');
19
- const deleteTrigger = deleteTriggerFunction && deleteTriggerFunction();
20
- const fileListValue = enumerators.data.get('file-list');
21
- // eslint-disable-next-line
22
- const fileList = fileListValue && (fileListValue() as Record<string, any>);
23
- const { required, label, i18nKeyPrefix } = props;
24
-
25
- const propertyId = i18nKeyPrefix as string;
26
-
27
- const variant = uischema?.options?.variant || 'button';
28
-
29
- function uploadFile(file: File) {
30
- if (uploadTrigger) {
31
- handleChange(propertyId, ['Loading', Array.isArray(data) ? data[1] : data, file?.name]);
32
- uploadTrigger(file, propertyId);
33
- }
34
- }
35
- function downloadFile(file: File) {
36
- if (downloadTrigger) {
37
- downloadTrigger(file, propertyId);
38
- }
39
- }
40
- function deleteFile(file: File) {
41
- if (deleteTrigger) {
42
- deleteTrigger(file, propertyId);
43
- }
44
- }
45
-
46
- useEffect(() => {
47
- // UseEffect is required because not having it causes a react update error, but
48
- // it doesn't function correctly within jsonforms unless there is a minor delay here
49
- const delayedFunction = () => {
50
- if (fileList && Array.isArray(data) && data[1] !== fileList[propertyId]?.urn) {
51
- handleChange(propertyId, fileList && fileList[propertyId]?.urn);
52
- }
53
- };
54
-
55
- const timeoutId = setTimeout(delayedFunction, 1);
56
- return () => clearTimeout(timeoutId);
57
- }, [data, handleChange, fileList, propertyId]);
58
-
59
- return (
60
- <FileUploaderStyle id="file-upload" className="FileUploader">
61
- {required ? (
62
- <GoAFormItem label={label} requirement="required"></GoAFormItem>
63
- ) : (
64
- <div className="label">{props.label}</div>
65
- )}
66
-
67
- <div className="file-upload">
68
- <GoAFileUploadInput variant={variant} onSelectFile={uploadFile} />
69
- </div>
70
- <div>
71
- {Array.isArray(data) && data[0] === 'Loading' ? (
72
- <GoAModal open={Array.isArray(data) && data[0] === 'Loading'}>
73
- <div className="align-center">
74
- <GoACircularProgress visible={true} message={`Uploading ${data[2]}`} size="large" />
75
- </div>
76
- </GoAModal>
77
- ) : (
78
- <div>
79
- {fileList && fileList[props.i18nKeyPrefix as string] && (
80
- <AttachmentBorder>
81
- <div>{fileList && fileList[props.i18nKeyPrefix as string].filename}</div>
82
- <GoAContextMenu>
83
- <GoAContextMenuIcon
84
- testId="download-icon"
85
- title="Download"
86
- type="download"
87
- onClick={() => downloadFile(fileList && fileList[props.i18nKeyPrefix as string])}
88
- />
89
- <GoAContextMenuIcon
90
- data-testid="delete-icon"
91
- title="Delete"
92
- type="trash"
93
- onClick={() => deleteFile(fileList && fileList[props.i18nKeyPrefix as string])}
94
- />
95
- </GoAContextMenu>
96
- </AttachmentBorder>
97
- )}
98
- </div>
99
- )}
100
- </div>
101
- </FileUploaderStyle>
102
- );
103
- };
104
-
105
- const AttachmentBorder = styled.div`
106
- display: flex;
107
- flex-direction: row;
108
- border: 1px solid #dcdcdc;
109
- border-radius: 0.25rem;
110
- padding: 0.5rem;
111
- width: fit-content;
112
- margin-top: 5px;
113
- `;
114
-
115
- const FileUploaderStyle = styled.div`
116
- .label {
117
- display: block;
118
- font-weight: var(--goa-font-weight-bold);
119
- color: var(--goa-color-text-default);
120
- font-size: var(--goa-font-size-4);
121
- padding: 0 0 0.5rem 0;
122
- }
123
-
124
- .align-center {
125
- text-align-last: center;
126
- }
127
-
128
- .file-upload {
129
- margin-bottom: 0.5rem;
130
- }
131
- `;
@@ -1,3 +0,0 @@
1
- import { rankWith, RankedTester, schemaTypeIs, and, formatIs } from '@jsonforms/core';
2
-
3
- export const FileUploaderTester: RankedTester = rankWith(3, and(schemaTypeIs('string'), formatIs('file-urn')));
@@ -1,10 +0,0 @@
1
- import styled from 'styled-components';
2
-
3
- export const ReviewItem = styled.div`
4
- display: flex;
5
- width: 100%;
6
- border: 1px solid grey;
7
- border-radius: 5px;
8
- margin: 5px;
9
- padding: 10px;
10
- `;
@@ -1,269 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- import { useState, useEffect } from 'react';
3
- import { GoAFormStepper, GoAFormStep, GoAPages, GoAButton } from '@abgov/react-components-new';
4
- import {
5
- Categorization,
6
- UISchemaElement,
7
- deriveLabelForUISchemaElement,
8
- Category,
9
- StatePropsOfLayout,
10
- isVisible,
11
- isEnabled,
12
- } from '@jsonforms/core';
13
-
14
- import { TranslateProps, withJsonFormsLayoutProps, withTranslateProps, useJsonForms } from '@jsonforms/react';
15
- import { AjvProps, withAjvProps } from '@jsonforms/material-renderers';
16
- import { JsonFormsDispatch } from '@jsonforms/react';
17
- import { Hidden } from '@mui/material';
18
- import { Grid, GridItem } from '../../common/Grid';
19
- import { ReviewItem, ReviewListItem, ReviewListWrapper } from './styled-components';
20
-
21
- export interface CategorizationStepperLayoutRendererProps extends StatePropsOfLayout, AjvProps, TranslateProps {
22
- // eslint-disable-next-line
23
- data: any;
24
- }
25
-
26
- export const FormStepper = ({
27
- uischema,
28
- data,
29
- schema,
30
- // eslint-disable-next-line
31
- ajv,
32
- path,
33
- cells,
34
- renderers,
35
- config,
36
- visible,
37
- enabled,
38
- t,
39
- }: CategorizationStepperLayoutRendererProps) => {
40
- const categorization = uischema as Categorization;
41
- const [step, setStep] = useState(0);
42
- const [isFormValid, setIsFormValid] = useState(false);
43
- const [showNextBtn, setShowNextBtn] = useState(true);
44
- const categories = useMemo(
45
- () => categorization.elements.filter((category) => isVisible(category, data, '', ajv)),
46
- [categorization, data, ajv]
47
- );
48
- const disabledCategoryMap: boolean[] = categories.map((c) => !isEnabled(c, data, '', ajv));
49
- const handleSubmit = () => {
50
- console.log('submitted', data);
51
- };
52
-
53
- const CategoryLabels = useMemo(() => {
54
- return categories.map((e: Category | Categorization) => deriveLabelForUISchemaElement(e, t));
55
- }, [categories, t]);
56
-
57
- useEffect(() => {}, [categories.length]);
58
-
59
- // eslint-disable-next-line react-hooks/exhaustive-deps
60
- const vslidateFormData = (formData: Array<UISchemaElement>) => {
61
- const validate = ajv.compile(schema);
62
- return validate(formData);
63
- };
64
-
65
- useEffect(() => {
66
- const valid = vslidateFormData(data);
67
- setIsFormValid(valid);
68
- }, [data, vslidateFormData]);
69
-
70
- if (categories?.length < 1) {
71
- // eslint-disable-next-line
72
- return <></>;
73
- }
74
-
75
- function nextPage(page: number, disabled: boolean[]) {
76
- page++;
77
- while (page <= disabled.length && disabled[page - 1]) {
78
- page++;
79
- }
80
- setPage(page);
81
- }
82
-
83
- function prevPage(page: number, disabled: boolean[]) {
84
- page--;
85
- while (page >= 0 && disabled[page - 1]) {
86
- page--;
87
- }
88
- setPage(page);
89
- }
90
-
91
- function setPage(page: number) {
92
- setStep(page);
93
- if (page < 1 || page > categories.length + 1) return;
94
- if (categories.length + 1 === page) {
95
- setShowNextBtn(false);
96
- } else {
97
- setShowNextBtn(true);
98
- }
99
- }
100
- // eslint-disable-next-line react-hooks/rules-of-hooks
101
- useEffect(() => {
102
- setStep(0);
103
- // eslint-disable-next-line react-hooks/exhaustive-deps
104
- }, []);
105
- const renderStepElements = (category: Category | Categorization, indexOfCategory: number) => {
106
- return (
107
- /*
108
- [Mar-04-2024][Paul Li] the GoAPages internal state cannot handle the hidden/display well. We need extra hide/display control to it appropriately.
109
- */
110
- <Hidden xsUp={indexOfCategory !== step - 1}>
111
- {category.elements.map((elementUiSchema, index) => {
112
- return (
113
- <JsonFormsDispatch
114
- key={index}
115
- schema={schema}
116
- uischema={elementUiSchema}
117
- renderers={renderers}
118
- cells={cells}
119
- path={path}
120
- visible={visible}
121
- enabled={enabled && !disabledCategoryMap[indexOfCategory]}
122
- />
123
- );
124
- })}
125
- </Hidden>
126
- );
127
- };
128
-
129
- return (
130
- <Hidden xsUp={!visible}>
131
- <div id={`${path || `goa`}-form-stepper`} className="formStepper">
132
- <GoAFormStepper
133
- testId="form-stepper-test"
134
- step={step}
135
- onChange={(step) => {
136
- setPage(step);
137
- }}
138
- >
139
- {categories?.map((category, index) => {
140
- return (
141
- <GoAFormStep
142
- key={`${CategoryLabels[index]}-tab`}
143
- text={`${CategoryLabels[index]}${disabledCategoryMap[index] ? ' (disabled)' : ''}`}
144
- status={'incomplete'}
145
- />
146
- );
147
- })}
148
- <GoAFormStep text="Review" status="incomplete" />
149
- </GoAFormStepper>
150
- <GoAPages current={step} mb="xl">
151
- {categories?.map((category, index) => {
152
- return (
153
- <div data-testid={`step_${index}-content`} key={`${CategoryLabels[index]}`}>
154
- {renderStepElements(category, index)}
155
- </div>
156
- );
157
- })}
158
- <div>
159
- <h3 style={{ flex: 1 }}>Summary</h3>
160
-
161
- <ReviewItem>
162
- <div style={{ width: '100%' }}>
163
- {data && Object.keys(data)?.length > 0 && (
164
- <Grid>
165
- {Object.keys(flattenObject(data)).map((key, ix) => {
166
- return (
167
- <GridItem key={ix} md={6} vSpacing={1} hSpacing={0.5}>
168
- <b>{key}</b> : <PreventControlElement key={ix} value={flattenObject(data)[key]} />
169
- </GridItem>
170
- );
171
- })}
172
- </Grid>
173
- )}
174
- </div>
175
- </ReviewItem>
176
- </div>
177
- </GoAPages>
178
- {step && step !== 0 && (
179
- <div style={{ display: 'flex', justifyContent: 'space-between' }}>
180
- {step !== 1 ? (
181
- <GoAButton
182
- type="secondary"
183
- disabled={disabledCategoryMap[step - 1] || !enabled}
184
- onClick={() => prevPage(step, disabledCategoryMap)}
185
- >
186
- Previous
187
- </GoAButton>
188
- ) : (
189
- <div></div>
190
- )}
191
- {step !== null && showNextBtn && (
192
- <GoAButton
193
- type="primary"
194
- disabled={disabledCategoryMap[step - 1] || !enabled}
195
- onClick={() => nextPage(step, disabledCategoryMap)}
196
- >
197
- Next
198
- </GoAButton>
199
- )}
200
- {!showNextBtn && (
201
- <div>
202
- <GoAButton type="primary" onClick={handleSubmit} disabled={!isFormValid || !enabled}>
203
- Submit
204
- </GoAButton>
205
- </div>
206
- )}
207
- </div>
208
- )}
209
- </div>
210
- </Hidden>
211
- );
212
- };
213
-
214
- interface PreventControlElement {
215
- value: unknown;
216
- }
217
-
218
- const PreventControlElement = (props: PreventControlElement): JSX.Element => {
219
- if (typeof props?.value === 'string') return <span>{props.value}</span>;
220
-
221
- if (Array.isArray(props?.value)) {
222
- return (
223
- <div>
224
- {props.value.map((item, index) => {
225
- return (
226
- <ReviewListWrapper key={index}>
227
- {item &&
228
- Object.keys(item).map((key, innerIndex) => {
229
- if (typeof item[key] === 'string') {
230
- return (
231
- <ReviewListItem key={innerIndex}>
232
- {key}: {item[key]}
233
- </ReviewListItem>
234
- );
235
- }
236
- return (
237
- <ReviewListItem key={innerIndex}>
238
- {key}: {String(item[key])}
239
- </ReviewListItem>
240
- );
241
- })}
242
- </ReviewListWrapper>
243
- );
244
- })}
245
- </div>
246
- );
247
- }
248
-
249
- // eslint-disable-next-line
250
- return <></>;
251
- };
252
-
253
- export const flattenObject = (obj: Record<string, string>): Record<string, string> => {
254
- const flattened = {} as Record<string, string>;
255
-
256
- Object.keys(obj || {}).forEach((key) => {
257
- const value = obj[key];
258
-
259
- if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
260
- Object.assign(flattened, flattenObject(value));
261
- } else {
262
- flattened[key] = value;
263
- }
264
- });
265
-
266
- return flattened;
267
- };
268
-
269
- export const FormStepperControl = withAjvProps(withTranslateProps(withJsonFormsLayoutProps(FormStepper)));
@@ -1,22 +0,0 @@
1
- import { rankWith, RankedTester, uiTypeIs, and, optionIs, UISchemaElement, isCategorization } from '@jsonforms/core';
2
-
3
- // Ensure that all children (Category) have valid elements or things tend
4
- // to blow up. If not, the the error control will report the problem.
5
- const categoriesAreValid = (uischema: UISchemaElement): boolean => {
6
- let isValid = true;
7
- if ('type' in uischema && uischema.type === 'Categorization' && 'elements' in uischema) {
8
- (uischema.elements as UISchemaElement[]).forEach((e) => {
9
- if (e.type !== 'Category' || !('elements' in e)) {
10
- isValid = false;
11
- }
12
- });
13
- } else {
14
- return false;
15
- }
16
- return isValid;
17
- };
18
-
19
- export const CategorizationRendererTester: RankedTester = rankWith(
20
- 2,
21
- and(uiTypeIs('Categorization'), categoriesAreValid, optionIs('variant', 'stepper'))
22
- );
@@ -1,17 +0,0 @@
1
- import styled from 'styled-components';
2
-
3
- export const ReviewItem = styled.div`
4
- display: flex;
5
- border: 1px solid grey;
6
- border-radius: 5px;
7
- margin: 5px;
8
- padding: 10px;
9
- `;
10
-
11
- export const ReviewListItem = styled.div`
12
- margin-left: 1rem;
13
- `;
14
-
15
- export const ReviewListWrapper = styled.div`
16
- margin-bottom: 1rem;
17
- `;
@@ -1,52 +0,0 @@
1
- import React, { useContext } from 'react';
2
- import { GoAFormItem } from '@abgov/react-components-new';
3
- import { ControlProps } from '@jsonforms/core';
4
- import { Hidden } from '@mui/material';
5
- import { checkFieldValidity, getLabelText } from '../../util/stringUtils';
6
- export type GoAInputType =
7
- | 'text'
8
- | 'password'
9
- | 'email'
10
- | 'number'
11
- | 'date'
12
- | 'datetime-local'
13
- | 'month'
14
- | 'range'
15
- | 'search'
16
- | 'tel'
17
- | 'time'
18
- | 'url'
19
- | 'week';
20
-
21
- export interface WithInput {
22
- //eslint-disable-next-line
23
- input: any;
24
- noLabel?: boolean;
25
- }
26
-
27
- export const GoAInputBaseControl = (props: ControlProps & WithInput): JSX.Element => {
28
- // eslint-disable-next-line
29
- const { id, description, errors, uischema, visible, config, label, input, required } = props;
30
- const isValid = errors.length === 0;
31
- const InnerComponent = input;
32
- const labelToUpdate: string = getLabelText(uischema.scope, label || '');
33
-
34
- let modifiedErrors = checkFieldValidity(props as ControlProps);
35
-
36
- if (modifiedErrors === 'should be equal to one of the allowed values' && uischema?.options?.enumContext) {
37
- modifiedErrors = '';
38
- }
39
-
40
- return (
41
- <Hidden xsUp={!visible}>
42
- <GoAFormItem
43
- requirement={required ? 'required' : undefined}
44
- error={modifiedErrors}
45
- label={props?.noLabel === true ? '' : labelToUpdate}
46
- helpText={typeof uischema?.options?.help === 'string' ? uischema?.options?.help : ''}
47
- >
48
- <InnerComponent {...props} />
49
- </GoAFormItem>
50
- </Hidden>
51
- );
52
- };
@@ -1,67 +0,0 @@
1
- import React from 'react';
2
- import { isBooleanControl, RankedTester, rankWith, ControlProps, isDescriptionHidden } from '@jsonforms/core';
3
- import { withJsonFormsControlProps } from '@jsonforms/react';
4
- import { Hidden } from '@mui/material';
5
- import { GoACheckbox } from '@abgov/react-components-new';
6
- import { GoAInputBaseControl } from './InputBaseControl';
7
- import { checkFieldValidity } from '../../util/stringUtils';
8
-
9
- export const BooleanComponent = ({
10
- data,
11
- visible,
12
- enabled,
13
- uischema,
14
- handleChange,
15
- path,
16
- config,
17
- label,
18
- required,
19
- errors,
20
- description,
21
- }: ControlProps) => {
22
- const appliedUiSchemaOptions = { ...config, ...uischema.options };
23
-
24
- const showDescription = !isDescriptionHidden(
25
- visible,
26
- description,
27
- false,
28
- appliedUiSchemaOptions.showUnfocusedDescription
29
- );
30
- const errorsFormInput = checkFieldValidity({
31
- data,
32
- uischema,
33
- label,
34
- required,
35
- errors,
36
- } as ControlProps);
37
-
38
- let text = label + (required ? ' (required)' : '');
39
-
40
- if (label && description) {
41
- text = description;
42
- if (required) {
43
- text = `${description} ` + (required ? ' (required)' : '');
44
- }
45
- }
46
-
47
- return (
48
- <GoACheckbox
49
- error={errorsFormInput.length > 0}
50
- testId={`${path}-checkbox-test-id`}
51
- disabled={!enabled}
52
- text={text}
53
- name={`${path}`}
54
- checked={data}
55
- onChange={(name: string, checked: boolean, value: string) => {
56
- handleChange(path, checked);
57
- }}
58
- {...uischema?.options?.componentProps}
59
- ></GoACheckbox>
60
- );
61
- };
62
- export const BooleanControl = (props: ControlProps) => (
63
- <GoAInputBaseControl {...{ ...props, noLabel: true }} input={BooleanComponent} />
64
- );
65
-
66
- export const GoABooleanControlTester: RankedTester = rankWith(2, isBooleanControl);
67
- export const GoABooleanControl = withJsonFormsControlProps(BooleanControl);