@solidxai/core-ui 0.1.3 → 0.1.4-beta.1

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 (150) hide show
  1. package/dist/components/auth/SolidInitialLoginOtp.d.ts.map +1 -1
  2. package/dist/components/auth/SolidInitialLoginOtp.js +0 -5
  3. package/dist/components/auth/SolidInitialLoginOtp.js.map +1 -1
  4. package/dist/components/auth/SolidInitialLoginOtp.tsx +0 -5
  5. package/dist/components/auth/SolidLogin.d.ts.map +1 -1
  6. package/dist/components/auth/SolidLogin.js +7 -5
  7. package/dist/components/auth/SolidLogin.js.map +1 -1
  8. package/dist/components/auth/SolidLogin.tsx +10 -8
  9. package/dist/components/common/GeneralSettings.d.ts.map +1 -1
  10. package/dist/components/common/GeneralSettings.js +48 -47
  11. package/dist/components/common/GeneralSettings.js.map +1 -1
  12. package/dist/components/common/GeneralSettings.tsx +41 -10
  13. package/dist/components/core/common/FilterComponent.js.map +1 -1
  14. package/dist/components/core/common/FilterComponent.tsx +1 -1
  15. package/dist/components/core/common/GroupingComponent.d.ts +54 -0
  16. package/dist/components/core/common/GroupingComponent.d.ts.map +1 -0
  17. package/dist/components/core/common/GroupingComponent.js +196 -0
  18. package/dist/components/core/common/GroupingComponent.js.map +1 -0
  19. package/dist/components/core/common/GroupingComponent.tsx +452 -0
  20. package/dist/components/core/common/SolidGlobalSearchElement.d.ts +18 -1
  21. package/dist/components/core/common/SolidGlobalSearchElement.d.ts.map +1 -1
  22. package/dist/components/core/common/SolidGlobalSearchElement.js +152 -52
  23. package/dist/components/core/common/SolidGlobalSearchElement.js.map +1 -1
  24. package/dist/components/core/common/SolidGlobalSearchElement.tsx +212 -35
  25. package/dist/components/core/extension/solid-core/modelSequence/modelSequenceFormViewChangeHandler.d.ts +19 -0
  26. package/dist/components/core/extension/solid-core/modelSequence/modelSequenceFormViewChangeHandler.d.ts.map +1 -0
  27. package/dist/components/core/extension/solid-core/modelSequence/modelSequenceFormViewChangeHandler.js +90 -0
  28. package/dist/components/core/extension/solid-core/modelSequence/modelSequenceFormViewChangeHandler.js.map +1 -0
  29. package/dist/components/core/extension/solid-core/modelSequence/modelSequenceFormViewChangeHandler.tsx +59 -0
  30. package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.d.ts.map +1 -1
  31. package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.js +17 -28
  32. package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.js.map +1 -1
  33. package/dist/components/core/extension/solid-core/roleMetadata/RolePermissionsManyToManyFieldWidget.tsx +71 -56
  34. package/dist/components/core/filter/SolidOneToManyFilterElement.d.ts +2 -0
  35. package/dist/components/core/filter/SolidOneToManyFilterElement.d.ts.map +1 -0
  36. package/dist/components/core/filter/SolidOneToManyFilterElement.js +86 -0
  37. package/dist/components/core/filter/SolidOneToManyFilterElement.js.map +1 -0
  38. package/dist/components/core/filter/SolidOneToManyFilterElement.tsx +62 -0
  39. package/dist/components/core/filter/SolidVarInputsFilterElement.d.ts +1 -0
  40. package/dist/components/core/filter/SolidVarInputsFilterElement.d.ts.map +1 -1
  41. package/dist/components/core/filter/SolidVarInputsFilterElement.js +4 -1
  42. package/dist/components/core/filter/SolidVarInputsFilterElement.js.map +1 -1
  43. package/dist/components/core/filter/SolidVarInputsFilterElement.tsx +10 -0
  44. package/dist/components/core/filter/fields/SolidRelationField.d.ts.map +1 -1
  45. package/dist/components/core/filter/fields/SolidRelationField.js +4 -2
  46. package/dist/components/core/filter/fields/SolidRelationField.js.map +1 -1
  47. package/dist/components/core/filter/fields/SolidRelationField.tsx +4 -2
  48. package/dist/components/core/filter/fields/relations/SolidRelationOneToManyField.d.ts +4 -0
  49. package/dist/components/core/filter/fields/relations/SolidRelationOneToManyField.d.ts.map +1 -0
  50. package/dist/components/core/filter/fields/relations/SolidRelationOneToManyField.js +25 -0
  51. package/dist/components/core/filter/fields/relations/SolidRelationOneToManyField.js.map +1 -0
  52. package/dist/components/core/filter/fields/relations/SolidRelationOneToManyField.tsx +60 -0
  53. package/dist/components/core/form/SolidFormFooter.js +4 -4
  54. package/dist/components/core/form/SolidFormFooter.js.map +1 -1
  55. package/dist/components/core/form/SolidFormFooter.tsx +4 -4
  56. package/dist/components/core/form/fields/SolidBooleanField.d.ts.map +1 -1
  57. package/dist/components/core/form/fields/SolidBooleanField.js +11 -8
  58. package/dist/components/core/form/fields/SolidBooleanField.js.map +1 -1
  59. package/dist/components/core/form/fields/SolidBooleanField.tsx +20 -8
  60. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.d.ts +40 -0
  61. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.d.ts.map +1 -1
  62. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.js +317 -157
  63. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.js.map +1 -1
  64. package/dist/components/core/form/fields/relations/SolidRelationManyToManyField.tsx +463 -243
  65. package/dist/components/core/form/fields/relations/SolidRelationOneToManyField.d.ts.map +1 -1
  66. package/dist/components/core/form/fields/relations/SolidRelationOneToManyField.js +46 -95
  67. package/dist/components/core/form/fields/relations/SolidRelationOneToManyField.js.map +1 -1
  68. package/dist/components/core/form/fields/relations/SolidRelationOneToManyField.tsx +57 -113
  69. package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.d.ts +15 -4
  70. package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.d.ts.map +1 -1
  71. package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.js +220 -33
  72. package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.js.map +1 -1
  73. package/dist/components/core/form/fields/relations/widgets/helpers/useRelationEntityHandler.ts +167 -36
  74. package/dist/components/core/kanban/SolidKanbanView.d.ts.map +1 -1
  75. package/dist/components/core/kanban/SolidKanbanView.js +13 -12
  76. package/dist/components/core/kanban/SolidKanbanView.js.map +1 -1
  77. package/dist/components/core/kanban/SolidKanbanView.tsx +8 -7
  78. package/dist/components/core/list/SolidListView.d.ts +18 -10
  79. package/dist/components/core/list/SolidListView.d.ts.map +1 -1
  80. package/dist/components/core/list/SolidListView.js +176 -177
  81. package/dist/components/core/list/SolidListView.js.map +1 -1
  82. package/dist/components/core/list/SolidListView.tsx +130 -143
  83. package/dist/components/core/list/SolidListViewConfigure.d.ts +7 -0
  84. package/dist/components/core/list/SolidListViewConfigure.d.ts.map +1 -1
  85. package/dist/components/core/list/SolidListViewConfigure.js +6 -5
  86. package/dist/components/core/list/SolidListViewConfigure.js.map +1 -1
  87. package/dist/components/core/list/SolidListViewConfigure.tsx +21 -12
  88. package/dist/components/core/list/columns/SolidShortTextColumn.d.ts.map +1 -1
  89. package/dist/components/core/list/columns/SolidShortTextColumn.js +1 -37
  90. package/dist/components/core/list/columns/SolidShortTextColumn.js.map +1 -1
  91. package/dist/components/core/list/columns/SolidShortTextColumn.tsx +0 -41
  92. package/dist/components/core/list/columns/relations/SolidRelationManyToOneColumn.d.ts.map +1 -1
  93. package/dist/components/core/list/columns/relations/SolidRelationManyToOneColumn.js +9 -5
  94. package/dist/components/core/list/columns/relations/SolidRelationManyToOneColumn.js.map +1 -1
  95. package/dist/components/core/list/columns/relations/SolidRelationManyToOneColumn.tsx +14 -3
  96. package/dist/components/core/list/listViewRegistry.js.map +1 -1
  97. package/dist/components/core/list/listViewRegistry.ts +1 -2
  98. package/dist/components/core/tree/SolidTreeView.d.ts +38 -0
  99. package/dist/components/core/tree/SolidTreeView.d.ts.map +1 -0
  100. package/dist/components/core/tree/SolidTreeView.js +1179 -0
  101. package/dist/components/core/tree/SolidTreeView.js.map +1 -0
  102. package/dist/components/core/tree/SolidTreeView.tsx +1637 -0
  103. package/dist/components/core/tree/treeViewRegistry.d.ts +7 -0
  104. package/dist/components/core/tree/treeViewRegistry.d.ts.map +1 -0
  105. package/dist/components/core/tree/treeViewRegistry.js +17 -0
  106. package/dist/components/core/tree/treeViewRegistry.js.map +1 -0
  107. package/dist/components/core/tree/treeViewRegistry.ts +23 -0
  108. package/dist/components/core/users/CreateUser.d.ts.map +1 -1
  109. package/dist/components/core/users/CreateUser.js +19 -6
  110. package/dist/components/core/users/CreateUser.js.map +1 -1
  111. package/dist/components/core/users/CreateUser.tsx +39 -0
  112. package/dist/helpers/helpers.d.ts +2 -0
  113. package/dist/helpers/helpers.d.ts.map +1 -1
  114. package/dist/helpers/helpers.js +3 -1
  115. package/dist/helpers/helpers.js.map +1 -1
  116. package/dist/helpers/helpers.ts +4 -1
  117. package/dist/helpers/registry.d.ts.map +1 -1
  118. package/dist/helpers/registry.js +5 -1
  119. package/dist/helpers/registry.js.map +1 -1
  120. package/dist/helpers/registry.ts +7 -2
  121. package/dist/index.d.ts +3 -1
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +2 -0
  124. package/dist/index.js.map +1 -1
  125. package/dist/index.ts +6 -1
  126. package/dist/resources/globals.css +32 -4
  127. package/dist/routes/pages/admin/core/ListPage.d.ts.map +1 -1
  128. package/dist/routes/pages/admin/core/ListPage.js +2 -2
  129. package/dist/routes/pages/admin/core/ListPage.js.map +1 -1
  130. package/dist/routes/pages/admin/core/ListPage.tsx +3 -2
  131. package/dist/routes/pages/admin/core/ModuleHomePage.d.ts.map +1 -1
  132. package/dist/routes/pages/admin/core/ModuleHomePage.js +4 -15
  133. package/dist/routes/pages/admin/core/ModuleHomePage.js.map +1 -1
  134. package/dist/routes/pages/admin/core/ModuleHomePage.tsx +4 -3
  135. package/dist/routes/pages/admin/core/TreePage.d.ts +2 -0
  136. package/dist/routes/pages/admin/core/TreePage.d.ts.map +1 -0
  137. package/dist/routes/pages/admin/core/TreePage.js +37 -0
  138. package/dist/routes/pages/admin/core/TreePage.js.map +1 -0
  139. package/dist/routes/pages/admin/core/TreePage.tsx +30 -0
  140. package/dist/routes/solidRoutes.d.ts.map +1 -1
  141. package/dist/routes/solidRoutes.js +2 -0
  142. package/dist/routes/solidRoutes.js.map +1 -1
  143. package/dist/routes/solidRoutes.tsx +3 -1
  144. package/dist/routes/types.d.ts +1 -1
  145. package/dist/routes/types.d.ts.map +1 -1
  146. package/dist/routes/types.js.map +1 -1
  147. package/dist/routes/types.ts +1 -0
  148. package/dist/types/index.d.ts +8 -2
  149. package/dist/types/solid-core.d.ts +40 -0
  150. package/package.json +1 -1
