@campxdev/react-blueprint 1.3.1 → 1.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/react-blueprint",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "main": "./export.ts",
5
5
  "private": false,
6
6
  "dependencies": {
@@ -103,7 +103,11 @@ const singleSelectReducer = (
103
103
  return { ...state, open: true };
104
104
  }
105
105
  case SingleSelectActionsTypes.CLOSE: {
106
- return { ...state, open: false, loadingInternalOptions: false };
106
+ return {
107
+ ...state,
108
+ open: false,
109
+ loadingInternalOptions: false,
110
+ };
107
111
  }
108
112
  case SingleSelectActionsTypes.LOAD_INTERNAL_OPTIONS_START: {
109
113
  return { ...state, loadingInternalOptions: true };
@@ -121,15 +125,19 @@ const singleSelectReducer = (
121
125
  return { ...state, ...stateChanges };
122
126
  }
123
127
  case SingleSelectActionsTypes.SET_SEARCH: {
124
- return { ...state, search: stateChanges.search, hasMore: true };
128
+ return {
129
+ ...state,
130
+ search: stateChanges.search,
131
+ hasMore: true,
132
+ };
125
133
  }
126
134
  case SingleSelectActionsTypes.CLEAR_SEARCH: {
127
135
  return {
128
136
  ...state,
129
137
  search: null,
130
138
  offset: 0,
131
- internalOptions: [],
132
- internalOptionsMap: {},
139
+ internalOptions: stateChanges.internalOptions,
140
+ internalOptionsMap: stateChanges.internalOptionsMap,
133
141
  };
134
142
  }
135
143
  case SingleSelectActionsTypes.SET_INTERNAL_OPTIONS: {
@@ -228,10 +236,10 @@ export const SingleSelect = ({
228
236
  params: {
229
237
  limit,
230
238
  offset,
231
- selectedValueData: value,
232
239
  dbValueProps: {
233
240
  ...dbValueProps,
234
241
  ...(dbValueProps.isObjectId && { isObjectId: true }),
242
+ selectedValueData: value,
235
243
  },
236
244
  dbLabelProps,
237
245
  ...optionsApiEndpointParams,
@@ -285,6 +293,16 @@ export const SingleSelect = ({
285
293
  if (optionsApiEndPoint) {
286
294
  dispatch({
287
295
  actionType: SingleSelectActionsTypes.CLEAR_SEARCH,
296
+ stateChanges: {
297
+ internalOptions: internalOptions.filter((o: any) =>
298
+ reason != 'selectOption' ? o.value == value : o.value != value,
299
+ ),
300
+ internalOptionsMap: generateOptionsMap(
301
+ internalOptions.filter((o: any) =>
302
+ reason != 'selectOption' ? o.value == value : o.value != value,
303
+ ),
304
+ ),
305
+ },
288
306
  });
289
307
  }
290
308
  if (onClose) {
@@ -308,13 +326,16 @@ export const SingleSelect = ({
308
326
  params: {
309
327
  limit: limit,
310
328
  offset: offset + 10,
311
- search: search,
312
- selectedValueData: value,
329
+
313
330
  dbValueProps: {
314
331
  ...dbValueProps,
315
332
  ...(dbValueProps.isObjectId && { isObjectId: true }),
333
+ selectedValueData: value,
334
+ },
335
+ dbLabelProps: {
336
+ search: search,
337
+ ...dbLabelProps,
316
338
  },
317
- dbLabelProps,
318
339
  ...optionsApiEndpointParams,
319
340
  },
320
341
  })
@@ -345,6 +366,12 @@ export const SingleSelect = ({
345
366
  if (!searchValue || searchValue.trim() === '') {
346
367
  dispatch({
347
368
  actionType: SingleSelectActionsTypes.CLEAR_SEARCH,
369
+ stateChanges: {
370
+ internalOptions: internalOptions.filter((o: any) => o.value == value),
371
+ internalOptionsMap: generateOptionsMap(
372
+ internalOptions.filter((o: any) => o.value == value),
373
+ ),
374
+ },
348
375
  });
349
376
  }
350
377
  if (optionsApiEndPoint) {
@@ -357,13 +384,15 @@ export const SingleSelect = ({
357
384
  params: {
358
385
  limit,
359
386
  offset: 0,
360
- selectedValueData: value,
361
387
  dbValueProps: {
362
388
  ...dbValueProps,
363
389
  ...(dbValueProps.isObjectId && { isObjectId: true }),
390
+ selectedValueData: value,
391
+ },
392
+ dbLabelProps: {
393
+ search: searchValue,
394
+ ...dbLabelProps,
364
395
  },
365
- dbLabelProps,
366
- search: searchValue,
367
396
  ...optionsApiEndpointParams,
368
397
  },
369
398
  })
@@ -373,8 +402,14 @@ export const SingleSelect = ({
373
402
  dispatch({
374
403
  actionType: SingleSelectActionsTypes.SET_INTERNAL_OPTIONS,
375
404
  stateChanges: {
376
- internalOptions: options,
377
- internalOptionsMap: generateOptionsMap(options),
405
+ internalOptions: [
406
+ ...options,
407
+ ...internalOptions.filter((o: any) => o.value == value),
408
+ ],
409
+ internalOptionsMap: generateOptionsMap([
410
+ ...options,
411
+ ...internalOptions.filter((o: any) => o.value == value),
412
+ ]),
378
413
  },
379
414
  });
380
415
  } catch (e) {
@@ -397,11 +432,11 @@ export const SingleSelect = ({
397
432
  }, 300);
398
433
  }, [searchDb]);
399
434
 
400
- const handleSearch = async (
401
- e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
402
- ) => {
403
- const searchValue = e.target.value;
404
- debouncedSendRequest(searchValue);
435
+ const handleSearch = async (e: any) => {
436
+ if (e) {
437
+ const searchValue = e.target.value;
438
+ debouncedSendRequest(searchValue);
439
+ }
405
440
  };
406
441
 
407
442
  const loadSelectedOptions = async () => {
@@ -413,13 +448,13 @@ export const SingleSelect = ({
413
448
  params: {
414
449
  limit,
415
450
  offset,
416
- selectedValueData: value,
417
451
  dbValueProps: {
418
452
  ...dbValueProps,
419
453
  ...(dbValueProps.isObjectId && { isObjectId: true }),
454
+ selectedValueData: value,
455
+ filterBySelectedValues: true,
420
456
  },
421
457
  dbLabelProps,
422
- filterBySelectedValues: true,
423
458
  },
424
459
  });
425
460
  dispatch({
@@ -468,6 +503,7 @@ export const SingleSelect = ({
468
503
  onChange={(e, value) => {
469
504
  onChange(getValue ? getValue(value) : value?.value);
470
505
  }}
506
+ onInputCapture={handleSearch}
471
507
  open={open}
472
508
  autoFocus={true}
473
509
  filterOptions={(options, state) => {
@@ -511,7 +547,6 @@ export const SingleSelect = ({
511
547
  label={label}
512
548
  required={required}
513
549
  name={name}
514
- onChange={handleSearch}
515
550
  error={error}
516
551
  helperText={helperText}
517
552
  />