oa-componentbook 1.0.1-stage.443 → 1.0.1-stage.444
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/components/oa-component-table-with-search-and-filter/TableWithSearchAndFilter.js
CHANGED
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
});
|
|
9
9
|
exports.default = void 0;
|
|
10
10
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
11
|
+
require("core-js/modules/es.array.sort.js");
|
|
11
12
|
require("core-js/modules/es.json.stringify.js");
|
|
12
13
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
14
|
var _Search = _interopRequireDefault(require("@material-ui/icons/Search"));
|
|
@@ -116,6 +117,7 @@ function TableWithSearchAndFilter(_ref) {
|
|
|
116
117
|
// Filter drawer state
|
|
117
118
|
const [isFilterDrawerVisible, setIsFilterDrawerVisible] = (0, _react.useState)(false);
|
|
118
119
|
const [filterValues, setFilterValues] = (0, _react.useState)({});
|
|
120
|
+
const [areAllRequiredFieldsFilled, setAreAllRequiredFieldsFilled] = (0, _react.useState)(true);
|
|
119
121
|
|
|
120
122
|
// Search handlers
|
|
121
123
|
const handleSearchChange = e => {
|
|
@@ -186,29 +188,33 @@ function TableWithSearchAndFilter(_ref) {
|
|
|
186
188
|
return keys;
|
|
187
189
|
}, [filterConfig]);
|
|
188
190
|
|
|
189
|
-
// Create a stable string
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
191
|
+
// Create a stable string signature of required field values for reliable dependency tracking
|
|
192
|
+
const requiredFieldsSignature = (0, _react.useMemo)(() => {
|
|
193
|
+
if (requiredKeys.length === 0) return '';
|
|
194
|
+
return requiredKeys.map(key => {
|
|
195
|
+
const value = filterValues[key];
|
|
196
|
+
if (value === undefined || value === null) return "".concat(key, ":null");
|
|
197
|
+
if (value instanceof Date) return "".concat(key, ":").concat(value.getTime());
|
|
198
|
+
if (Array.isArray(value)) return "".concat(key, ":array[").concat(value.length, "]");
|
|
199
|
+
if (typeof value === 'object') return "".concat(key, ":obj[").concat(Object.keys(value).length, "]");
|
|
200
|
+
return "".concat(key, ":").concat(JSON.stringify(value));
|
|
201
|
+
}).sort().join('|');
|
|
202
|
+
}, [requiredKeys, filterValues]);
|
|
198
203
|
|
|
199
|
-
//
|
|
200
|
-
|
|
204
|
+
// Use useEffect to update validation state whenever filterValues or requiredKeys change
|
|
205
|
+
// Using signature ensures reliable updates in production builds where object reference comparison might fail
|
|
206
|
+
(0, _react.useEffect)(() => {
|
|
201
207
|
// If no required fields, button should be enabled
|
|
202
208
|
if (requiredKeys.length === 0) {
|
|
203
|
-
|
|
209
|
+
setAreAllRequiredFieldsFilled(true);
|
|
210
|
+
return;
|
|
204
211
|
}
|
|
205
212
|
|
|
206
213
|
// Check each required field has a valid value
|
|
207
|
-
|
|
214
|
+
const allFilled = requiredKeys.every(requiredKey => {
|
|
208
215
|
const value = filterValues[requiredKey];
|
|
209
216
|
|
|
210
217
|
// Check if value exists and is not empty/null/undefined
|
|
211
|
-
// Also handle edge cases: empty arrays, empty objects, etc.
|
|
212
218
|
if (value === undefined || value === null || value === '') {
|
|
213
219
|
return false;
|
|
214
220
|
}
|
|
@@ -224,6 +230,7 @@ function TableWithSearchAndFilter(_ref) {
|
|
|
224
230
|
}
|
|
225
231
|
return true;
|
|
226
232
|
});
|
|
233
|
+
setAreAllRequiredFieldsFilled(allFilled);
|
|
227
234
|
}, [requiredKeys, requiredFieldsSignature, filterValues]);
|
|
228
235
|
|
|
229
236
|
// Helper function to determine notFoundContent message
|