@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
@@ -67,10 +67,435 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
67
67
  };
68
68
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
69
69
  import React, { useEffect, useCallback, useMemo, useState, useRef } from "react";
70
- import { objects_equivalent, read_local_storage, safeJSONParse, update_local_storage, user_display_name } from "@tellescope/utilities";
71
- import { ALL_ACCESS, UNSEARCHABLE_FIELDS } from "@tellescope/constants";
70
+ import { is_full_iso_string_heuristic, object_is_empty, objects_equivalent, read_local_storage, replace_keys_and_values_in_object, safeJSONParse, update_local_storage, user_display_name, value_for_dotted_key } from "@tellescope/utilities";
71
+ import { ALL_ACCESS, HEALTHIE_TITLE, UNSEARCHABLE_FIELDS } from "@tellescope/constants";
72
72
  import { useSearchAPI } from "./hooks";
73
- import { Button, Checkbox, Flex, HoverPaper, LoadingButton, LoadingData, ScrollingList, SearchTextInput, Typography, useAgentRecords, useAllergyCodes, useAppointmentBookingPages, useAppointmentLocations, useAutomationTriggers, useCalendarEventTemplates, useCallHoldQueues, useChatRooms, useDatabaseRecords, useDatabases, useDiagnosisCodes, useEnduserOrders, useEndusers, useFaxLogs, useFiles, useFormGroups, useForms, useForums, useJourneys, useManagedContentRecords, useMessageTemplateSnippets, useNotifications, useOrganizations, usePrescriptionRoutes, useResolvedSession, useSession, useSuggestedContacts, useTemplates, useTicketQueues, useTickets, useUsers, useWaitlists, value_is_loaded } from ".";
73
+ import { Button, Checkbox, Flex, HoverPaper, LoadingButton, LoadingData, ScrollingList, SearchTextInput, Typography, useAgentRecords, useAllergyCodes, useAppointmentBookingPages, useAppointmentLocations, useAutomationTriggers, useCalendarEventTemplates, useCallHoldQueues, useChatRooms, useDatabaseRecords, useDatabases, useDiagnosisCodes, useEnduserOrders, useEndusers, useFaxLogs, useFiles, useFormGroups, useForms, useForums, useJourneys, useManagedContentRecords, useMessageTemplateSnippets, useNotifications, useOrganization, useOrganizations, usePrescriptionRoutes, useResolvedSession, useSession, useSuggestedContacts, useTemplates, useTicketQueues, useTickets, useUsers, useWaitlists, value_is_loaded } from ".";
74
+ export var enduser_condition_to_mongodb_filter = function (condition, customFields) {
75
+ var _a, _b;
76
+ if (!condition) {
77
+ return condition;
78
+ }
79
+ if (condition.$and) {
80
+ return { $and: condition.$and.map(function (v) { return enduser_condition_to_mongodb_filter(v, customFields); }) };
81
+ }
82
+ if (condition.$or) {
83
+ return { $or: condition.$or.map(function (v) { return enduser_condition_to_mongodb_filter(v, customFields); }) };
84
+ }
85
+ if (condition.$nor) {
86
+ return { $nor: condition.$nor.map(function (v) { return enduser_condition_to_mongodb_filter(v, customFields); }) };
87
+ }
88
+ if (condition.$not) {
89
+ return { $not: enduser_condition_to_mongodb_filter(condition.$not, customFields) };
90
+ }
91
+ if (condition && typeof condition === 'object' && condition.constructor === Object) {
92
+ var updated = {};
93
+ for (var _i = 0, _c = Object.entries(condition); _i < _c.length; _i++) {
94
+ var _d = _c[_i], _key = _d[0], _value = _d[1];
95
+ var key = customFields.includes(_key) ? "fields.".concat(_key) : _key;
96
+ var value = enduser_condition_to_mongodb_filter(_value, customFields);
97
+ // console.log(key, _value, value)
98
+ if (key === 'condition') {
99
+ var toReturn = enduser_condition_to_mongodb_filter(value, customFields);
100
+ delete updated.condition;
101
+ return toReturn;
102
+ } // base case is comparison to value, so just return it
103
+ // journeys currently have a special ui/syntax in filter
104
+ if (key === 'Journeys') {
105
+ if ((typeof (value === null || value === void 0 ? void 0 : value.$in)) === 'string') {
106
+ return _a = {}, _a["journeys.".concat(value.$in)] = { $exists: true }, _a;
107
+ }
108
+ else if ((typeof (value === null || value === void 0 ? void 0 : value.$nin)) === 'string') {
109
+ return _b = {}, _b["journeys.".concat(value.$nin)] = { $exists: false }, _b;
110
+ }
111
+ }
112
+ if (key === 'Healthie ID') {
113
+ // $setSet ($nin null, '')
114
+ if (value === null || value === void 0 ? void 0 : value.$nin)
115
+ return { $or: [{ source: HEALTHIE_TITLE, externalId: { $nin: [null, ''] } }, { 'references.type': HEALTHIE_TITLE }] };
116
+ // $isNotSet ($in null, '')
117
+ if (value === null || value === void 0 ? void 0 : value.$in)
118
+ return { $and: [{ source: { $ne: HEALTHIE_TITLE } }, { 'references.type': { $ne: HEALTHIE_TITLE } }] };
119
+ }
120
+ // ensure to parse string to number values
121
+ if (key === 'height') {
122
+ return {
123
+ 'height.value': replace_keys_and_values_in_object(value, function (v) { return typeof v === 'string' && !v.startsWith('$') ? parseFloat(v) : v; })
124
+ };
125
+ }
126
+ if (key === 'weight') {
127
+ return {
128
+ 'weight.value': replace_keys_and_values_in_object(value, function (v) { return typeof v === 'string' && !v.startsWith('$') ? parseFloat(v) : v; })
129
+ };
130
+ }
131
+ if (key === "relationships") {
132
+ return {
133
+ 'relationships.type': value
134
+ };
135
+ }
136
+ // case for isSet and isNotSet includes empty string as unset value
137
+ if (key === '$isSet') {
138
+ updated.$nin = [null, '', []];
139
+ }
140
+ else if (key === '$isNotSet') {
141
+ updated.$in = [null, '', []];
142
+ }
143
+ else if (key === '$contains') {
144
+ updated.$regex = value;
145
+ }
146
+ else if (key === '$doesNotContain') {
147
+ updated.$not = { $regex: value };
148
+ }
149
+ else if (key === '$before') {
150
+ updated.$lt = value;
151
+ }
152
+ else if (key === '$after') {
153
+ updated.$gt = value;
154
+ }
155
+ else {
156
+ updated[key] = value;
157
+ }
158
+ }
159
+ return updated;
160
+ }
161
+ return condition;
162
+ };
163
+ export var mongo_db_filter_to_enduser_condition = function (filter) {
164
+ var _a;
165
+ var _b, _c;
166
+ if (!filter) {
167
+ return filter;
168
+ }
169
+ if (objects_equivalent(filter, {
170
+ "$and": [
171
+ {
172
+ "source": {
173
+ "$ne": "Healthie"
174
+ }
175
+ },
176
+ {
177
+ "references.type": {
178
+ "$ne": "Healthie"
179
+ }
180
+ }
181
+ ]
182
+ })) {
183
+ return { condition: { 'Healthie ID': { $isNotSet: 'Value' } } };
184
+ }
185
+ if (objects_equivalent(filter, {
186
+ "$or": [
187
+ {
188
+ "source": "Healthie",
189
+ "externalId": {
190
+ "$nin": [
191
+ null,
192
+ ""
193
+ ]
194
+ }
195
+ },
196
+ {
197
+ "references.type": "Healthie"
198
+ }
199
+ ]
200
+ })) {
201
+ return { condition: { 'Healthie ID': { $isSet: 'Value' } } };
202
+ }
203
+ if (filter.$and) {
204
+ return { $and: filter.$and.map(function (v) { return mongo_db_filter_to_enduser_condition(v); }) };
205
+ }
206
+ if (filter.$or) {
207
+ return { $or: filter.$or.map(function (v) { return mongo_db_filter_to_enduser_condition(v); }) };
208
+ }
209
+ if (filter.$nor) {
210
+ return { $nor: filter.$nor.map(function (v) { return mongo_db_filter_to_enduser_condition(v); }) };
211
+ }
212
+ if (filter.$not) {
213
+ return { $not: mongo_db_filter_to_enduser_condition(filter.$not) };
214
+ }
215
+ if (filter && typeof filter === 'object' && filter.constructor === Object) {
216
+ if (object_is_empty(filter))
217
+ return filter;
218
+ var updated = { condition: {} };
219
+ for (var _i = 0, _d = Object.entries(filter); _i < _d.length; _i++) {
220
+ var _e = _d[_i], _key = _e[0], value = _e[1];
221
+ var key = ((typeof _key === 'string' && _key.startsWith('fields.')) ? _key.replace('fields.', '')
222
+ : _key === 'height.value' ? 'height'
223
+ : _key === 'weight.value' ? 'weight'
224
+ : _key === 'relationships.type' ? 'relationships'
225
+ : _key);
226
+ if (value && typeof value === 'object' && value.constructor === Object) {
227
+ updated.condition[key] = {};
228
+ if (Object.keys(value)[0] === '$exists') {
229
+ if (key.startsWith('journeys.')) {
230
+ // journeys currently have a special ui/syntax in filter
231
+ updated.condition['Journeys'] = (_a = {}, _a[value.$exists ? '$in' : '$nin'] = key.split('.')[1], _a);
232
+ }
233
+ else if (value.$exists) {
234
+ updated.condition[key]['$isSet'] = "Value";
235
+ }
236
+ else {
237
+ updated.condition[key]['$isNotSet'] = "Value";
238
+ }
239
+ }
240
+ // case for isSet and isNotSet includes empty string as unset value
241
+ 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; })) {
242
+ updated.condition[key]['$isNotSet'] = "Value";
243
+ }
244
+ 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; })) {
245
+ updated.condition[key]['$isSet'] = "Value";
246
+ }
247
+ else if (Object.keys(value)[0] === '$gt' && (value.$gt instanceof Date || is_full_iso_string_heuristic(value.$gt) || value.$gt === '$now')) {
248
+ updated.condition[key]['$after'] = value.$gt;
249
+ }
250
+ else if (Object.keys(value)[0] === '$lt' && (value.$lt instanceof Date || is_full_iso_string_heuristic(value.$lt) || value.$lt === '$now')) {
251
+ updated.condition[key]['$before'] = value.$lt;
252
+ }
253
+ else if (Object.keys(value)[0] === '$regex') {
254
+ updated.condition[key]['$contains'] = value.$regex;
255
+ }
256
+ 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') {
257
+ updated.condition[key]['$doesNotContain'] = value.$not.$regex;
258
+ }
259
+ else {
260
+ updated.condition[key] = value;
261
+ }
262
+ }
263
+ else {
264
+ updated.condition[key] = value;
265
+ }
266
+ }
267
+ return updated;
268
+ }
269
+ return filter;
270
+ };
271
+ export var list_of_strings_with_qualifier_to_mongodb_filter = function (tags) {
272
+ if ((tags === null || tags === void 0 ? void 0 : tags.qualifier) === 'All Of') {
273
+ return { $all: tags.values || [] };
274
+ }
275
+ return { $in: (tags === null || tags === void 0 ? void 0 : tags.values) || [] };
276
+ };
277
+ export var mongo_db_filter_to_list_of_strings_with_qualifier = function (filter) {
278
+ var defaultValue = { qualifier: 'One Of', values: [] };
279
+ if (!filter) {
280
+ return defaultValue;
281
+ }
282
+ if (filter.$all) {
283
+ return { values: filter.$all, qualifier: 'All Of' };
284
+ }
285
+ if (filter.$in) {
286
+ return { values: filter.$in, qualifier: 'One Of' };
287
+ }
288
+ return defaultValue;
289
+ };
290
+ export var apply_mongodb_style_filter = function (data, filter, options) {
291
+ var matchesFilter = function (item, filter) {
292
+ if (!options.showArchived && (item === null || item === void 0 ? void 0 : item.archivedAt))
293
+ return false;
294
+ var _loop_1 = function (key, condition) {
295
+ if (key === "$and") {
296
+ if (!Array.isArray(condition) || !condition.every(function (subFilter) { return matchesFilter(item, subFilter); })) {
297
+ return { value: false };
298
+ }
299
+ }
300
+ else if (key === "$or") {
301
+ if (!Array.isArray(condition) || !condition.some(function (subFilter) { return matchesFilter(item, subFilter); })) {
302
+ return { value: false };
303
+ }
304
+ }
305
+ else if (key === "$nor") {
306
+ if (!Array.isArray(condition) || condition.some(function (subFilter) { return matchesFilter(item, subFilter); })) {
307
+ return { value: false };
308
+ }
309
+ }
310
+ else if (key === "$not") {
311
+ if (typeof condition !== "object" || matchesFilter(item, condition)) {
312
+ return { value: false };
313
+ }
314
+ }
315
+ else {
316
+ var value_1 = value_for_dotted_key(item, key, { handleArray: true });
317
+ // console.log('checking value', key, value, condition)
318
+ // to be consistent with mongodb, $in/$nin should match null and undefined
319
+ var modifyArrayOperandForNull = function (v) { return (__spreadArray(__spreadArray([], v, true), (v.includes(null) ? [undefined] : []), true)); };
320
+ if (Array.isArray(value_1)) {
321
+ if (typeof condition === "object" && condition !== null) {
322
+ for (var _c = 0, _d = Object.entries(condition); _c < _d.length; _c++) {
323
+ var _e = _d[_c], operator = _e[0], operand = _e[1];
324
+ // handle empty array
325
+ if (Array.isArray(value_1) && value_1.length === 0) {
326
+ if (operator === '$eq' && Array.isArray(operand) && operand.length === 0) {
327
+ continue;
328
+ }
329
+ if (operator === '$ne' && Array.isArray(operand) && operand.length === 0) {
330
+ return { value: false };
331
+ }
332
+ if (Array.isArray(operand) && operand.find(function (a) { return Array.isArray(a) && a.length === 0; })) {
333
+ if (operator === '$in') {
334
+ continue;
335
+ }
336
+ if (operator === '$nin') {
337
+ return { value: false };
338
+ }
339
+ }
340
+ }
341
+ if (operator === '$eq' && !value_1.includes(operand))
342
+ return { value: false };
343
+ if (operator === '$ne' && value_1.includes(operand))
344
+ return { value: false };
345
+ if (operator === "$in" && Array.isArray(operand) && !modifyArrayOperandForNull(operand).some(function (o) { return value_1.includes(o); }))
346
+ return { value: false };
347
+ if (operator === "$nin" && Array.isArray(operand) && modifyArrayOperandForNull(operand).some(function (o) { return value_1.includes(o); }))
348
+ return { value: false };
349
+ if (operator === "$all" && Array.isArray(operand) && !operand.every(function (o) { return value_1.includes(o); }))
350
+ return { value: false };
351
+ if (operator === '$all' && condition.length === 0)
352
+ return { value: false };
353
+ if (operator === '$all' && Array.isArray(operand) && operand.length === 0)
354
+ return { value: false };
355
+ if (operator === "$size" && value_1.length !== operand)
356
+ return { value: false };
357
+ if (operator === '$exists' && operand === false)
358
+ return { value: false };
359
+ }
360
+ }
361
+ else {
362
+ if (!value_1.includes(condition))
363
+ return { value: false };
364
+ }
365
+ }
366
+ else {
367
+ if (typeof condition === "object" && condition !== null) {
368
+ for (var _f = 0, _g = Object.entries(condition); _f < _g.length; _f++) {
369
+ var _h = _g[_f], operator = _h[0], operand = _h[1];
370
+ var numberValue = (is_full_iso_string_heuristic(value_1 === null || value_1 === void 0 ? void 0 : value_1.toString())
371
+ ? new Date(value_1).getTime()
372
+ : parseFloat(value_1));
373
+ var parsedOperandForNumber = (is_full_iso_string_heuristic(operand === null || operand === void 0 ? void 0 : operand.toString())
374
+ ? new Date(operand).getTime()
375
+ : operand === '$now'
376
+ ? new Date().getTime()
377
+ : parseFloat(operand));
378
+ if (operator === "$eq" && value_1 !== operand)
379
+ return { value: false };
380
+ if (operator === "$ne" && value_1 === operand)
381
+ return { value: false };
382
+ if (operator === "$in" && (!Array.isArray(operand) || !(modifyArrayOperandForNull(operand).includes(value_1))))
383
+ return { value: false };
384
+ if (operator === "$nin" && !(Array.isArray(operand) && !modifyArrayOperandForNull(operand).includes(value_1)))
385
+ return { value: false };
386
+ if (operator === "$exists" && ((operand && value_1 === undefined) || (!operand && value_1 !== undefined)))
387
+ return { value: false };
388
+ if (operator === "$regex" && !(typeof value_1 === "string" && new RegExp(operand).test(value_1)))
389
+ return { value: false };
390
+ if (operator === "$gt" && (numberValue <= parseFloat(parsedOperandForNumber) || isNaN(numberValue) || numberValue === null || numberValue === undefined))
391
+ return { value: false };
392
+ if (operator === "$gte" && (numberValue < parseFloat(parsedOperandForNumber) || isNaN(numberValue) || numberValue === null || numberValue === undefined))
393
+ return { value: false };
394
+ if (operator === "$lt" && (numberValue >= parseFloat(parsedOperandForNumber) || isNaN(numberValue) || numberValue === null || numberValue === undefined))
395
+ return { value: false };
396
+ if (operator === "$lte" && (numberValue > parseFloat(parsedOperandForNumber) || isNaN(numberValue) || numberValue === null || numberValue === undefined))
397
+ return { value: false };
398
+ // only valid for lists, shoujld return false by default
399
+ if (operator === '$all')
400
+ return { value: false };
401
+ }
402
+ }
403
+ else {
404
+ if (value_1 !== condition)
405
+ return { value: false };
406
+ }
407
+ }
408
+ }
409
+ };
410
+ for (var _i = 0, _a = Object.entries(filter); _i < _a.length; _i++) {
411
+ var _b = _a[_i], key = _b[0], condition = _b[1];
412
+ var state_1 = _loop_1(key, condition);
413
+ if (typeof state_1 === "object")
414
+ return state_1.value;
415
+ }
416
+ return true;
417
+ };
418
+ try {
419
+ return data.filter(function (item) { return matchesFilter(item, filter); });
420
+ }
421
+ catch (err) {
422
+ console.error("Filter error:", err);
423
+ }
424
+ return data;
425
+ };
426
+ export var remove_inactive_filters = function (filters) { return (filters.map(function (f) {
427
+ // gpt4o
428
+ var cleanedFilter = Object.entries(f).reduce(function (acc, _a) {
429
+ var key = _a[0], value = _a[1];
430
+ if (key === "$and" || key === "$or") {
431
+ var subFilters = Array.isArray(value) ? value.filter(function (sub) { return Object.keys(sub).length > 0; }) : [];
432
+ if (subFilters.length > 0) {
433
+ acc[key] = subFilters;
434
+ }
435
+ }
436
+ else if (key === "$in" || key === "$all") {
437
+ if (Array.isArray(value) && value.length > 0) {
438
+ acc[key] = value;
439
+ }
440
+ }
441
+ else if (key === "$exists" || key === "$not") {
442
+ acc[key] = value;
443
+ }
444
+ else if (typeof value === "object" && value !== null) {
445
+ var nestedFilter = remove_inactive_filters([value])[0];
446
+ if (nestedFilter && Object.keys(nestedFilter).length > 0) {
447
+ acc[key] = nestedFilter;
448
+ }
449
+ }
450
+ else {
451
+ acc[key] = value;
452
+ }
453
+ return acc;
454
+ }, {});
455
+ return Object.keys(cleanedFilter).length > 0 ? cleanedFilter : null;
456
+ })
457
+ .filter(function (v) { return v && !object_is_empty(v); })); };
458
+ export var useFiltersV2 = function (args) {
459
+ var _a = args !== null && args !== void 0 ? args : {}, onFilterChange = _a.onFilterChange, reload = _a.reload, memoryId = _a.memoryId, initialFilters = _a.initialFilters, showArchived = _a.showArchived;
460
+ var loadFilters = useCallback(function () { return (initialFilters || (memoryId
461
+ ? (safeJSONParse(read_local_storage(memoryId)) || {})
462
+ : {})); }, [initialFilters, memoryId]);
463
+ var _b = React.useState(loadFilters()), filters = _b[0], setFilters = _b[1];
464
+ var didReloadRef = useRef(false);
465
+ useEffect(function () {
466
+ if (!reload)
467
+ return;
468
+ if (didReloadRef.current)
469
+ return;
470
+ didReloadRef.current = true;
471
+ setFilters(loadFilters);
472
+ }, [reload, loadFilters]);
473
+ useEffect(function () {
474
+ if (!memoryId)
475
+ return;
476
+ update_local_storage(memoryId, JSON.stringify(filters));
477
+ }, [filters, memoryId]);
478
+ var prevFilterRef = React.useRef(filters);
479
+ useEffect(function () {
480
+ if (!onFilterChange)
481
+ return;
482
+ if (objects_equivalent(prevFilterRef.current, filters))
483
+ return;
484
+ prevFilterRef.current = filters;
485
+ onFilterChange(filters);
486
+ }, [filters, onFilterChange]);
487
+ var mdbFilter = useMemo(function () { return ({
488
+ $and: remove_inactive_filters(Object.values(filters))
489
+ }); }, [filters]);
490
+ var applyFilters = useCallback((function (data) { return apply_mongodb_style_filter(data, mdbFilter, { showArchived: !!showArchived }); }), [mdbFilter, showArchived]);
491
+ return {
492
+ mdbFilter: mdbFilter,
493
+ filters: filters,
494
+ setFilters: setFilters,
495
+ applyFilters: applyFilters,
496
+ activeFilterCount: Object.values(filters).filter(function (f) { return !!f.filter; }).length
497
+ };
498
+ };
74
499
  /* FILTER / SEARCH */
