@tellescope/react-components 1.182.0 → 1.184.0

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 (66) hide show
  1. package/lib/cjs/Forms/hooks.d.ts.map +1 -1
  2. package/lib/cjs/Forms/hooks.js +2 -1
  3. package/lib/cjs/Forms/hooks.js.map +1 -1
  4. package/lib/cjs/forms.d.ts +2 -1
  5. package/lib/cjs/forms.d.ts.map +1 -1
  6. package/lib/cjs/forms.js +2 -2
  7. package/lib/cjs/forms.js.map +1 -1
  8. package/lib/cjs/inputs_shared.d.ts +43 -0
  9. package/lib/cjs/inputs_shared.d.ts.map +1 -1
  10. package/lib/cjs/inputs_shared.js +441 -3
  11. package/lib/cjs/inputs_shared.js.map +1 -1
  12. package/lib/cjs/layout.d.ts.map +1 -1
  13. package/lib/cjs/layout.js +4 -2
  14. package/lib/cjs/layout.js.map +1 -1
  15. package/lib/cjs/state.d.ts +6 -1
  16. package/lib/cjs/state.d.ts.map +1 -1
  17. package/lib/cjs/state.js +38 -57
  18. package/lib/cjs/state.js.map +1 -1
  19. package/lib/cjs/table.d.ts +8 -3
  20. package/lib/cjs/table.d.ts.map +1 -1
  21. package/lib/cjs/table.js +16 -13
  22. package/lib/cjs/table.js.map +1 -1
  23. package/lib/esm/CMS/components.d.ts +1 -0
  24. package/lib/esm/CMS/components.d.ts.map +1 -1
  25. package/lib/esm/Forms/form_responses.d.ts +1 -0
  26. package/lib/esm/Forms/form_responses.d.ts.map +1 -1
  27. package/lib/esm/Forms/forms.d.ts +3 -3
  28. package/lib/esm/Forms/hooks.d.ts.map +1 -1
  29. package/lib/esm/Forms/hooks.js +2 -1
  30. package/lib/esm/Forms/hooks.js.map +1 -1
  31. package/lib/esm/Forms/inputs.d.ts +1 -1
  32. package/lib/esm/Forms/inputs.native.d.ts +1 -0
  33. package/lib/esm/Forms/inputs.native.d.ts.map +1 -1
  34. package/lib/esm/controls.d.ts +2 -2
  35. package/lib/esm/forms.d.ts +2 -1
  36. package/lib/esm/forms.d.ts.map +1 -1
  37. package/lib/esm/forms.js +2 -2
  38. package/lib/esm/forms.js.map +1 -1
  39. package/lib/esm/inputs.d.ts +1 -1
  40. package/lib/esm/inputs.native.d.ts +1 -0
  41. package/lib/esm/inputs.native.d.ts.map +1 -1
  42. package/lib/esm/inputs_shared.d.ts +43 -0
  43. package/lib/esm/inputs_shared.d.ts.map +1 -1
  44. package/lib/esm/inputs_shared.js +436 -5
  45. package/lib/esm/inputs_shared.js.map +1 -1
  46. package/lib/esm/layout.d.ts.map +1 -1
  47. package/lib/esm/layout.js +4 -2
  48. package/lib/esm/layout.js.map +1 -1
  49. package/lib/esm/state.d.ts +292 -287
  50. package/lib/esm/state.d.ts.map +1 -1
  51. package/lib/esm/state.js +38 -57
  52. package/lib/esm/state.js.map +1 -1
  53. package/lib/esm/table.d.ts +8 -3
  54. package/lib/esm/table.d.ts.map +1 -1
  55. package/lib/esm/table.js +16 -13
  56. package/lib/esm/table.js.map +1 -1
  57. package/lib/esm/theme.native.d.ts +1 -0
  58. package/lib/esm/theme.native.d.ts.map +1 -1
  59. package/lib/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +9 -9
  61. package/src/Forms/hooks.tsx +2 -1
  62. package/src/forms.tsx +3 -2
  63. package/src/inputs_shared.tsx +451 -6
  64. package/src/layout.tsx +10 -1
  65. package/src/state.tsx +38 -46
  66. package/src/table.tsx +31 -5
