From 2b3e269e28b2c190fdb2e3ebfba29ed47468fed0 Mon Sep 17 00:00:00 2001 From: Maxim Mordasov Date: Fri, 31 Mar 2023 12:12:21 +0300 Subject: [PATCH] Save selected teams filter in local storage (#1613) # What this PR does Selected teams filter is now saved in local storage ## Which issue(s) this PR fixes https://github.com/grafana/oncall/issues/1611 ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --------- Co-authored-by: Joey Orlando --- CHANGELOG.md | 4 ++++ grafana-plugin/src/models/filters/filters.ts | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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