Skip to content

Commit

Permalink
cache date time filter in local storage (#848) (#871)
Browse files Browse the repository at this point in the history
(cherry picked from commit a7c7eef)

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 9ce9a46 commit fa63948
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { Toast } from '@opensearch-project/oui/src/eui_components/toast/global_toast_list';
import { CoreStart } from 'opensearch-dashboards/public';
import { SaContextConsumer } from '../../services';
import { DEFAULT_DATE_RANGE, ROUTES } from '../../utils/constants';
import { DEFAULT_DATE_RANGE, DATE_TIME_FILTER_KEY, ROUTES } from '../../utils/constants';
import { CoreServicesConsumer } from '../../components/core_services';
import Findings from '../Findings';
import Detectors from '../Detectors';
Expand Down Expand Up @@ -104,13 +104,17 @@ const navItemIndexByRoute: { [route: string]: number } = {
export default class Main extends Component<MainProps, MainState> {
constructor(props: MainProps) {
super(props);
const cachedDateTimeFilter = localStorage?.getItem(DATE_TIME_FILTER_KEY);
const defaultDateTimeFilter = cachedDateTimeFilter
? JSON.parse(cachedDateTimeFilter)
: {
startTime: DEFAULT_DATE_RANGE.start,
endTime: DEFAULT_DATE_RANGE.end,
};
this.state = {
getStartedDismissedOnce: false,
selectedNavItemId: 1,
dateTimeFilter: {
startTime: DEFAULT_DATE_RANGE.start,
endTime: DEFAULT_DATE_RANGE.end,
},
dateTimeFilter: defaultDateTimeFilter,
findingFlyout: null,
};

Expand Down Expand Up @@ -154,8 +158,9 @@ export default class Main extends Component<MainProps, MainState> {

setDateTimeFilter = (dateTimeFilter: DateTimeFilter) => {
this.setState({
dateTimeFilter: dateTimeFilter,
dateTimeFilter,
});
localStorage?.setItem(DATE_TIME_FILTER_KEY, JSON.stringify(dateTimeFilter));
};

/**
Expand Down
1 change: 1 addition & 0 deletions public/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import _ from 'lodash';
export const DATE_MATH_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
export const MAX_RECENTLY_USED_TIME_RANGES = 5;
export const DEFAULT_DATE_RANGE = { start: 'now-24h', end: 'now' };
export const DATE_TIME_FILTER_KEY = 'security_analytics_time_filter';

export const PLUGIN_NAME = 'opensearch_security_analytics_dashboards';
export const OS_NOTIFICATION_PLUGIN = 'opensearch-notifications';
Expand Down

0 comments on commit fa63948

Please sign in to comment.