forked from grafana.jool/grafana-jool
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.5 KiB
44 lines
1.5 KiB
import { AnyAction } from 'redux';
|
|
import { createAction } from '@reduxjs/toolkit';
|
|
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;
|
|
};
|
|
|