@@ -45,16 +45,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
- if (ar || !(i in from)) {
51
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
- ar[i] = from[i];
53
- }
54
- }
55
- return to.concat(ar || Array.prototype.slice.call(from));
56
- };
57
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
48
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
58
49
  import { Message } from "primereact/message";
59
50
  import { useEffect, useState } from "react";
60
51
  import * as Yup from 'yup';
@@ -63,14 +54,18 @@ import { AutoComplete } from "primereact/autocomplete";
63
54
  import { Button } from "primereact/button";
64
55
  import { useRelationEntityHandler } from "./widgets/helpers/useRelationEntityHandler";
65
56
  import { InlineRelationEntityDialog } from "./widgets/helpers/InlineRelationEntityDialog";
66
- import { capitalize } from "lodash";
67
57
  import { Checkbox } from "primereact/checkbox";
68
58
  import { Panel } from "primereact/panel";
69
59
  import { SolidFieldTooltip } from "../../../../../components/common/SolidFieldTooltip";
70
60
  import qs from 'qs';
71
- // import Handlebars from "handlebars/dist/handlebars";
72
61
  import * as Handlebars from "handlebars";
73
62
  import { ERROR_MESSAGES } from "../../../../../constants/error-messages";
63
+ import { useRouter } from "../../../../../hooks/useRouter";
64
+ import { usePathname } from "../../../../../hooks/usePathname";
65
+ import { camelCase, capitalize } from "lodash";
66
+ import { SolidListView } from "../../../../core/list/SolidListView";
67
+ import { RenderSolidFormEmbededView } from "./SolidRelationManyToOneField";
68
+ import { Dialog } from "primereact/dialog";
74
69
  var SolidRelationManyToManyField = /** @class */ (function () {
75
70
  function SolidRelationManyToManyField(fieldContext) {
76
71
  Object.defineProperty(this, "fieldContext", {
@@ -86,20 +81,6 @@ var SolidRelationManyToManyField = /** @class */ (function () {
86
81
  configurable: true,
87
82
  writable: true,
88
83
  value: function () {
89
- var _a, _b;
90
- var manyToManyFieldData = this.fieldContext.data[this.fieldContext.field.attrs.name];
91
- var fieldMetadata = this.fieldContext.fieldMetadata;
92
- var userKeyField = (_b = (_a = fieldMetadata === null || fieldMetadata === void 0 ? void 0 : fieldMetadata.relationModel) === null || _a === void 0 ? void 0 : _a.userKeyField) === null || _b === void 0 ? void 0 : _b.name;
93
- if (manyToManyFieldData) {
94
- return manyToManyFieldData.map(function (e) {
95
- var manyToManyColVal = e[userKeyField] || '';
96
- return {
97
- label: manyToManyColVal,
98
- value: (e === null || e === void 0 ? void 0 : e.id) || '',
99
- original: e
100
- };
101
- });
102
- }
103
84
  return [];
104
85
  }
105
86
  });
@@ -108,28 +89,8 @@ var SolidRelationManyToManyField = /** @class */ (function () {
108
89
  configurable: true,
109
90
  writable: true,
110
91
  value: function (value, formData) {
111
- var fieldLayoutInfo = this.fieldContext.field;
112
- //if empty then clear the field
113
- if (value && value.length === 0) {
114
- formData.append("".concat(fieldLayoutInfo.attrs.name, "Command"), "clear");
115
- }
116
- if (value && value.length > 0) {
117
- var shouldUseOriginal_1 = value.every(function (item) { return item.original && item.original.id; });
118
- value.forEach(function (item, index) {
119
- if (shouldUseOriginal_1) {
120
- formData.append("".concat(fieldLayoutInfo.attrs.name, "Ids[").concat(index, "]"), item.value);
121
- }
122
- else {
123
- formData.append("".concat(fieldLayoutInfo.attrs.name, "[").concat(index, "]"), JSON.stringify(item.original));
124
- }
125
- });
126
- if (shouldUseOriginal_1) {
127
- formData.append("".concat(fieldLayoutInfo.attrs.name, "Command"), "set");
128
- }
129
- else {
130
- formData.append("".concat(fieldLayoutInfo.attrs.name, "Command"), "update");
131
- }
132
- }
92
+ // Link/unlink is handled per-interaction in each widget.
93
+ // No bulk update needed on form submit for many-to-many.
133
94
  }
134
95
  });
135
96
  Object.defineProperty(SolidRelationManyToManyField.prototype, "validationSchema", {
@@ -142,7 +103,6 @@ var SolidRelationManyToManyField = /** @class */ (function () {
142
103
  var fieldMetadata = this.fieldContext.fieldMetadata;
143
104
  var fieldLayoutInfo = this.fieldContext.field;
144
105
  var fieldLabel = (_a = fieldLayoutInfo.attrs.label) !== null && _a !== void 0 ? _a : fieldMetadata.displayName;
145
- // 1. required
146
106
  if (fieldMetadata.required) {
147
107
  schema = schema
148
108
  .min(1, ERROR_MESSAGES.SELECT_ATLEAST_ONE(fieldLabel))
@@ -156,24 +116,17 @@ var SolidRelationManyToManyField = /** @class */ (function () {
156
116
  configurable: true,
157
117
  writable: true,
158
118
  value: function (formik) {
159
- var _a, _b;
160
- var fieldMetadata = this.fieldContext.fieldMetadata;
119
+ var _a;
161
120
  var fieldLayoutInfo = this.fieldContext.field;
162
121
  var className = ((_a = fieldLayoutInfo.attrs) === null || _a === void 0 ? void 0 : _a.className) || 'field col-12';
163
- var isFormFieldValid = function (formik, fieldName) { return formik.touched[fieldName] && formik.errors[fieldName]; };
164
- var fieldLabel = (_b = fieldLayoutInfo.attrs.label) !== null && _b !== void 0 ? _b : fieldMetadata.displayName;
165
122
  var viewWidget = fieldLayoutInfo.attrs.viewWidget;
166
123
  var editWidget = fieldLayoutInfo.attrs.editWidget;
167
- if (!editWidget) {
124
+ if (!editWidget)
168
125
  editWidget = 'DefaultRelationManyToManyAutoCompleteFormEditWidget';
169
- }
170
- if (!viewWidget) {
171
- viewWidget = 'DefaultRelationOneToManyFormViewWidget';
172
- }
126
+ if (!viewWidget)
127
+ viewWidget = 'DefaultRelationManyToManyListFormEditWidget';
173
128
  var viewMode = this.fieldContext.viewMode;
174
- return (_jsx(_Fragment, { children: _jsxs("div", { className: className, children: [viewMode === "view" &&
175
- this.renderExtensionRenderMode(viewWidget, formik), viewMode === "edit" && (_jsx(_Fragment, { children: editWidget &&
176
- this.renderExtensionRenderMode(editWidget, formik) }))] }) }));
129
+ return (_jsxs("div", { className: className, children: [viewMode === "view" && this.renderExtensionRenderMode(viewWidget, formik), viewMode === "edit" && editWidget && this.renderExtensionRenderMode(editWidget, formik)] }));
177
130
  }
178
131
  });
179
132
  Object.defineProperty(SolidRelationManyToManyField.prototype, "renderExtensionRenderMode", {
@@ -182,36 +135,47 @@ var SolidRelationManyToManyField = /** @class */ (function () {
182
135
  writable: true,
183
136
  value: function (widget, formik) {
184
137
  var DynamicWidget = getExtensionComponent(widget);
185
- var widgetProps = {
186
- formik: formik,
187
- fieldContext: this.fieldContext,
188
- };
189
- return (_jsx(_Fragment, { children: DynamicWidget && _jsx(DynamicWidget, __assign({}, widgetProps)) }));
138
+ var widgetProps = { formik: formik, fieldContext: this.fieldContext };
139
+ return _jsx(_Fragment, { children: DynamicWidget && _jsx(DynamicWidget, __assign({}, widgetProps)) });
190
140
  }
191
141
  });
192
142
  return SolidRelationManyToManyField;
193
143
  }());
194
144
  export { SolidRelationManyToManyField };
145
+ /**
146
+ * AUTOCOMPLETE WIDGET
147
+ *
148
+ * State:
149
+ * currentValues — chips shown in the input (currently linked items)
150
+ * suggestions — dropdown options populated on each keystroke
151
+ *
152
+ * Flow:
153
+ * mount → fetchCurrentValues()
154
+ * user types → fetchSuggestions() via completeMethod
155
+ * user selects → linkItem() → on success, adds to currentValues
156
+ * user removes chip→ unlinkItem() → on success, removes from currentValues
157
+ */
195
158
  export var DefaultRelationManyToManyAutoCompleteFormEditWidget = function (_a) {
196
159
  var _b, _c, _d, _e, _f, _g;
197
160
  var formik = _a.formik, fieldContext = _a.fieldContext;
198
161
  var fieldMetadata = fieldContext.fieldMetadata;
199
162
  var fieldLayoutInfo = fieldContext.field;
200
- var className = ((_b = fieldLayoutInfo.attrs) === null || _b === void 0 ? void 0 : _b.className) || 'field col-12';
201
- var fieldLabel = (_c = fieldLayoutInfo.attrs.label) !== null && _c !== void 0 ? _c : fieldMetadata.displayName;
202
- var showFieldLabel = (_d = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _d === void 0 ? void 0 : _d.showLabel;
163
+ var fieldLabel = (_b = fieldLayoutInfo.attrs.label) !== null && _b !== void 0 ? _b : fieldMetadata.displayName;
164
+ var showFieldLabel = (_c = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _c === void 0 ? void 0 : _c.showLabel;
203
165
  var readOnlyPermission = fieldContext.readOnly;
204
- var disabled = (_e = fieldLayoutInfo.attrs) === null || _e === void 0 ? void 0 : _e.disabled;
205
- var readOnly = (_f = fieldLayoutInfo.attrs) === null || _f === void 0 ? void 0 : _f.readOnly;
206
- var whereClause = fieldLayoutInfo.attrs.whereClause;
166
+ var disabled = (_d = fieldLayoutInfo.attrs) === null || _d === void 0 ? void 0 : _d.disabled;
167
+ var readOnly = (_e = fieldLayoutInfo.attrs) === null || _e === void 0 ? void 0 : _e.readOnly;
207
168
  var _h = useState(false), visibleCreateDialog = _h[0], setVisibleCreateDialog = _h[1];
208
- var _j = useRelationEntityHandler({ fieldContext: fieldContext, formik: formik }), autoCompleteItems = _j.autoCompleteItems, fetchRelationEntities = _j.fetchRelationEntities, addNewRelation = _j.addNewRelation;
209
- var isFormFieldValid = function (formik, fieldName) { return formik.touched[fieldName] && formik.errors[fieldName]; };
210
- // const onChange = (e: any) => {
211
- // formik.setFieldValue(fieldContext.field.attrs.name, e.value);
212
- // };
169
+ var _j = useRelationEntityHandler({ fieldContext: fieldContext }), currentValues = _j.currentValues, suggestions = _j.suggestions, fetchCurrentValues = _j.fetchCurrentValues, fetchSuggestions = _j.fetchSuggestions, linkItem = _j.linkItem, unlinkItem = _j.unlinkItem, addNewRelation = _j.addNewRelation;
170
+ var isFormFieldValid = function (formik, fieldName) {
171
+ return formik.touched[fieldName] && formik.errors[fieldName];
172
+ };
173
+ // On mount: load already-linked items into currentValues
174
+ useEffect(function () {
175
+ fetchCurrentValues();
176
+ }, [(_f = fieldContext.data) === null || _f === void 0 ? void 0 : _f.id]);
213
177
  var autoCompleteSearch = function (event) { return __awaiter(void 0, void 0, void 0, function () {
214
- var queryData, fixedFilterToBeApplied, fixedFilterParsed, convertedFixedFilter, fixedFilterTemplate, renderedFilter, parsedFilter_1, isValid, autocompleteQs;
178
+ var queryData, fixedFilterToBeApplied, fixedFilterParsed, rawFilter, rendered, parsed, hasValue_1;
215
179
  var _a, _b;
216
180
  var _c, _d, _e, _f, _g, _h;
217
181
  return __generator(this, function (_j) {
@@ -224,147 +188,343 @@ export var DefaultRelationManyToManyAutoCompleteFormEditWidget = function (_a) {
224
188
  _a[(_d = (_c = fieldMetadata === null || fieldMetadata === void 0 ? void 0 : fieldMetadata.relationModel) === null || _c === void 0 ? void 0 : _c.userKeyField) === null || _d === void 0 ? void 0 : _d.name] = (_b = {},
225
189
  _b[((_e = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _e === void 0 ? void 0 : _e.autocompleteMatchMode) || '$containsi'] = event.query,
226
190
  _b),
227
- _a)
228
- ]
229
- }
191
+ _a),
192
+ ],
193
+ },
230
194
  };
231
195
  fixedFilterToBeApplied = false;
232
196
  fixedFilterParsed = false;
233
197
  if ((fieldMetadata === null || fieldMetadata === void 0 ? void 0 : fieldMetadata.relationFieldFixedFilter) || ((_f = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _f === void 0 ? void 0 : _f.whereClause)) {
234
- convertedFixedFilter = ((_g = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _g === void 0 ? void 0 : _g.whereClause) ? (_h = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _h === void 0 ? void 0 : _h.whereClause : fieldMetadata === null || fieldMetadata === void 0 ? void 0 : fieldMetadata.relationFieldFixedFilter;
198
+ rawFilter = (_h = (_g = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _g === void 0 ? void 0 : _g.whereClause) !== null && _h !== void 0 ? _h : fieldMetadata === null || fieldMetadata === void 0 ? void 0 : fieldMetadata.relationFieldFixedFilter;
235
199
  fixedFilterToBeApplied = true;
236
- fixedFilterTemplate = Handlebars.compile(convertedFixedFilter);
237
- renderedFilter = fixedFilterTemplate(formik.values);
200
+ rendered = Handlebars.compile(rawFilter)(formik.values);
238
201
  try {
239
- parsedFilter_1 = JSON.parse(renderedFilter);
240
- isValid = function (obj) {
241
- if (!obj || typeof obj !== 'object')
202
+ parsed = JSON.parse(rendered);
203
+ hasValue_1 = function (val) {
204
+ if (val === null || val === undefined || val === '')
242
205
  return false;
243
- var hasValidValue = function (val) {
244
- if (val === null || val === undefined || val === '')
245
- return false;
246
- if (typeof val === 'object') {
247
- return Object.values(val).some(hasValidValue);
248
- }
249
- return true;
250
- };
251
- return hasValidValue(parsedFilter_1);
206
+ if (typeof val === 'object')
207
+ return Object.values(val).some(hasValue_1);
208
+ return true;
252
209
  };
253
- if (isValid(parsedFilter_1)) {
254
- queryData.filters.$and.push(parsedFilter_1);
210
+ if (hasValue_1(parsed)) {
211
+ queryData.filters.$and.push(parsed);
255
212
  fixedFilterParsed = true;
256
213
  }
257
214
  else {
258
- console.warn(ERROR_MESSAGES.SKIPPING_EMPTY_FIXED_FILTER, parsedFilter_1);
215
+ console.warn(ERROR_MESSAGES.SKIPPING_EMPTY_FIXED_FILTER, parsed);
259
216
  }
260
217
  }
261
218
  catch (e) {
262
- console.error(ERROR_MESSAGES.INVALID_JSON_WHERECLAUSE, renderedFilter);
263
- parsedFilter_1 = {};
219
+ console.error(ERROR_MESSAGES.INVALID_JSON_WHERECLAUSE, rendered);
264
220
  }
265
221
  }
266
- autocompleteQs = qs.stringify(queryData, {
267
- encodeValuesOnly: true,
268
- });
269
- // if (whereClause) {
270
- // autocompleteQs = `${autocompleteQs}&${whereClause}`;
271
- // }
272
222
  if (fixedFilterToBeApplied && !fixedFilterParsed) {
273
223
  console.error(ERROR_MESSAGES.FIXED_FILTER_NOT_APPLIED);
274
224
  }
275
225
  else {
276
- // const autocompleteQs = qs.stringify(queryData, {
277
- // encodeValuesOnly: true,
278
- // });
279
- fetchRelationEntities(autocompleteQs);
226
+ fetchSuggestions(qs.stringify(queryData, { encodeValuesOnly: true }));
280
227
  }
281
228
  return [2 /*return*/];
282
229
  });
283
230
  }); };
284
- return (_jsxs("div", { className: "relative", children: [_jsxs("div", { className: "flex flex-column gap-2 mt-1 sm:mt-2 md:mt-3 lg:mt-4", children: [showFieldLabel != false &&
285
- _jsxs("label", { htmlFor: fieldLayoutInfo.attrs.name, className: "form-field-label", children: [fieldLabel, fieldMetadata.required && _jsx("span", { className: "text-red-500", children: " *" }), _jsx(SolidFieldTooltip, { fieldContext: fieldContext })] }), _jsxs("div", { className: "flex align-items-center gap-3", children: [_jsx(AutoComplete, __assign({ readOnly: readOnly || readOnlyPermission, disabled: disabled || readOnlyPermission, multiple: true }, formik.getFieldProps(fieldLayoutInfo.attrs.name), { id: fieldLayoutInfo.attrs.name, field: "label", value: formik.values[fieldLayoutInfo.attrs.name] || '', dropdown: !readOnlyPermission, suggestions: autoCompleteItems, completeMethod: autoCompleteSearch, onChange: function (e) { return fieldContext.onChange(e, 'onFieldChange'); }, className: "solid-standard-autocomplete w-full" })), fieldContext.field.attrs.inlineCreate && (_jsxs(_Fragment, { children: [_jsx("div", { children: _jsx(Button, { icon: "pi pi-plus", rounded: true, outlined: true, "aria-label": "Filter", type: "button", size: "small", onClick: function () { return setVisibleCreateDialog(true); }, className: "custom-add-button" }) }), _jsx(InlineRelationEntityDialog, { visible: visibleCreateDialog, setVisible: setVisibleCreateDialog, fieldContext: fieldContext, onCreate: addNewRelation })] }))] })] }), isFormFieldValid(formik, fieldLayoutInfo.attrs.name) && (_jsx("div", { className: "absolute mt-1", children: _jsx(Message, { severity: "error", text: (_g = formik === null || formik === void 0 ? void 0 : formik.errors[fieldLayoutInfo.attrs.name]) === null || _g === void 0 ? void 0 : _g.toString() }) }))] }));
231
+ return (_jsxs("div", { className: "relative", children: [_jsxs("div", { className: "flex flex-column gap-2 mt-1 sm:mt-2 md:mt-3 lg:mt-4", children: [showFieldLabel !== false && (_jsxs("label", { htmlFor: fieldLayoutInfo.attrs.name, className: "form-field-label", children: [fieldLabel, fieldMetadata.required && _jsx("span", { className: "text-red-500", children: " *" }), _jsx(SolidFieldTooltip, { fieldContext: fieldContext })] })), _jsxs("div", { className: "flex align-items-center gap-3", children: [_jsx(AutoComplete, { readOnly: readOnly || readOnlyPermission, disabled: disabled || readOnlyPermission, multiple: true, id: fieldLayoutInfo.attrs.name, field: "label", value: currentValues, dropdown: !readOnlyPermission, suggestions: suggestions, completeMethod: autoCompleteSearch, onChange: function () {
232
+ // Intentionally empty currentValues is managed via onSelect/onUnselect
233
+ }, onSelect: function (e) { return linkItem(e.value); }, onUnselect: function (e) { return unlinkItem(e.value); }, className: "solid-standard-autocomplete w-full" }), fieldContext.field.attrs.inlineCreate && (_jsxs(_Fragment, { children: [_jsx("div", { children: _jsx(Button, { icon: "pi pi-plus", rounded: true, outlined: true, "aria-label": "Filter", type: "button", size: "small", onClick: function () { return setVisibleCreateDialog(true); }, className: "custom-add-button" }) }), _jsx(InlineRelationEntityDialog, { visible: visibleCreateDialog, setVisible: setVisibleCreateDialog, fieldContext: fieldContext, onCreate: addNewRelation })] }))] })] }), isFormFieldValid(formik, fieldLayoutInfo.attrs.name) && (_jsx("div", { className: "absolute mt-1", children: _jsx(Message, { severity: "error", text: (_g = formik === null || formik === void 0 ? void 0 : formik.errors[fieldLayoutInfo.attrs.name]) === null || _g === void 0 ? void 0 : _g.toString() }) }))] }));
286
234
  };
235
+ /**
236
+ * CHECKBOX WIDGET
237
+ *
238
+ * State:
239
+ * allOptions — every possible item to render as a checkbox row
240
+ * currentValues — the subset that is currently linked (drives checked state)
241
+ *
242
+ * Flow:
243
+ * mount → fetchCurrentValues() + fetchAllOptions()
244
+ * user checks → linkItem() → on success, adds to currentValues
245
+ * user unchecks → unlinkItem() → on success, removes from currentValues
246
+ */
287
247
  export var DefaultRelationManyToManyCheckBoxFormEditWidget = function (_a) {
288
- var _b;
248
+ var _b, _c;
289
249
  var formik = _a.formik, fieldContext = _a.fieldContext;
290
250
  var fieldMetadata = fieldContext.fieldMetadata;
291
251
  var fieldLayoutInfo = fieldContext.field;
292
252
  var showFieldLabel = (_b = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _b === void 0 ? void 0 : _b.showLabel;
293
253
  var readOnlyPermission = fieldContext.readOnly;
294
- var _c = useState(false), visibleCreateDialog = _c[0], setVisibleCreateDialog = _c[1];
295
- var _d = useRelationEntityHandler({ fieldContext: fieldContext, formik: formik }), autoCompleteItems = _d.autoCompleteItems, fetchRelationEntities = _d.fetchRelationEntities, addNewRelation = _d.addNewRelation;
254
+ var _d = useState(false), visibleCreateDialog = _d[0], setVisibleCreateDialog = _d[1];
255
+ var _e = useRelationEntityHandler({ fieldContext: fieldContext }), currentValues = _e.currentValues, allOptions = _e.allOptions, fetchCurrentValues = _e.fetchCurrentValues, fetchAllOptions = _e.fetchAllOptions, linkItem = _e.linkItem, unlinkItem = _e.unlinkItem, addNewRelation = _e.addNewRelation;
256
+ // On mount: load already-linked items + all possible options
257
+ useEffect(function () {
258
+ fetchCurrentValues();
259
+ }, [(_c = fieldContext.data) === null || _c === void 0 ? void 0 : _c.id]);
296
260
  useEffect(function () {
297
261
  var _a, _b, _c;
298
- var fieldMetadata = fieldContext.fieldMetadata;
299
- var fieldLayoutInfo = fieldContext.field;
300
262
  var queryData = {
301
263
  offset: 0,
302
264
  limit: 1000,
303
- filters: {
304
- $and: []
305
- }
265
+ filters: { $and: [] },
306
266
  };
307
267
  var fixedFilterToBeApplied = false;
308
268
  var fixedFilterParsed = false;
309
269
  if ((fieldMetadata === null || fieldMetadata === void 0 ? void 0 : fieldMetadata.relationFieldFixedFilter) || ((_a = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _a === void 0 ? void 0 : _a.whereClause)) {
310
- var convertedFixedFilter = ((_b = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _b === void 0 ? void 0 : _b.whereClause) ? (_c = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _c === void 0 ? void 0 : _c.whereClause : fieldMetadata === null || fieldMetadata === void 0 ? void 0 : fieldMetadata.relationFieldFixedFilter;
270
+ var rawFilter = (_c = (_b = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _b === void 0 ? void 0 : _b.whereClause) !== null && _c !== void 0 ? _c : fieldMetadata === null || fieldMetadata === void 0 ? void 0 : fieldMetadata.relationFieldFixedFilter;
311
271
  fixedFilterToBeApplied = true;
312
- var fixedFilterTemplate = Handlebars.compile(convertedFixedFilter);
313
- var renderedFilter = fixedFilterTemplate(formik.values);
314
- var parsedFilter_2;
272
+ var rendered = Handlebars.compile(rawFilter)(formik.values);
315
273
  try {
316
- parsedFilter_2 = JSON.parse(renderedFilter);
317
- var isValid = function (obj) {
318
- if (!obj || typeof obj !== 'object')
274
+ var parsed = JSON.parse(rendered);
275
+ var hasValue_2 = function (val) {
276
+ if (val === null || val === undefined || val === '')
319
277
  return false;
320
- var hasValidValue = function (val) {
321
- if (val === null || val === undefined || val === '')
322
- return false;
323
- if (typeof val === 'object') {
324
- return Object.values(val).some(hasValidValue);
325
- }
326
- return true;
327
- };
328
- return hasValidValue(parsedFilter_2);
278
+ if (typeof val === 'object')
279
+ return Object.values(val).some(hasValue_2);
280
+ return true;
329
281
  };
330
- if (isValid(parsedFilter_2)) {
331
- queryData.filters.$and.push(parsedFilter_2);
282
+ if (hasValue_2(parsed)) {
283
+ queryData.filters.$and.push(parsed);
332
284
  fixedFilterParsed = true;
333
285
  }
334
286
  else {
335
- console.warn(ERROR_MESSAGES.SKIPPING_EMPTY_FIXED_FILTER, parsedFilter_2);
287
+ console.warn(ERROR_MESSAGES.SKIPPING_EMPTY_FIXED_FILTER, parsed);
336
288
  }
337
289
  }
338
290
  catch (e) {
339
- console.error(ERROR_MESSAGES.INVALID_JSON_WHERECLAUSE, renderedFilter);
340
- parsedFilter_2 = {};
291
+ console.error(ERROR_MESSAGES.INVALID_JSON_WHERECLAUSE, rendered);
341
292
  }
342
293
  }
343
294
  if (fixedFilterToBeApplied && !fixedFilterParsed) {
344
295
  console.error(ERROR_MESSAGES.FIXED_FILTER_NOT_APPLIED);
345
296
  }
346
297
  else {
347
- var autocompleteQs = qs.stringify(queryData, {
348
- encodeValuesOnly: true,
349
- });
350
- fetchRelationEntities(autocompleteQs);
298
+ fetchAllOptions(qs.stringify(queryData, { encodeValuesOnly: true }));
351
299
  }
352
300
  }, [fieldContext, formik.values]);
353
- var handleCheckboxChange = function (e) {
354
- if (formik.values[fieldLayoutInfo.attrs.name].some(function (item) { return item.value === e.value; })) {
355
- formik.setFieldValue(fieldLayoutInfo.attrs.name, formik.values[fieldLayoutInfo.attrs.name].filter(function (s) { return s.value !== e.value; }));
301
+ var handleCheckboxChange = function (item) {
302
+ var isCurrentlyLinked = currentValues.some(function (s) { return s.value === item.value; });
303
+ if (isCurrentlyLinked) {
304
+ unlinkItem(item);
356
305
  }
357
306
  else {
358
- formik.setFieldValue(fieldLayoutInfo.attrs.name, __spreadArray(__spreadArray([], formik.values[fieldLayoutInfo.attrs.name], true), [e], false));
307
+ linkItem(item);
359
308
  }
360
309
  };
361
- var headerTemplate = function (options) {
362
- var className = "".concat(options.className, " justify-content-space-between");
363
- return (_jsxs("div", { className: className, children: [_jsxs("div", { className: "flex align-items-center gap-3", children: [showFieldLabel != false &&
364
- _jsxs("label", { className: "form-field-label", children: [capitalize(fieldLayoutInfo.attrs.name), fieldMetadata.required && _jsx("span", { className: "text-red-500", children: " *" }), _jsx(SolidFieldTooltip, { fieldContext: fieldContext })] }), fieldContext.field.attrs.inlineCreate && (_jsxs(_Fragment, { children: [_jsx(Button, { icon: "pi pi-plus", rounded: true, outlined: true, "aria-label": "Filter", type: "button", size: "small", onClick: function () { return setVisibleCreateDialog(true); }, className: "custom-add-button" }), _jsx(InlineRelationEntityDialog, { visible: visibleCreateDialog, setVisible: setVisibleCreateDialog, fieldContext: fieldContext, onCreate: addNewRelation })] }))] }), _jsx("div", { children: options.togglerElement })] }));
310
+ var headerTemplate = function (options) { return (_jsxs("div", { className: "".concat(options.className, " justify-content-space-between"), children: [_jsxs("div", { className: "flex align-items-center gap-3", children: [showFieldLabel !== false && (_jsxs("label", { className: "form-field-label", children: [capitalize(fieldLayoutInfo.attrs.name), fieldMetadata.required && _jsx("span", { className: "text-red-500", children: " *" }), _jsx(SolidFieldTooltip, { fieldContext: fieldContext })] })), fieldContext.field.attrs.inlineCreate && (_jsxs(_Fragment, { children: [_jsx(Button, { icon: "pi pi-plus", rounded: true, outlined: true, "aria-label": "Filter", type: "button", size: "small", onClick: function () { return setVisibleCreateDialog(true); }, className: "custom-add-button" }), _jsx(InlineRelationEntityDialog, { visible: visibleCreateDialog, setVisible: setVisibleCreateDialog, fieldContext: fieldContext, onCreate: addNewRelation })] }))] }), _jsx("div", { children: options.togglerElement })] })); };
311
+ return (_jsx("div", { children: _jsx(Panel, { toggleable: true, headerTemplate: headerTemplate, children: _jsx("div", { className: "formgrid grid", children: allOptions.map(function (item, i) { return (_jsxs("div", { className: "field col-6 flex gap-2 ".concat(i >= 2 ? 'mt-3' : ''), children: [_jsx(Checkbox, { readOnly: readOnlyPermission, inputId: item.label, checked: currentValues.some(function (s) { return s.value === item.value; }), onChange: function () { return handleCheckboxChange(item); } }), _jsx("label", { htmlFor: item.label, className: "form-field-label m-0", children: item.label })] }, item.value)); }) }) }) }));
312
+ };
313
+ var buildRelationCustomFilter = function (_a) {
314
+ var _b;
315
+ var _c, _d, _e, _f, _g;
316
+ var fieldContext = _a.fieldContext, fieldLayoutInfo = _a.fieldLayoutInfo;
317
+ if (!fieldContext)
318
+ return { id: { $eq: -1 } };
319
+ var relationFieldName = (_d = (_c = fieldContext.fieldMetadata) === null || _c === void 0 ? void 0 : _c.relationCoModelFieldName) !== null && _d !== void 0 ? _d : fieldContext.modelName;
320
+ var parentId = (_f = (_e = fieldContext.data) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : -1;
321
+ var baseFilter = (_b = {}, _b[relationFieldName] = { id: { $eq: parentId } }, _b);
322
+ var whereClause = (_g = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _g === void 0 ? void 0 : _g.whereClause;
323
+ if (!whereClause)
324
+ return { $and: [baseFilter] };
325
+ try {
326
+ return { $and: [baseFilter, JSON.parse(whereClause)] };
327
+ }
328
+ catch (error) {
329
+ console.error("Failed to parse whereClause:", error);
330
+ return { $and: [baseFilter] };
331
+ }
332
+ };
333
+ export var DefaultRelationManyToManyListFormEditWidget = function (_a) {
334
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
335
+ var formik = _a.formik, fieldContext = _a.fieldContext;
336
+ var fieldMetadata = fieldContext.fieldMetadata;
337
+ var router = useRouter();
338
+ var fieldLayoutInfo = fieldContext.field;
339
+ var fieldLabel = (_b = fieldLayoutInfo.attrs.label) !== null && _b !== void 0 ? _b : fieldMetadata.displayName;
340
+ var solidFormViewMetaData = fieldContext.solidFormViewMetaData;
341
+ var _l = useState(false), visibleCreateRelationEntity = _l[0], setvisibleCreateRelationEntity = _l[1];
342
+ var _m = useState(), listViewParams = _m[0], setListViewParams = _m[1];
343
+ var _o = useState(), formViewParams = _o[0], setformViewParams = _o[1];
344
+ var _p = useState(false), refreshList = _p[0], setRefreshList = _p[1];
345
+ var showFieldLabel = (_c = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _c === void 0 ? void 0 : _c.showLabel;
346
+ var readOnlyPermission = fieldContext.readOnly;
347
+ var pathname = usePathname();
348
+ var lastPathSegment = pathname.split('/').pop();
349
+ var userKeyField = (_d = Object.entries(fieldContext.solidFormViewMetaData.data.solidFieldsMetadata).find(function (_a) {
350
+ var _ = _a[0], value = _a[1];
351
+ return value.isUserKey;
352
+ })) === null || _d === void 0 ? void 0 : _d[0];
353
+ var _q = useState(false), showSaveParentEntityConfirmationPopup = _q[0], setShowSaveParentEntityConfirmationPopup = _q[1];
354
+ var _r = useState(false), visibleLinkDialog = _r[0], setVisibleLinkDialog = _r[1];
355
+ var _s = useState([]), linkSearchResults = _s[0], setLinkSearchResults = _s[1];
356
+ var _t = useState(null), selectedLinkItem = _t[0], setSelectedLinkItem = _t[1];
357
+ var _u = useState(false), isLinking = _u[0], setIsLinking = _u[1];
358
+ var _v = useRelationEntityHandler({ fieldContext: fieldContext }), fetchSuggestions = _v.fetchSuggestions, linkItem = _v.linkItem, unlinkItem = _v.unlinkItem, suggestions = _v.suggestions;
359
+ var handleAddClickForEmbeddedView = function () {
360
+ if (lastPathSegment === "new") {
361
+ setShowSaveParentEntityConfirmationPopup(true);
362
+ }
363
+ else {
364
+ setSelectedLinkItem(null);
365
+ setLinkSearchResults([]);
366
+ setVisibleLinkDialog(true);
367
+ }
365
368
  };
366
- return (_jsx("div", { children: _jsx(Panel, { toggleable: true, headerTemplate: headerTemplate, children: _jsx("div", { className: "formgrid grid", children: autoCompleteItems && autoCompleteItems.map(function (a, i) {
367
- return (_jsxs("div", { className: "field col-6 flex gap-2 ".concat(i >= 2 ? 'mt-3' : ''), children: [_jsx(Checkbox, { readOnly: readOnlyPermission, inputId: a.label, checked: formik.values[fieldLayoutInfo.attrs.name].some(function (item) { return item.label === a.label; }), onChange: function () { return handleCheckboxChange(a); } }), _jsxs("label", { htmlFor: a.label, className: "form-field-label m-0", children: [" ", a.label] })] }, a.label));
368
- }) }) }) }));
369
+ var handleLinkSearch = function (event) { return __awaiter(void 0, void 0, void 0, function () {
370
+ var queryData;
371
+ var _a, _b;
372
+ var _c, _d, _e;
373
+ return __generator(this, function (_f) {
374
+ switch (_f.label) {
375
+ case 0:
376
+ queryData = {
377
+ offset: 0,
378
+ limit: 1000,
379
+ filters: {
380
+ $and: [
381
+ (_a = {},
382
+ _a[(_d = (_c = fieldMetadata === null || fieldMetadata === void 0 ? void 0 : fieldMetadata.relationModel) === null || _c === void 0 ? void 0 : _c.userKeyField) === null || _d === void 0 ? void 0 : _d.name] = (_b = {},
383
+ _b[((_e = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _e === void 0 ? void 0 : _e.autocompleteMatchMode) || '$containsi'] = event.query,
384
+ _b),
385
+ _a),
386
+ ],
387
+ },
388
+ };
389
+ return [4 /*yield*/, fetchSuggestions(qs.stringify(queryData, { encodeValuesOnly: true }))];
390
+ case 1:
391
+ _f.sent();
392
+ return [2 /*return*/];
393
+ }
394
+ });
395
+ }); };
396
+ var handleLinkConfirm = function () { return __awaiter(void 0, void 0, void 0, function () {
397
+ return __generator(this, function (_a) {
398
+ switch (_a.label) {
399
+ case 0:
400
+ if (!selectedLinkItem)
401
+ return [2 /*return*/];
402
+ setIsLinking(true);
403
+ _a.label = 1;
404
+ case 1:
405
+ _a.trys.push([1, , 3, 4]);
406
+ return [4 /*yield*/, linkItem(selectedLinkItem)];
407
+ case 2:
408
+ _a.sent();
409
+ setVisibleLinkDialog(false);
410
+ setSelectedLinkItem(null);
411
+ setRefreshList(function (prev) { return !prev; });
412
+ return [3 /*break*/, 4];
413
+ case 3:
414
+ setIsLinking(false);
415
+ return [7 /*endfinally*/];
416
+ case 4: return [2 /*return*/];
417
+ }
418
+ });
419
+ }); };
420
+ var handleDeleteClick = function (id) { return __awaiter(void 0, void 0, void 0, function () {
421
+ return __generator(this, function (_a) {
422
+ switch (_a.label) {
423
+ case 0: return [4 /*yield*/, unlinkItem({ value: id, label: '' })];
424
+ case 1:
425
+ _a.sent();
426
+ setRefreshList(function (prev) { return !prev; });
427
+ return [2 /*return*/];
428
+ }
429
+ });
430
+ }); };
431
+ var handleEditClickForEmbeddedView = function (id) {
432
+ var _a;
433
+ var _b, _c;
434
+ if (id === "new") {
435
+ setShowSaveParentEntityConfirmationPopup(true);
436
+ }
437
+ else {
438
+ setformViewParams({
439
+ moduleName: fieldContext.fieldMetadata.relationModelModuleName,
440
+ id: id,
441
+ embeded: true,
442
+ isCustomCreate: false,
443
+ customLayout: (_b = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _b === void 0 ? void 0 : _b.inlineCreateLayout,
444
+ modelName: camelCase(fieldContext.fieldMetadata.relationCoModelSingularName),
445
+ parentFieldName: fieldContext.fieldMetadata.relationCoModelFieldName,
446
+ parentData: userKeyField
447
+ ? (_a = {}, _a[userKeyField] = { solidManyToOneLabel: fieldContext.data[userKeyField], solidManyToOneValue: fieldContext.data['id'] }, _a) : {},
448
+ onEmbeddedFormSave: fieldContext.onEmbeddedFormSave,
449
+ inlineCreateAutoSave: (_c = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _c === void 0 ? void 0 : _c.inlineCreateAutoSave,
450
+ });
451
+ setvisibleCreateRelationEntity(true);
452
+ }
453
+ };
454
+ var handlePopupClose = function () {
455
+ var _a, _b, _c;
456
+ setvisibleCreateRelationEntity(false);
457
+ var currentUrl = new URL(window.location.href);
458
+ currentUrl.searchParams.delete('childEntity');
459
+ router.push(currentUrl.toString());
460
+ setRefreshList(function (prev) { return !prev; });
461
+ setListViewParams({
462
+ moduleName: fieldContext.fieldMetadata.relationModelModuleName,
463
+ modelName: camelCase(fieldContext.fieldMetadata.relationCoModelSingularName),
464
+ inlineCreate: readOnlyPermission === false,
465
+ customLayout: (_a = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _a === void 0 ? void 0 : _a.inlineListLayout,
466
+ embeded: true,
467
+ id: (_c = (_b = fieldContext.data) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : 'new',
468
+ customFilter: buildRelationCustomFilter({ fieldContext: fieldContext, fieldLayoutInfo: fieldLayoutInfo }),
469
+ });
470
+ };
471
+ useEffect(function () {
472
+ var _a;
473
+ var _b, _c, _d, _e, _f;
474
+ setListViewParams({
475
+ moduleName: fieldContext.fieldMetadata.relationModelModuleName,
476
+ modelName: camelCase(fieldContext.fieldMetadata.relationCoModelSingularName),
477
+ inlineCreate: readOnlyPermission === false,
478
+ customLayout: (_b = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _b === void 0 ? void 0 : _b.inlineListLayout,
479
+ embeded: true,
480
+ id: (_d = (_c = fieldContext.data) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : 'new',
481
+ customFilter: buildRelationCustomFilter({ fieldContext: fieldContext, fieldLayoutInfo: fieldLayoutInfo }),
482
+ });
483
+ setformViewParams({
484
+ moduleName: fieldContext.fieldMetadata.relationModelModuleName,
485
+ modelName: camelCase(fieldContext.fieldMetadata.relationCoModelSingularName),
486
+ parentFieldName: fieldContext.fieldMetadata.relationCoModelFieldName,
487
+ id: "new",
488
+ embeded: true,
489
+ isCustomCreate: false,
490
+ customLayout: (_e = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _e === void 0 ? void 0 : _e.inlineCreateLayout,
491
+ parentData: userKeyField
492
+ ? (_a = {}, _a[userKeyField] = { solidManyToOneLabel: fieldContext.data[userKeyField], solidManyToOneValue: fieldContext.data['id'] }, _a) : {},
493
+ onEmbeddedFormSave: fieldContext.onEmbeddedFormSave,
494
+ inlineCreateAutoSave: (_f = fieldLayoutInfo === null || fieldLayoutInfo === void 0 ? void 0 : fieldLayoutInfo.attrs) === null || _f === void 0 ? void 0 : _f.inlineCreateAutoSave,
495
+ });
496
+ }, [readOnlyPermission]);
497
+ var saveParentEntity = function () { return __awaiter(void 0, void 0, void 0, function () {
498
+ var currentUrl, _a;
499
+ return __generator(this, function (_b) {
500
+ switch (_b.label) {
501
+ case 0:
502
+ currentUrl = new URL(window.location.href);
503
+ currentUrl.searchParams.set('childEntity', fieldLayoutInfo.attrs.name);
504
+ currentUrl.searchParams.set('viewMode', 'edit');
505
+ _b.label = 1;
506
+ case 1:
507
+ _b.trys.push([1, 3, , 4]);
508
+ router.push(currentUrl.toString());
509
+ return [4 /*yield*/, formik.handleSubmit()];
510
+ case 2:
511
+ _b.sent();
512
+ return [3 /*break*/, 4];
513
+ case 3:
514
+ _a = _b.sent();
515
+ return [3 /*break*/, 4];
516
+ case 4:
517
+ setShowSaveParentEntityConfirmationPopup(false);
518
+ return [2 /*return*/];
519
+ }
520
+ });
521
+ }); };
522
+ return (_jsxs("div", { children: [showFieldLabel !== false && (_jsxs("label", { htmlFor: fieldLayoutInfo.attrs.name, className: "form-field-label", children: [fieldLabel, fieldMetadata.required && _jsx("span", { className: "text-red-500", children: " *" }), _jsx(SolidFieldTooltip, { fieldContext: fieldContext })] })), listViewParams && (_jsx(SolidListView, __assign({}, listViewParams, { embededFieldRelationType: "many-to-many", handleAddClickForEmbeddedView: handleAddClickForEmbeddedView, handleEditClickForEmbeddedView: handleEditClickForEmbeddedView, handleDeleteClick: handleDeleteClick }), refreshList.toString())), readOnlyPermission !== true && formViewParams && (_jsx(RenderSolidFormEmbededView, { formik: formik, fieldContext: fieldContext, visibleCreateRelationEntity: visibleCreateRelationEntity, setvisibleCreateRelationEntity: setvisibleCreateRelationEntity, formViewParams: formViewParams, handlePopupClose: handlePopupClose })), _jsx(Dialog, { header: "Link existing ".concat(fieldLabel), visible: visibleLinkDialog, style: { width: '30vw', minWidth: 320 }, onHide: function () { return setVisibleLinkDialog(false); }, footer: _jsxs("div", { className: "flex gap-2 justify-content-end", children: [_jsx(Button, { label: "Link", size: "small", disabled: !selectedLinkItem || isLinking, loading: isLinking, onClick: handleLinkConfirm }), _jsx(Button, { label: "Cancel", size: "small", outlined: true, className: "bg-primary-reverse", onClick: function () { return setVisibleLinkDialog(false); } })] }), children: _jsxs("div", { className: "flex flex-column gap-2 pt-2", children: [_jsxs("label", { className: "form-field-label", children: ["Search ", fieldLabel] }), _jsx(AutoComplete, { field: "label", value: selectedLinkItem, suggestions: suggestions, completeMethod: handleLinkSearch, onChange: function (e) { return setSelectedLinkItem(e.value); }, onSelect: function (e) { return setSelectedLinkItem(e.value); }, placeholder: "Type to search...", className: "w-full", dropdown: true })] }) }), _jsx(Dialog, { showHeader: false, headerClassName: "py-2", contentClassName: "px-0 pb-0", className: "solid-confirm-dialog", contentStyle: { borderRadius: 6 }, visible: showSaveParentEntityConfirmationPopup, style: { width: '20vw' }, onHide: function () {
523
+ if (!showSaveParentEntityConfirmationPopup)
524
+ return;
525
+ setShowSaveParentEntityConfirmationPopup(false);
526
+ }, children: _jsxs("div", { className: "p-4", children: [_jsxs("p", { className: "m-0 solid-primary-title", style: { fontSize: 16 }, children: ["Before Creating ", fieldLabel, " you need to save", ' ', ((_g = (_f = (_e = solidFormViewMetaData === null || solidFormViewMetaData === void 0 ? void 0 : solidFormViewMetaData.data) === null || _e === void 0 ? void 0 : _e.solidView) === null || _f === void 0 ? void 0 : _f.model) === null || _g === void 0 ? void 0 : _g.displayName)
527
+ ? (_k = (_j = (_h = solidFormViewMetaData === null || solidFormViewMetaData === void 0 ? void 0 : solidFormViewMetaData.data) === null || _h === void 0 ? void 0 : _h.solidView) === null || _j === void 0 ? void 0 : _j.model) === null || _k === void 0 ? void 0 : _k.displayName
528
+ : capitalize(fieldContext.modelName), ". Please click save if you wish to proceed?"] }), _jsxs("div", { className: "flex align-items-center justify-content-start gap-2 mt-3", children: [_jsx(Button, { label: "Save", size: "small", onClick: saveParentEntity }), _jsx(Button, { label: "Cancel", size: "small", onClick: function () { return setShowSaveParentEntityConfirmationPopup(false); }, outlined: true, className: "bg-primary-reverse" })] })] }) })] }));
369
529
  };
370
530
  //# sourceMappingURL=SolidRelationManyToManyField.js.map