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

Line filter: add case sensitive line filter state to local storage #956

Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 9 additions & 2 deletions src/Components/ServiceScene/LineFilterScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { reportAppInteraction, USER_EVENTS_ACTIONS, USER_EVENTS_PAGES } from 'se
import { SearchInput } from './Breakdowns/SearchInput';
import { LineFilterIcon } from './LineFilterIcon';
import { getLineFilterVariable } from '../../services/variableGetters';
import { getLineFilterCase, setLineFilterCase } from '../../services/store';

interface LineFilterState extends SceneObjectState {
lineFilter: string;
Expand All @@ -20,7 +21,7 @@ export class LineFilterScene extends SceneObjectBase<LineFilterState> {
constructor(state?: Partial<LineFilterState>) {
super({
lineFilter: state?.lineFilter || '',
caseSensitive: false,
caseSensitive: getLineFilterCase(false),
gtk-grafana marked this conversation as resolved.
Show resolved Hide resolved
...state,
});
this.addActivationHandler(this.onActivate);
Expand Down Expand Up @@ -66,10 +67,16 @@ export class LineFilterScene extends SceneObjectBase<LineFilterState> {
};

onCaseSensitiveToggle = (newState: 'sensitive' | 'insensitive') => {
const caseSensitive = newState === 'sensitive';

// Set value to scene state
this.setState({
caseSensitive: newState === 'sensitive',
caseSensitive,
});

// Set value in local storage
setLineFilterCase(caseSensitive);

this.updateFilter(this.state.lineFilter);
};

Expand Down
16 changes: 16 additions & 0 deletions src/services/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ export function setLogsVisualizationType(type: string) {
localStorage.setItem(VISUALIZATION_TYPE_LOCALSTORAGE_KEY, type);
}

// Line filter options
const LINE_FILTER_OPTIONS_LOCALSTORAGE_KEY = `${pluginJson.id}.logs.option`;
export function setLineFilterCase(caseSensitive: boolean) {
let storedValue = caseSensitive.toString();
if (typeof caseSensitive === 'boolean' && !caseSensitive) {
gtk-grafana marked this conversation as resolved.
Show resolved Hide resolved
storedValue = '';
}

localStorage.setItem(`${LINE_FILTER_OPTIONS_LOCALSTORAGE_KEY}.caseSensitive`, storedValue);
}

export function getLineFilterCase(defaultValue: boolean): boolean {
const storedValue = localStorage.getItem(`${LINE_FILTER_OPTIONS_LOCALSTORAGE_KEY}.caseSensitive`);
return storedValue === 'true' ? true : defaultValue;
}

// Panel options
const PANEL_OPTIONS_LOCALSTORAGE_KEY = `${pluginJson.id}.panel.option`;
export interface PanelOptions {
Expand Down
Loading