@solidstarters/solid-core-ui 1.1.30 → 1.1.32

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 (80) hide show
  1. package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.d.ts +7 -0
  2. package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.d.ts.map +1 -0
  3. package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.js +17 -0
  4. package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.js.map +1 -0
  5. package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.d.ts +7 -0
  6. package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.d.ts.map +1 -0
  7. package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.js +17 -0
  8. package/dist/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.js.map +1 -0
  9. package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.d.ts +3 -0
  10. package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.d.ts.map +1 -0
  11. package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.js +78 -0
  12. package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.js.map +1 -0
  13. package/dist/components/core/form/SolidFormView.d.ts.map +1 -1
  14. package/dist/components/core/form/SolidFormView.js +58 -20
  15. package/dist/components/core/form/SolidFormView.js.map +1 -1
  16. package/dist/components/core/form/fields/SolidLongTextField.d.ts +2 -0
  17. package/dist/components/core/form/fields/SolidLongTextField.d.ts.map +1 -1
  18. package/dist/components/core/form/fields/SolidLongTextField.js +32 -3
  19. package/dist/components/core/form/fields/SolidLongTextField.js.map +1 -1
  20. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.d.ts +1 -3
  21. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.d.ts.map +1 -1
  22. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.js +19 -274
  23. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.js.map +1 -1
  24. package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.d.ts +3 -0
  25. package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.d.ts.map +1 -0
  26. package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.js +38 -0
  27. package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.js.map +1 -0
  28. package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.d.ts +3 -0
  29. package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.d.ts.map +1 -0
  30. package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.js +48 -0
  31. package/dist/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.js.map +1 -0
  32. package/dist/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.d.ts +2 -0
  33. package/dist/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.d.ts.map +1 -0
  34. package/dist/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.js +35 -0
  35. package/dist/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.js.map +1 -0
  36. package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.d.ts +6 -0
  37. package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.d.ts.map +1 -0
  38. package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.js +119 -0
  39. package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.js.map +1 -0
  40. package/dist/helpers/registry.d.ts +1 -1
  41. package/dist/helpers/registry.d.ts.map +1 -1
  42. package/dist/helpers/registry.js +19 -2
  43. package/dist/helpers/registry.js.map +1 -1
  44. package/dist/resources/fonts/SF-Pro-Display-Black.otf +0 -0
  45. package/dist/resources/fonts/SF-Pro-Display-Bold.otf +0 -0
  46. package/dist/resources/fonts/SF-Pro-Display-Heavy.otf +0 -0
  47. package/dist/resources/fonts/SF-Pro-Display-Light.otf +0 -0
  48. package/dist/resources/fonts/SF-Pro-Display-Medium.otf +0 -0
  49. package/dist/resources/fonts/SF-Pro-Display-Regular.otf +0 -0
  50. package/dist/resources/fonts/SF-Pro-Display-Semibold.otf +0 -0
  51. package/dist/resources/fonts/SF-Pro-Display-Thin.otf +0 -0
  52. package/dist/resources/fonts/SF-Pro-Display-Ultralight.otf +0 -0
  53. package/dist/resources/solid-primereact.css +2983 -0
  54. package/dist/resources/themes/solid-dark-purple/theme.css +6082 -0
  55. package/dist/resources/themes/solid-light-purple/theme.css +6124 -0
  56. package/package.json +1 -1
  57. package/src/components/core/extension/solid-core/emailTemplate/emailFormTypeChangeHandler.ts +18 -0
  58. package/src/components/core/extension/solid-core/emailTemplate/emailFormTypeLoad.ts +18 -0
  59. package/src/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.tsx +123 -0
  60. package/src/components/core/form/SolidFormView.tsx +62 -18
  61. package/src/components/core/form/fields/SolidLongTextField.tsx +79 -20
  62. package/src/components/core/form/fields/relations/SolidRelationManyToManyField.tsx +20 -356
  63. package/src/components/core/form/fields/relations/widgets/SolidRelationManyToManyAutocompleteWidget.tsx +74 -0
  64. package/src/components/core/form/fields/relations/widgets/SolidRelationManyToManyCheckboxWidget.tsx +103 -0
  65. package/src/components/core/form/fields/relations/widgets/helpers/InlineRelationEntityDialog.tsx +33 -0
  66. package/src/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.ts +64 -0
  67. package/src/helpers/registry.ts +21 -2
  68. package/src/resources/fonts/SF-Pro-Display-Black.otf +0 -0
  69. package/src/resources/fonts/SF-Pro-Display-Bold.otf +0 -0
  70. package/src/resources/fonts/SF-Pro-Display-Heavy.otf +0 -0
  71. package/src/resources/fonts/SF-Pro-Display-Light.otf +0 -0
  72. package/src/resources/fonts/SF-Pro-Display-Medium.otf +0 -0
  73. package/src/resources/fonts/SF-Pro-Display-Regular.otf +0 -0
  74. package/src/resources/fonts/SF-Pro-Display-Semibold.otf +0 -0
  75. package/src/resources/fonts/SF-Pro-Display-Thin.otf +0 -0
  76. package/src/resources/fonts/SF-Pro-Display-Ultralight.otf +0 -0
  77. package/src/resources/solid-primereact.css +2983 -0
  78. package/src/resources/themes/solid-dark-purple/theme.css +6082 -0
  79. package/src/resources/themes/solid-light-purple/theme.css +6124 -0
  80. package/src/types/solid-core.d.ts +14 -1
