2024-05-22 14:13:07 +00:00
|
|
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
2025-01-03 12:35:09 +00:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
2021-09-08 17:32:22 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
import {
|
|
|
|
|
createMessage,
|
2023-04-10 12:59:14 +00:00
|
|
|
DEBUGGER_ERRORS,
|
2024-02-29 06:23:57 +00:00
|
|
|
DEBUGGER_LOGS,
|
2024-05-15 08:28:49 +00:00
|
|
|
DEBUGGER_RESPONSE,
|
2025-01-03 12:35:09 +00:00
|
|
|
DEBUGGER_STATE,
|
2021-09-08 17:32:22 +00:00
|
|
|
EXECUTING_FUNCTION,
|
2022-04-28 16:51:02 +00:00
|
|
|
NO_JS_FUNCTION_RETURN_VALUE,
|
2022-05-19 13:13:51 +00:00
|
|
|
UPDATING_JS_COLLECTION,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/constants/messages";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { EditorTheme } from "./CodeEditor/EditorConfig";
|
2021-09-08 17:32:22 +00:00
|
|
|
import DebuggerLogs from "./Debugger/DebuggerLogs";
|
2023-12-09 14:54:43 +00:00
|
|
|
import type { JSAction } from "entities/JSCollection";
|
2021-09-08 17:32:22 +00:00
|
|
|
import ReadOnlyEditor from "components/editorComponents/ReadOnlyEditor";
|
2024-08-09 14:20:29 +00:00
|
|
|
import { Flex, Text } from "@appsmith/ads";
|
2021-09-08 17:32:22 +00:00
|
|
|
import LoadingOverlayScreen from "components/editorComponents/LoadingOverlayScreen";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { JSCollectionData } from "ee/reducers/entityReducers/jsActionsReducer";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { EvaluationError } from "utils/DynamicBindingUtils";
|
2024-10-08 10:42:27 +00:00
|
|
|
import { DEBUGGER_TAB_KEYS } from "./Debugger/constants";
|
2024-02-29 06:23:57 +00:00
|
|
|
import type { BottomTab } from "./EntityBottomTabs";
|
2021-10-07 06:53:58 +00:00
|
|
|
import EntityBottomTabs from "./EntityBottomTabs";
|
2022-05-19 13:13:51 +00:00
|
|
|
import { getIsSavingEntity } from "selectors/editorSelectors";
|
2024-09-25 07:44:26 +00:00
|
|
|
import { getJSResponseViewState, JSResponseState } from "./utils";
|
|
|
|
|
import { NoResponse } from "PluginActionEditor/components/PluginActionResponse/components/NoResponse";
|
2023-04-10 12:59:14 +00:00
|
|
|
import {
|
2024-12-10 07:06:57 +00:00
|
|
|
ResponseErrorContainer,
|
|
|
|
|
ResponseErrorContent,
|
|
|
|
|
} from "PluginActionEditor/components/PluginActionResponse/components/Response";
|
2024-02-29 06:23:57 +00:00
|
|
|
import { getJsPaneDebuggerState } from "selectors/jsPaneSelectors";
|
|
|
|
|
import { setJsPaneDebuggerState } from "actions/jsPaneActions";
|
|
|
|
|
import { getIDEViewMode } from "selectors/ideSelectors";
|
2025-01-03 12:35:09 +00:00
|
|
|
import { EditorViewMode, IDE_TYPE } from "ee/entities/IDE/constants";
|
2024-02-29 06:23:57 +00:00
|
|
|
import ErrorLogs from "./Debugger/Errors";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { isBrowserExecutionAllowed } from "ee/utils/actionExecutionUtils";
|
|
|
|
|
import JSRemoteExecutionView from "ee/components/JSRemoteExecutionView";
|
2024-09-25 07:44:26 +00:00
|
|
|
import { IDEBottomView, ViewHideBehaviour } from "IDE";
|
2025-01-03 12:35:09 +00:00
|
|
|
import { StateInspector } from "./Debugger/StateInspector";
|
|
|
|
|
import { getErrorCount } from "selectors/debuggerSelectors";
|
|
|
|
|
import { getIDETypeByUrl } from "ee/entities/IDE/utils";
|
|
|
|
|
import { useLocation } from "react-router";
|
2021-09-08 17:32:22 +00:00
|
|
|
|
|
|
|
|
const ResponseTabWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
width: 100%;
|
2023-10-24 06:15:43 +00:00
|
|
|
height: 100%;
|
2023-05-19 18:37:06 +00:00
|
|
|
|
2021-09-21 06:02:45 +00:00
|
|
|
&.disable * {
|
|
|
|
|
opacity: 0.8;
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
}
|
2024-10-08 10:42:27 +00:00
|
|
|
|
2021-11-08 06:49:22 +00:00
|
|
|
.response-run {
|
|
|
|
|
margin: 0 10px;
|
|
|
|
|
}
|
2021-09-08 17:32:22 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-04-28 16:51:02 +00:00
|
|
|
const NoReturnValueWrapper = styled.div`
|
|
|
|
|
padding-left: ${(props) => props.theme.spaces[12]}px;
|
|
|
|
|
padding-top: ${(props) => props.theme.spaces[6]}px;
|
|
|
|
|
`;
|
|
|
|
|
|
2025-01-03 12:35:09 +00:00
|
|
|
interface Props {
|
|
|
|
|
currentFunction: JSAction | null;
|
|
|
|
|
theme?: EditorTheme;
|
|
|
|
|
errors: Array<EvaluationError>;
|
|
|
|
|
disabled: boolean;
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
onButtonClick: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
|
|
|
|
jsCollectionData: JSCollectionData | undefined;
|
|
|
|
|
debuggerLogsDefaultName?: string;
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function JSResponseView(props: Props) {
|
2022-04-28 16:51:02 +00:00
|
|
|
const {
|
|
|
|
|
currentFunction,
|
|
|
|
|
disabled,
|
|
|
|
|
errors,
|
|
|
|
|
isLoading,
|
2023-12-09 14:54:43 +00:00
|
|
|
jsCollectionData,
|
2022-04-28 16:51:02 +00:00
|
|
|
onButtonClick,
|
2025-01-03 12:35:09 +00:00
|
|
|
theme,
|
2022-04-28 16:51:02 +00:00
|
|
|
} = props;
|
|
|
|
|
const [responseStatus, setResponseStatus] = useState<JSResponseState>(
|
|
|
|
|
JSResponseState.NoResponse,
|
|
|
|
|
);
|
2025-01-03 12:35:09 +00:00
|
|
|
const errorCount = useSelector(getErrorCount);
|
|
|
|
|
|
|
|
|
|
const { isDirty, isExecuting, responses } = useMemo(() => {
|
|
|
|
|
return {
|
|
|
|
|
responses: (jsCollectionData && jsCollectionData.data) || {},
|
|
|
|
|
isDirty: (jsCollectionData && jsCollectionData.isDirty) || {},
|
|
|
|
|
isExecuting: (jsCollectionData && jsCollectionData.isExecuting) || {},
|
|
|
|
|
};
|
|
|
|
|
}, [jsCollectionData]);
|
|
|
|
|
|
2021-09-08 17:32:22 +00:00
|
|
|
const dispatch = useDispatch();
|
2025-01-03 12:35:09 +00:00
|
|
|
|
|
|
|
|
const response = useMemo(() => {
|
|
|
|
|
if (
|
|
|
|
|
!currentFunction ||
|
|
|
|
|
!currentFunction.id ||
|
|
|
|
|
!(currentFunction.id in responses)
|
|
|
|
|
) {
|
|
|
|
|
return { value: "" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { value: responses[currentFunction.id] as string };
|
|
|
|
|
}, [currentFunction, responses]);
|
|
|
|
|
|
2022-05-19 10:57:49 +00:00
|
|
|
// parse error found while trying to execute function
|
|
|
|
|
const hasExecutionParseErrors = responseStatus === JSResponseState.IsDirty;
|
|
|
|
|
// error found while trying to parse JS Object
|
2022-05-19 13:13:51 +00:00
|
|
|
const isSaving = useSelector(getIsSavingEntity);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2022-04-28 16:51:02 +00:00
|
|
|
useEffect(() => {
|
2022-05-19 13:13:51 +00:00
|
|
|
setResponseStatus(
|
|
|
|
|
getJSResponseViewState(
|
|
|
|
|
currentFunction,
|
|
|
|
|
isDirty,
|
|
|
|
|
isExecuting,
|
|
|
|
|
isSaving,
|
|
|
|
|
responses,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}, [responses, isExecuting, currentFunction, isSaving, isDirty]);
|
2023-04-10 12:59:14 +00:00
|
|
|
|
2024-05-04 00:16:37 +00:00
|
|
|
const localExecutionAllowed = useMemo(() => {
|
|
|
|
|
return isBrowserExecutionAllowed(
|
|
|
|
|
jsCollectionData?.config,
|
|
|
|
|
currentFunction || undefined,
|
|
|
|
|
);
|
|
|
|
|
}, [jsCollectionData?.config, currentFunction]);
|
|
|
|
|
|
2025-01-03 12:35:09 +00:00
|
|
|
const JSResponseTab = useMemo(() => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{localExecutionAllowed && hasExecutionParseErrors && (
|
|
|
|
|
<ResponseErrorContainer>
|
|
|
|
|
<ResponseErrorContent>
|
|
|
|
|
<div className="t--js-response-parse-error-call-out">
|
|
|
|
|
Function failed to execute. Check logs for more information.
|
|
|
|
|
</div>
|
|
|
|
|
</ResponseErrorContent>
|
|
|
|
|
</ResponseErrorContainer>
|
|
|
|
|
)}
|
|
|
|
|
<ResponseTabWrapper
|
|
|
|
|
className={errors.length && localExecutionAllowed ? "disable" : ""}
|
|
|
|
|
>
|
|
|
|
|
<Flex px="spaces-7" width="100%">
|
|
|
|
|
<>
|
|
|
|
|
{localExecutionAllowed && (
|
|
|
|
|
<>
|
|
|
|
|
{responseStatus === JSResponseState.NoResponse && (
|
|
|
|
|
<NoResponse
|
|
|
|
|
isRunDisabled={disabled}
|
|
|
|
|
isRunning={isLoading}
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
onRunClick={onButtonClick}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{responseStatus === JSResponseState.IsExecuting && (
|
|
|
|
|
<LoadingOverlayScreen theme={theme}>
|
|
|
|
|
{createMessage(EXECUTING_FUNCTION)}
|
|
|
|
|
</LoadingOverlayScreen>
|
|
|
|
|
)}
|
|
|
|
|
{responseStatus === JSResponseState.NoReturnValue && (
|
|
|
|
|
<NoReturnValueWrapper>
|
|
|
|
|
<Text kind="body-m">
|
|
|
|
|
{createMessage(
|
|
|
|
|
NO_JS_FUNCTION_RETURN_VALUE,
|
|
|
|
|
currentFunction?.name,
|
|
|
|
|
)}
|
|
|
|
|
</Text>
|
|
|
|
|
</NoReturnValueWrapper>
|
|
|
|
|
)}
|
|
|
|
|
{responseStatus === JSResponseState.ShowResponse && (
|
|
|
|
|
<ReadOnlyEditor folding height="100%" input={response} />
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{!localExecutionAllowed && (
|
|
|
|
|
<JSRemoteExecutionView collectionData={jsCollectionData} />
|
|
|
|
|
)}
|
|
|
|
|
{responseStatus === JSResponseState.IsUpdating && (
|
|
|
|
|
<LoadingOverlayScreen theme={theme}>
|
|
|
|
|
{createMessage(UPDATING_JS_COLLECTION)}
|
|
|
|
|
</LoadingOverlayScreen>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
</Flex>
|
|
|
|
|
</ResponseTabWrapper>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}, [
|
|
|
|
|
currentFunction?.name,
|
|
|
|
|
disabled,
|
|
|
|
|
errors.length,
|
|
|
|
|
hasExecutionParseErrors,
|
|
|
|
|
isLoading,
|
|
|
|
|
jsCollectionData,
|
|
|
|
|
localExecutionAllowed,
|
|
|
|
|
onButtonClick,
|
|
|
|
|
theme,
|
|
|
|
|
response,
|
|
|
|
|
responseStatus,
|
|
|
|
|
]);
|
|
|
|
|
|
2024-02-29 06:23:57 +00:00
|
|
|
const ideViewMode = useSelector(getIDEViewMode);
|
2025-01-03 12:35:09 +00:00
|
|
|
const location = useLocation();
|
2024-02-29 06:23:57 +00:00
|
|
|
|
2025-01-03 12:35:09 +00:00
|
|
|
const ideType = getIDETypeByUrl(location.pathname);
|
2021-09-08 17:32:22 +00:00
|
|
|
|
2025-01-03 12:35:09 +00:00
|
|
|
const tabs = useMemo(() => {
|
|
|
|
|
const jsTabs: BottomTab[] = [
|
|
|
|
|
{
|
|
|
|
|
key: DEBUGGER_TAB_KEYS.RESPONSE_TAB,
|
|
|
|
|
title: createMessage(DEBUGGER_RESPONSE),
|
|
|
|
|
panelComponent: JSResponseTab,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: DEBUGGER_TAB_KEYS.LOGS_TAB,
|
|
|
|
|
title: createMessage(DEBUGGER_LOGS),
|
|
|
|
|
panelComponent: <DebuggerLogs />,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (ideViewMode === EditorViewMode.FullScreen) {
|
|
|
|
|
jsTabs.push({
|
|
|
|
|
key: DEBUGGER_TAB_KEYS.ERROR_TAB,
|
|
|
|
|
title: createMessage(DEBUGGER_ERRORS),
|
|
|
|
|
count: errorCount,
|
|
|
|
|
panelComponent: <ErrorLogs />,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (ideType === IDE_TYPE.App) {
|
|
|
|
|
jsTabs.push({
|
|
|
|
|
key: DEBUGGER_TAB_KEYS.STATE_TAB,
|
|
|
|
|
title: createMessage(DEBUGGER_STATE),
|
|
|
|
|
panelComponent: <StateInspector />,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return jsTabs;
|
|
|
|
|
}, [JSResponseTab, errorCount, ideType, ideViewMode]);
|
2024-02-29 06:23:57 +00:00
|
|
|
|
2023-04-10 12:59:14 +00:00
|
|
|
// get the selected tab from the store.
|
2024-02-29 06:23:57 +00:00
|
|
|
const { open, responseTabHeight, selectedTab } = useSelector(
|
|
|
|
|
getJsPaneDebuggerState,
|
|
|
|
|
);
|
|
|
|
|
|
2023-04-10 12:59:14 +00:00
|
|
|
// set the selected tab in the store.
|
2025-01-03 12:35:09 +00:00
|
|
|
const setSelectedResponseTab = useCallback(
|
|
|
|
|
(selectedTab: string) => {
|
|
|
|
|
dispatch(setJsPaneDebuggerState({ open: true, selectedTab }));
|
|
|
|
|
},
|
|
|
|
|
[dispatch],
|
|
|
|
|
);
|
2023-04-10 12:59:14 +00:00
|
|
|
// set the height of the response pane on resize.
|
2025-01-03 12:35:09 +00:00
|
|
|
const setResponseHeight = useCallback(
|
|
|
|
|
(height: number) => {
|
|
|
|
|
dispatch(setJsPaneDebuggerState({ responseTabHeight: height }));
|
|
|
|
|
},
|
|
|
|
|
[dispatch],
|
|
|
|
|
);
|
2022-10-17 15:16:38 +00:00
|
|
|
|
2023-04-10 12:59:14 +00:00
|
|
|
// close the debugger
|
2024-05-22 14:13:07 +00:00
|
|
|
const onToggle = useCallback(
|
|
|
|
|
() => dispatch(setJsPaneDebuggerState({ open: !open })),
|
2025-01-03 12:35:09 +00:00
|
|
|
[dispatch, open],
|
2024-05-22 14:13:07 +00:00
|
|
|
);
|
2023-05-12 05:47:26 +00:00
|
|
|
|
|
|
|
|
// Do not render if header tab is selected in the bottom bar.
|
2024-05-22 14:13:07 +00:00
|
|
|
return (
|
|
|
|
|
<IDEBottomView
|
|
|
|
|
behaviour={ViewHideBehaviour.COLLAPSE}
|
|
|
|
|
className="t--js-editor-bottom-pane-container"
|
|
|
|
|
height={responseTabHeight}
|
|
|
|
|
hidden={!open}
|
|
|
|
|
onHideClick={onToggle}
|
|
|
|
|
setHeight={setResponseHeight}
|
2022-10-20 12:08:48 +00:00
|
|
|
>
|
2024-05-22 14:13:07 +00:00
|
|
|
<EntityBottomTabs
|
|
|
|
|
isCollapsed={!open}
|
|
|
|
|
onSelect={setSelectedResponseTab}
|
|
|
|
|
selectedTabKey={selectedTab || ""}
|
|
|
|
|
tabs={tabs}
|
2022-10-17 15:16:38 +00:00
|
|
|
/>
|
2024-05-22 14:13:07 +00:00
|
|
|
</IDEBottomView>
|
|
|
|
|
);
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-03 12:35:09 +00:00
|
|
|
export default JSResponseView;
|