Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/client/src/PluginActionEditor/PluginActionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import React, {
} from "react";
import type { Action } from "entities/Action";
import type { Plugin } from "api/PluginApi";
import type { Datasource } from "entities/Datasource";
import type { Datasource, EmbeddedRestDatasource } from "entities/Datasource";
import type { ActionResponse } from "api/ActionAPI";

interface PluginActionContextType {
action: Action;
actionResponse?: ActionResponse;
editorConfig: unknown[];
settingsConfig: unknown[];
plugin: Plugin;
datasource?: Datasource;
datasource?: EmbeddedRestDatasource | Datasource;
}

// No need to export this context to use it. Use the hook defined below instead
Expand Down
6 changes: 6 additions & 0 deletions app/client/src/PluginActionEditor/PluginActionEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { identifyEntityFromPath } from "../navigation/FocusEntity";
import { useSelector } from "react-redux";
import {
getActionByBaseId,
getActionResponses,
getDatasource,
getEditorConfig,
getPlugin,
Expand Down Expand Up @@ -39,6 +40,8 @@ const PluginActionEditor = (props: ChildrenProps) => {

const editorConfig = useSelector((state) => getEditorConfig(state, pluginId));

const actionResponses = useSelector(getActionResponses);

if (!isEditorInitialized) {
return (
<CenteredWrapper>
Expand Down Expand Up @@ -71,9 +74,12 @@ const PluginActionEditor = (props: ChildrenProps) => {
);
}

const actionResponse = actionResponses[action.id];

return (
<PluginActionContextProvider
action={action}
actionResponse={actionResponse}
datasource={datasource}
editorConfig={editorConfig}
plugin={plugin}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from "styled-components";
import FormRow from "../../../../../../components/editorComponents/FormRow";
import FormLabel from "../../../../../../components/editorComponents/FormLabel";
import FormRow from "components/editorComponents/FormRow";
import FormLabel from "components/editorComponents/FormLabel";
import { Button, Icon, Text, Tooltip } from "@appsmith/ads";
import {
API_PANE_AUTO_GENERATED_HEADER,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useCallback } from "react";
import { IDEBottomView, ViewHideBehaviour } from "IDE";
import { ActionExecutionResizerHeight } from "pages/Editor/APIEditor/constants";
import EntityBottomTabs from "components/editorComponents/EntityBottomTabs";
import { useDispatch, useSelector } from "react-redux";
import { getApiPaneDebuggerState } from "selectors/apiPaneSelectors";
import { setApiPaneDebuggerState } from "actions/apiPaneActions";
import { DEBUGGER_TAB_KEYS } from "components/editorComponents/Debugger/helpers";
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
import { usePluginActionResponseTabs } from "./hooks";

function PluginActionResponse() {
const dispatch = useDispatch();

const tabs = usePluginActionResponseTabs();

// TODO combine API and Query Debugger state
const { open, responseTabHeight, selectedTab } = useSelector(
getApiPaneDebuggerState,
);

const toggleHide = useCallback(
() => dispatch(setApiPaneDebuggerState({ open: !open })),
[dispatch, open],
);

const updateSelectedResponseTab = useCallback(
(tabKey: string) => {
if (tabKey === DEBUGGER_TAB_KEYS.ERROR_TAB) {
AnalyticsUtil.logEvent("OPEN_DEBUGGER", {
source: "API_PANE",
});
}

dispatch(setApiPaneDebuggerState({ open: true, selectedTab: tabKey }));
},
[dispatch],
);

const updateResponsePaneHeight = useCallback(
(height: number) => {
dispatch(setApiPaneDebuggerState({ responseTabHeight: height }));
},
[dispatch],
);

return (
<IDEBottomView
behaviour={ViewHideBehaviour.COLLAPSE}
className="t--action-bottom-pane-container"
height={responseTabHeight}
hidden={!open}
onHideClick={toggleHide}
setHeight={updateResponsePaneHeight}
>
<EntityBottomTabs
expandedHeight={`${ActionExecutionResizerHeight}px`}
isCollapsed={!open}
onSelect={updateSelectedResponseTab}
selectedTabKey={selectedTab || tabs[0].key}
tabs={tabs}
/>
</IDEBottomView>
);
}

export default PluginActionResponse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import React, { useCallback, useMemo, useState } from "react";
import { isArray, isString } from "lodash";
import { isHtml } from "../utils";
import ReadOnlyEditor from "components/editorComponents/ReadOnlyEditor";
import { SegmentedControlContainer } from "pages/Editor/QueryEditor/EditorJSONtoForm";
import { Flex, SegmentedControl } from "@appsmith/ads";
import type { ActionResponse } from "api/ActionAPI";
import { setActionResponseDisplayFormat } from "actions/pluginActionActions";
import { actionResponseDisplayDataFormats } from "pages/Editor/utils";
import { ResponseDisplayFormats } from "constants/ApiEditorConstants/CommonApiConstants";
import { useDispatch } from "react-redux";
import styled from "styled-components";
import { ResponseFormatTabs } from "./ResponseFormatTabs";

const ResponseBodyContainer = styled.div`
overflow-y: clip;
height: 100%;
display: grid;
`;

function ApiFormatSegmentedResponse(props: {
actionResponse: ActionResponse;
actionId: string;
responseTabHeight: number;
}) {
const dispatch = useDispatch();
const onResponseTabSelect = useCallback(
(tab: string) => {
dispatch(
setActionResponseDisplayFormat({
id: props.actionId,
field: "responseDisplayFormat",
value: tab,
}),
);
},
[dispatch, props.actionId],
);

const { responseDataTypes, responseDisplayFormat } =
actionResponseDisplayDataFormats(props.actionResponse);

let filteredResponseDataTypes: { key: string; title: string }[] = [
...responseDataTypes,
];

if (!!props.actionResponse.body && !isArray(props.actionResponse.body)) {
filteredResponseDataTypes = responseDataTypes.filter(
(item) => item.key !== ResponseDisplayFormats.TABLE,
);

if (responseDisplayFormat.title === ResponseDisplayFormats.TABLE) {
onResponseTabSelect(filteredResponseDataTypes[0]?.title);
}
}

const responseTabs = filteredResponseDataTypes?.map((dataType, index) => ({
index: index,
key: dataType.key,
title: dataType.title,
panelComponent: (
<ResponseFormatTabs
data={props.actionResponse.body as string | Record<string, unknown>[]}
responseType={dataType.key}
tableBodyHeight={props.responseTabHeight}
/>
),
}));

const segmentedControlOptions = responseTabs?.map((item) => ({
value: item.key,
label: item.title,
}));

const onChange = useCallback(
(value: string) => {
setSelectedControl(value);
onResponseTabSelect(value);
},
[onResponseTabSelect],
);

const [selectedControl, setSelectedControl] = useState(
segmentedControlOptions[0]?.value,
);

const selectedTabIndex = filteredResponseDataTypes?.findIndex(
(dataType) => dataType.title === responseDisplayFormat?.title,
);

const value = useMemo(
() => ({ value: props.actionResponse.body as string }),
[props.actionResponse.body],
);

return (
<ResponseBodyContainer>
{isString(props.actionResponse?.body) &&
isHtml(props.actionResponse?.body) ? (
<ReadOnlyEditor folding height={"100%"} input={value} />
) : responseTabs && responseTabs.length > 0 && selectedTabIndex !== -1 ? (
<SegmentedControlContainer>
<Flex>
<SegmentedControl
data-testid="t--response-tab-segmented-control"
defaultValue={segmentedControlOptions[0]?.value}
isFullWidth={false}
onChange={onChange}
options={segmentedControlOptions}
value={selectedControl}
/>
</Flex>
<ResponseFormatTabs
data={
props.actionResponse?.body as string | Record<string, unknown>[]
}
responseType={selectedControl || segmentedControlOptions[0]?.value}
tableBodyHeight={props.responseTabHeight}
/>
</SegmentedControlContainer>
) : null}
</ResponseBodyContainer>
);
}

export default ApiFormatSegmentedResponse;
Loading