preserve records pagination on delete/update and fix reactivity regression

This commit is contained in:
Gani Georgiev
2022-10-04 22:42:51 +03:00
parent 838ed661ce
commit 32393990bb
13 changed files with 152 additions and 142 deletions
+2 -2
View File
@@ -148,6 +148,6 @@
<RecordUpsertPanel
bind:this={recordPanel}
collection={$activeCollection}
on:save={() => recordsList?.load()}
on:delete={() => recordsList?.load()}
on:save={() => recordsList?.reloadLoadedPages()}
on:delete={() => recordsList?.reloadLoadedPages()}
/>
@@ -39,19 +39,19 @@
</span>
{:else if field.type === "select"}
<div class="inline-flex">
{#each CommonHelper.toArray(record[field.name]) as item}
{#each CommonHelper.toArray(record[field.name]) as item, i (i + item)}
<span class="label">{item}</span>
{/each}
</div>
{:else if field.type === "relation" || field.type === "user"}
<div class="inline-flex">
{#each CommonHelper.toArray(record[field.name]) as item}
{#each CommonHelper.toArray(record[field.name]) as item, i (i + item)}
<IdLabel id={item} />
{/each}
</div>
{:else if field.type === "file"}
<div class="inline-flex">
{#each CommonHelper.toArray(record[field.name]) as filename}
{#each CommonHelper.toArray(record[field.name]) as filename, i (i + filename)}
<figure class="thumb thumb-sm">
<RecordFilePreview {record} {filename} />
</figure>
+11 -1
View File
@@ -39,6 +39,16 @@
$: areAllRecordsSelected = records.length && totalBulkSelected === records.length;
export async function reloadLoadedPages() {
const loadedPages = currentPage;
for (let i = 1; i <= loadedPages; i++) {
if (i === 1 || canLoadMore) {
await load(i);
}
}
}
export async function load(page = 1) {
if (!collection?.id) {
return;
@@ -143,7 +153,7 @@
isDeleting = false;
// always reload because some of the records may not be deletable
return load();
return reloadLoadedPages();
});
}
</script>