mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 16:45:43 -06:00
* Split main reducer from item reducer * Move query related redux to separate file * Split more parts and tests * Fix import * Remove unused code * Update public/app/features/explore/state/datasource.ts Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> * Add section comments * Rename ExploreItem to ExplorePane * Fix imports Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import {
|
|
deleteAllFromRichHistory,
|
|
deleteQueryInRichHistory,
|
|
updateCommentInRichHistory,
|
|
updateStarredInRichHistory,
|
|
} from 'app/core/utils/richHistory';
|
|
import { ExploreId, ExploreItemState, ThunkResult } from 'app/types';
|
|
import { richHistoryUpdatedAction } from './main';
|
|
import { HistoryItem } from '@grafana/data';
|
|
import { AnyAction, createAction } from '@reduxjs/toolkit';
|
|
|
|
//
|
|
// Actions and Payloads
|
|
//
|
|
|
|
export interface HistoryUpdatedPayload {
|
|
exploreId: ExploreId;
|
|
history: HistoryItem[];
|
|
}
|
|
export const historyUpdatedAction = createAction<HistoryUpdatedPayload>('explore/historyUpdated');
|
|
|
|
//
|
|
// Action creators
|
|
//
|
|
|
|
export const updateRichHistory = (ts: number, property: string, updatedProperty?: string): ThunkResult<void> => {
|
|
return (dispatch, getState) => {
|
|
// Side-effect: Saving rich history in localstorage
|
|
let nextRichHistory;
|
|
if (property === 'starred') {
|
|
nextRichHistory = updateStarredInRichHistory(getState().explore.richHistory, ts);
|
|
}
|
|
if (property === 'comment') {
|
|
nextRichHistory = updateCommentInRichHistory(getState().explore.richHistory, ts, updatedProperty);
|
|
}
|
|
if (property === 'delete') {
|
|
nextRichHistory = deleteQueryInRichHistory(getState().explore.richHistory, ts);
|
|
}
|
|
dispatch(richHistoryUpdatedAction({ richHistory: nextRichHistory }));
|
|
};
|
|
};
|
|
|
|
export const deleteRichHistory = (): ThunkResult<void> => {
|
|
return dispatch => {
|
|
deleteAllFromRichHistory();
|
|
dispatch(richHistoryUpdatedAction({ richHistory: [] }));
|
|
};
|
|
};
|
|
|
|
export const historyReducer = (state: ExploreItemState, action: AnyAction): ExploreItemState => {
|
|
if (historyUpdatedAction.match(action)) {
|
|
return {
|
|
...state,
|
|
history: action.payload.history,
|
|
};
|
|
}
|
|
return state;
|
|
};
|