Skip to content

Commit 0167911

Browse files
authored
Merge pull request #20452 from davelopez/25.0_fix_pagination_state_in_files_dialog
[25.0] Fix pagination state in FilesDialog
2 parents 47bfa87 + 4eab348 commit 0167911

File tree

3 files changed

+56
-32
lines changed

3 files changed

+56
-32
lines changed

client/src/components/DataDialog/utilities.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@ export class UrlTracker {
66
}
77

88
/** Returns urls for data drilling **/
9-
getUrl(url) {
9+
getUrl(url, returnWithPrevious = false) {
10+
let previous = undefined;
1011
if (url) {
1112
this.navigation.push(url);
1213
} else {
13-
this.navigation.pop();
14+
previous = this.navigation.pop();
1415
const navigationLength = this.navigation.length;
1516
if (navigationLength > 0) {
1617
url = this.navigation[navigationLength - 1];
1718
} else {
1819
url = this.root;
1920
}
2021
}
21-
return url;
22+
23+
if (returnWithPrevious) {
24+
return { url, popped: previous };
25+
} else {
26+
return url;
27+
}
2228
}
2329

2430
/** Returns true if the last data is at navigation root **/

client/src/components/FilesDialog/FilesDialog.vue

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { faPlus } from "@fortawesome/free-solid-svg-icons";
33
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
44
import { BAlert } from "bootstrap-vue";
5-
import Vue, { computed, onMounted, ref } from "vue";
5+
import Vue, { computed, onMounted, ref, watch } from "vue";
66
77
import {
88
browseRemoteFiles,
@@ -70,6 +70,8 @@ const { config, isConfigLoaded } = useConfig();
7070
7171
const selectionModel = ref<Model>(new Model({ multiple: props.multiple }));
7272
73+
const query = ref<string>();
74+
const selectionDialog = ref();
7375
const allSelected = ref(false);
7476
const selectedDirectories = ref<SelectionItem[]>([]);
7577
const errorMessage = ref<string>();
@@ -249,13 +251,14 @@ function checkIfAllSelected(): boolean {
249251
}
250252
251253
function open(record: SelectionItem) {
252-
load(record);
254+
currentDirectory.value = urlTracker.value.getUrl({ ...record, parentPage: selectionDialog.value.currentPage });
255+
selectionDialog.value?.resetPagination(1);
256+
load();
253257
}
254258
255259
/** Performs server request to retrieve data records **/
256-
function load(record?: SelectionItem) {
257-
currentDirectory.value = urlTracker.value.getUrl(record);
258-
showFTPHelper.value = record?.url === "gxftp://";
260+
function load() {
261+
showFTPHelper.value = currentDirectory.value?.url === "gxftp://";
259262
filter.value = undefined;
260263
optionsShow.value = false;
261264
undoShow.value = !urlTracker.value.atRoot();
@@ -353,8 +356,8 @@ async function provideItems(ctx: ItemsProviderContext, url?: string): Promise<Se
353356
}
354357
const limit = ctx.perPage;
355358
const offset = (ctx.currentPage ? ctx.currentPage - 1 : 0) * ctx.perPage;
356-
const query = ctx.filter;
357-
const response = await browseRemoteFiles(url, false, props.requireWritable, limit, offset, query);
359+
query.value = ctx.filter;
360+
const response = await browseRemoteFiles(url, false, props.requireWritable, limit, offset, query.value);
358361
const result = response.entries.map(entryToRecord);
359362
totalItems.value = response.totalMatches;
360363
items.value = result;
@@ -437,21 +440,38 @@ function pushToPropRouter(route: string) {
437440
}
438441
}
439442
443+
function onGoBack(record?: SelectionItem) {
444+
const res = urlTracker.value.getUrl(record, true);
445+
446+
currentDirectory.value = res.url;
447+
448+
load();
449+
450+
if (res?.popped) {
451+
selectionDialog.value?.resetPagination(res?.popped.parentPage);
452+
}
453+
}
454+
455+
watch(query, () => {
456+
selectionDialog.value?.resetPagination(1);
457+
});
458+
440459
onMounted(() => {
441-
load(props.selectedItem);
460+
currentDirectory.value = urlTracker.value.getUrl(props.selectedItem);
461+
load();
442462
});
443463
</script>
444464

445465
<template>
446466
<SelectionDialog
467+
ref="selectionDialog"
447468
:disable-ok="okButtonDisabled"
448469
:error-message="errorMessage"
449470
:file-mode="fileMode"
450471
:fields="fields"
451472
:is-busy="isBusy"
452473
:items="items"
453474
:items-provider="itemsProvider"
454-
:provider-url="currentDirectory?.url"
455475
:total-items="totalItems"
456476
:modal-show="modalShow"
457477
:modal-static="modalStatic"
@@ -460,12 +480,13 @@ onMounted(() => {
460480
:select-all-variant="selectAllIcon"
461481
:show-select-icon="undoShow && multiple"
462482
:undo-show="undoShow"
483+
:watch-on-page-changes="false"
463484
@onCancel="() => (modalShow = false)"
464485
@onClick="clicked"
465486
@onOk="onOk"
466487
@onOpen="open"
467488
@onSelectAll="onSelectAll"
468-
@onUndo="load()">
489+
@onUndo="onGoBack">
469490
<template v-slot:helper>
470491
<BAlert v-if="showFTPHelper && isConfigLoaded" id="helper" variant="info" show>
471492
This Galaxy server allows you to upload files via FTP. To upload some files, log in to the FTP server at

client/src/components/SelectionDialog/SelectionDialog.vue

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface Props {
4545
searchTitle?: string;
4646
okButtonText?: string;
4747
filterClass?: Filtering<any>;
48+
watchOnPageChanges?: boolean;
4849
}
4950
5051
const props = withDefaults(defineProps<Props>(), {
@@ -71,6 +72,7 @@ const props = withDefaults(defineProps<Props>(), {
7172
searchTitle: undefined,
7273
okButtonText: "Select",
7374
filterClass: undefined,
75+
watchOnPageChanges: true,
7476
});
7577
7678
const emit = defineEmits<{
@@ -143,31 +145,26 @@ function resetFilter() {
143145
filter.value = "";
144146
}
145147
146-
function resetPagination() {
147-
currentPage.value = 1;
148+
function resetPagination(toInitialPage = 1) {
149+
currentPage.value = toInitialPage;
150+
}
151+
152+
if (props.watchOnPageChanges) {
153+
watch(
154+
() => props.items,
155+
() => {
156+
if (props.itemsProvider === undefined) {
157+
resetPagination();
158+
}
159+
}
160+
);
148161
}
149162
150163
defineExpose({
151164
resetFilter,
152165
resetPagination,
166+
currentPage,
153167
});
154-
155-
watch(
156-
() => props.items,
157-
() => {
158-
filtered(props.items);
159-
}
160-
);
161-
162-
watch(
163-
() => props.providerUrl,
164-
() => {
165-
// We need to reset the current page when drilling down sub-folders
166-
if (props.itemsProvider !== undefined) {
167-
resetPagination();
168-
}
169-
}
170-
);
171168
</script>
172169

173170
<template>

0 commit comments

Comments
 (0)