From 742d582d80e8e7392bd59c7555db1081103e8925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eva=20Mill=C3=A1n?= Date: Wed, 13 Dec 2023 12:03:21 +0100 Subject: [PATCH 1/2] [ui] Debounce organization selector API calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Limits the API calls made by the OrganizationSelector component by only executing them after 500 milliseconds after the last key press. It also adds a progress bar to the input to show when the list of organizations is loading. Signed-off-by: Eva Millán --- ui/src/components/OrganizationSelector.vue | 16 +++++- .../unit/__snapshots__/storybook.spec.js.snap | 52 +++++++++---------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/ui/src/components/OrganizationSelector.vue b/ui/src/components/OrganizationSelector.vue index 30698b67..b8515d2f 100644 --- a/ui/src/components/OrganizationSelector.vue +++ b/ui/src/components/OrganizationSelector.vue @@ -4,10 +4,12 @@ :items="organizations" :search-input.sync="search" :label="label" + :loading="isLoading" item-text="name" item-value="name" :no-data-text="`No matches for "${search}"`" - :hide-no-data="!search" + :hide-no-data="!search || isLoading" + cache-items clearable dense outlined @@ -33,6 +35,7 @@ export default { inputValue: this.value, organizations: [], search: this.value, + isLoading: false, }; }, props: { @@ -55,11 +58,19 @@ export default { }, }, methods: { + debounceSearch(searchValue) { + clearTimeout(this.timer); + + this.timer = setTimeout(() => { + this.getSelectorItems(searchValue); + }, 500); + }, async getSelectorItems(value) { const filters = value ? { term: value } : {}; const response = await this.fetchOrganizations(1, 10, filters); if (response) { this.organizations = response.entities; + this.isLoading = false; } }, async createOrganization() { @@ -89,7 +100,8 @@ export default { watch: { search(value) { if (value && value.length > 2) { - this.getSelectorItems(value); + this.isLoading = true; + this.debounceSearch(value); } }, value() { diff --git a/ui/tests/unit/__snapshots__/storybook.spec.js.snap b/ui/tests/unit/__snapshots__/storybook.spec.js.snap index 0f1012e9..c2b67cda 100644 --- a/ui/tests/unit/__snapshots__/storybook.spec.js.snap +++ b/ui/tests/unit/__snapshots__/storybook.spec.js.snap @@ -10563,13 +10563,13 @@ exports[`Storyshots OrganizationsTable Groups 1`] = ` > @@ -10729,13 +10729,13 @@ exports[`Storyshots OrganizationsTable Groups 1`] = ` > @@ -11020,13 +11020,13 @@ exports[`Storyshots OrganizationsTable Organizations 1`] = ` > @@ -11527,13 +11527,13 @@ exports[`Storyshots Search Filter Selector 1`] = ` > @@ -11624,13 +11624,13 @@ exports[`Storyshots Search Order Selector 1`] = ` > @@ -11693,7 +11693,7 @@ exports[`Storyshots Search Order Selector 1`] = ` @@ -12828,7 +12828,7 @@ exports[`Storyshots WorkSpace Drag And Drop 1`] = `