Skip to content

Commit

Permalink
feat: Updated GraphQL form UI (#36728)
Browse files Browse the repository at this point in the history
## Description

This PR has following new features and fixes
1. Feat: Update GraphQL to use form control dynamic text field instead
of custom implementation.
2. Feat: Added full width support for section component in action form.
3. Fix: Rest API headers not scrollable if there are more number of
items.

EE PR: appsmithorg/appsmith-ee#5297

Fixes #35494
Fixes #36410
Fixes #36499


## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11240771681>
> Commit: 14b3e00
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11240771681&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 09 Oct 2024 05:42:42 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced a streamlined form-based design for the `PostBodyData`
component, enhancing user interaction with dynamic text fields for
GraphQL queries and variables.
- Added a new styled component, `MainContainer`, to improve layout
responsiveness in the `CommonEditorForm`.
- Enhanced the `Section` component with an optional `isFullWidth`
property for greater configurability.

- **Bug Fixes**
- Adjusted the `LoadingContainer` height dynamically to enhance UI
responsiveness.

- **Style**
- Updated styles for the `Section` component to support full-width
expansion when applicable.

- **Removed Features**
- Deprecated the `QueryEditor` and `VariableEditor` components,
simplifying the editor interface.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
albinAppsmith authored Oct 10, 2024
1 parent 9a63c91 commit 579cb7d
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 229 deletions.
Original file line number Diff line number Diff line change
@@ -1,107 +1,87 @@
import React, { useCallback, useRef } from "react";
import React from "react";
import styled from "styled-components";
import QueryEditor from "pages/Editor/APIEditor/GraphQL/QueryEditor";
import VariableEditor from "pages/Editor/APIEditor/GraphQL/VariableEditor";
import useHorizontalResize from "utils/hooks/useHorizontalResize";
import { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig";
import classNames from "classnames";
import { tailwindLayers } from "constants/Layers";

const ResizableDiv = styled.div`
display: flex;
height: 100%;
flex-shrink: 0;
`;
import {
CodeEditorBorder,
EditorModes,
EditorSize,
EditorTheme,
TabBehaviour,
} from "components/editorComponents/CodeEditor/EditorConfig";
import DynamicTextField from "components/editorComponents/form/fields/DynamicTextField";
import { Section, Zone } from "pages/Editor/ActionForm";
import { AutocompleteDataType } from "utils/autocomplete/AutocompleteDataType";
import FormLabel from "components/editorComponents/FormLabel";

const PostBodyContainer = styled.div`
display: flex;
height: 100%;
overflow: hidden;
&&&& .CodeMirror {
height: 100%;
border-top: 1px solid var(--ads-v2-color-border);
border-bottom: 1px solid var(--ads-v2-color-border);
border-radius: 0;
padding: 0;
}
& .CodeMirror-scroll {
margin: 0px;
padding: 0px;
overflow: auto !important;
height: auto;
min-height: 250px;
}
`;

const ResizerHandler = styled.div<{ resizing: boolean }>`
width: 6px;
height: 100%;
margin-left: 2px;
border-right: 1px solid var(--ads-v2-color-border);
background: ${(props) =>
props.resizing ? "var(--ads-v2-color-border)" : "transparent"};
&:hover {
background: var(--ads-v2-color-border);
border-color: transparent;
const StyledFormLabel = styled(FormLabel)`
&& {
margin-bottom: var(--ads-v2-spaces-2);
padding: 0;
}
`;

const DEFAULT_GRAPHQL_VARIABLE_WIDTH = 300;

interface Props {
actionName: string;
}

const EXPECTED_VARIABLE = {
type: "object",
example:
'{\n "name":"{{ inputName.property }}",\n "preference":"{{ dropdownName.property }}"\n}',
autocompleteDataType: AutocompleteDataType.OBJECT,
};

function PostBodyData(props: Props) {
const { actionName } = props;
const theme = EditorTheme.LIGHT;
const resizeableRef = useRef<HTMLDivElement>(null);
const [variableEditorWidth, setVariableEditorWidth] = React.useState(
DEFAULT_GRAPHQL_VARIABLE_WIDTH,
);
/**
* Variable Editor's resizeable handler for the changing of width
*/
const onVariableEditorWidthChange = useCallback((newWidth) => {
setVariableEditorWidth(newWidth);
}, []);

const { onMouseDown, onMouseUp, onTouchStart, resizing } =
useHorizontalResize(
resizeableRef,
onVariableEditorWidthChange,
undefined,
true,
);

return (
<PostBodyContainer>
<QueryEditor
dataTreePath={`${actionName}.config.body`}
height="100%"
name="actionConfiguration.body"
theme={theme}
/>
<div
className={`w-2 h-full -ml-2 group cursor-ew-resize ${tailwindLayers.resizer}`}
onMouseDown={onMouseDown}
onTouchEnd={onMouseUp}
onTouchStart={onTouchStart}
>
<ResizerHandler
className={classNames({
"transform transition": true,
})}
resizing={resizing}
/>
</div>
<ResizableDiv
ref={resizeableRef}
style={{
width: `${variableEditorWidth}px`,
paddingRight: "2px",
}}
>
<VariableEditor actionName={actionName} theme={theme} />
</ResizableDiv>
<Section isFullWidth>
<Zone layout="single_column">
<div className="t--graphql-query-editor">
<StyledFormLabel>Query</StyledFormLabel>
<DynamicTextField
border={CodeEditorBorder.ALL_SIDE}
dataTreePath={`${actionName}.config.body`}
evaluatedPopUpLabel={"Query"}
mode={EditorModes.GRAPHQL_WITH_BINDING}
name="actionConfiguration.body"
placeholder={`{{\n\t{name: inputName.property, preference: dropdownName.property}\n}}`}
showLineNumbers
size={EditorSize.EXTENDED}
tabBehaviour={TabBehaviour.INDENT}
theme={theme}
/>
</div>
</Zone>
<Zone layout="single_column">
<div className="t--graphql-variable-editor">
<StyledFormLabel>Query variables</StyledFormLabel>
<DynamicTextField
border={CodeEditorBorder.ALL_SIDE}
dataTreePath={`${props.actionName}.config.pluginSpecifiedTemplates[1].value`}
evaluatedPopUpLabel={"Query variables"}
expected={EXPECTED_VARIABLE}
height="100%"
mode={EditorModes.JSON_WITH_BINDING}
name="actionConfiguration.pluginSpecifiedTemplates[1].value"
placeholder={`${EXPECTED_VARIABLE.example}\n\n\\\\Take widget inputs using {{ }}`}
showLightningMenu={false}
showLineNumbers
size={EditorSize.EXTENDED}
tabBehaviour={TabBehaviour.INDENT}
theme={theme}
/>
</div>
</Zone>
</Section>
</PostBodyContainer>
);
}
Expand Down
1 change: 1 addition & 0 deletions app/client/src/pages/Editor/APIEditor/CommonEditorForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const Wrapper = styled.div`
flex-direction: row;
height: 100%;
position: relative;
overflow: hidden;
`;

const MainContainer = styled.div`
Expand Down
3 changes: 2 additions & 1 deletion app/client/src/pages/Editor/APIEditor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,10 @@ class ApiEditor extends React.Component<Props> {

const formStyles: CSSProperties = {
position: "relative",
height: "100%",
display: "flex",
flexDirection: "column",
flexGrow: "1",
overflow: "auto",
};

// TODO: Fix this the next time the file is edited
Expand Down
67 changes: 0 additions & 67 deletions app/client/src/pages/Editor/APIEditor/GraphQL/QueryEditor.tsx

This file was deleted.

77 changes: 0 additions & 77 deletions app/client/src/pages/Editor/APIEditor/GraphQL/VariableEditor.tsx

This file was deleted.

3 changes: 3 additions & 0 deletions app/client/src/pages/Editor/ActionForm/Section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import styles from "./styles.module.css";
interface SectionProps extends React.HTMLAttributes<HTMLDivElement> {
children: React.ReactNode;
isStandalone?: boolean;
isFullWidth?: boolean;
}

const Section: React.FC<SectionProps> = ({
children,
className,
isFullWidth = false,
isStandalone = false,
...props
}) => {
Expand All @@ -18,6 +20,7 @@ const Section: React.FC<SectionProps> = ({
return (
<div
className={classNames}
data-fullwidth={isFullWidth.toString()}
data-standalone={isStandalone.toString()}
{...props}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
&[data-standalone="false"]:not(:last-child) {
border-bottom: 1px solid var(--ads-v2-color-border);
}

&[data-fullwidth="true"] {
max-width: none;
}
}

0 comments on commit 579cb7d

Please sign in to comment.