sccoreui 6.4.91 → 6.4.92

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.
@@ -15,6 +15,14 @@ const constants_1 = tslib_1.__importDefault(require("../../../constants"));
15
15
  const Conditions = (props) => {
16
16
  const { columnName, condition, value, columnsArray, conditionsArray, index, id, updateconditionsArray, removeConditionFromArray, addEmptyCondition, conditionsLength, conditionType, conditionTypes, handleConditionType, filterModelText, validationErrors, validationTouched, } = props;
17
17
  const valueError = Boolean(validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors.value) && Boolean(validationTouched === null || validationTouched === void 0 ? void 0 : validationTouched.value);
18
+ // Filter available conditions based on column data type
19
+ const filteredConditions = conditionsArray.filter((each) => {
20
+ var _a;
21
+ return (_a = constants_1.default.accessBasedOnDataType
22
+ .find((access) => access.datatype === (columnName === null || columnName === void 0 ? void 0 : columnName.dataType))) === null || _a === void 0 ? void 0 : _a.conditions.includes(each.value);
23
+ });
24
+ // Extract numeric value from condition (handles both object and number formats)
25
+ const conditionValue = typeof condition === 'object' ? condition === null || condition === void 0 ? void 0 : condition.value : condition;
18
26
  const onAddCondition = (index) => {
19
27
  addEmptyCondition(index);
20
28
  };
@@ -196,11 +204,7 @@ const Conditions = (props) => {
196
204
  };
197
205
  return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "grid my-1 align-items-center pt-2" }, { children: [index !== 0 ? ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { className: "operator-type filter_dropdown_and col-2 w-7rem mx-4 border-1 border-gray-300 h-44 -mt-2", options: conditionTypes, optionLabel: "label", placeholder: "Select", value: conditionType, disabled: index !== 1, onChange: (event) => handleConditionType(event.target.value) })) : ((0, jsx_runtime_1.jsx)("div", { className: "col-2 w-7rem mx-4" })), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "col-9 grid filter-dropdowns overflow-y-hidden" }, { children: [(0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { className: `condition-dropdown dropdown-focus-none border-noround-right col-4 pl-3`, options: columnsArray, optionLabel: "name", placeholder: (filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.elementOnePlaceHolder)
198
206
  ? filterModelText.elementOnePlaceHolder
199
- : "Select", value: columnsArray.find((item) => item.code === columnName.code), onChange: (event) => onUpdateColumnName(event.value), panelClassName: "w-14rem" }), (0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { className: "condition-type hide-focus border-noround remove-focus border-x-none filter-dropdown-grid col-4", value: condition, options: conditionsArray.filter((each) => {
200
- var _a;
201
- return (_a = constants_1.default.accessBasedOnDataType
202
- .find((access) => access.datatype === (columnName === null || columnName === void 0 ? void 0 : columnName.dataType))) === null || _a === void 0 ? void 0 : _a.conditions.includes(each.value);
203
- }), disabled: columnName === "", optionLabel: "name", placeholder: (filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.elementTwoPlaceHolder)
207
+ : "Select", value: columnsArray.find((item) => item.code === columnName.code), onChange: (event) => onUpdateColumnName(event.value), panelClassName: "w-14rem" }), (0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { className: "condition-type hide-focus border-noround remove-focus border-x-none filter-dropdown-grid col-4", value: conditionValue, options: filteredConditions, disabled: columnName === "", optionLabel: "name", optionValue: "value", placeholder: (filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.elementTwoPlaceHolder)
204
208
  ? filterModelText.elementTwoPlaceHolder
205
209
  : "Select", onChange: (event) => onUpdateCondition(event.value), panelClassName: "w-14rem status_select_field" }), renderDynamicField(columnName, valueError)] })), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "flex gap-1 col-1 -mt-2 md:px-2 lg:px-0" }, { children: [(0, jsx_runtime_1.jsx)("div", Object.assign({ className: "cursor-pointer conditional_btn", onClick: () => onAddCondition(index) }, { children: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "plus-circle", size: 20, color: "text-gray-500" }) })), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: `cursor-pointer conditional_btn delete-action ${conditionsLength === 1 ? "p-disabled" : ""}`, onClick: () => onRemoveCondition(id) }, { children: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "minus-circle", size: 20, color: "text-gray-500" }) }))] }))] })));
206
210
  };
@@ -4,42 +4,68 @@ const tslib_1 = require("tslib");
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const button_1 = require("primereact/button");
7
- const Conditions_1 = tslib_1.__importDefault(require("./conditions/Conditions"));
8
7
  const divider_1 = require("primereact/divider");
9
- const context_provider_1 = require("../../context-provider");
8
+ const dialog_1 = require("primereact/dialog");
10
9
  const inputtext_1 = require("primereact/inputtext");
11
- // import { OverlayPanel } from "primereact/overlaypanel";
10
+ const Yup = tslib_1.__importStar(require("yup"));
11
+ const Conditions_1 = tslib_1.__importDefault(require("./conditions/Conditions"));
12
+ const context_provider_1 = require("../../context-provider");
12
13
  const svg_component_1 = tslib_1.__importDefault(require("../../../../directives/svg-component"));
13
14
  const Types_1 = require("../../Types");
14
15
  const constants_1 = tslib_1.__importDefault(require("../../constants"));
15
16
  const helper_1 = require("../../helper");
