Skip to content

Commit 2b3cd7a

Browse files
authored
Merge pull request #2325 from appwrite/fix-filter-pagination
2 parents 543325a + dd37f64 commit 2b3cd7a

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/lib/components/filters/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function initQueries(initialValue = new Map<TagValue, string>()) {
6363
const currentLocation = window.location.pathname;
6464

6565
if (usableQueries.size) {
66-
const queryParam = mapToQueryParams(get(queries));
66+
const queryParam = mapToQueryParams(usableQueries);
6767
goto(`${currentLocation}?query=${queryParam}`, { noScroll: true });
6868
} else {
6969
goto(currentLocation, { noScroll: true });

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/+page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const load: PageLoad = async ({ params, depends, url, route, parent }) =>
3030
view,
3131
query,
3232
currentSort,
33+
parsedQueries,
3334
rows: await sdk.forProject(params.region, params.project).tablesDB.listRows({
3435
databaseId: params.database,
3536
tableId: params.table,

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import { hash } from '$lib/helpers/string';
8888
import { formatNumberWithCommas } from '$lib/helpers/numbers';
8989
import { chunks } from '$lib/helpers/array';
90+
import { mapToQueryParams } from '$lib/components/filters/store';
9091
9192
export let data: PageData;
9293
export let showRowCreateSheet: {
@@ -308,26 +309,31 @@
308309
309310
async function sort(query: string | null) {
310311
$spreadsheetLoading = true;
311-
312312
const url = new URL(page.url);
313+
const parsedQueries = data.parsedQueries;
314+
315+
if (parsedQueries.size > 0) {
316+
for (const [tagValue, queryString] of parsedQueries.entries()) {
317+
if (queryString.includes('orderAsc') || queryString.includes('orderDesc')) {
318+
parsedQueries.delete(tagValue);
319+
}
320+
}
321+
}
322+
323+
if (query !== null) {
324+
const { attribute, method } = JSON.parse(query);
325+
const tagValue = {
326+
tag: `${attribute} ${method}`,
327+
value: attribute
328+
};
313329
314-
if (query === null) {
330+
parsedQueries.set(tagValue, query);
331+
}
332+
333+
if (parsedQueries.size === 0) {
315334
url.searchParams.delete('query');
316335
} else {
317-
// compatible with `load` func!
318-
const { attribute, method } = JSON.parse(query);
319-
url.searchParams.set(
320-
'query',
321-
JSON.stringify([
322-
[
323-
{
324-
tag: `${attribute} ${method}`,
325-
value: attribute
326-
},
327-
query
328-
]
329-
])
330-
);
336+
url.searchParams.set('query', mapToQueryParams(parsedQueries));
331337
}
332338
333339
// save > navigate > restore!
@@ -611,6 +617,9 @@
611617
return false;
612618
}
613619
620+
const parsedQueries = data.parsedQueries;
621+
const filterQueries = parsedQueries.size ? data.parsedQueries.values() : [];
622+
614623
$paginatedRowsLoading = true;
615624
const loadedRows = await sdk
616625
.forProject(page.params.region, page.params.project)
@@ -621,6 +630,7 @@
621630
getCorrectOrderQuery(),
622631
Query.limit(SPREADSHEET_PAGE_LIMIT),
623632
Query.offset(pageToOffset(pageNumber, SPREADSHEET_PAGE_LIMIT)),
633+
...filterQueries /* filter queries */,
624634
...buildWildcardColumnsQuery($table)
625635
]
626636
});

0 commit comments

Comments
 (0)