-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: Init Plugin Action Response #36485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
38a5320
commit before I mess this up
hetunandu f26edee
Merge branch 'release' into chore/init-plugin-action-response
hetunandu dcbdf72
some type and usage improvements
hetunandu d4cc094
Merge branch 'release' into chore/init-plugin-action-response
hetunandu 9d1e369
Usage in the module
hetunandu 1c5041e
fix styles
hetunandu 329a461
fix index file
hetunandu 1a176c7
Merge branch 'refs/heads/release' into chore/init-plugin-action-response
hetunandu a80ef94
fix some deps
hetunandu c3b5b4b
tests and review improvements
hetunandu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...r/components/PluginActionForm/components/CommonEditorForm/components/DatasourceConfig.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
app/client/src/PluginActionEditor/components/PluginActionResponse/PluginActionResponse.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } | ||
hetunandu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default PluginActionResponse; | ||
126 changes: 126 additions & 0 deletions
126
...ginActionEditor/components/PluginActionResponse/components/ApiFormatSegmentedResponse.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} | ||
hetunandu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /> | ||
| </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; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.