Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(frontend): search parameters adjustments pt.2 #297

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions web/src/Components/HistoryTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,20 @@ function HistoryTasks() {
);

const updateSearchParameters = (start, end, application, page) => {
application ?
setSearchParams({
app: application ?? '',
start: Math.floor(start.getTime() / 1000),
end: Math.floor(end.getTime() / 1000),
page,
})
:
setSearchParams({
start: Math.floor(start.getTime() / 1000),
end: Math.floor(end.getTime() / 1000),
page,
});
const params = {
start: Math.floor(start.getTime() / 1000),
end: Math.floor(end.getTime() / 1000),
};

if (application) {
params.app = application;
}

if (page !== 1) {
params.page = page;
}

setSearchParams(params);
};

const refreshWithFilters = (start, end, application, page) => {
Expand Down
21 changes: 10 additions & 11 deletions web/src/Components/RecentTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,24 @@ function RecentTasks() {
);

const updateSearchParameters = (application, page) => {
application ?
setSearchParams({
app: application,
page,
})
:
setSearchParams({
page,
});
const params = {};
if (application) {
params.app = application;
}
if (page !== 1) {
params.page = page;
}
setSearchParams(params);
};

// Initial load
useEffect(() => {
// If the application has been changed or the timeframe has been changed, a new tasks fetching action is executed
refreshTasksInTimeframe(currentTimeframe, currentApplication);
// Current page is reset to the first one
setCurrentPage(1);
const initialPage = searchParams.get('page') ? Number(searchParams.get('page')) : 1;
// Save search parameters - application name and auto-refresh interval - to Local Storage for preservation across sessions
updateSearchParameters(currentApplication, currentPage);
updateSearchParameters(currentApplication, initialPage);
}, []);

useEffect(() => {
Expand Down
Loading