2022-08-04 05:40:44 +00:00
|
|
|
import { createReducer } from "utils/ReducerUtils";
|
2021-08-25 04:34:42 +00:00
|
|
|
import { Log } from "entities/AppsmithConsole";
|
2022-04-12 10:50:01 +00:00
|
|
|
import {
|
|
|
|
|
ReduxAction,
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2021-08-16 11:03:27 +00:00
|
|
|
import { omit, isUndefined } from "lodash";
|
2021-04-23 13:50:55 +00:00
|
|
|
|
|
|
|
|
const initialState: DebuggerReduxState = {
|
|
|
|
|
logs: [],
|
|
|
|
|
isOpen: false,
|
|
|
|
|
errors: {},
|
|
|
|
|
expandId: "",
|
2021-08-25 04:34:42 +00:00
|
|
|
hideErrors: true,
|
2021-10-07 06:53:58 +00:00
|
|
|
currentTab: "",
|
2021-04-23 13:50:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const debuggerReducer = createReducer(initialState, {
|
|
|
|
|
[ReduxActionTypes.DEBUGGER_LOG]: (
|
|
|
|
|
state: DebuggerReduxState,
|
2021-08-16 11:03:27 +00:00
|
|
|
action: ReduxAction<Log>,
|
2021-04-23 13:50:55 +00:00
|
|
|
) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
logs: [...state.logs, action.payload],
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.CLEAR_DEBUGGER_LOGS]: (state: DebuggerReduxState) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
logs: [],
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.SHOW_DEBUGGER]: (
|
|
|
|
|
state: DebuggerReduxState,
|
|
|
|
|
action: ReduxAction<boolean | undefined>,
|
|
|
|
|
) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
isOpen: isUndefined(action.payload) ? !state.isOpen : action.payload,
|
|
|
|
|
};
|
|
|
|
|
},
|
2021-08-16 11:03:27 +00:00
|
|
|
[ReduxActionTypes.DEBUGGER_ADD_ERROR_LOG]: (
|
2021-04-23 13:50:55 +00:00
|
|
|
state: DebuggerReduxState,
|
2021-08-16 11:03:27 +00:00
|
|
|
action: ReduxAction<Log>,
|
2021-04-23 13:50:55 +00:00
|
|
|
) => {
|
2021-08-16 11:03:27 +00:00
|
|
|
if (!action.payload.id) return state;
|
2021-04-23 13:50:55 +00:00
|
|
|
|
2021-09-14 14:51:07 +00:00
|
|
|
// Moving recent update to the top of the error list
|
|
|
|
|
const errors = omit(state.errors, action.payload.id);
|
2021-04-23 13:50:55 +00:00
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
errors: {
|
2021-08-16 11:03:27 +00:00
|
|
|
[action.payload.id]: action.payload,
|
2021-09-14 14:51:07 +00:00
|
|
|
...errors,
|
2021-04-23 13:50:55 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
2021-08-16 11:03:27 +00:00
|
|
|
[ReduxActionTypes.DEBUGGER_DELETE_ERROR_LOG]: (
|
2021-04-23 13:50:55 +00:00
|
|
|
state: DebuggerReduxState,
|
2021-08-16 11:03:27 +00:00
|
|
|
action: ReduxAction<string>,
|
2021-04-23 13:50:55 +00:00
|
|
|
) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
2021-08-16 11:03:27 +00:00
|
|
|
errors: omit(state.errors, action.payload),
|
2021-04-23 13:50:55 +00:00
|
|
|
};
|
|
|
|
|
},
|
2021-08-25 04:34:42 +00:00
|
|
|
[ReduxActionTypes.HIDE_DEBUGGER_ERRORS]: (
|
|
|
|
|
state: DebuggerReduxState,
|
|
|
|
|
action: ReduxAction<boolean>,
|
|
|
|
|
) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
hideErrors: action.payload,
|
|
|
|
|
};
|
|
|
|
|
},
|
2021-09-20 11:20:22 +00:00
|
|
|
[ReduxActionTypes.SET_CURRENT_DEBUGGER_TAB]: (
|
|
|
|
|
state: DebuggerReduxState,
|
2021-10-07 06:53:58 +00:00
|
|
|
action: ReduxAction<string>,
|
2021-09-20 11:20:22 +00:00
|
|
|
) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
currentTab: action.payload,
|
|
|
|
|
};
|
|
|
|
|
},
|
2021-10-04 04:27:23 +00:00
|
|
|
// Resetting debugger state after page switch
|
|
|
|
|
[ReduxActionTypes.SWITCH_CURRENT_PAGE_ID]: () => {
|
2021-05-17 10:01:22 +00:00
|
|
|
return {
|
|
|
|
|
...initialState,
|
|
|
|
|
};
|
|
|
|
|
},
|
2021-04-23 13:50:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export interface DebuggerReduxState {
|
2021-08-16 11:03:27 +00:00
|
|
|
logs: Log[];
|
2021-04-23 13:50:55 +00:00
|
|
|
isOpen: boolean;
|
2021-08-16 11:03:27 +00:00
|
|
|
errors: Record<string, Log>;
|
2021-04-23 13:50:55 +00:00
|
|
|
expandId: string;
|
2021-08-25 04:34:42 +00:00
|
|
|
hideErrors: boolean;
|
2021-10-07 06:53:58 +00:00
|
|
|
currentTab: string;
|
2021-04-23 13:50:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default debuggerReducer;
|