Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache date time filter in local storage #848

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading