Skip to content

Commit

Permalink
Line filter: add case sensitive line filter state to local storage (#956
Browse files Browse the repository at this point in the history
)

* feat: add case sensitive line filter state to local storage
  • Loading branch information
gtk-grafana authored and shantanualsi committed Dec 17, 2024
1 parent da3ff3f commit e52ae58
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions project-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,4 @@ keycombo
capslock
pageup
pagedown
linefilter
13 changes: 10 additions & 3 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),
...state,
});
this.addActivationHandler(this.onActivate);
Expand Down Expand Up @@ -66,11 +67,17 @@ 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,
});

this.updateFilter(this.state.lineFilter);
// Set value in local storage
setLineFilterCase(caseSensitive);

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

updateVariableDebounced = debounce((search: string) => {
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}.linefilter.option`;
export function setLineFilterCase(caseSensitive: boolean) {
let storedValue = caseSensitive.toString();
if (!caseSensitive) {
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

0 comments on commit e52ae58

Please sign in to comment.