mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-02-12 09:30:45 +03:00
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
|
import { Action, AnyAction } from 'redux';
|
||
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||
|
import {
|
||
|
QueryInfo,
|
||
|
RtkQueryMonitorState,
|
||
|
QueryFormValues,
|
||
|
RtkQueryMonitorProps,
|
||
|
QueryPreviewTabs,
|
||
|
} from './types';
|
||
|
import { QueryComparators } from './utils/comparators';
|
||
|
import { QueryFilters } from './utils/filters';
|
||
|
|
||
|
const initialState: RtkQueryMonitorState = {
|
||
|
queryForm: {
|
||
|
values: {
|
||
|
queryComparator: QueryComparators.fulfilledTimeStamp,
|
||
|
isAscendingQueryComparatorOrder: false,
|
||
|
searchValue: '',
|
||
|
isRegexSearch: false,
|
||
|
queryFilter: QueryFilters.queryKey,
|
||
|
},
|
||
|
},
|
||
|
selectedPreviewTab: QueryPreviewTabs.queryinfo,
|
||
|
selectedQueryKey: null,
|
||
|
};
|
||
|
|
||
|
const monitorSlice = createSlice({
|
||
|
/**
|
||
|
* `@@` prefix is mandatory.
|
||
|
* @see lifedAction @ `packages/redux-devtools-app/src/actions/index.ts`
|
||
|
*/
|
||
|
name: '@@rtk-query-monitor',
|
||
|
initialState,
|
||
|
reducers: {
|
||
|
changeQueryFormValues(
|
||
|
state,
|
||
|
action: PayloadAction<Partial<QueryFormValues>>
|
||
|
) {
|
||
|
state.queryForm.values = { ...state.queryForm.values, ...action.payload };
|
||
|
},
|
||
|
selectQueryKey(
|
||
|
state,
|
||
|
action: PayloadAction<Pick<QueryInfo, 'reducerPath' | 'queryKey'>>
|
||
|
) {
|
||
|
state.selectedQueryKey = {
|
||
|
queryKey: action.payload.queryKey,
|
||
|
reducerPath: action.payload.reducerPath,
|
||
|
};
|
||
|
},
|
||
|
selectedPreviewTab(state, action: PayloadAction<QueryPreviewTabs>) {
|
||
|
state.selectedPreviewTab = action.payload;
|
||
|
},
|
||
|
},
|
||
|
});
|
||
|
|
||
|
export function reducer<S, A extends Action<unknown>>(
|
||
|
props: RtkQueryMonitorProps<S, A>,
|
||
|
state: RtkQueryMonitorState | undefined,
|
||
|
action: AnyAction
|
||
|
): RtkQueryMonitorState {
|
||
|
return monitorSlice.reducer(state, action);
|
||
|
}
|
||
|
|
||
|
export const { selectQueryKey, changeQueryFormValues, selectedPreviewTab } =
|
||
|
monitorSlice.actions;
|