Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

chore: Change tabs order (#2907)

Oleg Isonen2e5e116b4787
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/assets/assets.tsx b/apps/builder/app/builder/features/sidebar-left/panels/assets/assets.tsx
index 2ebb19664b..3b3bb0d239 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/assets/assets.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/assets/assets.tsx
@@ -1,14 +1,10 @@
import { ImageIcon } from "@webstudio-is/icons";
import { Flex } from "@webstudio-is/design-system";
import { ImageManager } from "~/builder/shared/image-manager";
-import type { TabName } from "../../types";
+import type { TabContentProps } from "../../types";
import { Header, CloseButton } from "../../header";
-export const TabContent = ({
- onSetActiveTab,
-}: {
- onSetActiveTab: (tabName: TabName) => void;
-}) => {
+export const TabContent = ({ onSetActiveTab }: TabContentProps) => {
return (
<Flex direction="column" css={{ height: "100%" }}>
<Header
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/components/components.tsx b/apps/builder/app/builder/features/sidebar-left/panels/components/components.tsx
index 888d9f1c06..876596faf9 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/components/components.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/components/components.tsx
@@ -15,9 +15,8 @@ import {
ScrollArea,
} from "@webstudio-is/design-system";
import { PlusIcon } from "@webstudio-is/icons";
-import type { Publish } from "~/shared/pubsub";
import { CollapsibleSection } from "~/builder/shared/collapsible-section";
-import type { TabName } from "../../types";
+import type { TabContentProps } from "../../types";
import { Header, CloseButton } from "../../header";
import {
dragItemAttribute,
@@ -30,11 +29,6 @@ import { getMetaMaps } from "./get-meta-maps";
import { getInstanceLabel } from "~/shared/instance-utils";
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
-type TabContentProps = {
- onSetActiveTab: (tabName: TabName) => void;
- publish: Publish;
-};
-
export const TabContent = ({ publish, onSetActiveTab }: TabContentProps) => {
const metaByComponentName = useStore($registeredComponentMetas);
const { metaByCategory, componentNamesByMeta } = useMemo(
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/index.ts b/apps/builder/app/builder/features/sidebar-left/panels/index.ts
index 2a1c0bbbe8..7938123c7f 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/index.ts
+++ b/apps/builder/app/builder/features/sidebar-left/panels/index.ts
@@ -2,10 +2,17 @@ import * as components from "./components";
import * as navigator from "./navigator";
import * as assets from "./assets";
import * as pages from "./pages";
+import type { TabContentProps, TabName } from "../types";
+import type { ReactNode } from "react";
-export const panels = {
- components,
- navigator,
- assets,
- pages,
-} as const;
+type PanelExports = {
+ TabContent: (props: TabContentProps) => ReactNode;
+ icon: ReactNode;
+};
+
+export const panels = new Map<TabName, PanelExports>([
+ ["components", components],
+ ["pages", pages],
+ ["navigator", navigator],
+ ["assets", assets],
+]);
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/navigator/navigator.tsx b/apps/builder/app/builder/features/sidebar-left/panels/navigator/navigator.tsx
index f325ad07ac..20886818f1 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/navigator/navigator.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/navigator/navigator.tsx
@@ -1,10 +1,6 @@
import { ListNestedIcon } from "@webstudio-is/icons";
import { Navigator } from "../../navigator";
-import type { TabName } from "../../types";
-
-type TabContentProps = {
- onSetActiveTab: (tabName: TabName) => void;
-};
+import type { TabContentProps } from "../../types";
export const TabContent = ({ onSetActiveTab }: TabContentProps) => {
return (
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/pages/pages.tsx b/apps/builder/app/builder/features/sidebar-left/panels/pages/pages.tsx
index de2d2f4b6f..fcb84262e8 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/pages/pages.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/pages/pages.tsx
@@ -23,7 +23,7 @@ import {
NewPageIcon,
PageIcon,
} from "@webstudio-is/icons";
-import type { TabName } from "../../types";
+import type { TabContentProps } from "../../types";
import { CloseButton, Header } from "../../header";
import { SettingsPanel } from "./settings-panel";
import { NewPageSettings, PageSettings } from "./page-settings";
@@ -46,10 +46,6 @@ import { useMount } from "~/shared/hook-utils/use-mount";
import { ROOT_FOLDER_ID, type Folder } from "@webstudio-is/sdk";
import { atom } from "nanostores";
-type TabContentProps = {
- onSetActiveTab: (tabName: TabName) => void;
-};
-
const MenuButton = styled(DeprecatedIconButton, {
color: theme.colors.hint,
"&:hover, &:focus-visible": { color: theme.colors.hiContrast },
@@ -393,7 +389,7 @@ export const TabContent = ({ onSetActiveTab }: TabContentProps) => {
const pages = useStore($pages);
if (currentPageId === undefined || pages === undefined) {
- return null;
+ return;
}
return (
diff --git a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
index 21703e25c3..a05f6b5e06 100644
--- a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
@@ -3,7 +3,6 @@ import { Box, Tooltip } from "@webstudio-is/design-system";
import { useSubscribe, type Publish } from "~/shared/pubsub";
import { $dragAndDropState, $isPreviewMode } from "~/shared/nano-states";
import { panels } from "./panels";
-import type { TabName } from "./types";
import { useClientSettings } from "~/builder/shared/client-settings";
import { Flex } from "@webstudio-is/design-system";
import { theme } from "@webstudio-is/design-system";
@@ -101,7 +100,7 @@ type SidebarLeftProps = {
export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
const [activeTab, setActiveTab] = useActiveTab();
const dragAndDropState = useStore($dragAndDropState);
- const { TabContent } = activeTab === "none" ? none : panels[activeTab];
+ const { TabContent } = panels.get(activeTab) ?? none;
const isPreviewMode = useStore($isPreviewMode);
useSubscribe("dragEnd", () => {
@@ -122,20 +121,18 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
{isPreviewMode === false && (
<>
<SidebarTabsList>
- {(Object.keys(panels) as Array<TabName>).map(
- (tabName: TabName) => (
- <SidebarTabsTrigger
- key={tabName}
- aria-label={tabName}
- value={tabName}
- onClick={() => {
- setActiveTab(activeTab === tabName ? "none" : tabName);
- }}
- >
- {tabName !== "none" && panels[tabName].icon}
- </SidebarTabsTrigger>
- )
- )}
+ {Array.from(panels.keys()).map((tabName) => (
+ <SidebarTabsTrigger
+ key={tabName}
+ aria-label={tabName}
+ value={tabName}
+ onClick={() => {
+ setActiveTab(activeTab === tabName ? "none" : tabName);
+ }}
+ >
+ {tabName !== "none" && panels.get(tabName)?.icon}
+ </SidebarTabsTrigger>
+ ))}
<AiTabTrigger />
</SidebarTabsList>
<Box css={{ borderRight: `1px solid ${theme.colors.borderMain}` }}>
diff --git a/apps/builder/app/builder/features/sidebar-left/types.ts b/apps/builder/app/builder/features/sidebar-left/types.ts
index fb0636e8a0..8a74be4bee 100644
--- a/apps/builder/app/builder/features/sidebar-left/types.ts
+++ b/apps/builder/app/builder/features/sidebar-left/types.ts
@@ -1,3 +1,8 @@
-import type { panels } from "./panels";
+import type { Publish } from "~/shared/pubsub";
-export type TabName = keyof typeof panels | "none";
+export type TabName = "assets" | "components" | "navigator" | "pages" | "none";
+
+export type TabContentProps = {
+ onSetActiveTab: (tabName: TabName) => void;
+ publish: Publish;
+};