Skip to content
Closed
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
34 changes: 32 additions & 2 deletions app/client/src/IDE/Structure/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
import React from "react";
import React, { useEffect } from "react";
import { Flex } from "@appsmith/ads";

interface ToolbarProps {
children?: React.ReactNode[] | React.ReactNode;
}

const Toolbar = (props: ToolbarProps) => {
useEffect(function detectScrollbar() {
const ele = document.getElementById("uqi-editor-form-content");
const toolbar = document.getElementById("action-toolbar");

const handleScroll = function () {
if (ele && ele.scrollTop > 0) {
toolbar?.style.setProperty(
"box-shadow",
"0 4px 6px rgba(0, 0, 0, 0.1)",
);
} else {
toolbar?.style.setProperty("box-shadow", "none");
}
};

if (ele) {
ele.addEventListener("scroll", handleScroll);
}

return function cleanup() {
ele?.removeEventListener("scroll", handleScroll);
};
}, []);
Comment on lines +9 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using refs instead of direct DOM queries

The current implementation has several areas for improvement:

  1. Replace getElementById with React refs for better reliability and type safety
  2. Extract the shadow value to a constant
  3. Add null checks for better error handling
+ const toolbarRef = useRef<HTMLDivElement>(null);
+ const contentRef = useRef<HTMLDivElement>(null);
+ const TOOLBAR_SHADOW = "0 4px 6px rgba(0, 0, 0, 0.1)";

  useEffect(function detectScrollbar() {
-   const ele = document.getElementById("uqi-editor-form-content");
-   const toolbar = document.getElementById("action-toolbar");
+   const ele = contentRef.current;
+   const toolbar = toolbarRef.current;

    const handleScroll = function () {
-     if (ele && ele.scrollTop > 0) {
-       toolbar?.style.setProperty(
-         "box-shadow",
-         "0 4px 6px rgba(0, 0, 0, 0.1)",
-       );
+     if (ele?.scrollTop > 0 && toolbar) {
+       toolbar.style.setProperty("box-shadow", TOOLBAR_SHADOW);
      } else {
-       toolbar?.style.setProperty("box-shadow", "none");
+       toolbar?.style.setProperty("box-shadow", "none");
      }
    };

Committable suggestion skipped: line range outside the PR's diff.


return (
<Flex
alignItems="center"
borderBottom="1px solid var(--ads-v2-color-border-muted);"
flexDirection="row"
height="32px"
id="action-toolbar"
justifyContent="space-between"
padding="spaces-2"
style={{
transition: "box-shadow 0.3s ease",
position: "sticky",
top: 0,
}}
zIndex="10"
>
{props.children}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const PluginActionForm = () => {
const { plugin } = usePluginActionContext();

return (
<Flex flex="1" overflow="hidden" p="spaces-4" w="100%">
<Flex flex="1" overflow="hidden" p="spaces-4" pt="spaces-0" w="100%">
{plugin.uiComponent === UIComponentTypes.ApiEditorForm && (
<APIEditorForm />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@
& :global(.ads-v2-select > .rc-select-selector) {
min-width: unset;
}

/* Remove this once the config in DB is updated to use Section and Zone (Twilio, Airtable) */
& :global(.ar-form-info-text) {
max-width: unset;
}

/* Removable section ends here */
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ const UQIEditorForm = () => {
const { data, evaluationState } = useFormData();

return (
<Flex flexDirection="column" overflowY="scroll" w="100%">
<Flex
alignItems="center"
flexDirection="column"
id="uqi-editor-form-content"
overflowY="scroll"
w="100%"
>
<FormRender
editorConfig={editorConfig}
formData={data}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const StyledFormInfo = styled.span<{ config?: ControlProps }>`
? "5px"
: "0px"};
line-height: 16px;
max-width: 270px;
overflow: hidden;
break-word: break-all;
`;

const FormSubtitleText = styled.span<{ config?: ControlProps }>`
Expand Down Expand Up @@ -177,7 +180,9 @@ function FormLabel(props: FormLabelProps) {
//Wrapper on styled <span/>
function FormInfoText(props: FormLabelProps) {
return (
<StyledFormInfo config={props.config}>{props.children}</StyledFormInfo>
<StyledFormInfo className="ar-form-info-text" config={props.config}>
{props.children}
</StyledFormInfo>
);
}

Expand Down