Skip to content

Commit 959fd11

Browse files
authored
feat: Open current page in the publish dialog (#5277)
## Description 1. What is this PR about (link the issue and add a short description) ## 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 dff2946 commit 959fd11

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

apps/builder/app/builder/features/address-bar.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,16 @@ import {
2727
MenuList,
2828
} from "@webstudio-is/design-system";
2929
import { CheckMarkIcon, CopyIcon, DynamicPageIcon } from "@webstudio-is/icons";
30-
import {
31-
findParentFolderByChildId,
32-
ROOT_FOLDER_ID,
33-
getPagePath,
34-
} from "@webstudio-is/sdk";
35-
import { $pages, $publishedOrigin } from "~/shared/nano-states";
30+
import { $publishedOrigin } from "~/shared/nano-states";
3631
import {
3732
compilePathnamePattern,
3833
isPathnamePattern,
3934
matchPathnamePattern,
4035
tokenizePathnamePattern,
4136
} from "~/builder/shared/url-pattern";
42-
import { $selectedPage } from "~/shared/awareness";
37+
import { $selectedPage, $selectedPagePath } from "~/shared/awareness";
4338
import { $currentSystem, updateCurrentSystem } from "~/shared/system";
4439

45-
const $selectedPagePath = computed([$selectedPage, $pages], (page, pages) => {
46-
if (pages === undefined || page === undefined) {
47-
return "/";
48-
}
49-
const parentFolder = findParentFolderByChildId(page.id, pages.folders);
50-
const parentFolderId = parentFolder?.id ?? ROOT_FOLDER_ID;
51-
const foldersPath = getPagePath(parentFolderId, pages);
52-
return [foldersPath, page?.path ?? ""]
53-
.filter(Boolean)
54-
.join("/")
55-
.replace(/\/+/g, "/");
56-
});
57-
5840
const $selectedPageHistory = computed(
5941
$selectedPage,
6042
(page) => page?.history ?? []

apps/builder/app/builder/features/topbar/publish.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
import { validateProjectDomain, type Project } from "@webstudio-is/project";
4444
import {
4545
$awareness,
46+
$selectedPagePath,
4647
findAwarenessByInstanceId,
4748
type Awareness,
4849
} from "~/shared/awareness";
@@ -95,11 +96,15 @@ const ChangeProjectDomain = ({
9596
}: ChangeProjectDomainProps) => {
9697
const id = useId();
9798
const publishedOrigin = useStore($publishedOrigin);
99+
const selectedPagePath = useStore($selectedPagePath);
98100

99101
const [domain, setDomain] = useState(project.domain);
100102
const [error, setError] = useState<string>();
101103
const [isUpdateInProgress, setIsUpdateInProgress] = useOptimistic(false);
102104

105+
const pageUrl = new URL(publishedOrigin);
106+
pageUrl.pathname = selectedPagePath;
107+
103108
const updateProjectDomain = async () => {
104109
setIsUpdateInProgress(true);
105110
const validationResult = validateProjectDomain(domain);
@@ -138,7 +143,7 @@ const ChangeProjectDomain = ({
138143

139144
return (
140145
<CollapsibleDomainSection
141-
title={new URL(publishedOrigin).host}
146+
title={pageUrl.host}
142147
prefix={
143148
<DomainCheckbox
144149
defaultChecked={project.latestBuildVirtual?.domain === domain}
@@ -171,11 +176,18 @@ const ChangeProjectDomain = ({
171176
)}
172177
</Flex>
173178
</Tooltip>
174-
<Tooltip content={`Proceed to ${publishedOrigin}`}>
179+
<Tooltip
180+
content={
181+
<Text css={{ wordBreak: "break-all" }}>
182+
Proceed to ${pageUrl.toString()}
183+
</Text>
184+
}
185+
variant="wrapped"
186+
>
175187
<IconButton
176188
tabIndex={-1}
177189
onClick={(event) => {
178-
window.open(publishedOrigin, "_blank");
190+
window.open(pageUrl, "_blank");
179191
event.preventDefault();
180192
}}
181193
>

apps/builder/app/shared/awareness.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {
77
type Page,
88
rootComponent,
99
Pages,
10+
findParentFolderByChildId,
11+
getPagePath,
12+
ROOT_FOLDER_ID,
1013
} from "@webstudio-is/sdk";
1114
import { $pages } from "./nano-states/pages";
1215
import { $instances, $selectedInstanceSelector } from "./nano-states/instances";
@@ -33,6 +36,22 @@ export const $selectedPage = computed(
3336
}
3437
);
3538

39+
export const $selectedPagePath = computed(
40+
[$selectedPage, $pages],
41+
(page, pages) => {
42+
if (pages === undefined || page === undefined) {
43+
return "/";
44+
}
45+
const parentFolder = findParentFolderByChildId(page.id, pages.folders);
46+
const parentFolderId = parentFolder?.id ?? ROOT_FOLDER_ID;
47+
const foldersPath = getPagePath(parentFolderId, pages);
48+
return [foldersPath, page?.path ?? ""]
49+
.filter(Boolean)
50+
.join("/")
51+
.replace(/\/+/g, "/");
52+
}
53+
);
54+
3655
export const $temporaryInstances = atom<Instances>(new Map());
3756
export const addTemporaryInstance = (instance: Instance) => {
3857
$temporaryInstances.get().set(instance.id, instance);

0 commit comments

Comments
 (0)