Skip to content

Commit

Permalink
fix(ESSNTL-3730): Add delay before fetching groups again
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarat authored May 15, 2023
1 parent 5e04fc5 commit 8a91305
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/components/InventoryGroups/Modals/ModalSchemas/schemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import componentTypes from '@data-driven-forms/react-form-renderer/component-typ
import { nameValidator } from '../../helpers/validate';
import { Text } from '@patternfly/react-core';
import { getGroups } from '../../utils/api';
import awesomeDebouncePromise from 'awesome-debounce-promise';

export const createGroupSchema = (namePresenceValidator) => ({
fields: [
Expand Down Expand Up @@ -71,20 +72,21 @@ export const addHostSchema = (systemName) => ({
isRequired: true,
isClearable: true,
placeholder: 'Type or click to select a group',
loadOptions: (searchValue = '') =>
getGroups().then(({ results = [] }) => {
return results.reduce((acc, { name, id }) => {
if (name.toLowerCase().includes(searchValue.trim().toLowerCase())) {
return [
...acc,
{
label: name,
value: { name, id }
}
];
}
}, []);
}),
loadOptions: async (searchValue = '') => {
// add a slight delay for scenarios when a new group has been just created
const data = await awesomeDebouncePromise(getGroups, 500)();
return (data?.results || []).reduce((acc, { name, id }) => {
if (name.toLowerCase().includes(searchValue.trim().toLowerCase())) {
return [
...acc,
{
label: name,
value: { name, id }
}
];
}
}, []);
},
validate: [{ type: validatorTypes.REQUIRED }]
},
{
Expand Down

0 comments on commit 8a91305

Please sign in to comment.