75
500
  export var filter_setter_for_key = function (key, setFilters) { return function (f) { return setFilters(function (fs) {
76
501
  var _a;
@@ -226,7 +651,6 @@ export var filter_for_query = function (query, getAdditionalFields) {
226
651
  }
227
652
  var toAdd = getAdditionalFields === null || getAdditionalFields === void 0 ? void 0 : getAdditionalFields(record);
228
653
  var joined = __assign(__assign({}, toAdd), record);
229
- // console.log(JSON.stringify(joined, null, 2))
230
654
  for (var field in joined) {
231
655
  var value = joined[field];
232
656
  // exact match is useful for things like id match and easy heuristic check for others
@@ -335,13 +759,20 @@ export var performBulkAction = function (_a) {
335
759
  });
336
760
  };
337
761
  export var ModelSearchInput = function (_a) {
762
+ var _b, _c, _d;
338
763
  var filterKey = _a.filterKey, setFilters = _a.setFilters, searchAPI = _a.searchAPI, onLoad = _a.onLoad, attachSearchableFields = _a.attachSearchableFields,
339
764
  // @ts-ignore remove from props if provided by mistake
340
765
  activeFilterCount = _a.activeFilterCount,
341
766
  // @ts-ignore remove from props if provided by mistake
342
767
  compoundApiFilter = _a.compoundApiFilter, value = _a.value, onChange = _a.onChange, props = __rest(_a, ["filterKey", "setFilters", "searchAPI", "onLoad", "attachSearchableFields", "activeFilterCount", "compoundApiFilter", "value", "onChange"]);
768
+ var dontPersist = false;
769
+ try { // may fail to load if enduser session
770
+ var organizationLoading = useOrganization()[0];
771
+ dontPersist = !!(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);
772
+ }
773
+ catch (err) { }
343
774
  var cacheKey = "search-cache-".concat(filterKey);
344
- var _b = useState(read_local_storage(cacheKey) || ''), _query = _b[0], _setQuery = _b[1];
775
+ var _e = useState(dontPersist ? '' : (read_local_storage(cacheKey) || '')), _query = _e[0], _setQuery = _e[1];
345
776
  var query = value !== null && value !== void 0 ? value : _query;
346
777
  var setQuery = onChange !== null && onChange !== void 0 ? onChange : _setQuery;
347
778
  var filterOnLoadRef = useRef(!!query);