2024-05-22 14:13:07 +00:00
|
|
|
import React, { useCallback, useState } from "react";
|
2023-11-24 06:04:06 +00:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
2023-04-10 12:59:14 +00:00
|
|
|
import ReactJson from "react-json-view";
|
2019-10-25 05:35:20 +00:00
|
|
|
import styled from "styled-components";
|
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 { ActionResponse } from "api/ActionAPI";
|
2023-04-10 12:59:14 +00:00
|
|
|
import type { SourceEntity } from "entities/AppsmithConsole";
|
|
|
|
|
import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { ENTITY_TYPE } from "ee/entities/AppsmithConsole/utils";
|
2020-07-01 10:01:07 +00:00
|
|
|
import ReadOnlyEditor from "components/editorComponents/ReadOnlyEditor";
|
2022-03-30 13:12:15 +00:00
|
|
|
import { isArray, isEmpty, isString } from "lodash";
|
2021-06-09 12:45:41 +00:00
|
|
|
import {
|
|
|
|
|
CHECK_REQUEST_BODY,
|
|
|
|
|
createMessage,
|
2024-02-29 06:23:57 +00:00
|
|
|
DEBUGGER_ERRORS,
|
2021-06-09 12:45:41 +00:00
|
|
|
DEBUGGER_LOGS,
|
2024-05-15 08:28:49 +00:00
|
|
|
DEBUGGER_RESPONSE,
|
2021-07-07 03:46:16 +00:00
|
|
|
EMPTY_RESPONSE_FIRST_HALF,
|
|
|
|
|
EMPTY_RESPONSE_LAST_HALF,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/constants/messages";
|
2023-11-24 06:04:06 +00:00
|
|
|
import { EditorTheme } from "./CodeEditor/EditorConfig";
|
2023-05-19 18:37:06 +00:00
|
|
|
import NoResponseSVG from "assets/images/no-response.svg";
|
2021-04-23 13:50:55 +00:00
|
|
|
import DebuggerLogs from "./Debugger/DebuggerLogs";
|
|
|
|
|
import ErrorLogs from "./Debugger/Errors";
|
2024-08-06 14:52:22 +00:00
|
|
|
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
|
2024-08-08 12:55:00 +00:00
|
|
|
import { Classes, Text, TextType } from "@appsmith/ads-old";
|
2024-08-09 14:20:29 +00:00
|
|
|
import { Button, Callout, Flex, SegmentedControl } from "@appsmith/ads";
|
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";
|
|
|
|
|
import { DEBUGGER_TAB_KEYS } from "./Debugger/helpers";
|
2022-04-08 16:32:34 +00:00
|
|
|
import Table from "pages/Editor/QueryEditor/Table";
|
2022-09-09 15:59:47 +00:00
|
|
|
import { API_RESPONSE_TYPE_OPTIONS } from "constants/ApiEditorConstants/CommonApiConstants";
|
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 { setActionResponseDisplayFormat } from "actions/pluginActionActions";
|
2022-03-16 14:25:56 +00:00
|
|
|
import { isHtml } from "./utils";
|
2024-02-29 06:23:57 +00:00
|
|
|
import { getErrorCount } from "selectors/debuggerSelectors";
|
2022-10-17 15:16:38 +00:00
|
|
|
import { ActionExecutionResizerHeight } from "pages/Editor/APIEditor/constants";
|
2023-04-10 12:59:14 +00:00
|
|
|
import LogAdditionalInfo from "./Debugger/ErrorLogs/components/LogAdditionalInfo";
|
|
|
|
|
import {
|
|
|
|
|
JsonWrapper,
|
|
|
|
|
reactJsonProps,
|
|
|
|
|
} from "./Debugger/ErrorLogs/components/LogCollapseData";
|
|
|
|
|
import LogHelper from "./Debugger/ErrorLogs/components/LogHelper";
|
|
|
|
|
import { getUpdateTimestamp } from "./Debugger/ErrorLogs/ErrorLogItem";
|
|
|
|
|
import type { Action } from "entities/Action";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { SegmentedControlContainer } from "../../pages/Editor/QueryEditor/EditorJSONtoForm";
|
|
|
|
|
import ActionExecutionInProgressView from "./ActionExecutionInProgressView";
|
2023-07-16 18:49:41 +00:00
|
|
|
import { EMPTY_RESPONSE } from "./emptyResponse";
|
2024-02-29 06:23:57 +00:00
|
|
|
import { setApiPaneDebuggerState } from "actions/apiPaneActions";
|
|
|
|
|
import { getApiPaneDebuggerState } from "selectors/apiPaneSelectors";
|
|
|
|
|
import { getIDEViewMode } from "selectors/ideSelectors";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { EditorViewMode } from "ee/entities/IDE/constants";
|
2024-04-12 10:08:22 +00:00
|
|
|
import ApiResponseMeta from "./ApiResponseMeta";
|
2024-05-10 05:04:53 +00:00
|
|
|
import useDebuggerTriggerClick from "./Debugger/hooks/useDebuggerTriggerClick";
|
2024-05-22 14:13:07 +00:00
|
|
|
import { IDEBottomView, ViewHideBehaviour } from "IDE";
|
2020-12-08 09:24:36 +00:00
|
|
|
|
2021-02-22 06:15:02 +00:00
|
|
|
const ResponseTabWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
2023-05-19 18:37:06 +00:00
|
|
|
&.t--headers-tab {
|
|
|
|
|
padding-left: var(--ads-v2-spaces-7);
|
|
|
|
|
padding-right: var(--ads-v2-spaces-7);
|
|
|
|
|
}
|
2019-10-29 12:02:58 +00:00
|
|
|
`;
|
2019-10-25 05:35:20 +00:00
|
|
|
|
2021-02-11 12:54:00 +00:00
|
|
|
const NoResponseContainer = styled.div`
|
2021-09-02 18:26:30 +00:00
|
|
|
flex: 1;
|
2021-02-22 06:15:02 +00:00
|
|
|
width: 100%;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
flex-direction: column;
|
2021-02-11 12:54:00 +00:00
|
|
|
.${Classes.ICON} {
|
2023-05-19 18:37:06 +00:00
|
|
|
margin-right: 0;
|
2021-02-11 12:54:00 +00:00
|
|
|
svg {
|
|
|
|
|
width: 150px;
|
|
|
|
|
height: 150px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.${Classes.TEXT} {
|
|
|
|
|
margin-top: ${(props) => props.theme.spaces[9]}px;
|
|
|
|
|
}
|
2020-06-12 03:54:12 +00:00
|
|
|
`;
|
|
|
|
|
|
2021-07-09 17:01:50 +00:00
|
|
|
const HelpSection = styled.div`
|
2021-09-02 18:26:30 +00:00
|
|
|
padding-bottom: 5px;
|
|
|
|
|
padding-top: 10px;
|
2021-07-09 17:01:50 +00:00
|
|
|
`;
|
|
|
|
|
|
2022-04-11 14:59:13 +00:00
|
|
|
const ResponseBodyContainer = styled.div`
|
2023-05-29 05:40:41 +00:00
|
|
|
overflow-y: clip;
|
2022-05-19 03:02:43 +00:00
|
|
|
height: 100%;
|
|
|
|
|
display: grid;
|
2022-04-11 14:59:13 +00:00
|
|
|
`;
|
|
|
|
|
|
2023-11-24 06:04:06 +00:00
|
|
|
interface Props {
|
|
|
|
|
currentActionConfig?: Action;
|
|
|
|
|
theme?: EditorTheme;
|
|
|
|
|
apiName: string;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
onRunClick: () => void;
|
|
|
|
|
responseDataTypes: { key: string; title: string }[];
|
|
|
|
|
responseDisplayFormat: { title: string; value: string };
|
|
|
|
|
actionResponse?: ActionResponse;
|
|
|
|
|
isRunning: boolean;
|
2022-04-08 16:32:34 +00:00
|
|
|
}
|
2021-02-22 06:15:02 +00:00
|
|
|
|
2021-09-02 18:26:30 +00:00
|
|
|
const ResponseDataContainer = styled.div`
|
|
|
|
|
flex: 1;
|
|
|
|
|
overflow: auto;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
& .CodeEditorTarget {
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2023-04-10 12:59:14 +00:00
|
|
|
export const ResponseTabErrorContainer = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
padding: 8px 16px;
|
|
|
|
|
gap: 8px;
|
2023-05-19 18:37:06 +00:00
|
|
|
height: fit-content;
|
|
|
|
|
background: var(--ads-v2-color-bg-error);
|
|
|
|
|
border-bottom: 1px solid var(--ads-v2-color-border);
|
2023-04-10 12:59:14 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const ResponseTabErrorContent = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: flex-start;
|
|
|
|
|
gap: 4px;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
line-height: 16px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const ResponseTabErrorDefaultMessage = styled.div`
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const apiReactJsonProps = { ...reactJsonProps, collapsed: 0 };
|
|
|
|
|
|
2022-04-08 16:32:34 +00:00
|
|
|
export const responseTabComponent = (
|
|
|
|
|
responseType: string,
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2022-04-08 16:32:34 +00:00
|
|
|
output: any,
|
|
|
|
|
tableBodyHeight?: number,
|
|
|
|
|
): JSX.Element => {
|
|
|
|
|
return {
|
|
|
|
|
[API_RESPONSE_TYPE_OPTIONS.JSON]: (
|
|
|
|
|
<ReadOnlyEditor
|
|
|
|
|
folding
|
|
|
|
|
height={"100%"}
|
|
|
|
|
input={{
|
2022-04-14 07:23:07 +00:00
|
|
|
value: isString(output) ? output : JSON.stringify(output, null, 2),
|
2022-04-08 16:32:34 +00:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
[API_RESPONSE_TYPE_OPTIONS.TABLE]: (
|
|
|
|
|
<Table data={output} tableBodyHeight={tableBodyHeight} />
|
|
|
|
|
),
|
|
|
|
|
[API_RESPONSE_TYPE_OPTIONS.RAW]: (
|
|
|
|
|
<ReadOnlyEditor
|
|
|
|
|
folding
|
|
|
|
|
height={"100%"}
|
|
|
|
|
input={{
|
2022-04-14 07:23:07 +00:00
|
|
|
value: isString(output) ? output : JSON.stringify(output, null, 2),
|
2022-04-08 16:32:34 +00:00
|
|
|
}}
|
|
|
|
|
isRawView
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
}[responseType];
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
const StyledText = styled(Text)`
|
|
|
|
|
&&&& {
|
|
|
|
|
margin-top: 0;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
interface NoResponseProps {
|
|
|
|
|
isButtonDisabled: boolean | undefined;
|
|
|
|
|
isQueryRunning: boolean;
|
|
|
|
|
onRunClick: () => void;
|
|
|
|
|
}
|
|
|
|
|
export const NoResponse = (props: NoResponseProps) => (
|
|
|
|
|
<NoResponseContainer>
|
|
|
|
|
<img alt="no-response-yet" src={NoResponseSVG} />
|
|
|
|
|
<div className="flex gap-2 items-center mt-4">
|
|
|
|
|
<StyledText type={TextType.P1}>{EMPTY_RESPONSE_FIRST_HALF()}</StyledText>
|
|
|
|
|
<Button
|
|
|
|
|
isDisabled={props.isButtonDisabled}
|
|
|
|
|
isLoading={props.isQueryRunning}
|
|
|
|
|
onClick={props.onRunClick}
|
|
|
|
|
size="sm"
|
|
|
|
|
>
|
|
|
|
|
Run
|
|
|
|
|
</Button>
|
|
|
|
|
<StyledText type={TextType.P1}>{EMPTY_RESPONSE_LAST_HALF()}</StyledText>
|
|
|
|
|
</div>
|
|
|
|
|
</NoResponseContainer>
|
|
|
|
|
);
|
2022-08-12 07:19:17 +00:00
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
function ApiResponseView(props: Props) {
|
2019-11-22 17:04:40 +00:00
|
|
|
const {
|
2023-11-24 06:04:06 +00:00
|
|
|
actionResponse = EMPTY_RESPONSE,
|
2024-07-23 11:06:22 +00:00
|
|
|
apiName,
|
2023-11-24 06:04:06 +00:00
|
|
|
currentActionConfig,
|
2022-12-01 06:30:50 +00:00
|
|
|
disabled,
|
2023-11-24 06:04:06 +00:00
|
|
|
isRunning,
|
2022-04-08 16:32:34 +00:00
|
|
|
responseDataTypes,
|
|
|
|
|
responseDisplayFormat,
|
2023-11-24 06:04:06 +00:00
|
|
|
theme = EditorTheme.LIGHT,
|
2019-11-22 17:04:40 +00:00
|
|
|
} = props;
|
2023-11-24 06:04:06 +00:00
|
|
|
const hasFailed = actionResponse.statusCode
|
|
|
|
|
? actionResponse.statusCode[0] !== "2"
|
|
|
|
|
: false;
|
|
|
|
|
|
2021-10-04 08:01:46 +00:00
|
|
|
const dispatch = useDispatch();
|
2023-11-24 06:04:06 +00:00
|
|
|
const errorCount = useSelector(getErrorCount);
|
2024-02-29 06:23:57 +00:00
|
|
|
const { open, responseTabHeight, selectedTab } = useSelector(
|
|
|
|
|
getApiPaneDebuggerState,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const ideViewMode = useSelector(getIDEViewMode);
|
2020-05-30 02:39:18 +00:00
|
|
|
|
2024-05-10 05:04:53 +00:00
|
|
|
const onDebugClick = useDebuggerTriggerClick();
|
2021-04-23 13:50:55 +00:00
|
|
|
|
2021-07-26 10:59:15 +00:00
|
|
|
const onRunClick = () => {
|
|
|
|
|
props.onRunClick();
|
|
|
|
|
AnalyticsUtil.logEvent("RESPONSE_TAB_RUN_ACTION_CLICK", {
|
|
|
|
|
source: "API_PANE",
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-24 06:04:06 +00:00
|
|
|
const messages = actionResponse?.messages;
|
2022-03-30 13:12:15 +00:00
|
|
|
let responseHeaders = {};
|
2022-02-04 11:32:38 +00:00
|
|
|
|
|
|
|
|
// if no headers are present in the response, use the default body text.
|
2023-11-24 06:04:06 +00:00
|
|
|
if (actionResponse.headers) {
|
|
|
|
|
Object.entries(actionResponse.headers).forEach(([key, value]) => {
|
2022-03-30 13:12:15 +00:00
|
|
|
if (isArray(value) && value.length < 2)
|
|
|
|
|
return (responseHeaders = {
|
|
|
|
|
...responseHeaders,
|
|
|
|
|
[key]: value[0],
|
|
|
|
|
});
|
|
|
|
|
return (responseHeaders = {
|
|
|
|
|
...responseHeaders,
|
|
|
|
|
[key]: value,
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-02-04 11:32:38 +00:00
|
|
|
} else {
|
2022-03-30 13:12:15 +00:00
|
|
|
// if the response headers is empty show an empty object.
|
|
|
|
|
responseHeaders = {};
|
2022-02-04 11:32:38 +00:00
|
|
|
}
|
2021-09-02 18:26:30 +00:00
|
|
|
|
2022-10-17 15:16:38 +00:00
|
|
|
const onResponseTabSelect = (tab: string) => {
|
2023-11-24 06:04:06 +00:00
|
|
|
dispatch(
|
|
|
|
|
setActionResponseDisplayFormat({
|
|
|
|
|
id: currentActionConfig?.id || "",
|
|
|
|
|
field: "responseDisplayFormat",
|
|
|
|
|
value: tab,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2022-10-17 15:16:38 +00:00
|
|
|
};
|
|
|
|
|
|
2022-10-19 06:00:04 +00:00
|
|
|
let filteredResponseDataTypes: { key: string; title: string }[] = [
|
|
|
|
|
...responseDataTypes,
|
|
|
|
|
];
|
2023-11-24 06:04:06 +00:00
|
|
|
if (!!actionResponse.body && !isArray(actionResponse.body)) {
|
2022-10-19 06:00:04 +00:00
|
|
|
filteredResponseDataTypes = responseDataTypes.filter(
|
|
|
|
|
(item) => item.key !== API_RESPONSE_TYPE_OPTIONS.TABLE,
|
|
|
|
|
);
|
|
|
|
|
if (responseDisplayFormat.title === API_RESPONSE_TYPE_OPTIONS.TABLE) {
|
|
|
|
|
onResponseTabSelect(filteredResponseDataTypes[0]?.title);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
const responseTabs =
|
|
|
|
|
filteredResponseDataTypes &&
|
|
|
|
|
filteredResponseDataTypes.map((dataType, index) => {
|
|
|
|
|
return {
|
|
|
|
|
index: index,
|
|
|
|
|
key: dataType.key,
|
|
|
|
|
title: dataType.title,
|
|
|
|
|
panelComponent: responseTabComponent(
|
|
|
|
|
dataType.key,
|
2023-11-24 06:04:06 +00:00
|
|
|
actionResponse?.body,
|
2024-02-29 06:23:57 +00:00
|
|
|
responseTabHeight,
|
2023-05-19 18:37:06 +00:00
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const segmentedControlOptions =
|
|
|
|
|
responseTabs &&
|
|
|
|
|
responseTabs.map((item) => {
|
|
|
|
|
return { value: item.key, label: item.title };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const [selectedControl, setSelectedControl] = useState(
|
|
|
|
|
segmentedControlOptions[0]?.value,
|
|
|
|
|
);
|
|
|
|
|
|
2022-10-17 15:16:38 +00:00
|
|
|
const selectedTabIndex =
|
2022-10-19 06:00:04 +00:00
|
|
|
filteredResponseDataTypes &&
|
|
|
|
|
filteredResponseDataTypes.findIndex(
|
2022-10-17 15:16:38 +00:00
|
|
|
(dataType) => dataType.title === responseDisplayFormat?.title,
|
|
|
|
|
);
|
|
|
|
|
|
2023-04-10 12:59:14 +00:00
|
|
|
// update the selected tab in the response pane.
|
2022-10-17 15:16:38 +00:00
|
|
|
const updateSelectedResponseTab = useCallback((tabKey: string) => {
|
2022-11-14 07:01:55 +00:00
|
|
|
if (tabKey === DEBUGGER_TAB_KEYS.ERROR_TAB) {
|
|
|
|
|
AnalyticsUtil.logEvent("OPEN_DEBUGGER", {
|
|
|
|
|
source: "API_PANE",
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-05-22 14:13:07 +00:00
|
|
|
dispatch(setApiPaneDebuggerState({ open: true, selectedTab: tabKey }));
|
2022-10-17 15:16:38 +00:00
|
|
|
}, []);
|
2024-02-29 06:23:57 +00:00
|
|
|
|
2023-04-10 12:59:14 +00:00
|
|
|
// update the height of the response pane on resize.
|
2022-10-17 15:16:38 +00:00
|
|
|
const updateResponsePaneHeight = useCallback((height: number) => {
|
2024-02-29 06:23:57 +00:00
|
|
|
dispatch(setApiPaneDebuggerState({ responseTabHeight: height }));
|
2022-10-17 15:16:38 +00:00
|
|
|
}, []);
|
|
|
|
|
|
2023-04-10 12:59:14 +00:00
|
|
|
// get request timestamp formatted to human readable format.
|
2023-11-24 06:04:06 +00:00
|
|
|
const responseState = getUpdateTimestamp(actionResponse.request);
|
2023-04-10 12:59:14 +00:00
|
|
|
// action source for analytics.
|
|
|
|
|
const actionSource: SourceEntity = {
|
|
|
|
|
type: ENTITY_TYPE.ACTION,
|
|
|
|
|
name: currentActionConfig ? currentActionConfig.name : "API",
|
2023-11-24 06:04:06 +00:00
|
|
|
id: currentActionConfig?.id || "",
|
2023-04-10 12:59:14 +00:00
|
|
|
};
|
2024-02-29 06:23:57 +00:00
|
|
|
const tabs: BottomTab[] = [
|
2020-05-22 03:43:01 +00:00
|
|
|
{
|
2022-04-22 11:10:00 +00:00
|
|
|
key: "response",
|
2024-05-15 08:28:49 +00:00
|
|
|
title: createMessage(DEBUGGER_RESPONSE),
|
2020-05-22 03:43:01 +00:00
|
|
|
panelComponent: (
|
2021-02-22 06:15:02 +00:00
|
|
|
<ResponseTabWrapper>
|
2024-04-12 10:08:22 +00:00
|
|
|
<ApiResponseMeta
|
2024-07-23 11:06:22 +00:00
|
|
|
actionName={apiName || currentActionConfig?.name}
|
2024-04-12 10:08:22 +00:00
|
|
|
actionResponse={actionResponse}
|
|
|
|
|
/>
|
2021-09-02 18:26:30 +00:00
|
|
|
{Array.isArray(messages) && messages.length > 0 && (
|
2021-07-09 17:01:50 +00:00
|
|
|
<HelpSection>
|
|
|
|
|
{messages.map((msg, i) => (
|
2023-05-19 18:37:06 +00:00
|
|
|
<Callout key={i} kind="warning">
|
|
|
|
|
{msg}
|
|
|
|
|
</Callout>
|
2021-07-09 17:01:50 +00:00
|
|
|
))}
|
|
|
|
|
</HelpSection>
|
|
|
|
|
)}
|
2024-02-08 07:55:23 +00:00
|
|
|
{isRunning && (
|
|
|
|
|
<ActionExecutionInProgressView actionType="API" theme={theme} />
|
|
|
|
|
)}
|
2023-04-10 12:59:14 +00:00
|
|
|
{hasFailed && !isRunning ? (
|
|
|
|
|
<ResponseTabErrorContainer>
|
|
|
|
|
<ResponseTabErrorContent>
|
|
|
|
|
<ResponseTabErrorDefaultMessage>
|
|
|
|
|
Your API failed to execute
|
2023-11-24 06:04:06 +00:00
|
|
|
{actionResponse.pluginErrorDetails && ":"}
|
2023-04-10 12:59:14 +00:00
|
|
|
</ResponseTabErrorDefaultMessage>
|
2023-11-24 06:04:06 +00:00
|
|
|
{actionResponse.pluginErrorDetails && (
|
2023-04-10 12:59:14 +00:00
|
|
|
<>
|
2023-09-20 10:42:43 +00:00
|
|
|
<div className="t--debugger-log-downstream-message">
|
2023-11-24 06:04:06 +00:00
|
|
|
{actionResponse.pluginErrorDetails.downstreamErrorMessage}
|
2023-04-10 12:59:14 +00:00
|
|
|
</div>
|
2023-11-24 06:04:06 +00:00
|
|
|
{actionResponse.pluginErrorDetails.downstreamErrorCode && (
|
2023-04-10 12:59:14 +00:00
|
|
|
<LogAdditionalInfo
|
2023-11-24 06:04:06 +00:00
|
|
|
text={
|
|
|
|
|
actionResponse.pluginErrorDetails.downstreamErrorCode
|
|
|
|
|
}
|
2023-04-10 12:59:14 +00:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
<LogHelper
|
|
|
|
|
logType={LOG_TYPE.ACTION_EXECUTION_ERROR}
|
|
|
|
|
name="PluginExecutionError"
|
2023-11-24 06:04:06 +00:00
|
|
|
pluginErrorDetails={actionResponse.pluginErrorDetails}
|
2023-04-10 12:59:14 +00:00
|
|
|
source={actionSource}
|
|
|
|
|
/>
|
|
|
|
|
</ResponseTabErrorContent>
|
2023-11-24 06:04:06 +00:00
|
|
|
{actionResponse.request && (
|
2023-04-10 12:59:14 +00:00
|
|
|
<JsonWrapper
|
|
|
|
|
className="t--debugger-log-state"
|
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
>
|
|
|
|
|
<ReactJson src={responseState} {...apiReactJsonProps} />
|
|
|
|
|
</JsonWrapper>
|
|
|
|
|
)}
|
|
|
|
|
</ResponseTabErrorContainer>
|
|
|
|
|
) : (
|
|
|
|
|
<ResponseDataContainer>
|
2023-11-24 06:04:06 +00:00
|
|
|
{isEmpty(actionResponse.statusCode) ? (
|
2023-05-19 18:37:06 +00:00
|
|
|
<NoResponse
|
|
|
|
|
isButtonDisabled={disabled}
|
|
|
|
|
isQueryRunning={isRunning}
|
|
|
|
|
onRunClick={onRunClick}
|
|
|
|
|
/>
|
2023-04-10 12:59:14 +00:00
|
|
|
) : (
|
|
|
|
|
<ResponseBodyContainer>
|
2023-11-24 06:04:06 +00:00
|
|
|
{isString(actionResponse?.body) &&
|
|
|
|
|
isHtml(actionResponse?.body) ? (
|
2023-04-10 12:59:14 +00:00
|
|
|
<ReadOnlyEditor
|
|
|
|
|
folding
|
|
|
|
|
height={"100%"}
|
|
|
|
|
input={{
|
2023-11-24 06:04:06 +00:00
|
|
|
value: actionResponse?.body,
|
2023-04-10 12:59:14 +00:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : responseTabs &&
|
|
|
|
|
responseTabs.length > 0 &&
|
|
|
|
|
selectedTabIndex !== -1 ? (
|
2023-05-19 18:37:06 +00:00
|
|
|
<SegmentedControlContainer>
|
2024-04-12 10:08:22 +00:00
|
|
|
<Flex>
|
2024-02-13 08:22:04 +00:00
|
|
|
<SegmentedControl
|
|
|
|
|
data-testid="t--response-tab-segmented-control"
|
|
|
|
|
defaultValue={segmentedControlOptions[0]?.value}
|
|
|
|
|
isFullWidth={false}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
setSelectedControl(value);
|
|
|
|
|
onResponseTabSelect(value);
|
|
|
|
|
}}
|
|
|
|
|
options={segmentedControlOptions}
|
|
|
|
|
value={selectedControl}
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
2023-05-19 18:37:06 +00:00
|
|
|
{responseTabComponent(
|
|
|
|
|
selectedControl || segmentedControlOptions[0]?.value,
|
2023-11-24 06:04:06 +00:00
|
|
|
actionResponse?.body,
|
2024-02-29 06:23:57 +00:00
|
|
|
responseTabHeight,
|
2023-05-19 18:37:06 +00:00
|
|
|
)}
|
|
|
|
|
</SegmentedControlContainer>
|
2023-04-10 12:59:14 +00:00
|
|
|
) : null}
|
|
|
|
|
</ResponseBodyContainer>
|
|
|
|
|
)}
|
|
|
|
|
</ResponseDataContainer>
|
2021-02-11 12:54:00 +00:00
|
|
|
)}
|
2021-02-22 06:15:02 +00:00
|
|
|
</ResponseTabWrapper>
|
2020-05-22 03:43:01 +00:00
|
|
|
),
|
|
|
|
|
},
|
2022-02-04 11:32:38 +00:00
|
|
|
{
|
|
|
|
|
key: "headers",
|
|
|
|
|
title: "Headers",
|
|
|
|
|
panelComponent: (
|
2023-05-19 18:37:06 +00:00
|
|
|
<ResponseTabWrapper className="t--headers-tab">
|
2022-02-04 11:32:38 +00:00
|
|
|
{hasFailed && !isRunning && (
|
2023-05-19 18:37:06 +00:00
|
|
|
<Callout
|
|
|
|
|
kind="error"
|
|
|
|
|
links={[
|
|
|
|
|
{
|
|
|
|
|
children: "Debug",
|
|
|
|
|
endIcon: "bug",
|
2024-05-10 05:04:53 +00:00
|
|
|
onClick: onDebugClick,
|
2023-05-19 18:37:06 +00:00
|
|
|
to: "",
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
>
|
|
|
|
|
{createMessage(CHECK_REQUEST_BODY)}
|
|
|
|
|
</Callout>
|
2022-02-04 11:32:38 +00:00
|
|
|
)}
|
|
|
|
|
<ResponseDataContainer>
|
2023-11-24 06:04:06 +00:00
|
|
|
{isEmpty(actionResponse.statusCode) ? (
|
2023-05-19 18:37:06 +00:00
|
|
|
<NoResponse
|
|
|
|
|
isButtonDisabled={disabled}
|
|
|
|
|
isQueryRunning={isRunning}
|
|
|
|
|
onRunClick={onRunClick}
|
|
|
|
|
/>
|
2022-02-04 11:32:38 +00:00
|
|
|
) : (
|
|
|
|
|
<ReadOnlyEditor
|
|
|
|
|
folding
|
|
|
|
|
height={"100%"}
|
|
|
|
|
input={{
|
2022-11-19 13:59:15 +00:00
|
|
|
value: !isEmpty(responseHeaders)
|
2022-02-04 11:32:38 +00:00
|
|
|
? JSON.stringify(responseHeaders, null, 2)
|
|
|
|
|
: "",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</ResponseDataContainer>
|
|
|
|
|
</ResponseTabWrapper>
|
|
|
|
|
),
|
|
|
|
|
},
|
2020-05-22 03:43:01 +00:00
|
|
|
];
|
|
|
|
|
|
2024-02-29 06:23:57 +00:00
|
|
|
if (ideViewMode === EditorViewMode.FullScreen) {
|
|
|
|
|
tabs.push(
|
|
|
|
|
{
|
|
|
|
|
key: DEBUGGER_TAB_KEYS.ERROR_TAB,
|
|
|
|
|
title: createMessage(DEBUGGER_ERRORS),
|
|
|
|
|
count: errorCount,
|
|
|
|
|
panelComponent: <ErrorLogs />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: DEBUGGER_TAB_KEYS.LOGS_TAB,
|
|
|
|
|
title: createMessage(DEBUGGER_LOGS),
|
|
|
|
|
panelComponent: <DebuggerLogs searchQuery={props.apiName} />,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 12:59:14 +00:00
|
|
|
// close the debugger
|
|
|
|
|
//TODO: move this to a common place
|
2024-05-22 14:13:07 +00:00
|
|
|
const toggleHide = useCallback(
|
|
|
|
|
() => dispatch(setApiPaneDebuggerState({ open: !open })),
|
|
|
|
|
[open],
|
|
|
|
|
);
|
2023-04-10 12:59:14 +00:00
|
|
|
|
2019-10-25 05:35:20 +00:00
|
|
|
return (
|
2024-05-22 14:13:07 +00:00
|
|
|
<IDEBottomView
|
|
|
|
|
behaviour={ViewHideBehaviour.COLLAPSE}
|
|
|
|
|
className="t--api-bottom-pane-container"
|
|
|
|
|
height={responseTabHeight}
|
|
|
|
|
hidden={!open}
|
|
|
|
|
onHideClick={toggleHide}
|
|
|
|
|
setHeight={updateResponsePaneHeight}
|
2024-05-13 18:11:36 +00:00
|
|
|
>
|
2024-05-22 14:13:07 +00:00
|
|
|
<EntityBottomTabs
|
|
|
|
|
expandedHeight={`${ActionExecutionResizerHeight}px`}
|
|
|
|
|
isCollapsed={!open}
|
|
|
|
|
onSelect={updateSelectedResponseTab}
|
|
|
|
|
selectedTabKey={selectedTab || ""}
|
|
|
|
|
tabs={tabs}
|
2022-05-19 03:02:43 +00:00
|
|
|
/>
|
2024-05-22 14:13:07 +00:00
|
|
|
</IDEBottomView>
|
2019-10-25 05:35:20 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-10-25 05:35:20 +00:00
|
|
|
|
2023-11-24 06:04:06 +00:00
|
|
|
export default ApiResponseView;
|