diff --git a/app/client/src/PluginActionEditor/components/PluginActionResponse/PluginActionResponse.tsx b/app/client/src/PluginActionEditor/components/PluginActionResponse/PluginActionResponse.tsx index e450a2b782..ef8fdb3f45 100644 --- a/app/client/src/PluginActionEditor/components/PluginActionResponse/PluginActionResponse.tsx +++ b/app/client/src/PluginActionEditor/components/PluginActionResponse/PluginActionResponse.tsx @@ -9,20 +9,15 @@ import { DEBUGGER_TAB_KEYS } from "components/editorComponents/Debugger/constant import AnalyticsUtil from "ee/utils/AnalyticsUtil"; import { usePluginActionResponseTabs } from "./hooks"; import { usePluginActionContext } from "../../PluginActionContext"; -import { doesPluginRequireDatasource } from "ee/entities/Engine/actionHelpers"; -import useShowSchema from "./hooks/useShowSchema"; import { actionResponseDisplayDataFormats } from "pages/Editor/utils"; -import { PluginType } from "entities/Action"; import { hasFailed } from "./utils"; +import { useDefaultTab } from "ee/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab"; function PluginActionResponse() { const dispatch = useDispatch(); - const { actionResponse, plugin } = usePluginActionContext(); + const { actionResponse } = usePluginActionContext(); const tabs = usePluginActionResponseTabs(); - const pluginRequireDatasource = doesPluginRequireDatasource(plugin); - - const showSchema = useShowSchema(plugin?.id || "") && pluginRequireDatasource; // TODO combine API and Query Debugger state const { open, responseTabHeight, selectedTab } = useSelector( @@ -75,26 +70,7 @@ function PluginActionResponse() { [executionFailed, dispatch], ); - useEffect( - function openDefaultTabWhenNoTabIsSelected() { - if (showSchema && !selectedTab) { - dispatch( - setPluginActionEditorDebuggerState({ - open: true, - selectedTab: DEBUGGER_TAB_KEYS.DATASOURCE_TAB, - }), - ); - } else if (plugin.type === PluginType.API && !selectedTab) { - dispatch( - setPluginActionEditorDebuggerState({ - open: true, - selectedTab: DEBUGGER_TAB_KEYS.RESPONSE_TAB, - }), - ); - } - }, - [showSchema, selectedTab, dispatch, plugin.type], - ); + useDefaultTab(); const toggleHide = useCallback( () => dispatch(setPluginActionEditorDebuggerState({ open: !open })), diff --git a/app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab.tsx b/app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab.tsx new file mode 100644 index 0000000000..399b320647 --- /dev/null +++ b/app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab.tsx @@ -0,0 +1,40 @@ +import { useEffect } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import { DEBUGGER_TAB_KEYS } from "components/editorComponents/Debugger/constants"; +import { PluginType } from "entities/Action"; +import { usePluginActionContext } from "PluginActionEditor"; +import useShowSchema from "PluginActionEditor/components/PluginActionResponse/hooks/useShowSchema"; +import { + getPluginActionDebuggerState, + setPluginActionEditorDebuggerState, +} from "PluginActionEditor/store"; +import { doesPluginRequireDatasource } from "ee/entities/Engine/actionHelpers"; + +export function useDefaultTab() { + const dispatch = useDispatch(); + const { plugin } = usePluginActionContext(); + const pluginRequireDatasource = doesPluginRequireDatasource(plugin); + const showSchema = useShowSchema(plugin?.id || "") && pluginRequireDatasource; + const { selectedTab } = useSelector(getPluginActionDebuggerState); + + useEffect( + function openDefaultTabWhenNoTabIsSelected() { + if (showSchema && !selectedTab) { + dispatch( + setPluginActionEditorDebuggerState({ + open: true, + selectedTab: DEBUGGER_TAB_KEYS.DATASOURCE_TAB, + }), + ); + } else if (plugin.type === PluginType.API && !selectedTab) { + dispatch( + setPluginActionEditorDebuggerState({ + open: true, + selectedTab: DEBUGGER_TAB_KEYS.RESPONSE_TAB, + }), + ); + } + }, + [showSchema, selectedTab, dispatch, plugin.type], + ); +} diff --git a/app/client/src/ee/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab.tsx b/app/client/src/ee/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab.tsx new file mode 100644 index 0000000000..82827533ab --- /dev/null +++ b/app/client/src/ee/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab.tsx @@ -0,0 +1,5 @@ +import { useDefaultTab as CE_useDefaultTab } from "ce/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab"; + +export function useDefaultTab() { + return CE_useDefaultTab(); +}