Skip to content

Commit 0132c0c

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

4 files changed

Lines changed: 80 additions & 14 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: 63 additions & 8 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,23 +47,19 @@
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: {
58-
59-
},
62+
expose : [ "onPresetApplied", "clearPresetState" ],
6063
6164
data() {
6265
return {
@@ -68,16 +71,43 @@ export default {
6871
error: null,
6972
isSuperUser: false,
7073
isAdminOfAnyProduct: false,
74+
activePresetId: null,
75+
querySnapshot: null,
76+
isModified: false,
7177
};
7278
},
7379
7480
computed: {
7581
canSeeActions() {
7682
return this.isSuperUser || this.isAdminOfAnyProduct;
77-
}
83+
},
7884
},
7985
8086
watch: {
87+
"$route.query": {
88+
handler(newQuery) {
89+
if (!this.activePresetId || !this.querySnapshot) {
90+
this.isModified = false;
91+
return;
92+
}
93+
const normalize = q => {
94+
const sorted = {};
95+
for (const k of Object.keys(q).sort()) {
96+
const v = q[k];
97+
if (Array.isArray(v)) {
98+
sorted[ k ] = v.length === 1 ? v[ 0 ] : [ ...v ].sort();
99+
} else {
100+
sorted[k] = v;
101+
}
102+
}
103+
return sorted;
104+
};
105+
const normNew = normalize(newQuery);
106+
const normSnap = normalize(this.querySnapshot);
107+
this.isModified = !isEqual(normNew, normSnap);
108+
},
109+
deep: true,
110+
},
81111
},
82112
83113
created() {
@@ -133,7 +163,9 @@ export default {
133163
async applyPreset(id) {
134164
this.error = null;
135165
this.applyingId = id;
166+
this.querySnapshot = null;
136167
try {
168+
this.activePresetId = id;
137169
this.$emit("apply-preset", id);
138170
} catch (e) {
139171
this.error = (e && e.message) ? e.message : "Failed to apply preset";
@@ -142,6 +174,17 @@ export default {
142174
}
143175
},
144176
177+
onPresetApplied(settledQuery) {
178+
this.querySnapshot = settledQuery
179+
? { ...settledQuery }
180+
: { ...this.$route.query };
181+
},
182+
183+
clearPresetState() {
184+
this.activePresetId = null;
185+
this.querySnapshot = null;
186+
},
187+
145188
async deletePreset(id) {
146189
this.error = null;
147190
this.deletingId = id;
@@ -155,6 +198,10 @@ export default {
155198
});
156199
157200
this.presets = this.presets.filter(p => p.id !== id);
201+
202+
if (this.activePresetId === id) {
203+
this.clearPresetState();
204+
}
158205
} catch (e) {
159206
this.error = (e && e.message) ? e.message : "Failed to delete preset";
160207
} finally {
@@ -163,8 +210,16 @@ export default {
163210
},
164211
165212
handleClear() {
213+
this.clearPresetState();
166214
this.$emit("clear-preset");
167215
},
168216
},
169217
};
170-
</script>
218+
</script>
219+
220+
<style scoped>
221+
.preset-modified {
222+
color: orange;
223+
font-weight: bold;
224+
}
225+
</style>

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
<v-list-item-content>
3232
<preset-menu
3333
ref="FilterMenu"
34-
:namespace="namespace"
3534
@apply-preset="getFilterPreset"
36-
@update:url="updateUrl"
3735
@clear-preset="clearAllFilters"
3836
/>
3937
</v-list-item-content>
@@ -465,7 +463,6 @@ export default {
465463
activeDatePanelId: 0,
466464
open_preset_save: false,
467465
presetName: "",
468-
currentlyAppliedPreset: null,
469466
isSuperUser: false,
470467
isAdminOfAnyProduct: false,
471468
};
@@ -581,7 +578,7 @@ export default {
581578
});
582579
583580
// If all filters are initalized call a post function.
584-
Promise.all(results).then(() => {
581+
return Promise.all(results).then(() => {
585582
filters.forEach(filter => filter.afterInit());
586583
this.afterInit();
587584
@@ -781,7 +778,7 @@ export default {
781778
[ "fixed-before", toISO(rawValue?.before) || "" ],
782779
],
783780
isUnique: (_, rawValue) => [
784-
[ "is-unique", rawValue ? "true" : "false" ],
781+
[ "is-unique", rawValue ? "on" : "off" ],
785782
],
786783
runName: (_, rawValue) => [ //PTR
787784
[ "run-name", rawValue || "" ],
@@ -884,9 +881,19 @@ export default {
884881
await new Promise(resolve => setTimeout(resolve, 100));
885882
886883
const nextQuery = { ...presetQueryParams };
887-
await this.$router.replace({ query: nextQuery });
884+
await this.$router.replace({ query: nextQuery }).catch(() => {});
888885
889886
await this.initByUrl();
887+
888+
const filters = this.$refs.filters;
889+
const states = filters.map(f => f.getUrlState());
890+
const settledQuery = Object.assign({}, this.$route.query, ...states);
891+
892+
this.updateUrl();
893+
894+
if (this.$refs.FilterMenu && this.$refs.FilterMenu[0]) {
895+
this.$refs.FilterMenu[0].onPresetApplied(settledQuery);
896+
}
890897
},
891898
892899
async clearToolbarSilently() {
@@ -915,6 +922,10 @@ export default {
915922
async clearAllFilters() {
916923
const filters = this.$refs.filters;
917924
925+
if (this.$refs.FilterMenu && this.$refs.FilterMenu[0]) {
926+
this.$refs.FilterMenu[0].clearPresetState();
927+
}
928+
918929
// Unregister watchers.
919930
this.unregisterWatchers();
920931
filters.forEach(filter => filter.unregisterWatchers());

0 commit comments

Comments
 (0)