fix: split default tab logic (#38414)

## 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"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12546120368>
> Commit: 8fa499eb02ab83a9dd0737f39e4cc2372dc7f174
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12546120368&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Mon, 30 Dec 2024 13:26:11 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
This commit is contained in:
Valera Melnikov 2024-12-30 17:47:07 +03:00 committed by GitHub
parent 39328fbd7f
commit de2d5a4461
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 48 additions and 27 deletions

View File

@ -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 })),

View File

@ -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],
);
}

View File

@ -0,0 +1,5 @@
import { useDefaultTab as CE_useDefaultTab } from "ce/PluginActionEditor/components/PluginActionResponse/hooks/useDefaultTab";
export function useDefaultTab() {
return CE_useDefaultTab();
}