@@ -90,13 +90,445 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
90
90
  return to.concat(ar || Array.prototype.slice.call(from));
91
91
  };
92
92
  Object.defineProperty(exports, "__esModule", { value: true });
93
- exports.UserAndEnduserSelector = exports.DatabaseRecordSearch = exports.DatabaseSearch = exports.AppointmentBookingPagesSearch = exports.AppointmentLocationSearch = exports.CalendarEventTemplatesSearch = exports.ContentSearch = exports.MessageTemplateSnippetSearch = exports.EnduserOrUserSearch = exports.OrganizationSearch = exports.UserSearch = exports.ForumSearch = exports.TemplateSearch = exports.JourneySearch = exports.AutomationTriggerSearch = exports.FormGroupSearch = exports.FormSearch = exports.NotificationSearch = exports.TicketQueueSearch = exports.CallHoldQueueSearch = exports.DiagnosisCodeSearch = exports.AllergyCodeSearch = exports.AgentRecordSearch = exports.WaitlistSearch = exports.SuggestedContactSearch = exports.FileSearch = exports.FaxSearch = exports.PrescriptionRoutesSearch = exports.EnduserOrdersSearch = exports.ENDUSER_ORDERS_SEARCH_FILTER_KEY = exports.TicketSearch = exports.TICKET_SEARCH_FILTER_KEY = exports.ChatRoomSearch = exports.CHAT_ROOM_SEARCH = exports.EnduserSearch = exports.ModelSearchInput = exports.performBulkAction = exports.filter_for_query = exports.record_matches_for_query = exports.record_field_matches_query = exports.useFilters = exports.apply_filters = exports.filter_setter_for_key = void 0;
93
+ exports.UserAndEnduserSelector = exports.DatabaseRecordSearch = exports.DatabaseSearch = exports.AppointmentBookingPagesSearch = exports.AppointmentLocationSearch = exports.CalendarEventTemplatesSearch = exports.ContentSearch = exports.MessageTemplateSnippetSearch = exports.EnduserOrUserSearch = exports.OrganizationSearch = exports.UserSearch = exports.ForumSearch = exports.TemplateSearch = exports.JourneySearch = exports.AutomationTriggerSearch = exports.FormGroupSearch = exports.FormSearch = exports.NotificationSearch = exports.TicketQueueSearch = exports.CallHoldQueueSearch = exports.DiagnosisCodeSearch = exports.AllergyCodeSearch = exports.AgentRecordSearch = exports.WaitlistSearch = exports.SuggestedContactSearch = exports.FileSearch = exports.FaxSearch = exports.PrescriptionRoutesSearch = exports.EnduserOrdersSearch = exports.ENDUSER_ORDERS_SEARCH_FILTER_KEY = exports.TicketSearch = exports.TICKET_SEARCH_FILTER_KEY = exports.ChatRoomSearch = exports.CHAT_ROOM_SEARCH = exports.EnduserSearch = exports.ModelSearchInput = exports.performBulkAction = exports.filter_for_query = exports.record_matches_for_query = exports.record_field_matches_query = exports.useFilters = exports.apply_filters = exports.filter_setter_for_key = exports.useFiltersV2 = exports.remove_inactive_filters = exports.apply_mongodb_style_filter = exports.mongo_db_filter_to_list_of_strings_with_qualifier = exports.list_of_strings_with_qualifier_to_mongodb_filter = exports.mongo_db_filter_to_enduser_condition = exports.enduser_condition_to_mongodb_filter = void 0;
94
94
  var jsx_runtime_1 = require("react/jsx-runtime");
95
95
  var react_1 = __importStar(require("react"));
96
96
  var utilities_1 = require("@tellescope/utilities");
97
97
  var constants_1 = require("@tellescope/constants");
98
98
  var hooks_1 = require("./hooks");
99
99
  var _1 = require(".");
