Skip to content

Commit c4b2a89

Browse files
committed
Update task-by-name.js
1 parent 125c91b commit c4b2a89

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

frontend/src/task-by-name/task-by-name.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ module.exports = app => app.component('task-by-name', {
4242
page: 1,
4343
pageSize: 50,
4444
numDocs: 0,
45-
pageSizeOptions: PAGE_SIZE_OPTIONS
45+
pageSizeOptions: PAGE_SIZE_OPTIONS,
46+
_loadId: 0
4647
}),
4748
computed: {
4849
taskName() {
@@ -73,6 +74,12 @@ module.exports = app => app.component('task-by-name', {
7374
if (dateRange && DATE_FILTER_VALUES.includes(dateRange) && this.selectedRange !== dateRange) {
7475
this.selectedRange = dateRange;
7576
}
77+
const effectiveDateRange = (dateRange && DATE_FILTER_VALUES.includes(dateRange)) ? dateRange : (this.selectedRange || 'last_hour');
78+
const effectiveStatus = query.status ?? '';
79+
const key = `${effectiveDateRange}|${effectiveStatus}`;
80+
if (this._lastQueryFilters === key) return;
81+
this.page = 1;
82+
this.loadTasks();
7683
},
7784
deep: true
7885
}
@@ -98,6 +105,7 @@ module.exports = app => app.component('task-by-name', {
98105
},
99106
async loadTasks() {
100107
if (!this.taskName) return;
108+
const loadId = ++this._loadId;
101109
this.status = 'init';
102110
this.taskGroup = null;
103111
this.errorMessage = '';
@@ -119,13 +127,16 @@ module.exports = app => app.component('task-by-name', {
119127
};
120128
const statusFromQuery = this.$route.query.status;
121129
if (statusFromQuery) params.status = statusFromQuery;
130+
this._lastQueryFilters = `${dateRange}|${statusFromQuery ?? ''}`;
122131
try {
123132
const { tasks, numDocs } = await api.Task.getTasks(params);
133+
if (loadId !== this._loadId) return;
124134
this.numDocs = numDocs ?? tasks.length;
125135
this.taskGroup = buildTaskGroup(this.taskName, tasks);
126136
this.taskGroup.totalCount = this.numDocs;
127137
this.status = 'loaded';
128138
} catch (err) {
139+
if (loadId !== this._loadId) return;
129140
this.status = 'error';
130141
this.errorMessage = err?.response?.data?.message || err.message || 'Failed to load tasks';
131142
}

0 commit comments

Comments
 (0)