Files
Josh Hunt 3c6e0e8ef8 Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

46 lines
1.5 KiB
TypeScript

import { createAction } from '@reduxjs/toolkit';
import { AnyAction } from 'redux';
import { PanelPluginMeta, SelectableValue } from '@grafana/data';
import { FolderInfo } from '../../../../types';
export interface LibraryPanelsSearchState {
searchQuery: string;
sortDirection?: string;
panelFilter: string[];
folderFilter: string[];
}
export const initialLibraryPanelsSearchState: LibraryPanelsSearchState = {
searchQuery: '',
panelFilter: [],
folderFilter: [],
sortDirection: undefined,
};
export const searchChanged = createAction<string>('libraryPanels/search/searchChanged');
export const sortChanged = createAction<SelectableValue<string>>('libraryPanels/search/sortChanged');
export const panelFilterChanged = createAction<PanelPluginMeta[]>('libraryPanels/search/panelFilterChanged');
export const folderFilterChanged = createAction<FolderInfo[]>('libraryPanels/search/folderFilterChanged');
export const libraryPanelsSearchReducer = (state: LibraryPanelsSearchState, action: AnyAction) => {
if (searchChanged.match(action)) {
return { ...state, searchQuery: action.payload };
}
if (sortChanged.match(action)) {
return { ...state, sortDirection: action.payload.value };
}
if (panelFilterChanged.match(action)) {
return { ...state, panelFilter: action.payload.map((p) => p.id) };
}
if (folderFilterChanged.match(action)) {
return { ...state, folderFilter: action.payload.map((f) => String(f.id!)) };
}
return state;
};