diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e1f4c87..52e26ac6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,10 @@ Only some minor performance/developer setup changes to report in this version. ## v1.2.2 (2023-03-27) +### Added + +- Save selected teams filter in local storage ([1611](https://github.com/grafana/oncall/issues/1611)) + ### Changed - Drawers with Forms are not closing by clicking outside of the drawer. Only by clicking Cancel or X (by @Ukochka in [#1608](https://github.com/grafana/oncall/pull/1608)) diff --git a/grafana-plugin/src/models/filters/filters.ts b/grafana-plugin/src/models/filters/filters.ts index 8d5e2406..eaca60d7 100644 --- a/grafana-plugin/src/models/filters/filters.ts +++ b/grafana-plugin/src/models/filters/filters.ts @@ -3,10 +3,13 @@ import { action, observable } from 'mobx'; import BaseStore from 'models/base_store'; import { makeRequest } from 'network'; import { RootStore } from 'state'; +import { getItem, setItem } from 'utils/localStorage'; import { getApiPathByPage } from './filters.helpers'; import { FilterOption, FiltersValues } from './filters.types'; +const LOCAL_STORAGE_FILTERS_KEY = 'grafana.oncall.global-filters'; + export class FiltersStore extends BaseStore { @observable.shallow public options: { [page: string]: FilterOption[] } = {}; @@ -14,10 +17,25 @@ export class FiltersStore extends BaseStore { @observable.shallow public values: { [page: string]: FiltersValues } = {}; - public globalValues: FiltersValues = {}; + private _globalValues: FiltersValues = {}; constructor(rootStore: RootStore) { super(rootStore); + + const savedFilters = getItem(LOCAL_STORAGE_FILTERS_KEY); + if (savedFilters) { + this._globalValues = { ...savedFilters }; + } + } + + set globalValues(value: any) { + this._globalValues = value; + + setItem(LOCAL_STORAGE_FILTERS_KEY, value); + } + + get globalValues() { + return this._globalValues; } @action