100
+ var enduser_condition_to_mongodb_filter = function (condition, customFields) {
101
+ var _a, _b;
102
+ if (!condition) {
103
+ return condition;
104
+ }
105
+ if (condition.$and) {
106
+ return { $and: condition.$and.map(function (v) { return (0, exports.enduser_condition_to_mongodb_filter)(v, customFields); }) };
107
+ }
108
+ if (condition.$or) {
109
+ return { $or: condition.$or.map(function (v) { return (0, exports.enduser_condition_to_mongodb_filter)(v, customFields); }) };
110
+ }
111
+ if (condition.$nor) {
112
+ return { $nor: condition.$nor.map(function (v) { return (0, exports.enduser_condition_to_mongodb_filter)(v, customFields); }) };
113
+ }
114
+ if (condition.$not) {
115
+ return { $not: (0, exports.enduser_condition_to_mongodb_filter)(condition.$not, customFields) };
116
+ }
117
+ if (condition && typeof condition === 'object' && condition.constructor === Object) {
118
+ var updated = {};
119
+ for (var _i = 0, _c = Object.entries(condition); _i < _c.length; _i++) {
120
+ var _d = _c[_i], _key = _d[0], _value = _d[1];
121
+ var key = customFields.includes(_key) ? "fields.".concat(_key) : _key;
122
+ var value = (0, exports.enduser_condition_to_mongodb_filter)(_value, customFields);
123
+ // console.log(key, _value, value)
124
+ if (key === 'condition') {
125
+ var toReturn = (0, exports.enduser_condition_to_mongodb_filter)(value, customFields);
126
+ delete updated.condition;
127
+ return toReturn;
128
+ } // base case is comparison to value, so just return it
129
+ // journeys currently have a special ui/syntax in filter
130
+ if (key === 'Journeys') {
131
+ if ((typeof (value === null || value === void 0 ? void 0 : value.$in)) === 'string') {
132
+ return _a = {}, _a["journeys.".concat(value.$in)] = { $exists: true }, _a;
133
+ }
134
+ else if ((typeof (value === null || value === void 0 ? void 0 : value.$nin)) === 'string') {
135
+ return _b = {}, _b["journeys.".concat(value.$nin)] = { $exists: false }, _b;
136
+ }
137
+ }
138
+ if (key === 'Healthie ID') {
139
+ // $setSet ($nin null, '')
140
+ if (value === null || value === void 0 ? void 0 : value.$nin)
141
+ return { $or: [{ source: constants_1.HEALTHIE_TITLE, externalId: { $nin: [null, ''] } }, { 'references.type': constants_1.HEALTHIE_TITLE }] };
142
+ // $isNotSet ($in null, '')
143
+ if (value === null || value === void 0 ? void 0 : value.$in)
144
+ return { $and: [{ source: { $ne: constants_1.HEALTHIE_TITLE } }, { 'references.type': { $ne: constants_1.HEALTHIE_TITLE } }] };
145
+ }
146
+ // ensure to parse string to number values
147
+ if (key === 'height') {
148
+ return {
149
+ 'height.value': (0, utilities_1.replace_keys_and_values_in_object)(value, function (v) { return typeof v === 'string' && !v.startsWith('$') ? parseFloat(v) : v; })
150
+ };
151
+ }
152
+ if (key === 'weight') {
153
+ return {
154
+ 'weight.value': (0, utilities_1.replace_keys_and_values_in_object)(value, function (v) { return typeof v === 'string' && !v.startsWith('$') ? parseFloat(v) : v; })
155
+ };
156
+ }
157
+ if (key === "relationships") {
158
+ return {
159
+ 'relationships.type': value
160
+ };
161
+ }
162
+ // case for isSet and isNotSet includes empty string as unset value
163
+ if (key === '$isSet') {
164
+ updated.$nin = [null, '', []];
165
+ }
166
+ else if (key === '$isNotSet') {
167
+ updated.$in = [null, '', []];
168
+ }
169
+ else if (key === '$contains') {
170
+ updated.$regex = value;
171
+ }
172
+ else if (key === '$doesNotContain') {
173
+ updated.$not = { $regex: value };
174
+ }
175
+ else if (key === '$before') {
176
+ updated.$lt = value;
177
+ }
178
+ else if (key === '$after') {
179
+ updated.$gt = value;
180
+ }
181
+ else {
182
+ updated[key] = value;
183
+ }
184
+ }
185
+ return updated;
186
+ }
187
+ return condition;
188
+ };
189
+ exports.enduser_condition_to_mongodb_filter = enduser_condition_to_mongodb_filter;
190
+ var mongo_db_filter_to_enduser_condition = function (filter) {
191
+ var _a;
192
+ var _b, _c;
193
+ if (!filter) {
194
+ return filter;
195
+ }
196
+ if ((0, utilities_1.objects_equivalent)(filter, {
197
+ "$and": [
198
+ {
199
+ "source": {
200
+ "$ne": "Healthie"
201
+ }
202
+ },
203
+ {
204
+ "references.type": {
205
+ "$ne": "Healthie"
206
+ }
207
+ }
208
+ ]
209
+ })) {
210
+ return { condition: { 'Healthie ID': { $isNotSet: 'Value' } } };
211
+ }
212
+ if ((0, utilities_1.objects_equivalent)(filter, {
213
+ "$or": [
214
+ {
215
+ "source": "Healthie",
216
+ "externalId": {
217
+ "$nin": [
218
+ null,
219
+ ""
220
+ ]
221
+ }
222
+ },
223
+ {
224
+ "references.type": "Healthie"
225
+ }
226
+ ]
227
+ })) {
228
+ return { condition: { 'Healthie ID': { $isSet: 'Value' } } };
229
+ }
230
+ if (filter.$and) {
231
+ return { $and: filter.$and.map(function (v) { return (0, exports.mongo_db_filter_to_enduser_condition)(v); }) };
232
+ }
233
+ if (filter.$or) {
234
+ return { $or: filter.$or.map(function (v) { return (0, exports.mongo_db_filter_to_enduser_condition)(v); }) };
235
+ }
236
+ if (filter.$nor) {
237
+ return { $nor: filter.$nor.map(function (v) { return (0, exports.mongo_db_filter_to_enduser_condition)(v); }) };
238
+ }
239
+ if (filter.$not) {
240
+ return { $not: (0, exports.mongo_db_filter_to_enduser_condition)(filter.$not) };
241
+ }
242
+ if (filter && typeof filter === 'object' && filter.constructor === Object) {
243
+ if ((0, utilities_1.object_is_empty)(filter))
244
+ return filter;
245
+ var updated = { condition: {} };
246
+ for (var _i = 0, _d = Object.entries(filter); _i < _d.length; _i++) {
247
+ var _e = _d[_i], _key = _e[0], value = _e[1];
248
+ var key = ((typeof _key === 'string' && _key.startsWith('fields.')) ? _key.replace('fields.', '')
249
+ : _key === 'height.value' ? 'height'
250
+ : _key === 'weight.value' ? 'weight'
251
+ : _key === 'relationships.type' ? 'relationships'
252
+ : _key);
253
+ if (value && typeof value === 'object' && value.constructor === Object) {
254
+ updated.condition[key] = {};
255
+ if (Object.keys(value)[0] === '$exists') {
256
+ if (key.startsWith('journeys.')) {
257
+ // journeys currently have a special ui/syntax in filter
258
+ updated.condition['Journeys'] = (_a = {}, _a[value.$exists ? '$in' : '$nin'] = key.split('.')[1], _a);
259
+ }
260
+ else if (value.$exists) {
261
+ updated.condition[key]['$isSet'] = "Value";
262
+ }
263
+ else {
264
+ updated.condition[key]['$isNotSet'] = "Value";
265
+ }
266
+ }
267
+ // case for isSet and isNotSet includes empty string as unset value
268
+ else if (Array.isArray(value.$in) && value.$in.length === 3 && value.$in.includes(null) && value.$in.includes('') && value.$in.find(function (v) { return Array.isArray(v) && v.length === 0; })) {
269
+ updated.condition[key]['$isNotSet'] = "Value";
270
+ }
271
+ else if (Array.isArray(value.$nin) && value.$nin.length === 3 && value.$nin.includes(null) && value.$nin.includes('') && value.$nin.find(function (v) { return Array.isArray(v) && v.length === 0; })) {
272
+ updated.condition[key]['$isSet'] = "Value";
273
+ }
274
+ else if (Object.keys(value)[0] === '$gt' && (value.$gt instanceof Date || (0, utilities_1.is_full_iso_string_heuristic)(value.$gt) || value.$gt === '$now')) {
275
+ updated.condition[key]['$after'] = value.$gt;
276
+ }
277
+ else if (Object.keys(value)[0] === '$lt' && (value.$lt instanceof Date || (0, utilities_1.is_full_iso_string_heuristic)(value.$lt) || value.$lt === '$now')) {
278
+ updated.condition[key]['$before'] = value.$lt;
279
+ }
280
+ else if (Object.keys(value)[0] === '$regex') {
281
+ updated.condition[key]['$contains'] = value.$regex;
282
+ }
283
+ else if (Object.keys(value)[0] === '$not' && ((_c = Object.keys((_b = value.$not) !== null && _b !== void 0 ? _b : {})) === null || _c === void 0 ? void 0 : _c[0]) === '$regex') {
284
+ updated.condition[key]['$doesNotContain'] = value.$not.$regex;
285
+ }
286
+ else {
287
+ updated.condition[key] = value;
288
+ }
289
+ }
290
+ else {
291
+ updated.condition[key] = value;
292
+ }
293
+ }
294
+ return updated;
295
+ }
296
+ return filter;
297
+ };
298
+ exports.mongo_db_filter_to_enduser_condition = mongo_db_filter_to_enduser_condition;
299
+ var list_of_strings_with_qualifier_to_mongodb_filter = function (tags) {
300
+ if ((tags === null || tags === void 0 ? void 0 : tags.qualifier) === 'All Of') {
301
+ return { $all: tags.values || [] };
302
+ }
303
+ return { $in: (tags === null || tags === void 0 ? void 0 : tags.values) || [] };
304
+ };
305
+ exports.list_of_strings_with_qualifier_to_mongodb_filter = list_of_strings_with_qualifier_to_mongodb_filter;
306
+ var mongo_db_filter_to_list_of_strings_with_qualifier = function (filter) {
307
+ var defaultValue = { qualifier: 'One Of', values: [] };
308
+ if (!filter) {
309
+ return defaultValue;
310
+ }
311
+ if (filter.$all) {
312
+ return { values: filter.$all, qualifier: 'All Of' };
313
+ }
314
+ if (filter.$in) {
315
+ return { values: filter.$in, qualifier: 'One Of' };
316
+ }
317
+ return defaultValue;
318
+ };
319
+ exports.mongo_db_filter_to_list_of_strings_with_qualifier = mongo_db_filter_to_list_of_strings_with_qualifier;
320
+ var apply_mongodb_style_filter = function (data, filter, options) {
321
+ var matchesFilter = function (item, filter) {
322
+ if (!options.showArchived && (item === null || item === void 0 ? void 0 : item.archivedAt))
323
+ return false;
324
+ var _loop_1 = function (key, condition) {
325
+ if (key === "$and") {
326
+ if (!Array.isArray(condition) || !condition.every(function (subFilter) { return matchesFilter(item, subFilter); })) {
327
+ return { value: false };
328
+ }
329
+ }
330
+ else if (key === "$or") {
331
+ if (!Array.isArray(condition) || !condition.some(function (subFilter) { return matchesFilter(item, subFilter); })) {
332
+ return { value: false };
333
+ }
334
+ }
335
+ else if (key === "$nor") {
336
+ if (!Array.isArray(condition) || condition.some(function (subFilter) { return matchesFilter(item, subFilter); })) {
337
+ return { value: false };
338
+ }
339
+ }
340
+ else if (key === "$not") {
341
+ if (typeof condition !== "object" || matchesFilter(item, condition)) {
342
+ return { value: false };
343
+ }
344
+ }
345
+ else {
346
+ var value_1 = (0, utilities_1.value_for_dotted_key)(item, key, { handleArray: true });
347
+ // console.log('checking value', key, value, condition)
348
+ // to be consistent with mongodb, $in/$nin should match null and undefined
349
+ var modifyArrayOperandForNull = function (v) { return (__spreadArray(__spreadArray([], v, true), (v.includes(null) ? [undefined] : []), true)); };
350
+ if (Array.isArray(value_1)) {
351
+ if (typeof condition === "object" && condition !== null) {
352
+ for (var _c = 0, _d = Object.entries(condition); _c < _d.length; _c++) {
353
+ var _e = _d[_c], operator = _e[0], operand = _e[1];
354
+ // handle empty array
355
+ if (Array.isArray(value_1) && value_1.length === 0) {
356
+ if (operator === '$eq' && Array.isArray(operand) && operand.length === 0) {
357
+ continue;
358
+ }
359
+ if (operator === '$ne' && Array.isArray(operand) && operand.length === 0) {
360
+ return { value: false };
361
+ }
362
+ if (Array.isArray(operand) && operand.find(function (a) { return Array.isArray(a) && a.length === 0; })) {
363
+ if (operator === '$in') {
364
+ continue;
365
+ }
366
+ if (operator === '$nin') {
367
+ return { value: false };
368
+ }
369
+ }
370
+ }
371
+ if (operator === '$eq' && !value_1.includes(operand))
372
+ return { value: false };
373
+ if (operator === '$ne' && value_1.includes(operand))
374
+ return { value: false };
375
+ if (operator === "$in" && Array.isArray(operand) && !modifyArrayOperandForNull(operand).some(function (o) { return value_1.includes(o); }))
376
+ return { value: false };
377
+ if (operator === "$nin" && Array.isArray(operand) && modifyArrayOperandForNull(operand).some(function (o) { return value_1.includes(o); }))
378
+ return { value: false };
379
+ if (operator === "$all" && Array.isArray(operand) && !operand.every(function (o) { return value_1.includes(o); }))
380
+ return { value: false };
381
+ if (operator === '$all' && condition.length === 0)
382
+ return { value: false };
383
+ if (operator === '$all' && Array.isArray(operand) && operand.length === 0)
384
+ return { value: false };
385
+ if (operator === "$size" && value_1.length !== operand)
386
+ return { value: false };
387
+ if (operator === '$exists' && operand === false)
388
+ return { value: false };
389
+ }
390
+ }
391
+ else {
392
+ if (!value_1.includes(condition))
393
+ return { value: false };
394
+ }
395
+ }
396
+ else {
397
+ if (typeof condition === "object" && condition !== null) {
398
+ for (var _f = 0, _g = Object.entries(condition); _f < _g.length; _f++) {
399
+ var _h = _g[_f], operator = _h[0], operand = _h[1];
400
+ var numberValue = ((0, utilities_1.is_full_iso_string_heuristic)(value_1 === null || value_1 === void 0 ? void 0 : value_1.toString())
401
+ ? new Date(value_1).getTime()
402
+ : parseFloat(value_1));
403
+ var parsedOperandForNumber = ((0, utilities_1.is_full_iso_string_heuristic)(operand === null || operand === void 0 ? void 0 : operand.toString())
404
+ ? new Date(operand).getTime()
405
+ : operand === '$now'
406
+ ? new Date().getTime()
407
+ : parseFloat(operand));
408
+ if (operator === "$eq" && value_1 !== operand)
409
+ return { value: false };
410
+ if (operator === "$ne" && value_1 === operand)
411
+ return { value: false };
412
+ if (operator === "$in" && (!Array.isArray(operand) || !(modifyArrayOperandForNull(operand).includes(value_1))))
413
+ return { value: false };
414
+ if (operator === "$nin" && !(Array.isArray(operand) && !modifyArrayOperandForNull(operand).includes(value_1)))
415
+ return { value: false };
416
+ if (operator === "$exists" && ((operand && value_1 === undefined) || (!operand && value_1 !== undefined)))
417
+ return { value: false };
418
+ if (operator === "$regex" && !(typeof value_1 === "string" && new RegExp(operand).test(value_1)))
419
+ return { value: false };
420
+ if (operator === "$gt" && (numberValue <= parseFloat(parsedOperandForNumber) || isNaN(numberValue) || numberValue === null || numberValue === undefined))
421
+ return { value: false };
422
+ if (operator === "$gte" && (numberValue < parseFloat(parsedOperandForNumber) || isNaN(numberValue) || numberValue === null || numberValue === undefined))
423
+ return { value: false };
424
+ if (operator === "$lt" && (numberValue >= parseFloat(parsedOperandForNumber) || isNaN(numberValue) || numberValue === null || numberValue === undefined))
425
+ return { value: false };
426
+ if (operator === "$lte" && (numberValue > parseFloat(parsedOperandForNumber) || isNaN(numberValue) || numberValue === null || numberValue === undefined))
427
+ return { value: false };
428
+ // only valid for lists, shoujld return false by default
429
+ if (operator === '$all')
430
+ return { value: false };
431
+ }
432
+ }
433
+ else {
434
+ if (value_1 !== condition)
435
+ return { value: false };
436
+ }
437
+ }
438
+ }
439
+ };
440
+ for (var _i = 0, _a = Object.entries(filter); _i < _a.length; _i++) {
441
+ var _b = _a[_i], key = _b[0], condition = _b[1];
442
+ var state_1 = _loop_1(key, condition);
443
+ if (typeof state_1 === "object")
444
+ return state_1.value;
445
+ }
446
+ return true;
447
+ };
448
+ try {
449
+ return data.filter(function (item) { return matchesFilter(item, filter); });
450
+ }
451
+ catch (err) {
452
+ console.error("Filter error:", err);
453
+ }
454
+ return data;
455
+ };
456
+ exports.apply_mongodb_style_filter = apply_mongodb_style_filter;
457
+ var remove_inactive_filters = function (filters) { return (filters.map(function (f) {
458
+ // gpt4o
459
+ var cleanedFilter = Object.entries(f).reduce(function (acc, _a) {
460
+ var key = _a[0], value = _a[1];
461
+ if (key === "$and" || key === "$or") {
462
+ var subFilters = Array.isArray(value) ? value.filter(function (sub) { return Object.keys(sub).length > 0; }) : [];
463
+ if (subFilters.length > 0) {
464
+ acc[key] = subFilters;
465
+ }
466
+ }
467
+ else if (key === "$in" || key === "$all") {
468
+ if (Array.isArray(value) && value.length > 0) {
469
+ acc[key] = value;
470
+ }
471
+ }
472
+ else if (key === "$exists" || key === "$not") {
473
+ acc[key] = value;
474
+ }
475
+ else if (typeof value === "object" && value !== null) {
476
+ var nestedFilter = (0, exports.remove_inactive_filters)([value])[0];
477
+ if (nestedFilter && Object.keys(nestedFilter).length > 0) {
478
+ acc[key] = nestedFilter;
479
+ }
480
+ }
481
+ else {
482
+ acc[key] = value;
483
+ }
484
+ return acc;
485
+ }, {});
486
+ return Object.keys(cleanedFilter).length > 0 ? cleanedFilter : null;
487
+ })
488
+ .filter(function (v) { return v && !(0, utilities_1.object_is_empty)(v); })); };
489
+ exports.remove_inactive_filters = remove_inactive_filters;
490
+ var useFiltersV2 = function (args) {
491
+ var _a = args !== null && args !== void 0 ? args : {}, onFilterChange = _a.onFilterChange, reload = _a.reload, memoryId = _a.memoryId, initialFilters = _a.initialFilters, showArchived = _a.showArchived;
492
+ var loadFilters = (0, react_1.useCallback)(function () { return (initialFilters || (memoryId
493
+ ? ((0, utilities_1.safeJSONParse)((0, utilities_1.read_local_storage)(memoryId)) || {})
494
+ : {})); }, [initialFilters, memoryId]);
495
+ var _b = react_1.default.useState(loadFilters()), filters = _b[0], setFilters = _b[1];
496
+ var didReloadRef = (0, react_1.useRef)(false);
497
+ (0, react_1.useEffect)(function () {
498
+ if (!reload)
499
+ return;
500
+ if (didReloadRef.current)
501
+ return;
502
+ didReloadRef.current = true;
503
+ setFilters(loadFilters);
504
+ }, [reload, loadFilters]);
505
+ (0, react_1.useEffect)(function () {
506
+ if (!memoryId)
507
+ return;
508
+ (0, utilities_1.update_local_storage)(memoryId, JSON.stringify(filters));
509
+ }, [filters, memoryId]);
510
+ var prevFilterRef = react_1.default.useRef(filters);
511
+ (0, react_1.useEffect)(function () {
512
+ if (!onFilterChange)
513
+ return;
514
+ if ((0, utilities_1.objects_equivalent)(prevFilterRef.current, filters))
515
+ return;
516
+ prevFilterRef.current = filters;
517
+ onFilterChange(filters);
518
+ }, [filters, onFilterChange]);
519
+ var mdbFilter = (0, react_1.useMemo)(function () { return ({
520
+ $and: (0, exports.remove_inactive_filters)(Object.values(filters))
521
+ }); }, [filters]);
522
+ var applyFilters = (0, react_1.useCallback)((function (data) { return (0, exports.apply_mongodb_style_filter)(data, mdbFilter, { showArchived: !!showArchived }); }), [mdbFilter, showArchived]);
523
+ return {
524
+ mdbFilter: mdbFilter,
525
+ filters: filters,
526
+ setFilters: setFilters,
527
+ applyFilters: applyFilters,
528
+ activeFilterCount: Object.values(filters).filter(function (f) { return !!f.filter; }).length
529
+ };
530
+ };
531
+ exports.useFiltersV2 = useFiltersV2;
100
532
  /* FILTER / SEARCH */
