Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALS-6863] [ALS-6994] Update select all options and allow searching options in result filter #121

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/lib/components/OptionsSelectionList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
const contentHeight = element.scrollHeight;
const scrollBuffer = 30;
const hasLoadedAll = !unselectedOptions || unselectedOptions.length === 0;
return !hasLoadedAll && contentHeight - (scrollTop + containerHeight) <= scrollBuffer;
return (
hasLoadedAll ||
(!hasLoadedAll && contentHeight - (scrollTop + containerHeight) <= scrollBuffer)
);
}

function handleScroll() {
Expand Down Expand Up @@ -54,7 +57,7 @@
}

function selectAllOptions() {
selectedOptions = unselectedOptions;
selectedOptions = [...selectedOptions, ...unselectedOptions];
unselectedOptions = [];
selectedOptionEndLocation = 20;
}
Expand Down Expand Up @@ -88,6 +91,7 @@
<button
id="select-all"
class="btn variant-ringed-surface hover:variant-filled-primary ml-2"
disabled={unselectedOptions.length === 0}
on:click={selectAllOptions}>Select All</button
>
{/if}
Expand Down
36 changes: 20 additions & 16 deletions src/lib/components/explorer/AddFilter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
let pageSize = 20;
let unselectedOptions: string[] = [];
let selectedOptions: string[] = [];
let startLoacation = 20;
let startLocation = 0;
let lastSearchTerm = '';
let loading = false;

onMount(async () => {
Expand All @@ -41,6 +42,9 @@
data?.values?.filter((value) => {
return !selectedOptions.find((selected) => selected === value);
}) || [];
if (unselectedOptions.length >= 50) {
unselectedOptions = unselectedOptions.slice(0, pageSize);
}
} else if (existingFilter.filterType === 'numeric') {
min = existingFilter.min || '';
max = existingFilter.max || '';
Expand Down Expand Up @@ -97,26 +101,26 @@

loading = true;
try {
let nextOptions: string[] = [];
let end = startLoacation + pageSize;
if (end > totalOptions) {
end = totalOptions;
let nextOptions = (data?.values || []).filter((option) => !selectedOptions.includes(option));
let endLocation = Math.min(startLocation + pageSize, totalOptions);

if (search !== lastSearchTerm || !lastSearchTerm.includes(search)) {
// new search
startLocation = 0;
endLocation = startLocation + pageSize;
unselectedOptions = [];
lastSearchTerm = search;
}

if (search) {
nextOptions =
data?.values
?.filter((value) => value.toLowerCase().includes(search.toLowerCase()))
.slice(startLoacation, end) || [];
startLoacation = end;
} else {
nextOptions = data?.values?.slice(startLoacation, end) || [];
startLoacation = end;
nextOptions = nextOptions.filter((value) =>
value.toLowerCase().includes(search.toLowerCase()),
);
}

if (nextOptions && Array.isArray(nextOptions) && nextOptions.length > 0) {
unselectedOptions = [...unselectedOptions, ...nextOptions];
}
nextOptions = nextOptions.slice(startLocation, endLocation);
unselectedOptions = [...unselectedOptions, ...nextOptions];
startLocation = endLocation;
} catch (error) {
console.error(error);
toastStore.trigger({
Expand Down
Loading