Skip to content

Commit bd3efe0

Browse files
authored
feat: Disable AI and Page Settings editing in Content Mode (#4504)
## Description ref #3994 https://discord.com/channels/955905230107738152/1313579337940996096/1313591871926308914 ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 2d3d62a commit bd3efe0

File tree

3 files changed

+59
-37
lines changed

3 files changed

+59
-37
lines changed

apps/builder/app/builder/features/pages/page-settings.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import {
7676
$publishedOrigin,
7777
$project,
7878
$userPlanFeatures,
79+
$isDesignMode,
7980
} from "~/shared/nano-states";
8081
import {
8182
BindingControl,
@@ -1661,12 +1662,13 @@ const PageSettingsView = ({
16611662
onClose: () => void;
16621663
children: JSX.Element;
16631664
}) => {
1665+
const isDesignMode = useStore($isDesignMode);
16641666
return (
16651667
<>
16661668
<PanelTitle
16671669
suffix={
16681670
<>
1669-
{onDelete && (
1671+
{isDesignMode && onDelete && (
16701672
<Tooltip content="Delete page" side="bottom">
16711673
<Button
16721674
color="ghost"
@@ -1677,15 +1679,18 @@ const PageSettingsView = ({
16771679
/>
16781680
</Tooltip>
16791681
)}
1680-
<Tooltip content="Duplicate page" side="bottom">
1681-
<Button
1682-
color="ghost"
1683-
prefix={<CopyIcon />}
1684-
onClick={onDuplicate}
1685-
aria-label="Duplicate page"
1686-
tabIndex={2}
1687-
/>
1688-
</Tooltip>
1682+
{isDesignMode && (
1683+
<Tooltip content="Duplicate page" side="bottom">
1684+
<Button
1685+
color="ghost"
1686+
prefix={<CopyIcon />}
1687+
onClick={onDuplicate}
1688+
aria-label="Duplicate page"
1689+
tabIndex={2}
1690+
/>
1691+
</Tooltip>
1692+
)}
1693+
16891694
<Tooltip content="Close page settings" side="bottom">
16901695
<Button
16911696
color="ghost"
@@ -1701,7 +1706,11 @@ const PageSettingsView = ({
17011706
Page Settings
17021707
</PanelTitle>
17031708
<Separator />
1704-
<Form onSubmit={onClose}>{children}</Form>
1709+
<Form onSubmit={onClose}>
1710+
<fieldset style={{ display: "contents" }} disabled={!isDesignMode}>
1711+
{children}
1712+
</fieldset>
1713+
</Form>
17051714
</>
17061715
);
17071716
};

apps/builder/app/builder/features/pages/pages.tsx

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ import {
2727
} from "@webstudio-is/icons";
2828
import { ExtendedPanel } from "../../shared/extended-sidebar-panel";
2929
import { NewPageSettings, PageSettings } from "./page-settings";
30-
import { $editingPageId, $isContentMode, $pages } from "~/shared/nano-states";
30+
import {
31+
$editingPageId,
32+
$isContentMode,
33+
$isDesignMode,
34+
$pages,
35+
} from "~/shared/nano-states";
3136
import {
3237
getAllChildrenAndSelf,
3338
reparentOrphansMutable,
@@ -511,6 +516,7 @@ export const PagesPanel = ({ onClose }: { onClose: () => void }) => {
511516
const currentPage = useStore($selectedPage);
512517
const editingItemId = useStore($editingPageId);
513518
const pages = useStore($pages);
519+
const isDesignMode = useStore($isDesignMode);
514520

515521
if (currentPage === undefined || pages === undefined) {
516522
return;
@@ -521,30 +527,34 @@ export const PagesPanel = ({ onClose }: { onClose: () => void }) => {
521527
<PanelTitle
522528
suffix={
523529
<>
524-
<Tooltip content="New folder" side="bottom">
525-
<Button
526-
onClick={() => {
527-
$editingPageId.set(
528-
editingItemId === newFolderId ? undefined : newFolderId
529-
);
530-
}}
531-
aria-label="New folder"
532-
prefix={<NewFolderIcon />}
533-
color="ghost"
534-
/>
535-
</Tooltip>
536-
<Tooltip content="New page" side="bottom">
537-
<Button
538-
onClick={() => {
539-
$editingPageId.set(
540-
editingItemId === newPageId ? undefined : newPageId
541-
);
542-
}}
543-
aria-label="New page"
544-
prefix={<NewPageIcon />}
545-
color="ghost"
546-
/>
547-
</Tooltip>
530+
{isDesignMode && (
531+
<>
532+
<Tooltip content="New folder" side="bottom">
533+
<Button
534+
onClick={() => {
535+
$editingPageId.set(
536+
editingItemId === newFolderId ? undefined : newFolderId
537+
);
538+
}}
539+
aria-label="New folder"
540+
prefix={<NewFolderIcon />}
541+
color="ghost"
542+
/>
543+
</Tooltip>
544+
<Tooltip content="New page" side="bottom">
545+
<Button
546+
onClick={() => {
547+
$editingPageId.set(
548+
editingItemId === newPageId ? undefined : newPageId
549+
);
550+
}}
551+
aria-label="New page"
552+
prefix={<NewPageIcon />}
553+
color="ghost"
554+
/>
555+
</Tooltip>
556+
</>
557+
)}
548558
<Tooltip content="Close panel" side="bottom">
549559
<Button
550560
color="ghost"

apps/builder/app/builder/sidebar-left/sidebar-left.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useSubscribe, type Publish } from "~/shared/pubsub";
44
import {
55
$dragAndDropState,
66
$isContentMode,
7+
$isDesignMode,
78
$isPreviewMode,
89
} from "~/shared/nano-states";
910
import { Flex } from "@webstudio-is/design-system";
@@ -173,6 +174,7 @@ type SidebarLeftProps = {
173174
};
174175

175176
export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
177+
const isDesignMode = useStore($isDesignMode);
176178
const activePanel = useStore($activeSidebarPanel);
177179
const dragAndDropState = useStore($dragAndDropState);
178180
const { Panel } = panels.find((item) => item.name === activePanel) ?? none;
@@ -262,7 +264,8 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
262264
})}
263265
</SidebarTabsList>
264266
</div>
265-
<AiTabTrigger />
267+
{isDesignMode && <AiTabTrigger />}
268+
266269
<HelpTabTrigger />
267270
</Flex>
268271
)}

0 commit comments

Comments
 (0)