@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.
@@ -5288,14 +5288,55 @@ var AsyncSelectField = function AsyncSelectField(_ref) {
5288
5288
  hasMoreOptionsFirstLoad = _useState2[0],
5289
5289
  setHasMoreOptionsFirstLoad = _useState2[1];
5290
5290
 
5291
+ var _useState3 = useState(false),
5292
+ hasFirstLoadPerformed = _useState3[0],
5293
+ setHasFirstLoadPerformed = _useState3[1];
5294
+
5295
+ var _useState4 = useState(null),
5296
+ localOptions = _useState4[0],
5297
+ setLocalOptions = _useState4[1];
5298
+
5299
+ var ref = useRef(null);
5300
+
5301
+ var handleInternalSearch = function handleInternalSearch(inputValue, callback) {
5302
+ if (!localOptions) {
5303
+ return;
5304
+ }
5305
+
5306
+ var filteredOptions = localOptions.filter(function (option) {
5307
+ return option.label.toLowerCase().includes(inputValue.toLocaleLowerCase());
5308
+ });
5309
+ callback(filteredOptions);
5310
+ };
5311
+
5291
5312
  var handleLoadOptions = function handleLoadOptions(inputValue, callback) {
5292
5313
  if (hasMoreOptions) {
5293
5314
  setHasMoreOptions(false);
5294
5315
  }
5295
5316
 
5296
- return loadOptions(inputValue).then(function (_ref2) {
5317
+ if (localOptions) {
5318
+ handleInternalSearch(inputValue, callback);
5319
+ return;
5320
+ }
5321
+
5322
+ loadOptions(inputValue).then(function (_ref2) {
5323
+ var _ref$current;
5324
+
5297
5325
  var hasMore = _ref2.hasMore,
5298
5326
  options = _ref2.options;
5327
+
5328
+ 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'])) {
5329
+ return;
5330
+ }
5331
+
5332
+ if (!hasFirstLoadPerformed) {
5333
+ setHasFirstLoadPerformed(true);
5334
+
5335
+ if (!hasMore) {
5336
+ setLocalOptions(options);
5337
+ }
5338
+ }
5339
+
5299
5340
  setHasMoreOptions(hasMore);
5300
5341
 
5301
5342
  if (hasMoreOptionsFirstLoad === undefined) {
@@ -5303,7 +5344,6 @@ var AsyncSelectField = function AsyncSelectField(_ref) {
5303
5344
  }
5304
5345
 
5305
5346
  callback(options);
5306
- return options;
5307
5347
  });
5308
5348
  };
5309
5349
 
@@ -5327,9 +5367,9 @@ var AsyncSelectField = function AsyncSelectField(_ref) {
5327
5367
  cacheOptions: false,
5328
5368
  defaultOptions: true,
5329
5369
  loadOptions: debounce(handleLoadOptions, 500, {
5330
- leading: true,
5331
- trailing: false
5332
- })
5370
+ leading: true
5371
+ }),
5372
+ ref: ref
5333
5373
  }))));
5334
5374
  };
5335
5375