Skip to content

Commit 68e1cd3

Browse files
committed
add change on preset detection, fix diff-type wrong load content
1 parent e2f8db5 commit 68e1cd3

4 files changed

Lines changed: 82 additions & 10 deletions

File tree

166 Bytes
Binary file not shown.
Binary file not shown.

web/server/vue-cli/src/components/Report/ReportFilter/Filters/PresetMenu.vue

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<v-select
3+
v-model="activePresetId"
34
clearable
45
:items="presets"
56
item-text="name"
@@ -10,6 +11,12 @@
1011
@focus="fetchPresets"
1112
@click:clear="handleClear"
1213
>
14+
<template #selection="{ item }">
15+
<span :class="{ 'preset-modified': isModified }">
16+
{{ item.name }}<template v-if="isModified"> *</template>
17+
</span>
18+
</template>
19+
1320
<template #item="{ item }">
1421
<v-list-item-content
1522
@click="applyPreset(item.id)"
@@ -40,22 +47,22 @@
4047
</template>
4148

4249
<script>
50+
import isEqual from "lodash/isEqual";
4351
import {
4452
authService,
4553
ccService,
4654
handleThriftError,
4755
prodService } from "@cc-api";
4856
import { Permission } from "@cc/shared-types";
4957
50-
// import { is } froAEm "core-js/core/object";
51-
// import { ccService, handleThriftError } from "@cc-api";
52-
5358
5459
export default {
5560
name: "PresetMenu",
5661
57-
props: {
62+
expose : [ "onPresetApplied", "clearPresetState" ],
5863
64+
props: {
65+
namespace: { type: String, required: true },
5966
},
6067
6168
data() {
@@ -68,16 +75,43 @@ export default {
6875
error: null,
6976
isSuperUser: false,
7077
isAdminOfAnyProduct: false,
78+
activePresetId: null,
79+
querySnapshot: null,
80+
isModified: false,
7181
};
7282
},
7383
7484
computed: {
7585
canSeeActions() {
7686
return this.isSuperUser || this.isAdminOfAnyProduct;
77-
}
87+
},
7888
},
7989
8090
watch: {
91+
"$route.query": {
92+
handler(newQuery) {
93+
if (!this.activePresetId || !this.querySnapshot) {
94+
this.isModified = false;
95+
return;
96+
}
97+
const normalize = q => {
98+
const sorted = {};
99+
for (const k of Object.keys(q).sort()) {
100+
const v = q[k];
101+
if (Array.isArray(v)) {
102+
sorted[ k ] = v.length === 1 ? v[ 0 ] : [ ...v ].sort();
103+
} else {
104+
sorted[k] = v;
105+
}
106+
}
107+
return sorted;
108+
};
109+
const normNew = normalize(newQuery);
110+
const normSnap = normalize(this.querySnapshot);
111+
this.isModified = !isEqual(normNew, normSnap);
112+
},
113+
deep: true,
114+
},
81115
},
82116
83117
created() {
@@ -133,7 +167,9 @@ export default {
133167
async applyPreset(id) {
134168
this.error = null;
135169
this.applyingId = id;
170+
this.querySnapshot = null;
136171
try {
172+
this.activePresetId = id;
137173
this.$emit("apply-preset", id);
138174
} catch (e) {
139175
this.error = (e && e.message) ? e.message : "Failed to apply preset";
@@ -142,6 +178,17 @@ export default {
142178
}
143179
},
144180
181+
onPresetApplied(settledQuery) {
182+
this.querySnapshot = settledQuery
183+
? { ...settledQuery }
184+
: { ...this.$route.query };
185+
},
186+
187+
clearPresetState() {
188+
this.activePresetId = null;
189+
this.querySnapshot = null;
190+
},
191+
145192
async deletePreset(id) {
146193
this.error = null;
147194
this.deletingId = id;
@@ -155,6 +202,10 @@ export default {
155202
});
156203
157204
this.presets = this.presets.filter(p => p.id !== id);
205+
206+
if (this.activePresetId === id) {
207+
this.clearPresetState();
208+
}
158209
} catch (e) {
159210
this.error = (e && e.message) ? e.message : "Failed to delete preset";
160211
} finally {
@@ -163,8 +214,16 @@ export default {
163214
},
164215
165216
handleClear() {
217+
this.clearPresetState();
166218
this.$emit("clear-preset");
167219
},
168220
},
169221
};
170-
</script>
222+
</script>
223+
224+
<style scoped>
225+
.preset-modified {
226+
color: orange;
227+
font-weight: bold;
228+
}
229+
</style>

web/server/vue-cli/src/components/Report/ReportFilter/ReportFilter.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ export default {
465465
activeDatePanelId: 0,
466466
open_preset_save: false,
467467
presetName: "",
468-
currentlyAppliedPreset: null,
469468
isSuperUser: false,
470469
isAdminOfAnyProduct: false,
471470
};
@@ -581,7 +580,7 @@ export default {
581580
});
582581
583582
// If all filters are initalized call a post function.
584-
Promise.all(results).then(() => {
583+
return Promise.all(results).then(() => {
585584
filters.forEach(filter => filter.afterInit());
586585
this.afterInit();
587586
@@ -781,7 +780,7 @@ export default {
781780
[ "fixed-before", toISO(rawValue?.before) || "" ],
782781
],
783782
isUnique: (_, rawValue) => [
784-
[ "is-unique", rawValue ? "true" : "false" ],
783+
[ "is-unique", rawValue ? "on" : "off" ],
785784
],
786785
runName: (_, rawValue) => [ //PTR
787786
[ "run-name", rawValue || "" ],
@@ -884,9 +883,19 @@ export default {
884883
await new Promise(resolve => setTimeout(resolve, 100));
885884
886885
const nextQuery = { ...presetQueryParams };
887-
await this.$router.replace({ query: nextQuery });
886+
await this.$router.replace({ query: nextQuery }).catch(() => {});
888887
889888
await this.initByUrl();
889+
890+
const filters = this.$refs.filters;
891+
const states = filters.map(f => f.getUrlState());
892+
const settledQuery = Object.assign({}, this.$route.query, ...states);
893+
894+
this.updateUrl();
895+
896+
if (this.$refs.FilterMenu && this.$refs.FilterMenu[0]) {
897+
this.$refs.FilterMenu[0].onPresetApplied(settledQuery);
898+
}
890899
},
891900
892901
async clearToolbarSilently() {
@@ -915,6 +924,10 @@ export default {
915924
async clearAllFilters() {
916925
const filters = this.$refs.filters;
917926
927+
if (this.$refs.FilterMenu && this.$refs.FilterMenu[0]) {
928+
this.$refs.FilterMenu[0].clearPresetState();
929+
}
930+
918931
// Unregister watchers.
919932
this.unregisterWatchers();
920933
filters.forEach(filter => filter.unregisterWatchers());

0 commit comments

Comments
 (0)