Skip to content

Commit

Permalink
fix: reduce cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
hetunandu committed Feb 13, 2025
1 parent adaf576 commit 79d1ca3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,61 +1,9 @@
import { useMemo } from "react";
import { useLocation } from "react-router";
import {
FocusEntity,
type FocusEntityInfo,
identifyEntityFromPath,
} from "navigation/FocusEntity";
import { identifyEntityFromPath } from "navigation/FocusEntity";
import { useSelector } from "react-redux";
import { getIDEViewMode } from "selectors/ideSelectors";
import { setCanvasDebuggerState } from "actions/debuggerActions";
import { getCanvasDebuggerState } from "selectors/debuggerSelectors";
import {
getPluginActionDebuggerState,
setPluginActionEditorDebuggerState,
} from "PluginActionEditor/store";
import type { CanvasDebuggerState } from "reducers/uiReducers/debuggerReducer";
import type { ReduxAction } from "actions/ReduxActionTypes";
import type { AppState } from "ee/reducers";
import { EditorViewMode } from "IDE/Interfaces/EditorTypes";
import { setJsPaneDebuggerState } from "actions/jsPaneActions";
import { getJsPaneDebuggerState } from "selectors/jsPaneSelectors";

interface Config {
set: (
payload: Partial<CanvasDebuggerState>,
) => ReduxAction<Partial<CanvasDebuggerState>>;
get: (state: AppState) => CanvasDebuggerState;
}

const canvasDebuggerConfig: Config = {
set: setCanvasDebuggerState,
get: getCanvasDebuggerState,
};
const pluginActionEditorDebuggerConfig: Config = {
set: setPluginActionEditorDebuggerState,
get: getPluginActionDebuggerState,
};

export const getDebuggerPaneConfig = (
focusInfo: FocusEntityInfo,
ideViewMode: EditorViewMode,
): Config => {
if (ideViewMode === EditorViewMode.SplitScreen) {
return canvasDebuggerConfig;
}

switch (focusInfo.entity) {
case FocusEntity.QUERY:
return pluginActionEditorDebuggerConfig;
case FocusEntity.JS_OBJECT:
return {
set: setJsPaneDebuggerState,
get: getJsPaneDebuggerState,
};
default:
return canvasDebuggerConfig;
}
};
import { getDebuggerPaneConfig } from "../utils/getDebuggerPaneConfig";

export const useDebuggerConfig = () => {
const location = useLocation();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
getPluginActionDebuggerState,
setPluginActionEditorDebuggerState,
} from "PluginActionEditor/store";
import { FocusEntity, type FocusEntityInfo } from "navigation/FocusEntity";
import { EditorViewMode } from "IDE/Interfaces/EditorTypes";
import { setJsPaneDebuggerState } from "actions/jsPaneActions";
import { getJsPaneDebuggerState } from "selectors/jsPaneSelectors";
import type { CanvasDebuggerState } from "reducers/uiReducers/debuggerReducer";
import type { ReduxAction } from "actions/ReduxActionTypes";
import type { AppState } from "ee/reducers";
import { setCanvasDebuggerState } from "actions/debuggerActions";
import { getCanvasDebuggerState } from "selectors/debuggerSelectors";

interface Config {
set: (
payload: Partial<CanvasDebuggerState>,
) => ReduxAction<Partial<CanvasDebuggerState>>;
get: (state: AppState) => CanvasDebuggerState;
}

const canvasDebuggerConfig: Config = {
set: setCanvasDebuggerState,
get: getCanvasDebuggerState,
};
const pluginActionEditorDebuggerConfig: Config = {
set: setPluginActionEditorDebuggerState,
get: getPluginActionDebuggerState,
};

export const getDebuggerPaneConfig = (
focusInfo: FocusEntityInfo,
ideViewMode: EditorViewMode,
): Config => {
if (ideViewMode === EditorViewMode.SplitScreen) {
return canvasDebuggerConfig;
}

switch (focusInfo.entity) {
case FocusEntity.QUERY:
return pluginActionEditorDebuggerConfig;
case FocusEntity.JS_OBJECT:
return {
set: setJsPaneDebuggerState,
get: getJsPaneDebuggerState,
};
default:
return canvasDebuggerConfig;
}
};
2 changes: 1 addition & 1 deletion app/client/src/sagas/DebuggerSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ import {
import { identifyEntityFromPath } from "../navigation/FocusEntity";
import { getIDEViewMode } from "../selectors/ideSelectors";
import type { EditorViewMode } from "IDE/Interfaces/EditorTypes";
import { getDebuggerPaneConfig } from "../components/editorComponents/Debugger/hooks/useDebuggerConfig";
import { DEBUGGER_TAB_KEYS } from "../components/editorComponents/Debugger/constants";
import { getDebuggerPaneConfig } from "../components/editorComponents/Debugger/utils/getDebuggerPaneConfig";

let blockedSource: string | null = null;

Expand Down

0 comments on commit 79d1ca3

Please sign in to comment.