## Description ### Fixes - [x] https://github.com/appsmithorg/appsmith/issues/19383 - [x] https://github.com/appsmithorg/appsmith/issues/19384 - [x] https://github.com/appsmithorg/appsmith/issues/19385 - [x] https://github.com/appsmithorg/appsmith/issues/19386 - [x] https://github.com/appsmithorg/appsmith/issues/19387 - [x] https://github.com/appsmithorg/appsmith/issues/19388 - [x] https://github.com/appsmithorg/appsmith/issues/19389 - [x] https://github.com/appsmithorg/appsmith/issues/19390 - [x] https://github.com/appsmithorg/appsmith/issues/19391 - [x] https://github.com/appsmithorg/appsmith/issues/19392 - [x] https://github.com/appsmithorg/appsmith/issues/19393 - [x] https://github.com/appsmithorg/appsmith/issues/19394 - [x] https://github.com/appsmithorg/appsmith/issues/19395 - [x] https://github.com/appsmithorg/appsmith/issues/19396 - [x] https://github.com/appsmithorg/appsmith/issues/19397 - [x] https://github.com/appsmithorg/appsmith/issues/19398 - [x] https://github.com/appsmithorg/appsmith/issues/19399 - [x] https://github.com/appsmithorg/appsmith/issues/19400 - [x] https://github.com/appsmithorg/appsmith/issues/19401 - [x] https://github.com/appsmithorg/appsmith/issues/19402 - [x] https://github.com/appsmithorg/appsmith/issues/19403 - [x] https://github.com/appsmithorg/appsmith/issues/19404 - [x] https://github.com/appsmithorg/appsmith/issues/19405 - [x] https://github.com/appsmithorg/appsmith/issues/19406 - [x] https://github.com/appsmithorg/appsmith/issues/19407 - [x] https://github.com/appsmithorg/appsmith/issues/19408 - [x] https://github.com/appsmithorg/appsmith/issues/19409 Fixes # (issue) > if no issue exists, please create an issue and ask the maintainers about this first Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update ## How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. > Please also list any relevant details for your test configuration. > Delete anything that is not important - Manual - Jest - Cypress ### 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 - [ ] 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 - [ ] 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: Ankita Kinger <ankita@appsmith.com> Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvi@appsmith.com> Co-authored-by: Arsalan <arsalanyaldram0211@outlook.com> Co-authored-by: Aman Agarwal <aman@appsmith.com> Co-authored-by: Rohit Agarwal <rohit_agarwal@live.in> Co-authored-by: Nilesh Sarupriya <nilesh@appsmith.com> Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Aishwarya UR <aishwarya@appsmith.com> Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local> Co-authored-by: Vijetha-Kaja <vijetha@appsmith.com> Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io> Co-authored-by: Saroj <43822041+sarojsarab@users.noreply.github.com> Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aishwarya-U-R <91450662+Aishwarya-U-R@users.noreply.github.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Preet Sidhu <preetsidhu.bits@gmail.com> Co-authored-by: Vijetha-Kaja <119562824+Vijetha-Kaja@users.noreply.github.com> Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
373 lines
11 KiB
TypeScript
373 lines
11 KiB
TypeScript
import type { RefObject } from "react";
|
|
import React, { useEffect, useRef, useCallback, useState } from "react";
|
|
import { connect, useDispatch, useSelector } from "react-redux";
|
|
import type { RouteComponentProps } from "react-router";
|
|
import { withRouter } from "react-router";
|
|
import styled from "styled-components";
|
|
import { every, includes } from "lodash";
|
|
import type { AppState } from "@appsmith/reducers";
|
|
import type { JSEditorRouteParams } from "constants/routes";
|
|
import {
|
|
createMessage,
|
|
DEBUGGER_LOGS,
|
|
DEBUGGER_ERRORS,
|
|
EXECUTING_FUNCTION,
|
|
NO_JS_FUNCTION_RETURN_VALUE,
|
|
UPDATING_JS_COLLECTION,
|
|
} from "@appsmith/constants/messages";
|
|
import type { EditorTheme } from "./CodeEditor/EditorConfig";
|
|
import DebuggerLogs from "./Debugger/DebuggerLogs";
|
|
import ErrorLogs from "./Debugger/Errors";
|
|
import Resizer, { ResizerCSS } from "./Debugger/Resizer";
|
|
import type { JSCollection, JSAction } from "entities/JSCollection";
|
|
import ReadOnlyEditor from "components/editorComponents/ReadOnlyEditor";
|
|
import { Text } from "design-system";
|
|
import LoadingOverlayScreen from "components/editorComponents/LoadingOverlayScreen";
|
|
import type { JSCollectionData } from "reducers/entityReducers/jsActionsReducer";
|
|
import type { EvaluationError } from "utils/DynamicBindingUtils";
|
|
import { DEBUGGER_TAB_KEYS } from "./Debugger/helpers";
|
|
import EntityBottomTabs from "./EntityBottomTabs";
|
|
import { TAB_MIN_HEIGHT } from "design-system-old";
|
|
import { CodeEditorWithGutterStyles } from "pages/Editor/JSEditor/constants";
|
|
import { getIsSavingEntity } from "selectors/editorSelectors";
|
|
import { getJSResponseViewState } from "./utils";
|
|
import {
|
|
getDebuggerSelectedTab,
|
|
getFilteredErrors,
|
|
getResponsePaneHeight,
|
|
} from "selectors/debuggerSelectors";
|
|
import { ActionExecutionResizerHeight } from "pages/Editor/APIEditor/constants";
|
|
import {
|
|
setDebuggerSelectedTab,
|
|
setResponsePaneHeight,
|
|
showDebugger,
|
|
} from "actions/debuggerActions";
|
|
import {
|
|
NoResponse,
|
|
ResponseTabErrorContainer,
|
|
ResponseTabErrorContent,
|
|
} from "./ApiResponseView";
|
|
import LogHelper from "./Debugger/ErrorLogs/components/LogHelper";
|
|
import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
|
import type { SourceEntity, Log } from "entities/AppsmithConsole";
|
|
import { ENTITY_TYPE } from "entities/AppsmithConsole";
|
|
import { CloseDebugger } from "./Debugger/DebuggerTabs";
|
|
|
|
const ResponseContainer = styled.div`
|
|
${ResizerCSS};
|
|
width: 100%;
|
|
// Minimum height of bottom tabs as it can be resized
|
|
min-height: ${TAB_MIN_HEIGHT};
|
|
background-color: var(--ads-v2-color-bg);
|
|
height: ${ActionExecutionResizerHeight}px;
|
|
|
|
.ads-v2-tabs__panel {
|
|
${CodeEditorWithGutterStyles};
|
|
overflow-y: auto;
|
|
height: calc(100% - ${TAB_MIN_HEIGHT});
|
|
}
|
|
`;
|
|
|
|
const ResponseTabWrapper = styled.div`
|
|
display: flex;
|
|
width: 100%;
|
|
|
|
&.disable * {
|
|
opacity: 0.8;
|
|
pointer-events: none;
|
|
}
|
|
.response-run {
|
|
margin: 0 10px;
|
|
}
|
|
`;
|
|
|
|
const TabbedViewWrapper = styled.div`
|
|
height: 100%;
|
|
`;
|
|
|
|
const ResponseViewer = styled.div`
|
|
width: 100%;
|
|
padding: 0 var(--ads-v2-spaces-7);
|
|
`;
|
|
|
|
const NoReturnValueWrapper = styled.div`
|
|
padding-left: ${(props) => props.theme.spaces[12]}px;
|
|
padding-top: ${(props) => props.theme.spaces[6]}px;
|
|
`;
|
|
|
|
export enum JSResponseState {
|
|
IsExecuting = "IsExecuting",
|
|
IsDirty = "IsDirty",
|
|
IsUpdating = "IsUpdating",
|
|
NoResponse = "NoResponse",
|
|
ShowResponse = "ShowResponse",
|
|
NoReturnValue = "NoReturnValue",
|
|
}
|
|
|
|
interface ReduxStateProps {
|
|
responses: Record<string, any>;
|
|
isExecuting: Record<string, boolean>;
|
|
isDirty: Record<string, boolean>;
|
|
seletedJsObject?: JSCollectionData;
|
|
}
|
|
|
|
type Props = ReduxStateProps &
|
|
RouteComponentProps<JSEditorRouteParams> & {
|
|
currentFunction: JSAction | null;
|
|
theme?: EditorTheme;
|
|
jsObject: JSCollection;
|
|
errorCount: number;
|
|
errors: Array<EvaluationError>;
|
|
disabled: boolean;
|
|
isLoading: boolean;
|
|
onButtonClick: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
|
selectedJSObject: JSCollectionData | undefined;
|
|
};
|
|
|
|
function JSResponseView(props: Props) {
|
|
const {
|
|
currentFunction,
|
|
disabled,
|
|
errorCount,
|
|
errors,
|
|
isDirty,
|
|
isExecuting,
|
|
isLoading,
|
|
jsObject,
|
|
onButtonClick,
|
|
responses,
|
|
selectedJSObject,
|
|
} = props;
|
|
const [responseStatus, setResponseStatus] = useState<JSResponseState>(
|
|
JSResponseState.NoResponse,
|
|
);
|
|
const panelRef: RefObject<HTMLDivElement> = useRef(null);
|
|
const dispatch = useDispatch();
|
|
const response =
|
|
currentFunction && currentFunction.id && currentFunction.id in responses
|
|
? responses[currentFunction.id]
|
|
: "";
|
|
// parse error found while trying to execute function
|
|
const hasExecutionParseErrors = responseStatus === JSResponseState.IsDirty;
|
|
// error found while trying to parse JS Object
|
|
const hasJSObjectParseError = errors.length > 0;
|
|
|
|
const isSaving = useSelector(getIsSavingEntity);
|
|
useEffect(() => {
|
|
setResponseStatus(
|
|
getJSResponseViewState(
|
|
currentFunction,
|
|
isDirty,
|
|
isExecuting,
|
|
isSaving,
|
|
responses,
|
|
),
|
|
);
|
|
}, [responses, isExecuting, currentFunction, isSaving, isDirty]);
|
|
|
|
const filteredErrors = useSelector(getFilteredErrors);
|
|
let errorMessage: string | undefined;
|
|
let errorType = "ValidationError";
|
|
|
|
// action source for analytics.
|
|
let actionSource: SourceEntity = {
|
|
type: ENTITY_TYPE.JSACTION,
|
|
name: "",
|
|
id: "",
|
|
};
|
|
try {
|
|
let errorObject: Log | undefined;
|
|
//get JS execution error from redux store.
|
|
if (
|
|
selectedJSObject &&
|
|
selectedJSObject.config &&
|
|
selectedJSObject.activeJSActionId
|
|
) {
|
|
every(filteredErrors, (error) => {
|
|
if (
|
|
includes(
|
|
error.id,
|
|
selectedJSObject?.config.id +
|
|
"-" +
|
|
selectedJSObject?.activeJSActionId,
|
|
)
|
|
) {
|
|
errorObject = error;
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
// update error message.
|
|
if (errorObject) {
|
|
if (errorObject.source) {
|
|
// update action source.
|
|
actionSource = errorObject.source;
|
|
}
|
|
if (errorObject.messages) {
|
|
// update error message.
|
|
errorMessage =
|
|
errorObject.messages[0].message.name +
|
|
": " +
|
|
errorObject.messages[0].message.message;
|
|
errorType = errorObject.messages[0].message.name;
|
|
}
|
|
}
|
|
} catch (e) {}
|
|
const tabs = [
|
|
{
|
|
key: "response",
|
|
title: "Response",
|
|
panelComponent: (
|
|
<>
|
|
{(hasExecutionParseErrors ||
|
|
(hasJSObjectParseError && errorMessage)) && (
|
|
<ResponseTabErrorContainer>
|
|
<ResponseTabErrorContent>
|
|
<div className="t--js-response-parse-error-call-out">
|
|
{errorMessage}
|
|
</div>
|
|
|
|
<LogHelper
|
|
logType={LOG_TYPE.EVAL_ERROR}
|
|
name={errorType}
|
|
source={actionSource}
|
|
/>
|
|
</ResponseTabErrorContent>
|
|
</ResponseTabErrorContainer>
|
|
)}
|
|
<ResponseTabWrapper className={errors.length ? "disable" : ""}>
|
|
<ResponseViewer>
|
|
<>
|
|
{responseStatus === JSResponseState.NoResponse && (
|
|
<NoResponse
|
|
isButtonDisabled={disabled}
|
|
isQueryRunning={isLoading}
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore
|
|
onRunClick={onButtonClick}
|
|
/>
|
|
)}
|
|
{responseStatus === JSResponseState.IsExecuting && (
|
|
<LoadingOverlayScreen theme={props.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={{
|
|
value: response,
|
|
}}
|
|
/>
|
|
)}
|
|
{responseStatus === JSResponseState.IsUpdating && (
|
|
<LoadingOverlayScreen theme={props.theme}>
|
|
{createMessage(UPDATING_JS_COLLECTION)}
|
|
</LoadingOverlayScreen>
|
|
)}
|
|
</>
|
|
</ResponseViewer>
|
|
</ResponseTabWrapper>
|
|
</>
|
|
),
|
|
},
|
|
{
|
|
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={jsObject?.name} />,
|
|
},
|
|
];
|
|
|
|
// get the selected tab from the store.
|
|
const selectedResponseTab = useSelector(getDebuggerSelectedTab);
|
|
// set the selected tab in the store.
|
|
const setSelectedResponseTab = useCallback((selectedTab: string) => {
|
|
dispatch(setDebuggerSelectedTab(selectedTab));
|
|
}, []);
|
|
// get the height of the response pane.
|
|
const responseTabHeight = useSelector(getResponsePaneHeight);
|
|
// set the height of the response pane on resize.
|
|
const setResponseHeight = useCallback((height: number) => {
|
|
dispatch(setResponsePaneHeight(height));
|
|
}, []);
|
|
|
|
// close the debugger
|
|
const onClose = () => dispatch(showDebugger(false));
|
|
|
|
// Do not render if header tab is selected in the bottom bar.
|
|
return !(selectedResponseTab === DEBUGGER_TAB_KEYS.HEADER_TAB) ? (
|
|
<ResponseContainer
|
|
className="t--js-editor-bottom-pane-container"
|
|
ref={panelRef}
|
|
>
|
|
<Resizer
|
|
initialHeight={responseTabHeight}
|
|
onResizeComplete={setResponseHeight}
|
|
panelRef={panelRef}
|
|
/>
|
|
<TabbedViewWrapper>
|
|
<EntityBottomTabs
|
|
expandedHeight={`${ActionExecutionResizerHeight}px`}
|
|
onSelect={setSelectedResponseTab}
|
|
selectedTabKey={selectedResponseTab}
|
|
tabs={tabs}
|
|
/>
|
|
|
|
<CloseDebugger
|
|
className="close-debugger t--close-debugger"
|
|
isIconButton
|
|
kind="tertiary"
|
|
onClick={onClose}
|
|
size="md"
|
|
startIcon="close-modal"
|
|
/>
|
|
</TabbedViewWrapper>
|
|
</ResponseContainer>
|
|
) : null;
|
|
}
|
|
|
|
const mapStateToProps = (
|
|
state: AppState,
|
|
props: { jsObject: JSCollection },
|
|
) => {
|
|
const jsActions = state.entities.jsActions;
|
|
const { jsObject } = props;
|
|
|
|
const errorCount = state.ui.debugger.context.errorCount;
|
|
const selectedJSObject =
|
|
jsObject &&
|
|
jsActions.find(
|
|
(action: JSCollectionData) => action.config.id === jsObject.id,
|
|
);
|
|
const responses = (selectedJSObject && selectedJSObject.data) || {};
|
|
const isDirty = (selectedJSObject && selectedJSObject.isDirty) || {};
|
|
const isExecuting = (selectedJSObject && selectedJSObject.isExecuting) || {};
|
|
return {
|
|
responses,
|
|
isExecuting,
|
|
isDirty,
|
|
selectedJSObject: selectedJSObject,
|
|
errorCount,
|
|
};
|
|
};
|
|
|
|
export default connect(mapStateToProps)(withRouter(JSResponseView));
|