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

[gui] Remember filters when navigate between pages #2913

Merged
merged 1 commit into from
Sep 9, 2020
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
5 changes: 4 additions & 1 deletion web/server/vue-cli/src/components/Layout/TheHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
:key="item.name"
:to="{
name: item.route,
query: item.query || {}
query: queries[item.route] === undefined
? item.query || {}
: queries[item.route]
}"
:class="item.active.includes($route.name) &&
'v-btn--active router-link-active'"
Expand Down Expand Up @@ -165,6 +167,7 @@ export default {

computed: {
...mapGetters([
"queries",
"authParams",
"isAuthenticated",
"announcement",
Expand Down
32 changes: 30 additions & 2 deletions web/server/vue-cli/src/components/Run/RunNameColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
<v-list-item-content>
<v-list-item-title>
<router-link
:to="{ name: 'reports', query: reportFilterQuery }"
:to="{ name: 'reports',
query: {
...(queries['reports'] === undefined
? defaultReportFilterValues
: queries['reports']),
...reportFilterQuery
}
}"
class="name mr-2"
>
{{ name }}
Expand Down Expand Up @@ -53,7 +60,13 @@
</v-btn>

<v-btn
:to="{ name: 'statistics', query: statisticsFilterQuery }"
:to="{ name: 'statistics',
query: {
...(queries['statistics'] === undefined
? defaultStatisticsFilterValues
: queries['statistics']),
...statisticsFilterQuery
} }"
class="show-statistics"
title="Show statistics"
color="green"
Expand Down Expand Up @@ -108,8 +121,12 @@
</template>

<script>
import { mapGetters } from "vuex";
import { RunDescription } from "@/components/Run";

import { defaultReportFilterValues } from "@/components/Report/ReportFilter";
import { defaultStatisticsFilterValues } from "@/components/Statistics";

import { DetectionStatusMixin, StrToColorMixin } from "@/mixins";
import { DetectionStatusIcon } from "@/components/Icons";

Expand All @@ -130,6 +147,17 @@ export default {
openCheckCommandDialog: { type: Function, default: () => {} },
reportFilterQuery: { type: Object, default: () => {} },
statisticsFilterQuery: { type: Object, default: () => {} },
},
data() {
return {
defaultReportFilterValues,
defaultStatisticsFilterValues
};
},
computed: {
...mapGetters([
"queries"
])
}
};
</script>
Expand Down
8 changes: 8 additions & 0 deletions web/server/vue-cli/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
GET_CURRENT_PRODUCT,
GET_CURRENT_PRODUCT_CONFIG
} from "@/store/actions.type";
import { CLEAR_QUERIES, SET_QUERIES } from "@/store/mutations.type";
import convertOldUrlToNew from "./router/backward-compatible-url";

import router from "./router";
Expand Down Expand Up @@ -84,6 +85,13 @@ router.beforeResolve((to, from, next) => {
});
});

router.afterEach(to => {
if (to.name === "products")
store.commit(CLEAR_QUERIES, { except: [ "products" ] });

store.commit(SET_QUERIES, { location: to.name, query: to.query });
});

new Vue({
router,
store,
Expand Down
4 changes: 3 additions & 1 deletion web/server/vue-cli/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import config from "./modules/config";
import error from "./modules/error";
import product from "./modules/product";
import serverInfo from "./modules/server-info";
import url from "./modules/url";

import report from "./modules/report";
import statistics from "./modules/statistics";
Expand All @@ -20,6 +21,7 @@ export default new Vuex.Store({
product,
report,
statistics,
serverInfo
serverInfo,
url
}
});
34 changes: 34 additions & 0 deletions web/server/vue-cli/src/store/modules/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CLEAR_QUERIES, SET_QUERIES } from "../mutations.type";

const state = {
queries: {}
};

const getters = {
queries(state) {
return state.queries;
}
};

const mutations = {
[CLEAR_QUERIES](state, { except }) {
if (except) {
Object.keys(state.queries).forEach(key => {
if (!except.includes(key))
delete state.queries[key];
});
} else {
state.queries = {};
}
},

[SET_QUERIES](state, { location, query }) {
state.queries[location] = query;
}
};

export default {
state,
mutations,
getters
};
3 changes: 3 additions & 0 deletions web/server/vue-cli/src/store/mutations.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ export const SET_ANNOUNCEMENT = "setAnnouncement";

export const ADD_ERROR = "addError";
export const CLEAR_ERRORS = "clearErrors";

export const CLEAR_QUERIES = "clearQueries";
export const SET_QUERIES = "setQueries";
4 changes: 1 addition & 3 deletions web/server/vue-cli/src/views/ProductDetail.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<template>
<v-container id="product" fluid>
<keep-alive>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is keep-alive removed? the router-view must be re-rendered now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use keep-alive, it will caches the components states. It should be handled properly, when a cached component is showed but something is changed in the URL. It was easier to remove it and initialize it properly when the component is mounted again.

<router-view />
</keep-alive>
<router-view />
</v-container>
</template>

Expand Down
9 changes: 2 additions & 7 deletions web/server/vue-cli/src/views/RunHistoryList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@
import _ from "lodash";
import { format, max, min, parse } from "date-fns";

import { defaultReportFilterValues } from "@/components/Report/ReportFilter";
import { defaultStatisticsFilterValues } from "@/components/Statistics";

import {
AnalyzerStatisticsBtn,
AnalyzerStatisticsDialog,
Expand Down Expand Up @@ -517,16 +514,14 @@ export default {
return {
run: history.runName,
"run-tag": history.versionTag || undefined,
"detected-before": history.versionTag ? undefined : history.time,
...defaultReportFilterValues
"detected-before": history.versionTag ? undefined : history.time

};
},

getStatisticsFilterQuery(history) {
return {
run: history.runName,
...defaultStatisticsFilterValues
run: history.runName
};
}
}
Expand Down
9 changes: 2 additions & 7 deletions web/server/vue-cli/src/views/RunList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@
<script>
import _ from "lodash";

import { defaultReportFilterValues } from "@/components/Report/ReportFilter";
import { defaultStatisticsFilterValues } from "@/components/Statistics";

import {
AnalyzerStatisticsBtn,
AnalyzerStatisticsDialog,
Expand Down Expand Up @@ -446,16 +443,14 @@ export default {

getReportFilterQuery(run) {
return {
run: run.name,
...defaultReportFilterValues
run: run.name

};
},

getStatisticsFilterQuery(run) {
return {
run: run.name,
...defaultStatisticsFilterValues
run: run.name
};
}
}
Expand Down