fix(core): properly sync default namespace filters from settings with default filter (#13685)

This commit is contained in:
Piyush Bhaskar
2025-12-16 15:30:55 +05:30
committed by GitHub
parent 216b124294
commit b167c52e76
2 changed files with 31 additions and 8 deletions

View File

@@ -25,22 +25,18 @@ export function applyDefaultFilters(
includeScope,
legacyQuery,
}: DefaultFilterOptions = {}): { query: LocationQuery, change: boolean } {
if(currentQuery && Object.keys(currentQuery).length > 0) {
return {
query: currentQuery,
change: false,
}
}
const query = {...currentQuery};
let change = false;
if (namespace === undefined && defaultNamespace() && !hasFilterKey(query, NAMESPACE_FILTER_PREFIX)) {
query[legacyQuery ? "namespace" : `${NAMESPACE_FILTER_PREFIX}[PREFIX]`] = defaultNamespace();
change = true;
}
if (includeScope && !hasFilterKey(query, SCOPE_FILTER_PREFIX)) {
query[legacyQuery ? "scope" : `${SCOPE_FILTER_PREFIX}[EQUALS]`] = "USER";
change = true;
}
const TIME_FILTER_KEYS = /startDate|endDate|timeRange/;
@@ -48,9 +44,10 @@ export function applyDefaultFilters(
if (includeTimeRange && !Object.keys(query).some(key => TIME_FILTER_KEYS.test(key))) {
const defaultDuration = useMiscStore().configs?.chartDefaultDuration ?? "P30D";
query[legacyQuery ? "timeRange" : `${TIME_RANGE_FILTER_PREFIX}[EQUALS]`] = defaultDuration;
change = true;
}
return {query, change: true};
return {query, change};
}
export function useDefaultFilter(

View File

@@ -648,6 +648,7 @@
},
async saveAllSettings() {
let refreshWhenSaved = false
const previousDefaultNamespace = localStorage.getItem("defaultNamespace")
for (const key in this.pendingSettings){
const storedKey = this.settingsKeyMapping[key]
switch(key) {
@@ -706,11 +707,36 @@
this.originalSettings = JSON.parse(JSON.stringify(this.pendingSettings));
this.hasUnsavedChanges = false;
this.checkDefaultStates();
// Clear namespace filters from sessionStorage if default namespace changed/cleared
if (previousDefaultNamespace !== this.pendingSettings.defaultNamespace) {
this.clearNamespaceFilters();
}
if(refreshWhenSaved){
document.location.assign(document.location.href)
}
this.$toast().saved(this.$t("settings.label"), undefined, {multiple: true});
},
clearNamespaceFilters() {
Object.keys(sessionStorage)
.filter(key => key.includes("_restore_url"))
.forEach(key => {
const value = sessionStorage.getItem(key);
if (!value) return;
const filters = JSON.parse(value);
const updated = Object.fromEntries(
Object.entries(filters).filter(([k]) => k !== "namespace" && !k.startsWith("filters[namespace]"))
);
if (Object.keys(updated).length) {
sessionStorage.setItem(key, JSON.stringify(updated));
} else {
sessionStorage.removeItem(key);
}
});
},
updateThemeBasedOnSystem() {
if (this.theme === "syncWithSystem") {
Utils.switchTheme(this.miscStore, "syncWithSystem");