@homefile/components-v2 2.25.3 → 2.25.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/dist/components/forms/dynamicForm/DynamicForm.js +4 -1
- package/dist/components/forms/dynamicForm/fields/EditCollapsible.d.ts +2 -0
- package/dist/components/forms/dynamicForm/fields/EditCollapsible.js +19 -0
- package/dist/components/forms/dynamicForm/fields/index.d.ts +1 -0
- package/dist/components/forms/dynamicForm/fields/index.js +1 -0
- package/dist/utils/DynamicForm.utils.js +32 -4
- package/package.json +1 -1
- package/src/components/forms/dynamicForm/DynamicForm.tsx +7 -0
- package/src/components/forms/dynamicForm/fields/EditCollapsible.tsx +34 -0
- package/src/components/forms/dynamicForm/fields/index.ts +1 -0
- package/src/utils/DynamicForm.utils.ts +37 -4
|
@@ -14,7 +14,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
14
14
|
import { FormProvider } from 'react-hook-form';
|
|
15
15
|
import { t } from 'i18next';
|
|
16
16
|
import { Box, Stack, Text } from '@chakra-ui/react';
|
|
17
|
-
import { HiddenFieldSection, GroupField, TextField, TextAreaField, SelectField, RatingField, GridField, FieldWithDelete, FileField, SwitchField, DateField, NumberField, CurrencyField, TileBody, CheckboxGroupField, CheckboxAgreement, AIGridField, SearchItemLoader, } from '../..';
|
|
17
|
+
import { HiddenFieldSection, GroupField, TextField, TextAreaField, SelectField, RatingField, GridField, FieldWithDelete, FileField, SwitchField, DateField, NumberField, CurrencyField, TileBody, CheckboxGroupField, CheckboxAgreement, AIGridField, SearchItemLoader, EditCollapsible, } from '../..';
|
|
18
18
|
import { useDynamicForm } from '../../../hooks';
|
|
19
19
|
import { fieldIcons } from '../../../helpers';
|
|
20
20
|
export const DynamicForm = (_a) => {
|
|
@@ -68,6 +68,9 @@ export const DynamicForm = (_a) => {
|
|
|
68
68
|
_jsx(RatingField, Object.assign({}, baseProps))));
|
|
69
69
|
case 'ai-grid':
|
|
70
70
|
return (_jsxs(Stack, { p: "base", spacing: "base", bg: "lightBlue.2", children: [description && (_jsx(Text, { fontFamily: "secondary", children: description })), _jsx(AIGridField, Object.assign({}, baseProps, { onRemove: onRemoveImage, onUpload: (files) => handleFilesUpload({ id, files }), onAISend: onAISend, children: children }))] }, id));
|
|
71
|
+
case 'collapsible':
|
|
72
|
+
return (_createElement(FieldWithDelete, Object.assign({}, fieldWithDeleteBaseProps, { key: id }),
|
|
73
|
+
_jsx(EditCollapsible, Object.assign({}, field))));
|
|
71
74
|
case 'grid':
|
|
72
75
|
return (_createElement(FieldWithDelete, Object.assign({}, fieldWithDeleteBaseProps, { key: id }),
|
|
73
76
|
_jsx(GridField, Object.assign({}, baseProps, { showIcon: showIcon, children: children }))));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Stack } from '@chakra-ui/react';
|
|
3
|
+
import { Collapsible, TextAreaField } from '../../..';
|
|
4
|
+
export const EditCollapsible = ({ children, }) => {
|
|
5
|
+
return (_jsx(Stack, { bg: "lightBlue.2", spacing: "2px", width: '100%', children: children === null || children === void 0 ? void 0 : children.map(({ id, name = '', value, type }) => {
|
|
6
|
+
const baseProps = {
|
|
7
|
+
id,
|
|
8
|
+
value,
|
|
9
|
+
type,
|
|
10
|
+
name,
|
|
11
|
+
};
|
|
12
|
+
switch (type) {
|
|
13
|
+
case 'textarea':
|
|
14
|
+
return (_jsx(Collapsible, { title: name, showShadow: false, children: _jsx(TextAreaField, Object.assign({}, baseProps)) }, `${id}-${name}-${value}-${type}`));
|
|
15
|
+
default:
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}) }));
|
|
19
|
+
};
|
|
@@ -28,12 +28,14 @@ export const mapApiObjectToFormFields = ({ obj = {}, depth = 0, labelPrefix = ''
|
|
|
28
28
|
}
|
|
29
29
|
// string array
|
|
30
30
|
if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
|
|
31
|
-
return [buildField(currentLabel, 'textarea', value.join('<br/>'))]
|
|
31
|
+
// return [buildField(currentLabel, 'textarea', value.join('<br/>'))]
|
|
32
|
+
return [buildCollapsibleField(currentLabel, value.join('<br/>'))];
|
|
32
33
|
}
|
|
33
34
|
// object array directly
|
|
34
35
|
if (Array.isArray(value) &&
|
|
35
36
|
value.every((v) => Object.prototype.toString.call(v) === '[object Object]')) {
|
|
36
|
-
return [buildField(currentLabel, 'textarea', renderObjectArray(value))]
|
|
37
|
+
// return [buildField(currentLabel, 'textarea', renderObjectArray(value))]
|
|
38
|
+
return [buildCollapsibleField(currentLabel, renderObjectArray(value))];
|
|
37
39
|
}
|
|
38
40
|
// object with single array field
|
|
39
41
|
if (isRecord(value)) {
|
|
@@ -44,7 +46,7 @@ export const mapApiObjectToFormFields = ({ obj = {}, depth = 0, labelPrefix = ''
|
|
|
44
46
|
const [subKey, subArr] = entries[0];
|
|
45
47
|
const label = `${currentLabel} - ${capitalize(subKey)}`;
|
|
46
48
|
return [
|
|
47
|
-
Object.assign(Object.assign({},
|
|
49
|
+
Object.assign(Object.assign({}, buildCollapsibleField(label, renderObjectArray(subArr))), { name: label, label }),
|
|
48
50
|
];
|
|
49
51
|
}
|
|
50
52
|
}
|
|
@@ -58,7 +60,8 @@ export const mapApiObjectToFormFields = ({ obj = {}, depth = 0, labelPrefix = ''
|
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
62
|
// shallow object -> flatten
|
|
61
|
-
return [buildField(currentLabel, 'textarea', renderObject(value))]
|
|
63
|
+
// return [buildField(currentLabel, 'textarea', renderObject(value))]
|
|
64
|
+
return [buildCollapsibleField(currentLabel, renderObject(value))];
|
|
62
65
|
}
|
|
63
66
|
// fallback
|
|
64
67
|
return [buildField(currentLabel, 'default', String(value), false)];
|
|
@@ -75,6 +78,31 @@ const buildField = (name, type, value, visible = true) => ({
|
|
|
75
78
|
type: type,
|
|
76
79
|
visible,
|
|
77
80
|
});
|
|
81
|
+
const buildCollapsibleField = (name,
|
|
82
|
+
// type: string,
|
|
83
|
+
value, visible = true) => {
|
|
84
|
+
const childObj = {
|
|
85
|
+
id: uuidv4(),
|
|
86
|
+
name,
|
|
87
|
+
label: name,
|
|
88
|
+
description: '',
|
|
89
|
+
comments: '',
|
|
90
|
+
value,
|
|
91
|
+
type: 'textarea',
|
|
92
|
+
visible,
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
id: uuidv4(),
|
|
96
|
+
name,
|
|
97
|
+
label: name,
|
|
98
|
+
description: '',
|
|
99
|
+
comments: '',
|
|
100
|
+
value,
|
|
101
|
+
type: 'collapsible',
|
|
102
|
+
visible,
|
|
103
|
+
children: [childObj]
|
|
104
|
+
};
|
|
105
|
+
};
|
|
78
106
|
const renderObjectArray = (arr) => arr
|
|
79
107
|
.map((item) => `<div>${renderObject(item).replace(/<br\/\>/g, '')}</div>`)
|
|
80
108
|
.join('<br/>');
|
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
CheckboxAgreement,
|
|
22
22
|
AIGridField,
|
|
23
23
|
SearchItemLoader,
|
|
24
|
+
EditCollapsible,
|
|
24
25
|
} from '@/components'
|
|
25
26
|
import { useDynamicForm } from '@/hooks'
|
|
26
27
|
import { fieldIcons } from '@/helpers'
|
|
@@ -173,6 +174,12 @@ export const DynamicForm = ({
|
|
|
173
174
|
</AIGridField>
|
|
174
175
|
</Stack>
|
|
175
176
|
)
|
|
177
|
+
case 'collapsible':
|
|
178
|
+
return (
|
|
179
|
+
<FieldWithDelete {...fieldWithDeleteBaseProps} key={id}>
|
|
180
|
+
<EditCollapsible {...field} />
|
|
181
|
+
</FieldWithDelete>
|
|
182
|
+
)
|
|
176
183
|
case 'grid':
|
|
177
184
|
return (
|
|
178
185
|
<FieldWithDelete {...fieldWithDeleteBaseProps} key={id}>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Stack } from '@chakra-ui/react'
|
|
2
|
+
import { Collapsible, TextAreaField } from '@/components'
|
|
3
|
+
import { ReportI } from '@/interfaces'
|
|
4
|
+
|
|
5
|
+
export const EditCollapsible = ({
|
|
6
|
+
children,
|
|
7
|
+
}: Pick<ReportI, 'children'>) => {
|
|
8
|
+
return (
|
|
9
|
+
<Stack bg="lightBlue.2" spacing="2px" width={'100%'}>
|
|
10
|
+
{children?.map(({ id, name = '', value, type }) => {
|
|
11
|
+
const baseProps = {
|
|
12
|
+
id,
|
|
13
|
+
value,
|
|
14
|
+
type,
|
|
15
|
+
name,
|
|
16
|
+
}
|
|
17
|
+
switch (type) {
|
|
18
|
+
case 'textarea':
|
|
19
|
+
return (
|
|
20
|
+
<Collapsible
|
|
21
|
+
title={name}
|
|
22
|
+
showShadow={false}
|
|
23
|
+
key={`${id}-${name}-${value}-${type}`}
|
|
24
|
+
>
|
|
25
|
+
<TextAreaField {...baseProps} />
|
|
26
|
+
</Collapsible>
|
|
27
|
+
)
|
|
28
|
+
default:
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
})}
|
|
32
|
+
</Stack>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
@@ -47,7 +47,8 @@ export const mapApiObjectToFormFields = ({
|
|
|
47
47
|
|
|
48
48
|
// string array
|
|
49
49
|
if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
|
|
50
|
-
return [buildField(currentLabel, 'textarea', value.join('<br/>'))]
|
|
50
|
+
// return [buildField(currentLabel, 'textarea', value.join('<br/>'))]
|
|
51
|
+
return [buildCollapsibleField(currentLabel, value.join('<br/>'))]
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
// object array directly
|
|
@@ -57,7 +58,8 @@ export const mapApiObjectToFormFields = ({
|
|
|
57
58
|
(v) => Object.prototype.toString.call(v) === '[object Object]'
|
|
58
59
|
)
|
|
59
60
|
) {
|
|
60
|
-
return [buildField(currentLabel, 'textarea', renderObjectArray(value))]
|
|
61
|
+
// return [buildField(currentLabel, 'textarea', renderObjectArray(value))]
|
|
62
|
+
return [buildCollapsibleField(currentLabel, renderObjectArray(value))]
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
// object with single array field
|
|
@@ -72,7 +74,8 @@ export const mapApiObjectToFormFields = ({
|
|
|
72
74
|
const label = `${currentLabel} - ${capitalize(subKey)}`
|
|
73
75
|
return [
|
|
74
76
|
{
|
|
75
|
-
...buildField(label, 'textarea', renderObjectArray(subArr)),
|
|
77
|
+
// ...buildField(label, 'textarea', renderObjectArray(subArr)),
|
|
78
|
+
...buildCollapsibleField(label, renderObjectArray(subArr)),
|
|
76
79
|
name: label,
|
|
77
80
|
label,
|
|
78
81
|
},
|
|
@@ -90,7 +93,8 @@ export const mapApiObjectToFormFields = ({
|
|
|
90
93
|
})
|
|
91
94
|
}
|
|
92
95
|
// shallow object -> flatten
|
|
93
|
-
return [buildField(currentLabel, 'textarea', renderObject(value))]
|
|
96
|
+
// return [buildField(currentLabel, 'textarea', renderObject(value))]
|
|
97
|
+
return [buildCollapsibleField(currentLabel, renderObject(value))]
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
// fallback
|
|
@@ -115,6 +119,35 @@ const buildField = (
|
|
|
115
119
|
visible,
|
|
116
120
|
})
|
|
117
121
|
|
|
122
|
+
const buildCollapsibleField = (
|
|
123
|
+
name: string,
|
|
124
|
+
// type: string,
|
|
125
|
+
value: string,
|
|
126
|
+
visible = true
|
|
127
|
+
): ReportI => {
|
|
128
|
+
const childObj: ReportI = {
|
|
129
|
+
id: uuidv4(),
|
|
130
|
+
name,
|
|
131
|
+
label: name,
|
|
132
|
+
description: '',
|
|
133
|
+
comments: '',
|
|
134
|
+
value,
|
|
135
|
+
type: 'textarea',
|
|
136
|
+
visible,
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
id: uuidv4(),
|
|
140
|
+
name,
|
|
141
|
+
label: name,
|
|
142
|
+
description: '',
|
|
143
|
+
comments: '',
|
|
144
|
+
value,
|
|
145
|
+
type: 'collapsible',
|
|
146
|
+
visible,
|
|
147
|
+
children: [childObj]
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
118
151
|
const renderObjectArray = (arr: Record<string, any>[]): string =>
|
|
119
152
|
arr
|
|
120
153
|
.map((item) => `<div>${renderObject(item).replace(/<br\/\>/g, '')}</div>`)
|