16
17
  const utilComponents_1 = require("../../utilComponents");
17
18
  const FeatureSkeleton_1 = tslib_1.__importDefault(require("../../../skeletons/FeatureSkeleton"));
18
- const dialog_1 = require("primereact/dialog");
19
- const Yup = tslib_1.__importStar(require("yup"));
20
19
  const form_1 = tslib_1.__importDefault(require("../../../form/form"));
21
- // import "./TableFilter.module.scss";
20
+ /**
21
+ * TableFilter Component
22
+ *
23
+ * Provides an advanced filtering UI for AG Grid tables. Allows users to:
24
+ * - Add multiple filter conditions with AND/OR logic
25
+ * - Filter by different data types (string, number, date, etc.)
26
+ * - Save filter configurations as named views
27
+ * - Pre-populate filters from default values
28
+ */
22
29
  const TableFilter = () => {
30
+ // Context values for filter state management
23
31
  const { featureDetails, columnData, conditionType, conditionTypes, globalFilters, setConditionType, setGlobalFilters, setFeatureDetails, callGrid, setViewName, viewName, createView, enableViewCreate, filterModelText, enableAdvancedFilter, gridApi, conditionsToDisplay, } = (0, react_1.useContext)(context_provider_1.FeatureContext);
32
+ // Form reference for validation
24
33
  const formRef = (0, react_1.useRef)(null);
25
- // console.log("createView", FeatureContext);
26
- // debugger;
34
+ // Column mapping keys
27
35
  const columnId = "field";
28
- const columnName = "headerName";
29
- // const showFilter = useRef<any>(null);
36
+ const columnNameKey = "headerName";
37
+ // Local state
30
38
  const [conditionsArray, setConditionsArray] = (0, react_1.useState)([]);
31
39
  const [allFieldsFilled, setAllFieldsFilled] = (0, react_1.useState)(false);
32
- const [enbleApply, setEnableApply] = (0, react_1.useState)(true);
33
- // const [isOverlayOpened, setIsOverlayOpened] = useState<boolean>(false);
40
+ const [enableApply, setEnableApply] = (0, react_1.useState)(true);
34
41
  const [isVisible, setIsVisible] = (0, react_1.useState)(false);
35
42
  const [displayInput, setDisplayInput] = (0, react_1.useState)(false);
43
+ // Check if filter component is disabled
36
44
  const isDisabled = (0, helper_1.isComponentDisable)(conditionsToDisplay.displayFilter);
45
+ // ============================================================================
46
+ // Condition Type Helpers
47
+ // ============================================================================
48
+ /**
49
+ * Check if condition is IS_KNOWN or IS_UNKNOWN (no value required)
50
+ */
37
51
  const isKnownOrUnknown = (condition) => condition === Types_1.FilteredConditionTypes.IS_KNOWN ||
38
52
  condition === Types_1.FilteredConditionTypes.IS_UNKNOWN;
53
+ /**
54
+ * Check if condition is a between/range condition
55
+ */
39
56
  const isBetweenCondition = (condition) => condition === Types_1.FilteredConditionTypes.IS_BETWEEN ||
40
57
  condition === Types_1.FilteredConditionTypes.IS_NOT_BETWEEN;
58
+ /**
59
+ * Check if condition is any of/none of (multi-value)
60
+ */
41
61
  const isAnyOrNoneOf = (condition) => condition === Types_1.FilteredConditionTypes.IS_ANY_OF ||
42
62
  condition === Types_1.FilteredConditionTypes.IS_NONE_OF;
63
+ // ============================================================================
64
+ // Validation Functions
65
+ // ============================================================================
66
+ /**
67
+ * Validate number values based on condition type
68
+ */
43
69
  const validateNumberValue = (value, condition) => {
44
70
  if (isBetweenCondition(condition)) {
45
71
  return (Array.isArray(value) &&
@@ -54,6 +80,9 @@ const TableFilter = () => {
54
80
  }
55
81
  return value !== undefined && value !== null && value !== "";
56
82
  };
83
+ /**
84
+ * Validate date values based on condition type
85
+ */
57
86
  const validateDateValue = (value, condition) => {
58
87
  if (isBetweenCondition(condition)) {
59
88
  return (Array.isArray(value) &&
@@ -66,6 +95,9 @@ const TableFilter = () => {
66
95
  }
67
96
  return Boolean(value);
68
97
  };
98
+ /**
99
+ * Validate string values based on condition type
100
+ */
69
101
  const validateStringValue = (value, condition) => {
70
102
  const allowedStringRegex = /^(?!^$)(?!^\s)(?!.*\s$)(?!.*\s\s)[A-Za-z0-9\s-!@#$%^&*()_+={}\[\]:;"'<>,.?/~`|\\]+$/;
71
103
  if (condition === Types_1.FilteredConditionTypes.IS_EQUAL_TO ||
@@ -84,6 +116,9 @@ const TableFilter = () => {
84
116
  typeof item === "string" &&
85
117
  allowedStringRegex.test(item)));
86
118
  };
119
+ /**
120
+ * Validate filter value based on column data type
121
+ */
87
122
  const validateValueByType = (column, condition, value) => {
88
123
  if (isKnownOrUnknown(condition))
89
124
  return true;
@@ -114,8 +149,14 @@ const TableFilter = () => {
114
149
  return true;
115
150
  }
116
151
  };
152
+ // ============================================================================
153
+ // Derived Data
154
+ // ============================================================================
155
+ /**
156
+ * Transform column data into format required by filter dropdowns
157
+ */
117
158
  const tableColumns = columnData === null || columnData === void 0 ? void 0 : columnData.filter((eachColumn) => eachColumn === null || eachColumn === void 0 ? void 0 : eachColumn.isFilterable).map((eachColumn) => ({
118
- name: eachColumn[columnName],
159
+ name: eachColumn[columnNameKey],
119
160
  code: eachColumn[columnId],
120
161
  fieldName: eachColumn.field,
121
162
  dataType: eachColumn.dataType,
@@ -124,6 +165,9 @@ const TableFilter = () => {
124
165
  fieldKey: eachColumn === null || eachColumn === void 0 ? void 0 : eachColumn.fieldKey,
125
166
  attributeType: eachColumn.attributeType ? eachColumn.attributeType : 1,
126
167
  }));
168
+ /**
169
+ * Default empty condition template
170
+ */
127
171
  const defaultCondition = {
128
172
  columnName: "",
129
173
  condition: "",
@@ -131,6 +175,9 @@ const TableFilter = () => {
131
175
  id: Math.random().toString(),
132
176
  isActive: false,
133
177
  };
178
+ /**
179
+ * Form validation schema using Yup
180
+ */
134
181
  const validationSchema = (0, react_1.useMemo)(() => Yup.object().shape({
135
182
  conditions: Yup.array()
136
183
  .of(Yup.object().shape({
@@ -146,94 +193,109 @@ const TableFilter = () => {
146
193
  .min(1),
147
194
  viewName: Yup.string(),
148
195
  }), []);
149
- // console.log("tableColumns", tableColumns);
196
+ /**
197
+ * Form initial values - memoized to prevent unnecessary re-renders
198
+ */
199
+ const formInitialValues = (0, react_1.useMemo)(() => ({
200
+ conditions: conditionsArray,
201
+ viewName,
202
+ }), [conditionsArray, viewName]);
203
+ // ============================================================================
204
+ // Event Handlers
205
+ // ============================================================================
206
+ /**
207
+ * Apply filter conditions to the grid
208
+ */
150
209
  const applyAdvancedFilter = (array) => {
151
210
  const allQueries = array.map((query) => {
152
211
  const column = { code: query.columnName };
153
212
  const operation = query.condition;
154
- let queryToAdd = {
213
+ return {
155
214
  selectedColumn: column,
156
215
  selectedOperation: operation,
157
216
  value: query.value,
158
217
  logicalOperator: conditionType.id,
159
218
  };
160
- return queryToAdd;
161
219
  });
162
- // const requestFilters: any[] = allQueries.map((element: any) => ({
163
- // fieldName: element?.selectedColumn?.code?.code,
164
- // fieldValue: element?.value.toString(),
165
- // conditionalOperator: element?.selectedOperation,
166
- // logicalOperator: element.logicalOperator,
167
- // attributeType: element?.selectedColumn?.code?.attributeType
168
- // ? element?.selectedColumn?.code.attributeType
169
- // : 1,
170
- // }));
171
220
  setGlobalFilters(array);
172
221
  const currentFeature = Object.assign({}, featureDetails);
173
222
  currentFeature.filterQueries = allQueries;
174
223
  setFeatureDetails(Object.assign(Object.assign({}, featureDetails), { filterQueries: allQueries }));
175
- // setConditionsArray(requestFilters);
176
224
  callGrid(currentFeature);
177
225
  return [];
178
226
  };
227
+ /**
228
+ * Handle AND/OR condition type change
229
+ */
179
230
  const handleConditionType = (value) => {
180
231
  setConditionType(value);
181
232
  };
233
+ /**
234
+ * Handle filter button click - show dialog or AG Grid advanced filter
235
+ */
182
236
  const onClickFilter = (event) => {
183
237
  var _a;
184
238
  if (enableAdvancedFilter && gridApi.current) {
185
239
  (_a = gridApi.current.api) === null || _a === void 0 ? void 0 : _a.showAdvancedFilterBuilder(event);
186
240
  }
187
241
  else {
188
- // showFilter.current.toggle(event);
189
242
  setIsVisible(true);
190
243
  }
191
244
  };
192
- const updateconditionsArray = (conditionObj, conditionIndex, formSetter) => {
245
+ /**
246
+ * Update a specific condition in the array
247
+ */
248
+ const updateConditionsArray = (conditionObj, conditionIndex, formSetter) => {
193
249
  const updatedConditions = conditionsArray.map((eachCondition) => {
194
250
  if (eachCondition.id === conditionIndex) {
195
251
  return conditionObj;
196
252
  }
197
- else {
198
- return eachCondition;
199
- }
253
+ return eachCondition;
200
254
  });
201
255
  setConditionsArray(updatedConditions);
202
256
  formSetter === null || formSetter === void 0 ? void 0 : formSetter("conditions", updatedConditions);
203
257
  };
258
+ /**
259
+ * Add a new empty condition after the specified index
260
+ */
204
261
  const addEmptyCondition = (index, formSetter) => {
205
- const updatedconditionsArray = [...conditionsArray];
206
- updatedconditionsArray.splice(index + 1, 0, defaultCondition);
207
- setConditionsArray(updatedconditionsArray);
208
- formSetter === null || formSetter === void 0 ? void 0 : formSetter("conditions", updatedconditionsArray);
262
+ const updatedConditionsArray = [...conditionsArray];
263
+ const newCondition = Object.assign(Object.assign({}, defaultCondition), { id: Math.random().toString() });
264
+ updatedConditionsArray.splice(index + 1, 0, newCondition);
265
+ setConditionsArray(updatedConditionsArray);
266
+ formSetter === null || formSetter === void 0 ? void 0 : formSetter("conditions", updatedConditionsArray);
209
267
  };
268
+ /**
269
+ * Remove a condition from the array by ID
270
+ */
210
271
  const removeConditionFromArray = (conditionIndex, formSetter) => {
211
- const updatedconditionsArray = conditionsArray.filter((condition) => condition.id !== conditionIndex);
212
- setConditionsArray(updatedconditionsArray);
213
- formSetter === null || formSetter === void 0 ? void 0 : formSetter("conditions", updatedconditionsArray);
272
+ const updatedConditionsArray = conditionsArray.filter((condition) => condition.id !== conditionIndex);
273
+ setConditionsArray(updatedConditionsArray);
274
+ formSetter === null || formSetter === void 0 ? void 0 : formSetter("conditions", updatedConditionsArray);
214
275
  };
276
+ /**
277
+ * Apply current filters and close dialog
278
+ */
215
279
  const onApplyFilter = () => {
216
- const arr = conditionsArray.map((condition) => {
217
- return Object.assign(Object.assign({}, condition), { isActive: true, logicalOperator: conditionType.id });
218
- });
280
+ const arr = conditionsArray.map((condition) => (Object.assign(Object.assign({}, condition), { isActive: true, logicalOperator: conditionType.id })));
219
281
  applyAdvancedFilter(arr);
220
282
  setConditionsArray(arr);
221
283
  setIsVisible(false);
222
- // showFilter.current.toggle(false);
223
284
  };
224
- const onresetFilter = (formSetter) => {
285
+ /**
286
+ * Reset all filters to default state
287
+ */
288
+ const onResetFilter = (formSetter) => {
225
289
  applyAdvancedFilter([]);
226
- setConditionsArray([defaultCondition]);
290
+ const newDefault = Object.assign(Object.assign({}, defaultCondition), { id: Math.random().toString() });
291
+ setConditionsArray([newDefault]);
227
292
  setViewName("");
228
- formSetter === null || formSetter === void 0 ? void 0 : formSetter("conditions", [defaultCondition]);
293
+ formSetter === null || formSetter === void 0 ? void 0 : formSetter("conditions", [newDefault]);
229
294
  formSetter === null || formSetter === void 0 ? void 0 : formSetter("viewName", "");
230
- // showFilter.current.toggle(false);
231
- // showFilter.current.hide();
232
- };
233
- const renderCondition = (conditions, key, formSetter, formErrors, formTouched) => {
234
- const { columnName, condition, value, id } = conditions;
235
- return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: "" }, { children: (0, jsx_runtime_1.jsx)(Conditions_1.default, { index: key, setEnableApply: (value) => setEnableApply(value), id: id, columnName: columnName, condition: condition, conditionType: conditionType, conditionTypes: conditionTypes, value: value, columnsArray: tableColumns, conditionsArray: constants_1.default.conditionsList, handleConditionType: handleConditionType, updateconditionsArray: (conditionObj, conditionIndex) => updateconditionsArray(conditionObj, conditionIndex, formSetter), addEmptyCondition: (index) => addEmptyCondition(index, formSetter), removeConditionFromArray: (conditionIndex) => removeConditionFromArray(conditionIndex, formSetter), conditionsLength: conditionsArray.length, filterModelText: filterModelText, validationErrors: formErrors, validationTouched: formTouched }, key) })));
236
295
  };
296
+ /**
297
+ * Create a saved view from current filter configuration
298
+ */
237
299
  const createViewFromFilters = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
238
300
  var _a;
239
301
  yield Promise.all((_a = [formRef]) === null || _a === void 0 ? void 0 : _a.map((form) => {
@@ -245,75 +307,98 @@ const TableFilter = () => {
245
307
  if (errors && Object.keys(errors).length > 0) {
246
308
  return;
247
309
  }
248
- const newFilters = conditionsArray.map((condition) => {
249
- // Convert value type to string when data comes in object or array form
250
- // if (typeof condition.value !== "string")
251
- // condition.value = JSON.stringify(condition.value);
252
- return Object.assign(Object.assign({}, condition), { isActive: true, logicalOperator: conditionType.id });
253
- });
310
+ const newFilters = conditionsArray.map((condition) => (Object.assign(Object.assign({}, condition), { isActive: true, logicalOperator: conditionType.id })));
254
311
  const viewDetails = {
255
312
  viewName: viewName,
256
313
  viewFilter: newFilters,
257
314
  };
258
315
  createView(viewDetails);
259
- // showFilter.current.toggle(false);
260
316
  });
317
+ /**
318
+ * Close filter dialog and reset input state
319
+ */
261
320
  const filterLogoToggle = () => {
262
- setIsVisible(false), setDisplayInput(false), setViewName("");
321
+ setIsVisible(false);
322
+ setDisplayInput(false);
323
+ setViewName("");
324
+ };
325
+ /**
326
+ * Render a single filter condition row
327
+ */
328
+ const renderCondition = (conditions, key, formSetter, formErrors, formTouched) => {
329
+ const { columnName, condition, value, id } = conditions;
330
+ return ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: "" }, { children: (0, jsx_runtime_1.jsx)(Conditions_1.default, { index: key, setEnableApply: (value) => setEnableApply(value), id: id, columnName: columnName, condition: condition, conditionType: conditionType, conditionTypes: conditionTypes, value: value, columnsArray: tableColumns, conditionsArray: constants_1.default.conditionsList, handleConditionType: handleConditionType, updateconditionsArray: (conditionObj, conditionIndex) => updateConditionsArray(conditionObj, conditionIndex, formSetter), addEmptyCondition: (index) => addEmptyCondition(index, formSetter), removeConditionFromArray: (conditionIndex) => removeConditionFromArray(conditionIndex, formSetter), conditionsLength: conditionsArray.length, filterModelText: filterModelText, validationErrors: formErrors, validationTouched: formTouched }, key) })));
263
331
  };
332
+ // ============================================================================
333
+ // Effects
334
+ // ============================================================================
335
+ /**
336
+ * Initialize conditionsArray from globalFilters when they change
337
+ * This handles pre-populating filters from default values
338
+ */
264
339
  (0, react_1.useEffect)(() => {
265
- if (conditionsArray.length === 0) {
266
- setConditionsArray([defaultCondition]);
340
+ if (globalFilters.length > 0) {
341
+ setConditionsArray(globalFilters);
267
342
  }
268
- });
269
- (0, react_1.useEffect)(() => {
270
- if (globalFilters.length === 0) {
271
- setConditionsArray([defaultCondition]);
343
+ else if (conditionsArray.length === 0) {
344
+ setConditionsArray([Object.assign(Object.assign({}, defaultCondition), { id: Math.random().toString() })]);
272
345
  }
273
- else {
274
- setConditionsArray(globalFilters);
346
+ }, [globalFilters]);
347
+ /**
348
+ * Sync conditionsArray when dialog opens
349
+ */
350
+ (0, react_1.useEffect)(() => {
351
+ if (isVisible) {
352
+ if (globalFilters.length === 0) {
353
+ setConditionsArray([Object.assign(Object.assign({}, defaultCondition), { id: Math.random().toString() })]);
354
+ }
355
+ else {
356
+ setConditionsArray(globalFilters);
357
+ }
275
358
  }
276
359
  }, [isVisible]);
360
+ /**
361
+ * Validate all fields and update allFieldsFilled state
362
+ */
277
363
  (0, react_1.useEffect)(() => {
278
364
  const isAllFieldsFilled = conditionsArray.every((eachCondition) => {
279
365
  if (!(eachCondition === null || eachCondition === void 0 ? void 0 : eachCondition.columnName) || !(eachCondition === null || eachCondition === void 0 ? void 0 : eachCondition.condition))
280
366
  return false;
281
367
  return validateValueByType(eachCondition === null || eachCondition === void 0 ? void 0 : eachCondition.columnName, eachCondition === null || eachCondition === void 0 ? void 0 : eachCondition.condition, eachCondition === null || eachCondition === void 0 ? void 0 : eachCondition.value);
282
368
  });
283
- setAllFieldsFilled(isAllFieldsFilled && enbleApply);
284
- }, [conditionsArray, enbleApply]);
285
- const formInitialValues = (0, react_1.useMemo)(() => ({
286
- conditions: conditionsArray,
287
- viewName,
288
- }), [conditionsArray, viewName]);
289
- return (0, utilComponents_1.skeletonLoding)() ? ((0, jsx_runtime_1.jsx)(FeatureSkeleton_1.default, {})) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `cursor-pointer filter-btn-grid font-semibold hover:bg-primary-25 sc_icon_hover flex align-items-center gap-2 border-round-6 ${isDisabled && "disabled"} ${isVisible ||
290
- (globalFilters === null || globalFilters === void 0 ? void 0 : globalFilters.filter((each) => each.isActive).length) >= 1
291
- ? "bg-primary-50"
292
- : "bg-white"}`, title: "Apply Filters" }, { children: [(0, jsx_runtime_1.jsx)("div", { id: "advancedFilterParent", className: "hidden" }), (0, jsx_runtime_1.jsxs)("span", Object.assign({ onClick: (e) => !isDisabled && onClickFilter(e), className: "flex zoom_animate", id: "advance-filter-id" }, { children: [(0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "filter-lines", size: 18, color: isVisible ||
293
- (globalFilters === null || globalFilters === void 0 ? void 0 : globalFilters.filter((each) => each.isActive).length) >= 1
294
- ? "#243DC6"
295
- : "#667085" }), (globalFilters === null || globalFilters === void 0 ? void 0 : globalFilters.filter((each) => each.isActive).length) >= 1 && ((0, jsx_runtime_1.jsxs)("span", Object.assign({ id: "selected-filters", className: "flex gap-2 align-items-center text-primary-400 pl-2" }, { children: [`${globalFilters === null || globalFilters === void 0 ? void 0 : globalFilters.filter((each) => each.isActive).length} ${(filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.onSelectedFilter)
369
+ setAllFieldsFilled(isAllFieldsFilled && enableApply);
370
+ }, [conditionsArray, enableApply]);
371
+ // ============================================================================
372
+ // Render
373
+ // ============================================================================
374
+ // Show skeleton while loading
375
+ if ((0, utilComponents_1.skeletonLoding)()) {
376
+ return (0, jsx_runtime_1.jsx)(FeatureSkeleton_1.default, {});
377
+ }
378
+ // Count of active filters for display
379
+ const activeFilterCount = (globalFilters === null || globalFilters === void 0 ? void 0 : globalFilters.filter((each) => each.isActive).length) || 0;
380
+ const hasActiveFilters = activeFilterCount >= 1;
381
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `cursor-pointer filter-btn-grid font-semibold hover:bg-primary-25 sc_icon_hover flex align-items-center gap-2 border-round-6 ${isDisabled && "disabled"} ${isVisible || hasActiveFilters ? "bg-primary-50" : "bg-white"}`, title: "Apply Filters" }, { children: [(0, jsx_runtime_1.jsx)("div", { id: "advancedFilterParent", className: "hidden" }), (0, jsx_runtime_1.jsxs)("span", Object.assign({ onClick: (e) => !isDisabled && onClickFilter(e), className: "flex zoom_animate", id: "advance-filter-id" }, { children: [(0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "filter-lines", size: 18, color: isVisible || hasActiveFilters ? "#243DC6" : "#667085" }), hasActiveFilters && ((0, jsx_runtime_1.jsxs)("span", Object.assign({ id: "selected-filters", className: "flex gap-2 align-items-center text-primary-400 pl-2" }, { children: [`${activeFilterCount} ${(filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.onSelectedFilter)
296
382
  ? filterModelText.onSelectedFilter
297
383
  : "Selected"}`, (0, jsx_runtime_1.jsx)("span", Object.assign({ onClick: (e) => {
298
384
  e.preventDefault();
299
385
  e.stopPropagation();
300
- onresetFilter();
386
+ onResetFilter();
301
387
  } }, { children: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "x-close", size: 18, color: "#243DC6" }) }))] })))] }))] })), (0, jsx_runtime_1.jsx)(form_1.default, Object.assign({ values: formInitialValues, enableReinitialize: true, formRef: formRef, validateOnChange: true, validateOnBlur: false, validateOnMount: true, validations: validationSchema, className: "h-full", onSubmit: () => onApplyFilter() }, { children: ({ handleSubmit, setFieldValue, isValid, values, errors, touched }) => {
302
388
  const conditionsToRender = (values === null || values === void 0 ? void 0 : values.conditions) && values.conditions.length > 0
303
389
  ? values.conditions
304
390
  : conditionsArray;
305
- const isFormReady = isValid && allFieldsFilled && enbleApply;
306
- console.log(conditionsToRender, "conditionsToRender", isFormReady);
307
- return ((0, jsx_runtime_1.jsxs)(dialog_1.Dialog, Object.assign({ visible: isVisible, onHide: () => filterLogoToggle(), className: "modal_filter mt-5 -ml-2" }, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "p-4" }, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "flex justify-content-between text-lg font-semibold line-height-3 text-gray-900" }, { children: [(filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.header) ? filterModelText.header : "Filter", " ", (0, jsx_runtime_1.jsx)(button_1.Button, { className: "p-0 h-auto px-1 bg-transparent hover:bg-gray-100", onClick: () => setIsVisible(false), icon: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "x-close", size: 15, color: "text-gray-600" }) })] })), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "text-sm text-gray-600" }, { children: (filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.subHeader)
391
+ const isFormReady = isValid && allFieldsFilled && enableApply;
392
+ return ((0, jsx_runtime_1.jsxs)(dialog_1.Dialog, Object.assign({ visible: isVisible, onHide: () => filterLogoToggle(), className: "modal_filter mt-5 -ml-2" }, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "p-4" }, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "flex justify-content-between text-lg font-semibold line-height-3 text-gray-900" }, { children: [(filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.header) ? filterModelText.header : "Filter", (0, jsx_runtime_1.jsx)(button_1.Button, { className: "p-0 h-auto px-1 bg-transparent hover:bg-gray-100", onClick: () => setIsVisible(false), icon: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "x-close", size: 15, color: "text-gray-600" }) })] })), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "text-sm text-gray-600" }, { children: (filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.subHeader)
308
393
  ? filterModelText.subHeader
309
- : "Streamline Your Search With Filters" }))] })), (0, jsx_runtime_1.jsx)(divider_1.Divider, { className: "w-full p-0 m-0" }), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "p-2" }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "max-h-14rem\toverflow-y-auto overflow-x-hidden flex flex-column gap-1" }, { children: conditionsToRender.map((eachCondition, index) => {
394
+ : "Streamline Your Search With Filters" }))] })), (0, jsx_runtime_1.jsx)(divider_1.Divider, { className: "w-full p-0 m-0" }), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "p-2" }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "max-h-14rem overflow-y-auto overflow-x-hidden flex flex-column gap-1" }, { children: conditionsToRender.map((eachCondition, index) => {
310
395
  var _a, _b;
311
- return ((0, jsx_runtime_1.jsx)("div", { children: renderCondition(eachCondition, index, setFieldValue, (_a = errors === null || errors === void 0 ? void 0 : errors.conditions) === null || _a === void 0 ? void 0 : _a[index], (_b = touched === null || touched === void 0 ? void 0 : touched.conditions) === null || _b === void 0 ? void 0 : _b[index]) }, index));
396
+ return ((0, jsx_runtime_1.jsx)("div", { children: renderCondition(eachCondition, index, setFieldValue, (_a = errors === null || errors === void 0 ? void 0 : errors.conditions) === null || _a === void 0 ? void 0 : _a[index], (_b = touched === null || touched === void 0 ? void 0 : touched.conditions) === null || _b === void 0 ? void 0 : _b[index]) }, eachCondition.id || index));
312
397
  }) })) })), (0, jsx_runtime_1.jsx)(divider_1.Divider, { className: "w-full p-0 m-0" }), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "p-4 flex justify-content-between" }, { children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(button_1.Button, { outlined: true, className: "focus:shadow-none font-semibold border-none hover:bg-primary-25 text-primary-400", label: (filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.resetFilterAction)
313
398
  ? filterModelText.resetFilterAction
314
- : "Reset Filter", onClick: () => onresetFilter(setFieldValue) }) }), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "flex align-items-center gap-3" }, { children: [!displayInput && enableViewCreate && ((0, jsx_runtime_1.jsx)(button_1.Button, { className: "text-base px-2 font-semibold text-primary-400 flex gap-2 p-1 px-4 flex justify-content-center focus:shadow-none mr-3", label: (filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.createViewAction)
399
+ : "Reset Filter", onClick: () => onResetFilter(setFieldValue) }) }), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "flex align-items-center gap-3" }, { children: [!displayInput && enableViewCreate && ((0, jsx_runtime_1.jsx)(button_1.Button, { className: "text-base px-2 font-semibold text-primary-400 flex gap-2 p-1 px-4 flex justify-content-center focus:shadow-none mr-3", label: (filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.createViewAction)
315
400
  ? filterModelText.createViewAction
316
- : "Create view", onClick: () => setDisplayInput(true), disabled: !isFormReady, text: true, iconPos: "left", icon: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "plus", color: "text-primary-400 mr-2" }) })), displayInput && ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "p-input-icon-left p-input-icon-right w-full" }, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ className: `p-input-suffix` }, { children: [displayInput && ((0, jsx_runtime_1.jsx)(button_1.Button, { onClick: createViewFromFilters, disabled: !viewName.length, className: "p-0 h-auto mr-2", text: true, icon: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "check", color: "text-gray-500" }) })), (0, jsx_runtime_1.jsx)(button_1.Button, { onClick: () => {
401
+ : "Create view", onClick: () => setDisplayInput(true), disabled: !isFormReady, text: true, iconPos: "left", icon: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "plus", color: "text-primary-400 mr-2" }) })), displayInput && ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "p-input-icon-left p-input-icon-right w-full" }, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "p-input-suffix" }, { children: [(0, jsx_runtime_1.jsx)(button_1.Button, { onClick: createViewFromFilters, disabled: !viewName.length, className: "p-0 h-auto mr-2", text: true, icon: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "check", color: "text-gray-500" }) }), (0, jsx_runtime_1.jsx)(button_1.Button, { onClick: () => {
317
402
  setViewName("");
318
403
  setFieldValue("viewName", "");
319
404
  }, className: "p-0 h-auto", disabled: !viewName.length, text: true, icon: (0, jsx_runtime_1.jsx)(svg_component_1.default, { icon: "x-close", color: "text-gray-500" }) })] })), (0, jsx_runtime_1.jsx)(inputtext_1.InputText, { placeholder: (filterModelText === null || filterModelText === void 0 ? void 0 : filterModelText.createViewInputPlaceHolder)
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FeatureContext = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const jsx_runtime_1 = require("react/jsx-runtime");
5
6
  const react_1 = require("react");
6
7
  const helper_1 = require("./helper");
7
8
  const hooks_1 = require("primereact/hooks");
9
+ const constants_1 = tslib_1.__importDefault(require("./constants"));
8
10
  exports.FeatureContext = (0, react_1.createContext)(null);
9
11
  function MyProvider({ children, value }) {
10
- const { featureDetails, setFeatureDetails, gridData, callGrid, totalRecords, initialFeature, defaultFilters, createView, enableViewCreate, filterModelText, sortModelText, recordDetailModelText, sidePanelText, sortOptions, filterConditions, clearFilters, setGridData, gridApi, updateColumnsForGrid, enableManageColumnsCallback, columnToRender, selectedGroup, setSelectedGroup, initialCheckBoxData, intialColumns, setIntialColumns, rowModelType, quickSearch, enableAdvancedFilter, conditionsToDisplay, gridViewFun, gridViewData, setGridViewData, gridView, serverSideSelectRow } = value;
12
+ const { featureDetails, setFeatureDetails, gridData, callGrid, totalRecords, initialFeature, defaultFilters, defaultSort, createView, enableViewCreate, filterModelText, sortModelText, recordDetailModelText, sidePanelText, sortOptions, filterConditions, clearFilters, setGridData, gridApi, updateColumnsForGrid, enableManageColumnsCallback, columnToRender, selectedGroup, setSelectedGroup, initialCheckBoxData, intialColumns, setIntialColumns, rowModelType, quickSearch, enableAdvancedFilter, conditionsToDisplay, gridViewFun, gridViewData, setGridViewData, gridView, serverSideSelectRow } = value;
11
13
  // States for sort
12
14
  const [columnData] = (0, react_1.useState)(gridData === null || gridData === void 0 ? void 0 : gridData.columnData);
13
15
  const [inputValue, deboucedValue, setInputValue] = (0, hooks_1.useDebounce)("", 500);
@@ -46,18 +48,62 @@ function MyProvider({ children, value }) {
46
48
  setInputValue("");
47
49
  callGrid(emptyFeatures);
48
50
  };
51
+ /**
52
+ * Transform and set default filters to globalFilters state
53
+ * Handles both API output format and internal format:
54
+ * - API format: { selectedColumn: { code: {...} }, selectedOperation: 1, value, logicalOperator }
55
+ * - Internal format: { columnName: {...}, condition: {...}, value, logicalOperator }
56
+ */
49
57
  (0, react_1.useEffect)(() => {
50
58
  if (defaultFilters.length) {
51
59
  const filtersToAdd = defaultFilters.map((filter) => {
52
- filter.value = (0, helper_1.parseIfNeeded)(filter.value);
53
- return filter;
60
+ var _a, _b, _c;
61
+ // Extract column data from either format
62
+ const columnName = ((_a = filter.selectedColumn) === null || _a === void 0 ? void 0 : _a.code) || filter.columnName;
63
+ // Extract condition - can be a number or object
64
+ const conditionValue = (_b = filter.selectedOperation) !== null && _b !== void 0 ? _b : filter.condition;
65
+ const condition = typeof conditionValue === 'object'
66
+ ? conditionValue
67
+ : constants_1.default.conditionsList.find((c) => c.value === conditionValue);
68
+ return {
69
+ columnName,
70
+ condition,
71
+ value: (0, helper_1.parseIfNeeded)(filter.value),
72
+ id: filter.id || Math.random().toString(),
73
+ isActive: (_c = filter.isActive) !== null && _c !== void 0 ? _c : true,
74
+ logicalOperator: filter.logicalOperator,
75
+ };
54
76
  });
55
77
  setGlobalFilters(filtersToAdd);
56
78
  }
57
79
  }, [defaultFilters]);
80
+ /**
81
+ * Transform and set default sort to sortValue and sortBy states
82
+ * Handles API format: { direction: 1|2, propertyName: "fieldName" }
83
+ * - direction: 1 = ascending, 2 = descending
84
+ * - propertyName: field name to sort by
85
+ */
86
+ (0, react_1.useEffect)(() => {
87
+ if (defaultSort && defaultSort.propertyName && defaultSort.direction) {
88
+ // Find matching column from columnData based on propertyName
89
+ const matchingColumn = columnData === null || columnData === void 0 ? void 0 : columnData.find((col) => col.field === defaultSort.propertyName ||
90
+ col.fieldKey === defaultSort.propertyName ||
91
+ col.headerName === defaultSort.propertyName);
92
+ if (matchingColumn) {
93
+ setSortValue(matchingColumn);
94
+ // Find matching sort option based on direction and dataType
95
+ const matchingSortOption = sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.find((opt) => opt.sortId === defaultSort.direction &&
96
+ opt.dataType === matchingColumn.dataType);
97
+ if (matchingSortOption) {
98
+ setSortBy(matchingSortOption);
99
+ }
100
+ }
101
+ }
102
+ }, [defaultSort, columnData, sortOptions]);
58
103
  // Empty filters and call the grid
59
104
  (0, react_1.useEffect)(() => {
60
- if (clearFilters) {
105
+ // Only clear if clearFilters is explicitly true (not just truthy like [])
106
+ if (clearFilters === true) {
61
107
  let currentFeature = featureDetails;
62
108
  currentFeature.filterQueries = [];
63
109
  setSelectedGroup([]);
@@ -20,10 +20,16 @@ const isComponentDisable = (state) => {
20
20
  exports.isComponentDisable = isComponentDisable;
21
21
  const applyDefaultFilters = (defaultFilters) => {
22
22
  const filters = defaultFilters === null || defaultFilters === void 0 ? void 0 : defaultFilters.map((item) => {
23
+ var _a, _b;
24
+ // Handle both input formats:
25
+ // Format 1 (API output): { selectedColumn: { code: {...} }, selectedOperation: 1, value, logicalOperator }
26
+ // Format 2 (internal): { columnName: {...}, condition: {...}, value, logicalOperator }
27
+ const selectedColumn = (item === null || item === void 0 ? void 0 : item.selectedColumn) || { code: item === null || item === void 0 ? void 0 : item.columnName };
28
+ const selectedOperation = (_a = item === null || item === void 0 ? void 0 : item.selectedOperation) !== null && _a !== void 0 ? _a : (typeof (item === null || item === void 0 ? void 0 : item.condition) === 'object' ? (_b = item === null || item === void 0 ? void 0 : item.condition) === null || _b === void 0 ? void 0 : _b.value : item === null || item === void 0 ? void 0 : item.condition);
23
29
  const obj = {
24
30
  logicalOperator: item === null || item === void 0 ? void 0 : item.logicalOperator,
25
- selectedColumn: item === null || item === void 0 ? void 0 : item.columnName,
26
- selectedOperation: item === null || item === void 0 ? void 0 : item.condition,
31
+ selectedColumn: selectedColumn,
32
+ selectedOperation: selectedOperation,
27
33
  value: item === null || item === void 0 ? void 0 : item.value,
28
34
  };
29
35
  return obj;