-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: Move Sidebar to IDE/Components #34487
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
Changes from 8 commits
86392ea
c796df7
cad6f3b
9b4c703
7a017e0
c86818a
1156e73
0d560d1
d3d23fe
4c14038
c88428c
79a9358
71e5795
e26ee7a
f2d0e9f
0b685d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { render } from "test/testUtils"; | ||
| import React from "react"; | ||
| import SidebarButton, { type SidebarButtonProps } from "./SidebarButton"; | ||
| import { Condition } from "../../Interfaces/Condition"; | ||
|
|
||
| const sidebarButtonProps: SidebarButtonProps = { | ||
| icon: "down-arrow", | ||
| onClick: () => {}, | ||
| selected: false, | ||
| title: "Test", | ||
| }; | ||
|
|
||
| describe("SidebarButton", () => { | ||
| it("should render the warning icon in case the datasource list is empty", () => { | ||
| const withWarningCondition = { | ||
| ...sidebarButtonProps, | ||
| condition: Condition.Warn, | ||
| }; | ||
|
|
||
| const { container } = render(<SidebarButton {...withWarningCondition} />); | ||
|
|
||
| const svgs = container.querySelectorAll("svg"); | ||
| expect(svgs).toHaveLength(2); | ||
| }); | ||
| }); |
|
alex-golovanov marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import React, { useCallback } from "react"; | ||
| import styled from "styled-components"; | ||
| import SidebarButton from "./SidebarButton"; | ||
| import type { EditorState } from "@appsmith/entities/IDE/constants"; | ||
| import type { ISidebarButton } from "../../Interfaces/ISidebarButton"; | ||
|
|
||
| const Container = styled.div` | ||
| width: 50px; | ||
| border-right: 1px solid var(--ads-v2-color-border); | ||
| height: 100%; | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: space-between; | ||
| background-color: var(--ads-v2-color-bg); | ||
| position: relative; | ||
| `; | ||
|
|
||
| interface IDESidebarProps { | ||
| id?: string; | ||
| topButtons: ISidebarButton[]; | ||
| bottomButtons: ISidebarButton[]; | ||
| appState: EditorState; | ||
|
alex-golovanov marked this conversation as resolved.
Outdated
|
||
| onClick: (suffix: string) => void; | ||
| } | ||
|
|
||
| function IDESidebar(props: IDESidebarProps) { | ||
| const { appState, bottomButtons, onClick, topButtons } = props; | ||
|
|
||
| const handleOnClick = useCallback( | ||
| (button: ISidebarButton) => { | ||
| if (appState !== button.state) { | ||
| onClick(button.urlSuffix); | ||
| } | ||
| }, | ||
| [appState], | ||
| ); | ||
|
|
||
| return ( | ||
| <Container className="t--sidebar" id={props.id}> | ||
| <div> | ||
| {topButtons.map((b) => ( | ||
|
alex-golovanov marked this conversation as resolved.
Outdated
|
||
| <SidebarButton | ||
| icon={b.icon} | ||
| key={b.state} | ||
| onClick={() => { | ||
| handleOnClick(b); | ||
| }} | ||
| selected={appState === b.state} | ||
| title={b.title} | ||
| tooltip={b.tooltip} | ||
| /> | ||
| ))} | ||
| </div> | ||
| <div> | ||
| {bottomButtons.map((b) => ( | ||
| <SidebarButton | ||
| icon={b.icon} | ||
| key={b.state} | ||
| onClick={() => { | ||
|
alex-golovanov marked this conversation as resolved.
Outdated
|
||
| handleOnClick(b); | ||
| }} | ||
| selected={appState === b.state} | ||
| title={b.title} | ||
| tooltip={b.tooltip} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </Container> | ||
| ); | ||
| } | ||
|
|
||
| export default IDESidebar; | ||
|
alex-golovanov marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export enum Condition { | ||
| Warn = "Warn", | ||
| // Error = "Error", | ||
| // Success = "Success", | ||
| } |
|
alex-golovanov marked this conversation as resolved.
Outdated
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { EditorState } from "@appsmith/entities/IDE/constants"; | ||
|
|
||
| import type { Condition } from "./Condition"; | ||
|
|
||
| export interface ISidebarButton { | ||
|
alex-golovanov marked this conversation as resolved.
Outdated
|
||
| state: EditorState; | ||
| icon: string; | ||
| title?: string; | ||
| urlSuffix: string; | ||
| condition?: Condition; | ||
| tooltip?: string; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import React, { useCallback, useEffect, useState } from "react"; | ||
| import { useDispatch, useSelector } from "react-redux"; | ||
| import { builderURL } from "@appsmith/RouteBuilder"; | ||
| import { getCurrentPageId } from "selectors/editorSelectors"; | ||
| import history, { NavigationMethod } from "utils/history"; | ||
| import { useCurrentAppState } from "./hooks"; | ||
| import { getCurrentWorkspaceId } from "@appsmith/selectors/selectedWorkspaceSelectors"; | ||
| import { fetchWorkspace } from "@appsmith/actions/workspaceActions"; | ||
| import { IDESidebar, Condition } from "IDE"; | ||
| import { | ||
| BottomButtons, | ||
| EditorState, | ||
| TopButtons, | ||
| } from "@appsmith/entities/IDE/constants"; | ||
| import { getDatasources } from "@appsmith/selectors/entitiesSelector"; | ||
| import { | ||
| createMessage, | ||
| EMPTY_DATASOURCE_TOOLTIP_SIDEBUTTON, | ||
| } from "@appsmith/constants/messages"; | ||
|
|
||
| function Sidebar() { | ||
| const [topButtons, setTopButtons] = useState(TopButtons); | ||
| const dispatch = useDispatch(); | ||
| const appState = useCurrentAppState(); | ||
| const pageId = useSelector(getCurrentPageId); | ||
| const currentWorkspaceId = useSelector(getCurrentWorkspaceId); | ||
| const datasources = useSelector(getDatasources); | ||
|
|
||
| useEffect(() => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need for Something like this: const topButtons = React.useMemo(() => {
return datasourcesExist
? TopButtons
: TopButtons.map((button) => {
if (button.state === EditorState.DATA) {
return {
...button,
condition: Condition.Warn,
tooltip: createMessage(EMPTY_DATASOURCE_TOOLTIP_SIDEBUTTON),
};
}
return button;
});
}, [datasourcesExist]); |
||
| if (datasources.length === 0) { | ||
|
alex-golovanov marked this conversation as resolved.
Outdated
|
||
| setTopButtons( | ||
| TopButtons.map((button) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The casing here |
||
| if (button.state === EditorState.DATA) { | ||
| return { | ||
| ...button, | ||
| condition: Condition.Warn, | ||
| tooltip: createMessage(EMPTY_DATASOURCE_TOOLTIP_SIDEBUTTON), | ||
| }; | ||
| } | ||
| return button; | ||
| }), | ||
| ); | ||
| } else { | ||
| setTopButtons(TopButtons); | ||
| } | ||
| }, [datasources]); | ||
|
|
||
| useEffect(() => { | ||
| dispatch(fetchWorkspace(currentWorkspaceId)); | ||
| }, [currentWorkspaceId]); | ||
|
alex-golovanov marked this conversation as resolved.
Outdated
|
||
|
|
||
| const onClick = useCallback( | ||
| (suffix) => { | ||
| history.push( | ||
| builderURL({ | ||
| pageId, | ||
| suffix, | ||
| }), | ||
| { | ||
| invokedBy: NavigationMethod.AppSidebar, | ||
| }, | ||
| ); | ||
| }, | ||
| [pageId], | ||
| ); | ||
|
|
||
| return ( | ||
| <IDESidebar | ||
| appState={appState} | ||
| bottomButtons={BottomButtons} | ||
| id={"t--app-sidebar"} | ||
| onClick={onClick} | ||
| topButtons={topButtons} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default Sidebar; | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not critical by any means, but it would be more appropriate for constants to be in a separate file.