2021-04-23 13:50:55 +00:00
|
|
|
import { createReducer } from "utils/AppsmithUtils";
|
2021-08-16 11:03:27 +00:00
|
|
|
import { Log, Severity } from "entities/AppsmithConsole";
|
2021-04-23 13:50:55 +00:00
|
|
|
import { ReduxAction, ReduxActionTypes } from "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: [],
|
|
|
|
|
errorCount: 0,
|
|
|
|
|
isOpen: false,
|
|
|
|
|
errors: {},
|
|
|
|
|
expandId: "",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
) => {
|
|
|
|
|
const isError = action.payload.severity === Severity.ERROR;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
logs: [...state.logs, action.payload],
|
|
|
|
|
errorCount: isError ? state.errorCount + 1 : state.errorCount,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.CLEAR_DEBUGGER_LOGS]: (state: DebuggerReduxState) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
logs: [],
|
|
|
|
|
errorCount: 0,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
[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
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
errors: {
|
|
|
|
|
...state.errors,
|
2021-08-16 11:03:27 +00:00
|
|
|
[action.payload.id]: action.payload,
|
2021-04-23 13:50:55 +00:00
|
|
|
},
|
2021-08-16 11:03:27 +00:00
|
|
|
expandId: action.payload.id,
|
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-05-28 14:14:44 +00:00
|
|
|
[ReduxActionTypes.INIT_CANVAS_LAYOUT]: () => {
|
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
|
|
|
errorCount: number;
|
|
|
|
|
isOpen: boolean;
|
2021-08-16 11:03:27 +00:00
|
|
|
errors: Record<string, Log>;
|
2021-04-23 13:50:55 +00:00
|
|
|
expandId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default debuggerReducer;
|