@solidstarters/solid-core-ui 1.1.31 → 1.1.33
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/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.d.ts +7 -0
- package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.d.ts.map +1 -0
- package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.js +17 -0
- package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.js.map +1 -0
- package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.d.ts +7 -0
- package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.d.ts.map +1 -0
- package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.js +17 -0
- package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.js.map +1 -0
- package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.d.ts +3 -0
- package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.d.ts.map +1 -0
- package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.js +78 -0
- package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.js.map +1 -0
- package/dist/components/core/form/SolidFormView.d.ts.map +1 -1
- package/dist/components/core/form/SolidFormView.js +89 -36
- package/dist/components/core/form/SolidFormView.js.map +1 -1
- package/dist/components/core/form/fields/SolidBooleanField.d.ts +1 -0
- package/dist/components/core/form/fields/SolidBooleanField.d.ts.map +1 -1
- package/dist/components/core/form/fields/SolidBooleanField.js +36 -8
- package/dist/components/core/form/fields/SolidBooleanField.js.map +1 -1
- package/dist/components/core/form/fields/SolidLongTextField.d.ts +2 -0
- package/dist/components/core/form/fields/SolidLongTextField.d.ts.map +1 -1
- package/dist/components/core/form/fields/SolidLongTextField.js +32 -3
- package/dist/components/core/form/fields/SolidLongTextField.js.map +1 -1
- package/dist/components/core/form/fields/SolidSelectionStaticField.d.ts +1 -0
- package/dist/components/core/form/fields/SolidSelectionStaticField.d.ts.map +1 -1
- package/dist/components/core/form/fields/SolidSelectionStaticField.js +19 -20
- package/dist/components/core/form/fields/SolidSelectionStaticField.js.map +1 -1
- package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.d.ts +1 -3
- package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.d.ts.map +1 -1
- package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.js +19 -274
- package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.js.map +1 -1
- package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.d.ts +3 -0
- package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.d.ts.map +1 -0
- package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.js +38 -0
- package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.js.map +1 -0
- package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.d.ts +3 -0
- package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.d.ts.map +1 -0
- package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.js +48 -0
- package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.js.map +1 -0
- package/dist/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.d.ts +2 -0
- package/dist/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.d.ts.map +1 -0
- package/dist/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.js +35 -0
- package/dist/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.js.map +1 -0
- package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.d.ts +6 -0
- package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.d.ts.map +1 -0
- package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.js +119 -0
- package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.js.map +1 -0
- package/dist/components/core/form/fields/widgets/SolidBooleanCheckboxFieldWidget.d.ts +3 -0
- package/dist/components/core/form/fields/widgets/SolidBooleanCheckboxFieldWidget.d.ts.map +1 -0
- package/dist/components/core/form/fields/widgets/SolidBooleanCheckboxFieldWidget.js +57 -0
- package/dist/components/core/form/fields/widgets/SolidBooleanCheckboxFieldWidget.js.map +1 -0
- package/dist/components/core/form/fields/widgets/SolidBooleanSelectFieldWidget.d.ts +3 -0
- package/dist/components/core/form/fields/widgets/SolidBooleanSelectFieldWidget.d.ts.map +1 -0
- package/dist/components/core/form/fields/widgets/SolidBooleanSelectFieldWidget.js +30 -0
- package/dist/components/core/form/fields/widgets/SolidBooleanSelectFieldWidget.js.map +1 -0
- package/dist/components/core/form/fields/widgets/SolidSelectionStaticAutocompleteFieldWidget.d.ts +3 -0
- package/dist/components/core/form/fields/widgets/SolidSelectionStaticAutocompleteFieldWidget.d.ts.map +1 -0
- package/dist/components/core/form/fields/widgets/SolidSelectionStaticAutocompleteFieldWidget.js +50 -0
- package/dist/components/core/form/fields/widgets/SolidSelectionStaticAutocompleteFieldWidget.js.map +1 -0
- package/dist/components/core/form/fields/widgets/SolidSelectionStaticRadioFieldWidget.d.ts +3 -0
- package/dist/components/core/form/fields/widgets/SolidSelectionStaticRadioFieldWidget.d.ts.map +1 -0
- package/dist/components/core/form/fields/widgets/SolidSelectionStaticRadioFieldWidget.js +32 -0
- package/dist/components/core/form/fields/widgets/SolidSelectionStaticRadioFieldWidget.js.map +1 -0
- package/dist/helpers/registry.d.ts +1 -1
- package/dist/helpers/registry.d.ts.map +1 -1
- package/dist/helpers/registry.js +27 -2
- package/dist/helpers/registry.js.map +1 -1
- package/package.json +1 -1
- package/src/components/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.ts +18 -0
- package/src/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.ts +18 -0
- package/src/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.tsx +123 -0
- package/src/components/core/form/SolidFormView.tsx +75 -21
- package/src/components/core/form/fields/SolidBooleanField.tsx +45 -37
- package/src/components/core/form/fields/SolidLongTextField.tsx +79 -20
- package/src/components/core/form/fields/SolidSelectionStaticField.tsx +33 -46
- package/src/components/core/form/fields/relations/SolidRelationManyToManyField.tsx +20 -356
- package/src/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.tsx +74 -0
- package/src/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.tsx +103 -0
- package/src/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.tsx +33 -0
- package/src/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.ts +64 -0
- package/src/components/core/form/fields/widgets/SolidBooleanCheckboxFieldWidget.tsx +79 -0
- package/src/components/core/form/fields/widgets/SolidBooleanSelectFieldWidget.tsx +68 -0
- package/src/components/core/form/fields/widgets/SolidSelectionStaticAutocompleteFieldWidget.tsx +72 -0
- package/src/components/core/form/fields/widgets/SolidSelectionStaticRadioFieldWidget.tsx +71 -0
- package/src/helpers/registry.ts +29 -2
- package/src/types/solid-core.d.ts +23 -1
|
@@ -5,6 +5,8 @@ import { useState } from "react";
|
|
|
5
5
|
import * as Yup from 'yup';
|
|
6
6
|
import { Schema } from "yup";
|
|
7
7
|
import { FormikObject, ISolidField, SolidFieldProps } from "./ISolidField";
|
|
8
|
+
import { getExtensionComponent } from "@/helpers/registry";
|
|
9
|
+
import { SolidSelectionStaticFieldWidgetProps } from "@/types/solid-core";
|
|
8
10
|
|
|
9
11
|
export class SolidSelectionStaticField implements ISolidField {
|
|
10
12
|
|
|
@@ -84,54 +86,39 @@ export class SolidSelectionStaticField implements ISolidField {
|
|
|
84
86
|
|
|
85
87
|
const formDisabled = solidFormViewMetaData.data.solidView?.layout?.attrs?.disabled;
|
|
86
88
|
const formReadonly = solidFormViewMetaData.data.solidView?.layout?.attrs?.readonly;
|
|
87
|
-
|
|
88
|
-
const [selectionStaticItems, setSelectionStaticItems] = useState([]);
|
|
89
|
-
const selectionStaticSearch = (event: AutoCompleteCompleteEvent) => {
|
|
90
|
-
const selectionStaticData = fieldMetadata.selectionStaticValues.map((i: string) => {
|
|
91
|
-
return {
|
|
92
|
-
label: i.split(":")[1],
|
|
93
|
-
value: i.split(":")[0]
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
const suggestionData = selectionStaticData.filter((t: any) => t.value.toLowerCase().startsWith(event.query.toLowerCase()));
|
|
97
|
-
setSelectionStaticItems(suggestionData)
|
|
98
|
-
}
|
|
99
89
|
const isFormFieldValid = (formik: any, fieldName: string) => formik.touched[fieldName] && formik.errors[fieldName];
|
|
100
|
-
|
|
90
|
+
let renderMode = fieldLayoutInfo.attrs.renderMode;
|
|
91
|
+
if (!renderMode) {
|
|
92
|
+
renderMode = 'field-autocomplete';
|
|
93
|
+
}
|
|
101
94
|
return (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
</label>
|
|
110
|
-
}
|
|
111
|
-
<AutoComplete
|
|
112
|
-
readOnly={formReadonly || fieldReadonly || readOnlyPermission}
|
|
113
|
-
disabled={formDisabled || fieldDisabled}
|
|
114
|
-
{...formik.getFieldProps(fieldLayoutInfo.attrs.name)}
|
|
115
|
-
id={fieldLayoutInfo.attrs.name}
|
|
116
|
-
name={fieldLayoutInfo.attrs.name}
|
|
117
|
-
field="label"
|
|
118
|
-
value={formik.values[fieldLayoutInfo.attrs.name] || ''}
|
|
119
|
-
dropdown
|
|
120
|
-
suggestions={selectionStaticItems}
|
|
121
|
-
completeMethod={selectionStaticSearch}
|
|
122
|
-
// onChange={(e) => updateInputs(index, e.value)} />
|
|
123
|
-
// onChange={formik.handleChange}
|
|
124
|
-
onChange={(e) => this.fieldContext.onChange(e, 'onFieldChange')}
|
|
125
|
-
className="solid-standard-autocomplete"
|
|
126
|
-
/>
|
|
95
|
+
<>
|
|
96
|
+
{renderMode &&
|
|
97
|
+
this.renderExtensionRenderMode(renderMode, formik)
|
|
98
|
+
}
|
|
99
|
+
{isFormFieldValid(formik, fieldLayoutInfo.attrs.name) && (
|
|
100
|
+
<div className="absolute mt-1">
|
|
101
|
+
<Message severity="error" text={formik?.errors[fieldLayoutInfo.attrs.name]?.toString()} />
|
|
127
102
|
</div>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
<Message severity="error" text={formik?.errors[fieldLayoutInfo.attrs.name]?.toString()} />
|
|
131
|
-
</div>
|
|
132
|
-
)}
|
|
133
|
-
</div>
|
|
134
|
-
</div>
|
|
103
|
+
)}
|
|
104
|
+
</>
|
|
135
105
|
);
|
|
136
106
|
}
|
|
137
|
-
|
|
107
|
+
|
|
108
|
+
renderExtensionRenderMode(widgetName: string, formik: FormikObject) {
|
|
109
|
+
let DynamicWidget = getExtensionComponent(widgetName);
|
|
110
|
+
if (!DynamicWidget) {
|
|
111
|
+
DynamicWidget = getExtensionComponent('field-autocomplete');
|
|
112
|
+
}
|
|
113
|
+
const widgetProps: SolidSelectionStaticFieldWidgetProps = {
|
|
114
|
+
formik: formik,
|
|
115
|
+
fieldContext: this.fieldContext,
|
|
116
|
+
}
|
|
117
|
+
return (
|
|
118
|
+
<>
|
|
119
|
+
{DynamicWidget && <DynamicWidget {...widgetProps} />}
|
|
120
|
+
</>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createSolidEntityApi } from "@/redux/api/solidEntityApi";
|
|
3
|
-
import { camelCase, capitalize } from "lodash";
|
|
4
|
-
import { AutoComplete, AutoCompleteCompleteEvent } from "primereact/autocomplete";
|
|
5
|
-
import { Button } from "primereact/button";
|
|
6
|
-
import { Checkbox } from "primereact/checkbox";
|
|
7
|
-
import { Dialog } from "primereact/dialog";
|
|
8
2
|
import { Message } from "primereact/message";
|
|
9
|
-
import {
|
|
10
|
-
import qs from "qs";
|
|
11
|
-
import { useEffect, useState } from "react";
|
|
3
|
+
import { useState } from "react";
|
|
12
4
|
import * as Yup from 'yup';
|
|
13
5
|
import { Schema } from "yup";
|
|
14
|
-
import SolidFormView from "../../SolidFormView";
|
|
15
6
|
import { FormikObject, ISolidField, SolidFieldProps } from "../ISolidField";
|
|
7
|
+
import { getExtensionComponent } from "@/helpers/registry";
|
|
8
|
+
import { SolidRelationManyToManyFieldWidgetProps } from "@/types/solid-core";
|
|
16
9
|
|
|
17
10
|
|
|
18
11
|
|
|
@@ -40,7 +33,6 @@ export class SolidRelationManyToManyField implements ISolidField {
|
|
|
40
33
|
};
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
|
-
// return { label: manyToOneColVal || '', value: manyToOneFieldData?.id || '' };
|
|
44
36
|
|
|
45
37
|
return [];
|
|
46
38
|
}
|
|
@@ -48,10 +40,6 @@ export class SolidRelationManyToManyField implements ISolidField {
|
|
|
48
40
|
updateFormData(value: any, formData: FormData): any {
|
|
49
41
|
const fieldLayoutInfo = this.fieldContext.field;
|
|
50
42
|
if (value && value.length > 0) {
|
|
51
|
-
// value.forEach((value: any, index: any) => {
|
|
52
|
-
// formData.append(`${fieldLayoutInfo.attrs.name}Ids[${index}]`, value.value)
|
|
53
|
-
// formData.append(`${fieldLayoutInfo.attrs.name}[${index}]`, JSON.stringify(value.original))
|
|
54
|
-
// });
|
|
55
43
|
const shouldUseOriginal = value.every((item: any) => item.original && item.original.id);
|
|
56
44
|
|
|
57
45
|
value.forEach((item: any, index: number) => {
|
|
@@ -95,366 +83,42 @@ export class SolidRelationManyToManyField implements ISolidField {
|
|
|
95
83
|
}
|
|
96
84
|
|
|
97
85
|
render(formik: FormikObject) {
|
|
98
|
-
const fieldMetadata = this.fieldContext.fieldMetadata;
|
|
99
86
|
const fieldLayoutInfo = this.fieldContext.field;
|
|
100
|
-
const
|
|
101
|
-
const fieldLabel = fieldLayoutInfo.attrs.label ?? fieldMetadata.displayName;
|
|
102
|
-
const fieldDescription = fieldLayoutInfo.attrs.description ?? fieldMetadata.description;
|
|
103
|
-
const solidFormViewMetaData = this.fieldContext.solidFormViewMetaData;
|
|
104
|
-
const [visibleCreateRelationEntity, setvisibleCreateRelationEntity] = useState(false);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const fieldDisabled = fieldLayoutInfo.attrs?.disabled;
|
|
108
|
-
const fieldReadonly = fieldLayoutInfo.attrs?.readonly;
|
|
109
|
-
|
|
110
|
-
const formDisabled = solidFormViewMetaData.data.solidView?.layout?.attrs?.disabled;
|
|
111
|
-
const formReadonly = solidFormViewMetaData.data.solidView?.layout?.attrs?.readonly;
|
|
112
|
-
|
|
87
|
+
const [visibleCreateRelationEntity, setVisibleCreateRelationEntity] = useState(false);
|
|
113
88
|
|
|
114
89
|
const isFormFieldValid = (formik: any, fieldName: string) => formik.touched[fieldName] && formik.errors[fieldName];
|
|
115
90
|
|
|
116
|
-
|
|
91
|
+
let renderMode = fieldLayoutInfo.attrs.renderMode;
|
|
92
|
+
if (!renderMode) {
|
|
93
|
+
renderMode = 'autocomplete';
|
|
94
|
+
}
|
|
117
95
|
return (
|
|
118
96
|
<>
|
|
119
|
-
{
|
|
120
|
-
|
|
121
|
-
<div className={className}>
|
|
122
|
-
{this.renderCheckBoxMode(formik, visibleCreateRelationEntity, setvisibleCreateRelationEntity)}
|
|
123
|
-
</div>
|
|
124
|
-
}
|
|
125
|
-
{(!fieldLayoutInfo.attrs.renderMode || fieldLayoutInfo.attrs.renderMode === "autocomplete") &&
|
|
126
|
-
this.renderAutoCompleteMode(formik, visibleCreateRelationEntity, setvisibleCreateRelationEntity)
|
|
97
|
+
{renderMode &&
|
|
98
|
+
this.renderExtensionRenderMode(renderMode, formik, visibleCreateRelationEntity, setVisibleCreateRelationEntity)
|
|
127
99
|
}
|
|
128
100
|
{isFormFieldValid(formik, fieldLayoutInfo.attrs.name) && (
|
|
129
101
|
<div className="absolute mt-1">
|
|
130
102
|
<Message severity="error" text={formik?.errors[fieldLayoutInfo.attrs.name]?.toString()} />
|
|
131
103
|
</div>
|
|
132
104
|
)}
|
|
133
|
-
{/* </div> */}
|
|
134
105
|
</>
|
|
135
106
|
);
|
|
136
107
|
}
|
|
137
108
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const fieldLabel = fieldLayoutInfo.attrs.label ?? fieldMetadata.displayName;
|
|
143
|
-
const showFieldLabel = fieldLayoutInfo?.attrs?.showLabel;
|
|
144
|
-
|
|
145
|
-
const readOnlyPermission = this.fieldContext.readOnly;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// auto complete specific code.
|
|
149
|
-
const entityApi = createSolidEntityApi(fieldMetadata.relationCoModelSingularName);
|
|
150
|
-
const { useLazyGetSolidEntitiesQuery } = entityApi;
|
|
151
|
-
const [triggerGetSolidEntities] = useLazyGetSolidEntitiesQuery();
|
|
152
|
-
|
|
153
|
-
const disabled = fieldLayoutInfo.attrs?.disabled;
|
|
154
|
-
const readOnly = fieldLayoutInfo.attrs?.readOnly;
|
|
155
|
-
|
|
156
|
-
const [autoCompleteItems, setAutoCompleteItems] = useState<any>([]);
|
|
157
|
-
const autoCompleteSearch = async (query?: any) => {
|
|
158
|
-
let filterQuery;
|
|
159
|
-
if (query) {
|
|
160
|
-
filterQuery = {
|
|
161
|
-
[fieldMetadata?.relationModel?.userKeyField?.name]: {
|
|
162
|
-
'$containsi': query
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// Get the list view layout & metadata first.
|
|
167
|
-
const queryData = {
|
|
168
|
-
offset: 0,
|
|
169
|
-
limit: 1000,
|
|
170
|
-
filters: filterQuery
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const autocompleteQs = qs.stringify(queryData, {
|
|
174
|
-
encodeValuesOnly: true,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// TODO: do error handling here, possible errors like modelname is incorrect etc...
|
|
178
|
-
const autocompleteResponse = await triggerGetSolidEntities(autocompleteQs);
|
|
179
|
-
|
|
180
|
-
// TODO: if no data found then can we show no matching "entities", where entities can be replaced with the model plural name,
|
|
181
|
-
const autocompleteData = autocompleteResponse.data;
|
|
182
|
-
|
|
183
|
-
if (autocompleteData) {
|
|
184
|
-
const autoCompleteItems = autocompleteData.records.map((item: any) => {
|
|
185
|
-
return {
|
|
186
|
-
label: item[fieldMetadata?.relationModel?.userKeyField?.name],
|
|
187
|
-
value: item['id'],
|
|
188
|
-
original: item
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
setAutoCompleteItems(autoCompleteItems);
|
|
192
|
-
}
|
|
109
|
+
renderExtensionRenderMode(widgetName: string, formik: FormikObject, visibleCreateRelationEntity: any, setvisibleCreateRelationEntity: any) {
|
|
110
|
+
let DynamicWidget = getExtensionComponent(widgetName);
|
|
111
|
+
if (!DynamicWidget) {
|
|
112
|
+
DynamicWidget = getExtensionComponent('autocomplete');
|
|
193
113
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
}, [visibleCreateRelationEntity])
|
|
199
|
-
|
|
200
|
-
const handleCheckboxChange = (e: any) => {
|
|
201
|
-
if (formik.values[fieldLayoutInfo.attrs.name].some((item: any) => item.value === e.value)) {
|
|
202
|
-
formik.setFieldValue(fieldLayoutInfo.attrs.name, formik.values[fieldLayoutInfo.attrs.name].filter((s: any) => s.value !== e.value));
|
|
203
|
-
} else {
|
|
204
|
-
formik.setFieldValue(fieldLayoutInfo.attrs.name, [...formik.values[fieldLayoutInfo.attrs.name], e]);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const customCreateHandler = (values: any) => {
|
|
209
|
-
const currentRelationData = formik.values[fieldLayoutInfo.attrs.name] || [];
|
|
210
|
-
const jsonValues = Object.fromEntries(values.entries());
|
|
211
|
-
|
|
212
|
-
// Create a new array with the existing data and the new entry
|
|
213
|
-
const updatedRelationData = [
|
|
214
|
-
...currentRelationData,
|
|
215
|
-
{
|
|
216
|
-
label: jsonValues[fieldMetadata?.relationModel?.userKeyField?.name],
|
|
217
|
-
value: "new",
|
|
218
|
-
original: jsonValues,
|
|
219
|
-
},
|
|
220
|
-
];
|
|
221
|
-
|
|
222
|
-
formik.setFieldValue(fieldLayoutInfo.attrs.name, updatedRelationData);
|
|
223
|
-
// const updatedAutoCompleteItems = [
|
|
224
|
-
// ...autoCompleteItems, ...updatedRelationData
|
|
225
|
-
// ];
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const updatedAutoCompleteItems = [...autoCompleteItems, ...updatedRelationData].reduce((acc, current) => {
|
|
229
|
-
if (!acc.some((item: any) => item.label === current.label && item.value === current.value)) {
|
|
230
|
-
acc.push(current);
|
|
231
|
-
}
|
|
232
|
-
return acc;
|
|
233
|
-
}, []);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
setAutoCompleteItems(updatedAutoCompleteItems)
|
|
114
|
+
const widgetProps: SolidRelationManyToManyFieldWidgetProps = {
|
|
115
|
+
formik: formik,
|
|
116
|
+
fieldContext: this.fieldContext,
|
|
238
117
|
}
|
|
239
|
-
|
|
240
|
-
const headerTemplate = (options: any) => {
|
|
241
|
-
const className = `${options.className} justify-content-space-between`;
|
|
242
|
-
|
|
243
|
-
return (
|
|
244
|
-
<div className={className}>
|
|
245
|
-
<div className="relative">
|
|
246
|
-
<div className="flex align-items-center gap-3">
|
|
247
|
-
{showFieldLabel != false &&
|
|
248
|
-
<label className="form-field-label">
|
|
249
|
-
{capitalize(fieldLayoutInfo.attrs.name)}
|
|
250
|
-
{fieldMetadata.required && <span className="text-red-500"> *</span>}
|
|
251
|
-
</label>
|
|
252
|
-
}
|
|
253
|
-
{fieldLayoutInfo.attrs.inlineCreate === "true" &&
|
|
254
|
-
this.renderSolidFormEmbededView(formik, customCreateHandler, visibleCreateRelationEntity, setvisibleCreateRelationEntity)
|
|
255
|
-
}
|
|
256
|
-
<div className="many-to-many-add" >
|
|
257
|
-
{/* <Button icon="pi pi-plus"
|
|
258
|
-
rounded
|
|
259
|
-
outlined
|
|
260
|
-
aria-label="Filter"
|
|
261
|
-
type="button"
|
|
262
|
-
onClick={() => autoCompleteSearch()}
|
|
263
|
-
/> */}
|
|
264
|
-
</div>
|
|
265
|
-
</div>
|
|
266
|
-
<div>
|
|
267
|
-
{options.togglerElement}
|
|
268
|
-
</div>
|
|
269
|
-
</div>
|
|
270
|
-
</div>
|
|
271
|
-
);
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
118
|
return (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
<div className="formgrid grid">
|
|
282
|
-
{autoCompleteItems && autoCompleteItems.map((a: any, i: number) => {
|
|
283
|
-
return (
|
|
284
|
-
<div key={a.label} className={`field col-6 flex gap-2 ${i >= 2 ? 'mt-3' : ''}`}>
|
|
285
|
-
<Checkbox
|
|
286
|
-
readOnly={readOnlyPermission}
|
|
287
|
-
inputId={a.label}
|
|
288
|
-
checked={formik.values[fieldLayoutInfo.attrs.name].some((item: any) => item.label === a.label)}
|
|
289
|
-
onChange={() => handleCheckboxChange(a)}
|
|
290
|
-
/>
|
|
291
|
-
<label htmlFor={a.label} className="form-field-label m-0"> {a.label}</label>
|
|
292
|
-
</div>
|
|
293
|
-
)
|
|
294
|
-
})}
|
|
295
|
-
</div>
|
|
296
|
-
</Panel>
|
|
297
|
-
</div>
|
|
298
|
-
|
|
299
|
-
)
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
renderAutoCompleteMode(formik: FormikObject, visibleCreateRelationEntity: any, setvisibleCreateRelationEntity: any) {
|
|
304
|
-
const fieldMetadata = this.fieldContext.fieldMetadata;
|
|
305
|
-
const fieldLayoutInfo = this.fieldContext.field;
|
|
306
|
-
const className = fieldLayoutInfo.attrs?.className || 'field col-12';
|
|
307
|
-
const fieldLabel = fieldLayoutInfo.attrs.label ?? fieldMetadata.displayName;
|
|
308
|
-
const showFieldLabel = fieldLayoutInfo?.attrs?.showLabel;
|
|
309
|
-
const readOnlyPermission = this.fieldContext.readOnly;
|
|
310
|
-
|
|
311
|
-
// auto complete specific code.
|
|
312
|
-
const entityApi = createSolidEntityApi(fieldMetadata.relationCoModelSingularName);
|
|
313
|
-
const { useLazyGetSolidEntitiesQuery } = entityApi;
|
|
314
|
-
const [triggerGetSolidEntities] = useLazyGetSolidEntitiesQuery();
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const disabled = fieldLayoutInfo.attrs?.disabled;
|
|
318
|
-
const readOnly = fieldLayoutInfo.attrs?.readOnly;
|
|
319
|
-
|
|
320
|
-
const [autoCompleteItems, setAutoCompleteItems] = useState([]);
|
|
321
|
-
const autoCompleteSearch = async (event: AutoCompleteCompleteEvent) => {
|
|
322
|
-
|
|
323
|
-
// Get the list view layout & metadata first.
|
|
324
|
-
const queryData = {
|
|
325
|
-
offset: 0,
|
|
326
|
-
limit: 10,
|
|
327
|
-
filters: {
|
|
328
|
-
[fieldMetadata?.relationModel?.userKeyField?.name]: {
|
|
329
|
-
'$containsi': event.query
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
const autocompleteQs = qs.stringify(queryData, {
|
|
335
|
-
encodeValuesOnly: true,
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
// TODO: do error handling here, possible errors like modelname is incorrect etc...
|
|
339
|
-
const autocompleteResponse = await triggerGetSolidEntities(autocompleteQs);
|
|
340
|
-
|
|
341
|
-
// TODO: if no data found then can we show no matching "entities", where entities can be replaced with the model plural name,
|
|
342
|
-
const autocompleteData = autocompleteResponse.data;
|
|
343
|
-
|
|
344
|
-
if (autocompleteData) {
|
|
345
|
-
const autoCompleteItems = autocompleteData.records.map((item: any) => {
|
|
346
|
-
return {
|
|
347
|
-
label: item[fieldMetadata?.relationModel?.userKeyField?.name],
|
|
348
|
-
value: item['id'],
|
|
349
|
-
original: item
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
setAutoCompleteItems(autoCompleteItems);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
const customCreateHandler = (values: any) => {
|
|
358
|
-
const currentRelationData = formik.values[fieldLayoutInfo.attrs.name] || [];
|
|
359
|
-
const jsonValues = Object.fromEntries(values.entries());
|
|
360
|
-
const updatedRelationData = [
|
|
361
|
-
...currentRelationData,
|
|
362
|
-
{
|
|
363
|
-
label: jsonValues[fieldMetadata?.relationModel?.userKeyField?.name],
|
|
364
|
-
value: "new",
|
|
365
|
-
original: jsonValues,
|
|
366
|
-
},
|
|
367
|
-
];
|
|
368
|
-
|
|
369
|
-
formik.setFieldValue(fieldLayoutInfo.attrs.name, updatedRelationData);
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
return (
|
|
376
|
-
<div className={className}>
|
|
377
|
-
<div className="mt-4">
|
|
378
|
-
{showFieldLabel != false &&
|
|
379
|
-
<label htmlFor={fieldLayoutInfo.attrs.name} className="form-field-label">
|
|
380
|
-
{fieldLabel}
|
|
381
|
-
{fieldMetadata.required && <span className="text-red-500"> *</span>}
|
|
382
|
-
</label>
|
|
383
|
-
}
|
|
384
|
-
<div className="flex align-items-center gap-3 mt-2">
|
|
385
|
-
<AutoComplete
|
|
386
|
-
readOnly={readOnly || readOnlyPermission}
|
|
387
|
-
disabled={disabled || readOnlyPermission}
|
|
388
|
-
multiple
|
|
389
|
-
{...formik.getFieldProps(fieldLayoutInfo.attrs.name)}
|
|
390
|
-
id={fieldLayoutInfo.attrs.name}
|
|
391
|
-
field="label"
|
|
392
|
-
value={formik.values[fieldLayoutInfo.attrs.name] || ''}
|
|
393
|
-
dropdown={!readOnlyPermission}
|
|
394
|
-
suggestions={autoCompleteItems}
|
|
395
|
-
completeMethod={autoCompleteSearch}
|
|
396
|
-
onChange={formik.handleChange}
|
|
397
|
-
className="solid-standard-autocomplete w-full"
|
|
398
|
-
/>
|
|
399
|
-
{fieldLayoutInfo.attrs.inlineCreate === "true" && readOnlyPermission === false &&
|
|
400
|
-
this.renderSolidFormEmbededView(formik, customCreateHandler, visibleCreateRelationEntity, setvisibleCreateRelationEntity)
|
|
401
|
-
}
|
|
402
|
-
</div>
|
|
403
|
-
</div>
|
|
404
|
-
</div>
|
|
405
|
-
);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
renderSolidFormEmbededView(formik: FormikObject, customCreateHandler: any, visibleCreateRelationEntity: any, setvisibleCreateRelationEntity: any) {
|
|
409
|
-
|
|
410
|
-
const fieldMetadata = this.fieldContext.fieldMetadata;
|
|
411
|
-
const fieldLayoutInfo = this.fieldContext.field;
|
|
412
|
-
const className = fieldLayoutInfo.attrs?.className || 'field col-12';
|
|
413
|
-
const fieldLabel = fieldLayoutInfo.attrs.label ?? fieldMetadata.displayName;
|
|
414
|
-
|
|
415
|
-
const params = {
|
|
416
|
-
moduleName: this.fieldContext.fieldMetadata.relationModelModuleName,
|
|
417
|
-
id: "new",
|
|
418
|
-
embeded: true,
|
|
419
|
-
layout: fieldLayoutInfo?.attrs?.inlineCreateLayout,
|
|
420
|
-
customCreateHandler: ((values: any) => {
|
|
421
|
-
setvisibleCreateRelationEntity(false);
|
|
422
|
-
customCreateHandler(values)
|
|
423
|
-
}),
|
|
424
|
-
inlineCreateAutoSave: fieldLayoutInfo?.attrs?.inlineCreateAutoSave,
|
|
425
|
-
handlePopupClose: (() => {
|
|
426
|
-
setvisibleCreateRelationEntity(false);
|
|
427
|
-
}),
|
|
428
|
-
modelName: camelCase(this.fieldContext.fieldMetadata.relationCoModelSingularName)
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
return (
|
|
432
|
-
<div >
|
|
433
|
-
<Button
|
|
434
|
-
icon="pi pi-plus"
|
|
435
|
-
rounded
|
|
436
|
-
outlined
|
|
437
|
-
aria-label="Filter"
|
|
438
|
-
type="button"
|
|
439
|
-
size="small"
|
|
440
|
-
onClick={() => setvisibleCreateRelationEntity(true)}
|
|
441
|
-
className="custom-add-button"
|
|
442
|
-
/>
|
|
443
|
-
<Dialog
|
|
444
|
-
header=""
|
|
445
|
-
showHeader={false}
|
|
446
|
-
visible={visibleCreateRelationEntity}
|
|
447
|
-
style={{ width: fieldLayoutInfo?.attrs?.inlineCreateLayout?.attrs?.width ?? "60vw" }}
|
|
448
|
-
onHide={() => {
|
|
449
|
-
if (!visibleCreateRelationEntity) return;
|
|
450
|
-
setvisibleCreateRelationEntity(false);
|
|
451
|
-
}}
|
|
452
|
-
className="solid-dialog"
|
|
453
|
-
>
|
|
454
|
-
<SolidFormView {...params} />
|
|
455
|
-
|
|
456
|
-
</Dialog>
|
|
457
|
-
</div>
|
|
119
|
+
<>
|
|
120
|
+
{DynamicWidget && <DynamicWidget {...widgetProps} />}
|
|
121
|
+
</>
|
|
458
122
|
)
|
|
459
123
|
}
|
|
460
124
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { SolidRelationManyToManyFieldWidgetProps } from "@/types/solid-core";
|
|
3
|
+
import { AutoComplete } from "primereact/autocomplete";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { Button } from "primereact/button";
|
|
6
|
+
import { useRelationEntityHandler } from "./helpers/useRelationEntityHandler";
|
|
7
|
+
import { InlineRelationEntityDialog } from "./helpers/InlineRelationEntityDialog";
|
|
8
|
+
|
|
9
|
+
export const SolidRelationManyToManyAutocompleteWidget = ({ formik, fieldContext }: SolidRelationManyToManyFieldWidgetProps) => {
|
|
10
|
+
const fieldMetadata = fieldContext.fieldMetadata;
|
|
11
|
+
const fieldLayoutInfo = fieldContext.field;
|
|
12
|
+
const className = fieldLayoutInfo.attrs?.className || 'field col-12';
|
|
13
|
+
const fieldLabel = fieldLayoutInfo.attrs.label ?? fieldMetadata.displayName;
|
|
14
|
+
const showFieldLabel = fieldLayoutInfo?.attrs?.showLabel;
|
|
15
|
+
const readOnlyPermission = fieldContext.readOnly;
|
|
16
|
+
const disabled = fieldLayoutInfo.attrs?.disabled;
|
|
17
|
+
const readOnly = fieldLayoutInfo.attrs?.readOnly;
|
|
18
|
+
|
|
19
|
+
const [visibleCreateDialog, setVisibleCreateDialog] = useState(false);
|
|
20
|
+
const { autoCompleteItems, fetchRelationEntities, addNewRelation } = useRelationEntityHandler({ fieldContext, formik });
|
|
21
|
+
|
|
22
|
+
const onChange = (e: any) => {
|
|
23
|
+
formik.setFieldValue(fieldContext.field.attrs.name, e.value);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className={className}>
|
|
28
|
+
<div className="mt-4">
|
|
29
|
+
{showFieldLabel != false &&
|
|
30
|
+
<label htmlFor={fieldLayoutInfo.attrs.name} className="form-field-label">
|
|
31
|
+
{fieldLabel}
|
|
32
|
+
{fieldMetadata.required && <span className="text-red-500"> *</span>}
|
|
33
|
+
</label>
|
|
34
|
+
}
|
|
35
|
+
<div className="flex align-items-center gap-3 mt-2">
|
|
36
|
+
<AutoComplete
|
|
37
|
+
readOnly={readOnly || readOnlyPermission}
|
|
38
|
+
disabled={disabled || readOnlyPermission}
|
|
39
|
+
multiple
|
|
40
|
+
{...formik.getFieldProps(fieldLayoutInfo.attrs.name)}
|
|
41
|
+
id={fieldLayoutInfo.attrs.name}
|
|
42
|
+
field="label"
|
|
43
|
+
value={formik.values[fieldLayoutInfo.attrs.name] || ''}
|
|
44
|
+
dropdown={!readOnlyPermission}
|
|
45
|
+
suggestions={autoCompleteItems}
|
|
46
|
+
completeMethod={(e) => fetchRelationEntities(e.query)}
|
|
47
|
+
onChange={onChange}
|
|
48
|
+
className="solid-standard-autocomplete w-full"
|
|
49
|
+
/>
|
|
50
|
+
{fieldContext.field.attrs.inlineCreate && (
|
|
51
|
+
<>
|
|
52
|
+
<Button
|
|
53
|
+
icon="pi pi-plus"
|
|
54
|
+
rounded
|
|
55
|
+
outlined
|
|
56
|
+
aria-label="Filter"
|
|
57
|
+
type="button"
|
|
58
|
+
size="small"
|
|
59
|
+
onClick={() => setVisibleCreateDialog(true)}
|
|
60
|
+
className="custom-add-button"
|
|
61
|
+
/>
|
|
62
|
+
<InlineRelationEntityDialog
|
|
63
|
+
visible={visibleCreateDialog}
|
|
64
|
+
setVisible={setVisibleCreateDialog}
|
|
65
|
+
fieldContext={fieldContext}
|
|
66
|
+
onCreate={addNewRelation}
|
|
67
|
+
/>
|
|
68
|
+
</>
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|