@abgov/nx-adsp 5.9.0-beta.3 → 5.9.0-beta.4
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/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
GoAButtonGroup,
|
|
4
4
|
GoACallout,
|
|
5
5
|
GoACheckbox,
|
|
6
|
+
GoADivider,
|
|
6
7
|
GoADropdown,
|
|
7
8
|
GoADropdownItem,
|
|
8
9
|
GoAFormItem,
|
|
@@ -35,6 +36,20 @@ import {
|
|
|
35
36
|
} from './<%= fileName %>.slice';
|
|
36
37
|
import styles from './<%= fileName %>.module.css';
|
|
37
38
|
|
|
39
|
+
// Function that supports raising change events for updates to properties on array items.
|
|
40
|
+
// Note that this is not needed if the form does not include an array field.
|
|
41
|
+
function onArrayItemChange(
|
|
42
|
+
onChange: (value: Record<string, unknown>) => void,
|
|
43
|
+
value: Record<string, unknown>,
|
|
44
|
+
arrayProperty: string,
|
|
45
|
+
index: number,
|
|
46
|
+
updatedItem: object
|
|
47
|
+
) {
|
|
48
|
+
const updatedArray = [...(value[arrayProperty] as object[])];
|
|
49
|
+
updatedArray[index] = updatedItem;
|
|
50
|
+
onChange({ ...value, [arrayProperty]: updatedArray });
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
interface FieldSetProps {
|
|
39
54
|
className?: string;
|
|
40
55
|
inReview: boolean;
|
|
@@ -62,8 +77,8 @@ const <%= section.className %>FieldSet: FunctionComponent<FieldSetProps> = ({
|
|
|
62
77
|
<p><%= section.description %></p>
|
|
63
78
|
{!isReadOnly && inReview && <GoAButton type="tertiary" onClick={onEdit}>Edit</GoAButton>}
|
|
64
79
|
</div>
|
|
65
|
-
<%_ Object.entries(section.properties).forEach(function([key,
|
|
66
|
-
<%- include(`${includesPath}/input-template.ejs`, {key
|
|
80
|
+
<%_ Object.entries(section.properties).forEach(function([key, property]) { _%>
|
|
81
|
+
<%- include(`${includesPath}/input-template.ejs`, {key, property, path: key, inArray: false, includesPath}); %>
|
|
67
82
|
<%_ }); _%>
|
|
68
83
|
</fieldset>
|
|
69
84
|
);
|
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
<%_
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<%_ const valueVar = inArray ? 'item' : 'value'; %>
|
|
2
|
+
<%_ if (!property.type) { _%>
|
|
3
|
+
<%_ if (property.constant) { _%>
|
|
4
|
+
<p><%= property.constant %></p>
|
|
4
5
|
<%_ } _%>
|
|
5
6
|
<%_ } else { _%>
|
|
6
|
-
<GoAFormItem mb="m" label="<%=
|
|
7
|
-
<%_ switch(
|
|
7
|
+
<GoAFormItem mb="m" label="<%= property.title || key %>" helpText="<%= property.description %>">
|
|
8
|
+
<%_ switch(property.type) {
|
|
8
9
|
case 'string': _%>
|
|
9
|
-
<%_ if (
|
|
10
|
+
<%_ if (property.enum) { _%>
|
|
10
11
|
<GoADropdown
|
|
11
12
|
name="<%= key %>"
|
|
12
13
|
disabled={isReadOnly || inReview}
|
|
13
|
-
onChange={(name,updated) => onChange
|
|
14
|
-
value={`${
|
|
14
|
+
onChange={(name,updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: updated })}
|
|
15
|
+
value={`${<%= valueVar %>.<%= key %> || ''}`}
|
|
15
16
|
>
|
|
16
|
-
<%_
|
|
17
|
+
<%_ property.enum.forEach((enumValue) => { _%>
|
|
17
18
|
<GoADropdownItem value="<%= enumValue %>" label="<%= enumValue %>" />
|
|
18
19
|
<%_ }); _%>
|
|
19
20
|
</GoADropdown>
|
|
20
21
|
<%_ } else { _%>
|
|
21
|
-
<%_ switch(
|
|
22
|
+
<%_ switch(property.format) {
|
|
22
23
|
case 'date-time': _%>
|
|
23
24
|
<GoAInputDateTime
|
|
24
25
|
name="<%= key %>"
|
|
25
26
|
disabled={isReadOnly || inReview}
|
|
26
|
-
value={
|
|
27
|
-
onChange={(name, updated) => onChange
|
|
27
|
+
value={<%= valueVar %>.<%= key %> ? new Date(<%= valueVar %>.<%= key %> as string) : null}
|
|
28
|
+
onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: (updated as Date)?.toISOString() })}
|
|
28
29
|
/>
|
|
29
30
|
<%_ break;
|
|
30
31
|
case 'date': _%>
|
|
31
32
|
<GoAInputDate
|
|
32
33
|
name="<%= key %>"
|
|
33
34
|
disabled={isReadOnly || inReview}
|
|
34
|
-
value={
|
|
35
|
-
onChange={(name, updated) => onChange
|
|
35
|
+
value={<%= valueVar %>.<%= key %> ? new Date(<%= valueVar %>.<%= key %> as string) : null}
|
|
36
|
+
onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: (updated as Date)?.toISOString() })}
|
|
36
37
|
/>
|
|
37
38
|
<%_ break;
|
|
38
39
|
case 'time': _%>
|
|
@@ -40,28 +41,28 @@
|
|
|
40
41
|
name="<%= key %>"
|
|
41
42
|
step={1}
|
|
42
43
|
disabled={isReadOnly || inReview}
|
|
43
|
-
value={
|
|
44
|
-
onChange={(name, updated) => onChange
|
|
44
|
+
value={<%= valueVar %>.<%= key %> ? new Date(<%= valueVar %>.<%= key %> as string) : null}
|
|
45
|
+
onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: (updated as Date)?.toISOString() })}
|
|
45
46
|
/>
|
|
46
47
|
<%_ break;
|
|
47
48
|
default: _%>
|
|
48
|
-
<% if (
|
|
49
|
+
<% if (property.maxLength > 100) { %>
|
|
49
50
|
<GoATextArea
|
|
50
51
|
disabled={isReadOnly || inReview}
|
|
51
|
-
error={errors[
|
|
52
|
-
placeholder="<%=
|
|
53
|
-
onChange={(name, updated) => onChange
|
|
54
|
-
value={`${
|
|
52
|
+
error={errors[`<%= path %>`]}
|
|
53
|
+
placeholder="<%= property?.examples?.join(', ') || '' %>"
|
|
54
|
+
onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: updated })}
|
|
55
|
+
value={`${<%= valueVar %>.<%= key %> || ''}`}
|
|
55
56
|
name="<%= key %>"
|
|
56
57
|
/>
|
|
57
58
|
<% } else { %>
|
|
58
59
|
<GoAInput
|
|
59
60
|
type="text"
|
|
60
61
|
disabled={isReadOnly || inReview}
|
|
61
|
-
error={errors[
|
|
62
|
-
placeholder="<%=
|
|
63
|
-
onChange={(name, updated) => onChange
|
|
64
|
-
value={`${
|
|
62
|
+
error={errors[`<%= path %>`]}
|
|
63
|
+
placeholder="<%= property?.examples?.join(', ') || '' %>"
|
|
64
|
+
onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: updated })}
|
|
65
|
+
value={`${<%= valueVar %>.<%= key %> || ''}`}
|
|
65
66
|
name="<%= key %>"
|
|
66
67
|
/>
|
|
67
68
|
<% } %>
|
|
@@ -74,31 +75,69 @@
|
|
|
74
75
|
<GoAInput
|
|
75
76
|
type="number"
|
|
76
77
|
disabled={isReadOnly || inReview}
|
|
77
|
-
error={errors[
|
|
78
|
-
placeholder="<%=
|
|
79
|
-
onChange={(name, updated) => onChange
|
|
80
|
-
value={`${
|
|
78
|
+
error={errors[`<%= path %>`]}
|
|
79
|
+
placeholder="<%= property?.examples || []%>"
|
|
80
|
+
onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: parseFloat(updated) })}
|
|
81
|
+
value={`${<%= valueVar %>.<%= key %> || ''}`}
|
|
81
82
|
name="<%= key %>"
|
|
82
|
-
<%_ if (
|
|
83
|
-
max={<%=
|
|
83
|
+
<%_ if (property?.maximum !== undefined) { _%>
|
|
84
|
+
max={<%= property.maximum %>}
|
|
84
85
|
<%_ } _%>
|
|
85
|
-
<%_ if (
|
|
86
|
-
min={<%=
|
|
86
|
+
<%_ if (property?.minimum !== undefined) { _%>
|
|
87
|
+
min={<%= property.minimum %>}
|
|
87
88
|
<%_ } _%>
|
|
88
|
-
<%_ if (
|
|
89
|
-
step={<%=
|
|
89
|
+
<%_ if (property?.multipleOf !== undefined) { _%>
|
|
90
|
+
step={<%= property.multipleOf %>}
|
|
90
91
|
<%_ } _%>
|
|
91
92
|
/>
|
|
92
93
|
<%_ break;
|
|
93
94
|
case 'boolean': _%>
|
|
94
95
|
<GoACheckbox
|
|
95
96
|
disabled={isReadOnly || inReview}
|
|
96
|
-
checked={
|
|
97
|
-
onChange={(name, updated) => onChange
|
|
97
|
+
checked={<%= valueVar %>.<%= key %> as any || false}
|
|
98
|
+
onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: updated })}
|
|
98
99
|
name="<%= key %>"
|
|
99
100
|
/>
|
|
100
101
|
<%_ break;
|
|
101
102
|
case 'array': _%>
|
|
103
|
+
<% if (!inArray && property.items?.type === 'object') { %>
|
|
104
|
+
<fieldset>
|
|
105
|
+
<legend><%= property.items.title || key %></legend>
|
|
106
|
+
<p><%= property.items.description %></p>
|
|
107
|
+
{(<%= valueVar %>.<%= key %> as Record<string, unknown>[])?.map((item, idx) => (
|
|
108
|
+
<div key={idx}>
|
|
109
|
+
<% Object.entries(property.items.properties || {}).map(([key, property]) => { %>
|
|
110
|
+
<%- include(`${includesPath}/input-template.ejs`, {key, property, parent: path, path: path + ".[${idx}]." + key, inArray: true, includesPath}); %>
|
|
111
|
+
<% }); %>
|
|
112
|
+
{!inReview && <GoAButtonGroup alignment="end">
|
|
113
|
+
<GoAButton
|
|
114
|
+
disabled={isReadOnly}
|
|
115
|
+
type="tertiary"
|
|
116
|
+
onClick={() => {
|
|
117
|
+
const update = [...(<%= valueVar %>.<%= key %> as [] || [])];
|
|
118
|
+
update.splice(idx, 1);
|
|
119
|
+
<%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, <%= key %>: update })
|
|
120
|
+
}}
|
|
121
|
+
>
|
|
122
|
+
Remove
|
|
123
|
+
</GoAButton>
|
|
124
|
+
</GoAButtonGroup>}
|
|
125
|
+
<GoADivider mb="l" />
|
|
126
|
+
</div>
|
|
127
|
+
))}
|
|
128
|
+
{!inReview && <GoAButtonGroup alignment="end">
|
|
129
|
+
<GoAButton
|
|
130
|
+
disabled={isReadOnly}
|
|
131
|
+
type="tertiary"
|
|
132
|
+
onClick={() =>
|
|
133
|
+
<%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, <%= key %>: [...(<%= valueVar %>.<%= key %> as [] || []), {}] })
|
|
134
|
+
}
|
|
135
|
+
>
|
|
136
|
+
Add
|
|
137
|
+
</GoAButton>
|
|
138
|
+
</GoAButtonGroup>}
|
|
139
|
+
</fieldset>
|
|
140
|
+
<% } %>
|
|
102
141
|
<%_ break;
|
|
103
142
|
default:
|
|
104
143
|
break; _%>
|