@7shifts/sous-chef 2.12.1 → 2.12.2
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.
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Props as SelectProps } from '../SelectField/SelectField';
|
|
2
2
|
import { AsyncSelectOptions } from './types';
|
|
3
3
|
declare type Props<T> = {
|
|
4
|
-
/** It is a function that takes the input search as parameter and returns a Promise with all the options and if there are more options to load. */
|
|
4
|
+
/** It is a function that takes the input search as parameter and returns a Promise with all the options and if there are more options to load. If it brings all the options on the first load, it won't call the `loadOptions` to perform the search. */
|
|
5
5
|
loadOptions: (inputValue: string) => Promise<AsyncSelectOptions<T>>;
|
|
6
|
+
/** It fires `loadOptions` again if this key value changes. Used when it depends on other fields to load its options */
|
|
7
|
+
key?: string | number;
|
|
6
8
|
} & Omit<SelectProps<T>, 'options'>;
|
|
7
9
|
/**
|
|
8
10
|
* Component to make possible choose from async options. It looks exactly as the [SelectField](./?path=/docs/forms-selectfield--default) but, this one handle asynchronous options.
|
package/dist/index.js
CHANGED
|
@@ -5293,14 +5293,55 @@ var AsyncSelectField = function AsyncSelectField(_ref) {
|
|
|
5293
5293
|
hasMoreOptionsFirstLoad = _useState2[0],
|
|
5294
5294
|
setHasMoreOptionsFirstLoad = _useState2[1];
|
|
5295
5295
|
|
|
5296
|
+
var _useState3 = React.useState(false),
|
|
5297
|
+
hasFirstLoadPerformed = _useState3[0],
|
|
5298
|
+
setHasFirstLoadPerformed = _useState3[1];
|
|
5299
|
+
|
|
5300
|
+
var _useState4 = React.useState(null),
|
|
5301
|
+
localOptions = _useState4[0],
|
|
5302
|
+
setLocalOptions = _useState4[1];
|
|
5303
|
+
|
|
5304
|
+
var ref = React.useRef(null);
|
|
5305
|
+
|
|
5306
|
+
var handleInternalSearch = function handleInternalSearch(inputValue, callback) {
|
|
5307
|
+
if (!localOptions) {
|
|
5308
|
+
return;
|
|
5309
|
+
}
|
|
5310
|
+
|
|
5311
|
+
var filteredOptions = localOptions.filter(function (option) {
|
|
5312
|
+
return option.label.toLowerCase().includes(inputValue.toLocaleLowerCase());
|
|
5313
|
+
});
|
|
5314
|
+
callback(filteredOptions);
|
|
5315
|
+
};
|
|
5316
|
+
|
|
5296
5317
|
var handleLoadOptions = function handleLoadOptions(inputValue, callback) {
|
|
5297
5318
|
if (hasMoreOptions) {
|
|
5298
5319
|
setHasMoreOptions(false);
|
|
5299
5320
|
}
|
|
5300
5321
|
|
|
5301
|
-
|
|
5322
|
+
if (localOptions) {
|
|
5323
|
+
handleInternalSearch(inputValue, callback);
|
|
5324
|
+
return;
|
|
5325
|
+
}
|
|
5326
|
+
|
|
5327
|
+
loadOptions(inputValue).then(function (_ref2) {
|
|
5328
|
+
var _ref$current;
|
|
5329
|
+
|
|
5302
5330
|
var hasMore = _ref2.hasMore,
|
|
5303
5331
|
options = _ref2.options;
|
|
5332
|
+
|
|
5333
|
+
if (ref.current && inputValue !== (ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current['state']['inputValue'])) {
|
|
5334
|
+
return;
|
|
5335
|
+
}
|
|
5336
|
+
|
|
5337
|
+
if (!hasFirstLoadPerformed) {
|
|
5338
|
+
setHasFirstLoadPerformed(true);
|
|
5339
|
+
|
|
5340
|
+
if (!hasMore) {
|
|
5341
|
+
setLocalOptions(options);
|
|
5342
|
+
}
|
|
5343
|
+
}
|
|
5344
|
+
|
|
5304
5345
|
setHasMoreOptions(hasMore);
|
|
5305
5346
|
|
|
5306
5347
|
if (hasMoreOptionsFirstLoad === undefined) {
|
|
@@ -5308,7 +5349,6 @@ var AsyncSelectField = function AsyncSelectField(_ref) {
|
|
|
5308
5349
|
}
|
|
5309
5350
|
|
|
5310
5351
|
callback(options);
|
|
5311
|
-
return options;
|
|
5312
5352
|
});
|
|
5313
5353
|
};
|
|
5314
5354
|
|
|
@@ -5332,9 +5372,9 @@ var AsyncSelectField = function AsyncSelectField(_ref) {
|
|
|
5332
5372
|
cacheOptions: false,
|
|
5333
5373
|
defaultOptions: true,
|
|
5334
5374
|
loadOptions: lodashEs.debounce(handleLoadOptions, 500, {
|
|
5335
|
-
leading: true
|
|
5336
|
-
|
|
5337
|
-
|
|
5375
|
+
leading: true
|
|
5376
|
+
}),
|
|
5377
|
+
ref: ref
|
|
5338
5378
|
}))));
|
|
5339
5379
|
};
|
|
5340
5380
|
|