Reset Dataset page to 0 when samples change (#9093)

* checkout

* format

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Abubakar Abid 2024-08-12 15:12:55 -07:00 committed by GitHub
parent 6e641e2133
commit 60650d84b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/dataset": patch
"gradio": patch
---
fix:Reset `Dataset` page to 0 when samples change

View File

@ -14,6 +14,7 @@
export let label = "Examples";
export let headers: string[];
export let samples: any[][] | null = null;
let old_samples: any[][] | null = null;
export let sample_labels: string[] | null = null;
export let elem_id = "";
export let elem_classes: string[] = [];
@ -35,6 +36,7 @@
? `/proxy=${proxy_url}file=`
: `${root}/file=`;
let page = 0;
$: gallery = components.length < 2 || sample_labels !== null;
let paginate = samples ? samples.length > samples_per_page : false;
@ -58,6 +60,10 @@
} else if (!samples) {
samples = [];
}
if (samples !== old_samples) {
page = 0;
old_samples = samples;
}
paginate = samples.length > samples_per_page;
if (paginate) {
visible_pages = [];