@@ -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 { Panel } from "primereact/panel";
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 className = fieldLayoutInfo.attrs?.className || 'field col-12';
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
- {/* <div className={className}> */}
120
- {fieldLayoutInfo.attrs.renderMode === "checkbox" &&
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
- renderCheckBoxMode(formik: FormikObject, visibleCreateRelationEntity: any, setvisibleCreateRelationEntity: any) {
139
- const fieldMetadata = this.fieldContext.fieldMetadata;
140
- const fieldLayoutInfo = this.fieldContext.field;
141
- const className = fieldLayoutInfo.attrs?.className || 'field col-12';
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
- useEffect(() => {
195
- if (visibleCreateRelationEntity === false) {
196
- autoCompleteSearch();
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
- <div>
278
-
279
- <Panel toggleable headerTemplate={headerTemplate}>
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
+ }
@@ -0,0 +1,103 @@
1
+ "use client";
2
+ import { SolidRelationManyToManyFieldWidgetProps } from "@/types/solid-core";
3
+ import { capitalize } from "lodash";
4
+ import { Checkbox } from "primereact/checkbox";
5
+ import { Panel } from "primereact/panel";
6
+ import { useEffect, useState } from "react";
7
+ import { Button } from "primereact/button";
8
+ import { useRelationEntityHandler } from "./helpers/useRelationEntityHandler";
9
+ import { InlineRelationEntityDialog } from "./helpers/InlineRelationEntityDialog";
10
+
11
+ export const SolidRelationManyToManyCheckboxWidget = ({formik, fieldContext }: SolidRelationManyToManyFieldWidgetProps) => {
12
+ const fieldMetadata = fieldContext.fieldMetadata;
13
+ const fieldLayoutInfo = fieldContext.field;
14
+ const showFieldLabel = fieldLayoutInfo?.attrs?.showLabel;
15
+
16
+ const readOnlyPermission = fieldContext.readOnly;
17
+ const [visibleCreateDialog, setVisibleCreateDialog] = useState(false);
18
+ const { autoCompleteItems, fetchRelationEntities, addNewRelation } = useRelationEntityHandler({ fieldContext, formik });
19
+
20
+ useEffect(() => {
21
+ fetchRelationEntities();
22
+ }, []);
23
+
24
+ const handleCheckboxChange = (e: any) => {
25
+ if (formik.values[fieldLayoutInfo.attrs.name].some((item: any) => item.value === e.value)) {
26
+ formik.setFieldValue(fieldLayoutInfo.attrs.name, formik.values[fieldLayoutInfo.attrs.name].filter((s: any) => s.value !== e.value));
27
+ } else {
28
+ formik.setFieldValue(fieldLayoutInfo.attrs.name, [...formik.values[fieldLayoutInfo.attrs.name], e]);
29
+ }
30
+ };
31
+
32
+ const headerTemplate = (options: any) => {
33
+ const className = `${options.className} justify-content-space-between`;
34
+
35
+ return (
36
+ <div className={className}>
37
+ <div className="flex align-items-center gap-3">
38
+ {showFieldLabel != false &&
39
+ <label className="form-field-label">
40
+ {capitalize(fieldLayoutInfo.attrs.name)}
41
+ {fieldMetadata.required && <span className="text-red-500"> *</span>}
42
+ </label>
43
+ }
44
+ {fieldContext.field.attrs.inlineCreate && (
45
+ <>
46
+ <Button
47
+ icon="pi pi-plus"
48
+ rounded
49
+ outlined
50
+ aria-label="Filter"
51
+ type="button"
52
+ size="small"
53
+ onClick={() => setVisibleCreateDialog(true)}
54
+ className="custom-add-button"
55
+ />
56
+ <InlineRelationEntityDialog
57
+ visible={visibleCreateDialog}
58
+ setVisible={setVisibleCreateDialog}
59
+ fieldContext={fieldContext}
60
+ onCreate={addNewRelation}
61
+ />
62
+ </>
63
+ )}
64
+ {/* <div className="many-to-many-add" >
65
+ <Button icon="pi pi-plus"
66
+ rounded
67
+ outlined
68
+ aria-label="Filter"
69
+ type="button"
70
+ onClick={() => autoCompleteSearch()}
71
+ />
72
+ </div> */}
73
+ </div>
74
+ <div>
75
+ {options.togglerElement}
76
+ </div>
77
+ </div>
78
+ );
79
+ };
80
+ return (
81
+ <div>
82
+
83
+ <Panel toggleable headerTemplate={headerTemplate}>
84
+ <div className="formgrid grid">
85
+ {autoCompleteItems && autoCompleteItems.map((a: any, i: number) => {
86
+ return (
87
+ <div key={a.label} className={`field col-6 flex gap-2 ${i >= 2 ? 'mt-3' : ''}`}>
88
+ <Checkbox
89
+ readOnly={readOnlyPermission}
90
+ inputId={a.label}
91
+ checked={formik.values[fieldLayoutInfo.attrs.name].some((item: any) => item.label === a.label)}
92
+ onChange={() => handleCheckboxChange(a)}
93
+ />
94
+ <label htmlFor={a.label} className="form-field-label m-0"> {a.label}</label>
95
+ </div>
96
+ )
97
+ })}
98
+ </div>
99
+ </Panel>
100
+ </div>
101
+ )
102
+
103
+ }
@@ -0,0 +1,33 @@
1
+ import { Dialog } from "primereact/dialog";
2
+ import { camelCase } from "lodash";
3
+ import SolidFormView from "@/components/core/form/SolidFormView";
4
+
5
+ export const InlineRelationEntityDialog = ({ visible, setVisible, fieldContext, onCreate }: any) => {
6
+ const fieldLayoutInfo = fieldContext.field;
7
+
8
+ const params = {
9
+ moduleName: fieldContext.fieldMetadata.relationModelModuleName,
10
+ id: "new",
11
+ embeded: true,
12
+ layout: fieldLayoutInfo?.attrs?.inlineCreateLayout,
13
+ customCreateHandler: (values: any) => {
14
+ setVisible(false);
15
+ onCreate(values);
16
+ },
17
+ inlineCreateAutoSave: fieldLayoutInfo?.attrs?.inlineCreateAutoSave,
18
+ handlePopupClose: () => setVisible(false),
19
+ modelName: camelCase(fieldContext.fieldMetadata.relationCoModelSingularName)
20
+ };
21
+
22
+ return (
23
+ <Dialog
24
+ visible={visible}
25
+ showHeader={false}
26
+ style={{ width: fieldLayoutInfo?.attrs?.inlineCreateLayout?.attrs?.width ?? "60vw" }}
27
+ onHide={() => setVisible(false)}
28
+ className="solid-dialog"
29
+ >
30
+ <SolidFormView {...params} />
31
+ </Dialog>
32
+ );
33
+ };