101
533
  var filter_setter_for_key = function (key, setFilters) { return function (f) { return setFilters(function (fs) {
102
534
  var _a;
@@ -257,7 +689,6 @@ var filter_for_query = function (query, getAdditionalFields) {
257
689
  }
258
690
  var toAdd = getAdditionalFields === null || getAdditionalFields === void 0 ? void 0 : getAdditionalFields(record);
259
691
  var joined = __assign(__assign({}, toAdd), record);
260
- // console.log(JSON.stringify(joined, null, 2))
261
692
  for (var field in joined) {
262
693
  var value = joined[field];
263
694
  // exact match is useful for things like id match and easy heuristic check for others
@@ -368,13 +799,20 @@ var performBulkAction = function (_a) {
368
799
  };
369
800
  exports.performBulkAction = performBulkAction;
370
801
  var ModelSearchInput = function (_a) {
802
+ var _b, _c, _d;
371
803
  var filterKey = _a.filterKey, setFilters = _a.setFilters, searchAPI = _a.searchAPI, onLoad = _a.onLoad, attachSearchableFields = _a.attachSearchableFields,
372
804
  // @ts-ignore remove from props if provided by mistake
373
805
  activeFilterCount = _a.activeFilterCount,
374
806
  // @ts-ignore remove from props if provided by mistake
375
807
  compoundApiFilter = _a.compoundApiFilter, value = _a.value, onChange = _a.onChange, props = __rest(_a, ["filterKey", "setFilters", "searchAPI", "onLoad", "attachSearchableFields", "activeFilterCount", "compoundApiFilter", "value", "onChange"]);
808
+ var dontPersist = false;
809
+ try { // may fail to load if enduser session
810
+ var organizationLoading = (0, _1.useOrganization)()[0];
811
+ dontPersist = !!((0, _1.value_is_loaded)(organizationLoading) ? (_d = (_c = (_b = organizationLoading.value) === null || _b === void 0 ? void 0 : _b.settings) === null || _c === void 0 ? void 0 : _c.interface) === null || _d === void 0 ? void 0 : _d.dontPersistSearches : undefined);
812
+ }
813
+ catch (err) { }
376
814
  var cacheKey = "search-cache-".concat(filterKey);
377
- var _b = (0, react_1.useState)((0, utilities_1.read_local_storage)(cacheKey) || ''), _query = _b[0], _setQuery = _b[1];
815
+ var _e = (0, react_1.useState)(dontPersist ? '' : ((0, utilities_1.read_local_storage)(cacheKey) || '')), _query = _e[0], _setQuery = _e[1];
378
816
  var query = value !== null && value !== void 0 ? value : _query;
379
817
  var setQuery = onChange !== null && onChange !== void 0 ? onChange : _setQuery;
380
818
  var filterOnLoadRef = (0, react_1.useRef)(!!query);