From de2d5a4461fc357aadf108d9f69eb6674233ba16 Mon Sep 17 00:00:00 2001 From: Valera Melnikov Date: Mon, 30 Dec 2024 17:47:07 +0300 Subject: [PATCH] fix: split default tab logic (#38414) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Split the logic for the plugin action tabs. Now the files in CE and EE repo for the `ce` folder are the same. Redefine the logic in EE hooks only. EE PR — https://github.com/appsmithorg/appsmith-ee/pull/5840 ## Automation /ok-to-test tags="@tag.All" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 8fa499eb02ab83a9dd0737f39e4cc2372dc7f174 > Cypress dashboard. > Tags: `@tag.All` > Spec: >
Mon, 30 Dec 2024 13:26:11 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No --- .../PluginActionResponse.tsx | 30 ++------------ .../hooks/useDefaultTab.tsx | 40 +++++++++++++++++++ .../hooks/useDefaultTab.tsx | 5 +++ 3 files changed, 48 insertions(+), 27 deletions(-) create mode 100644 app/client/src/ce/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab.tsx create mode 100644 app/client/src/ee/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab.tsx 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(); +}