@campxdev/react-blueprint 1.3.2 → 1.3.4

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.2",
3
+ "version": "1.3.4",
4
4
  "main": "./export.ts",
5
5
  "private": false,
6
6
  "dependencies": {
@@ -42,6 +42,8 @@ export type SingleSelectProps = {
42
42
  dbValueProps?: {
43
43
  valueKey: string;
44
44
  isObjectId?: boolean;
45
+ isInt?: boolean;
46
+ isFloat?: boolean;
45
47
  };
46
48
  dbLabelProps?: { labelKey: string; subLabelKey?: string };
47
49
  onChange: (value: any) => void;
@@ -103,7 +105,11 @@ const singleSelectReducer = (
103
105
  return { ...state, open: true };
104
106
  }
105
107
  case SingleSelectActionsTypes.CLOSE: {
106
- return { ...state, open: false, loadingInternalOptions: false };
108
+ return {
109
+ ...state,
110
+ open: false,
111
+ loadingInternalOptions: false,
112
+ };
107
113
  }
108
114
  case SingleSelectActionsTypes.LOAD_INTERNAL_OPTIONS_START: {
109
115
  return { ...state, loadingInternalOptions: true };
@@ -121,15 +127,19 @@ const singleSelectReducer = (
121
127
  return { ...state, ...stateChanges };
122
128
  }
123
129
  case SingleSelectActionsTypes.SET_SEARCH: {
124
- return { ...state, search: stateChanges.search, hasMore: true };
130
+ return {
131
+ ...state,
132
+ search: stateChanges.search,
133
+ hasMore: true,
134
+ };
125
135
  }
126
136
  case SingleSelectActionsTypes.CLEAR_SEARCH: {
127
137
  return {
128
138
  ...state,
129
139
  search: null,
130
140
  offset: 0,
131
- internalOptions: [],
132
- internalOptionsMap: {},
141
+ internalOptions: stateChanges.internalOptions,
142
+ internalOptionsMap: stateChanges.internalOptionsMap,
133
143
  };
134
144
  }
135
145
  case SingleSelectActionsTypes.SET_INTERNAL_OPTIONS: {
@@ -180,6 +190,8 @@ export const SingleSelect = ({
180
190
  dbValueProps = {
181
191
  valueKey: 'id',
182
192
  isObjectId: false,
193
+ isInt: false,
194
+ isFloat: false,
183
195
  },
184
196
  dbLabelProps,
185
197
  onOpen,
@@ -285,6 +297,16 @@ export const SingleSelect = ({
285
297
  if (optionsApiEndPoint) {
286
298
  dispatch({
287
299
  actionType: SingleSelectActionsTypes.CLEAR_SEARCH,
300
+ stateChanges: {
301
+ internalOptions: internalOptions.filter((o: any) =>
302
+ reason != 'selectOption' ? o.value == value : o.value != value,
303
+ ),
304
+ internalOptionsMap: generateOptionsMap(
305
+ internalOptions.filter((o: any) =>
306
+ reason != 'selectOption' ? o.value == value : o.value != value,
307
+ ),
308
+ ),
309
+ },
288
310
  });
289
311
  }
290
312
  if (onClose) {
@@ -308,13 +330,18 @@ export const SingleSelect = ({
308
330
  params: {
309
331
  limit: limit,
310
332
  offset: offset + 10,
311
- search: search,
333
+
312
334
  dbValueProps: {
313
- ...dbValueProps,
335
+ valueKey: dbValueProps.valueKey,
314
336
  ...(dbValueProps.isObjectId && { isObjectId: true }),
337
+ ...(dbValueProps.isInt && { isInt: true }),
338
+ ...(dbValueProps.isFloat && { isFloat: true }),
315
339
  selectedValueData: value,
316
340
  },
317
- dbLabelProps,
341
+ dbLabelProps: {
342
+ search: search,
343
+ ...dbLabelProps,
344
+ },
318
345
  ...optionsApiEndpointParams,
319
346
  },
320
347
  })
@@ -345,6 +372,12 @@ export const SingleSelect = ({
345
372
  if (!searchValue || searchValue.trim() === '') {
346
373
  dispatch({
347
374
  actionType: SingleSelectActionsTypes.CLEAR_SEARCH,
375
+ stateChanges: {
376
+ internalOptions: internalOptions.filter((o: any) => o.value == value),
377
+ internalOptionsMap: generateOptionsMap(
378
+ internalOptions.filter((o: any) => o.value == value),
379
+ ),
380
+ },
348
381
  });
349
382
  }
350
383
  if (optionsApiEndPoint) {
@@ -358,12 +391,16 @@ export const SingleSelect = ({
358
391
  limit,
359
392
  offset: 0,
360
393
  dbValueProps: {
361
- ...dbValueProps,
394
+ valueKey: dbValueProps.valueKey,
362
395
  ...(dbValueProps.isObjectId && { isObjectId: true }),
396
+ ...(dbValueProps.isInt && { isInt: true }),
397
+ ...(dbValueProps.isFloat && { isFloat: true }),
363
398
  selectedValueData: value,
364
399
  },
365
- dbLabelProps,
366
- search: searchValue,
400
+ dbLabelProps: {
401
+ search: searchValue,
402
+ ...dbLabelProps,
403
+ },
367
404
  ...optionsApiEndpointParams,
368
405
  },
369
406
  })
@@ -373,8 +410,14 @@ export const SingleSelect = ({
373
410
  dispatch({
374
411
  actionType: SingleSelectActionsTypes.SET_INTERNAL_OPTIONS,
375
412
  stateChanges: {
376
- internalOptions: options,
377
- internalOptionsMap: generateOptionsMap(options),
413
+ internalOptions: [
414
+ ...options,
415
+ ...internalOptions.filter((o: any) => o.value == value),
416
+ ],
417
+ internalOptionsMap: generateOptionsMap([
418
+ ...options,
419
+ ...internalOptions.filter((o: any) => o.value == value),
420
+ ]),
378
421
  },
379
422
  });
380
423
  } catch (e) {
@@ -397,11 +440,11 @@ export const SingleSelect = ({
397
440
  }, 300);
398
441
  }, [searchDb]);
399
442
 
400
- const handleSearch = async (
401
- e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
402
- ) => {
403
- const searchValue = e.target.value;
404
- debouncedSendRequest(searchValue);
443
+ const handleSearch = async (e: any) => {
444
+ if (e) {
445
+ const searchValue = e.target.value;
446
+ debouncedSendRequest(searchValue);
447
+ }
405
448
  };
406
449
 
407
450
  const loadSelectedOptions = async () => {
@@ -414,8 +457,10 @@ export const SingleSelect = ({
414
457
  limit,
415
458
  offset,
416
459
  dbValueProps: {
417
- ...dbValueProps,
460
+ valueKey: dbValueProps.valueKey,
418
461
  ...(dbValueProps.isObjectId && { isObjectId: true }),
462
+ ...(dbValueProps.isInt && { isInt: true }),
463
+ ...(dbValueProps.isFloat && { isFloat: true }),
419
464
  selectedValueData: value,
420
465
  filterBySelectedValues: true,
421
466
  },
@@ -468,6 +513,7 @@ export const SingleSelect = ({
468
513
  onChange={(e, value) => {
469
514
  onChange(getValue ? getValue(value) : value?.value);
470
515
  }}
516
+ onInputCapture={handleSearch}
471
517
  open={open}
472
518
  autoFocus={true}
473
519
  filterOptions={(options, state) => {
@@ -511,7 +557,6 @@ export const SingleSelect = ({
511
557
  label={label}
512
558
  required={required}
513
559
  name={name}
514
- onChange={handleSearch}
515
560
  error={error}
516
561
  helperText={helperText}
517
562
  />