mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-06 15:22:32 +09:00
## Summary - add optional `instanceId` support to the shared Builder link parameters used by `builderPath` and `builderUrl` - synchronize the selected instance into the Builder URL without adding a browser-history entry for every selection - restore the selected page and full instance selector when opening an instance deep link - render a **Show element** link for pre-publish audit findings that identify an instance - switch to the affected page, select and scroll to the instance, and close the publish popover when the link is used ## Why The pre-publish audit introduced in #5922 identifies the invalid page and instance, but its error was text-only. Users still had to locate the offending element manually. A shared instance deep-link parameter also makes these links copyable and reusable outside the audit UI. ## Impact Builder URLs can now include `instanceId` alongside `pageId`. Existing page-opening links continue using the same central `builderPath`/`builderUrl` abstraction. Missing or stale instance IDs safely fall back to the requested page. ## Validation - focused Builder tests passed (4 tests) - `@webstudio-is/builder` typecheck passed - focused Oxlint passed - focused Oxfmt check passed - `git diff --check` passed
162 lines
3.8 KiB
TypeScript
162 lines
3.8 KiB
TypeScript
import type { AUTH_PROVIDERS } from "~/shared/session";
|
|
import { getAuthorizationServerOrigin } from "./origins";
|
|
import type { BuilderMode } from "../nano-states/misc";
|
|
|
|
const searchParams = (params: Record<string, string | undefined | null>) => {
|
|
const searchParams = new URLSearchParams();
|
|
for (const [key, value] of Object.entries(params)) {
|
|
if (typeof value === "string") {
|
|
searchParams.set(key, value);
|
|
}
|
|
}
|
|
const asString = searchParams.toString();
|
|
return asString === "" ? "" : `?${asString}`;
|
|
};
|
|
|
|
export type BuilderLinkParams = {
|
|
pageId?: string;
|
|
instanceId?: string;
|
|
authToken?: string;
|
|
pageHash?: string;
|
|
mode?: BuilderMode;
|
|
safemode?: boolean;
|
|
};
|
|
|
|
export const builderPath = ({
|
|
pageId,
|
|
instanceId,
|
|
authToken,
|
|
pageHash,
|
|
mode,
|
|
safemode = false,
|
|
}: BuilderLinkParams = {}) => {
|
|
return `/${searchParams({
|
|
pageId,
|
|
instanceId,
|
|
authToken,
|
|
pageHash,
|
|
mode,
|
|
safemode: safemode ? "true" : undefined,
|
|
})}`;
|
|
};
|
|
|
|
export const builderUrl = ({
|
|
projectId,
|
|
origin,
|
|
...link
|
|
}: BuilderLinkParams & {
|
|
projectId: string;
|
|
origin: string;
|
|
}) => {
|
|
const authServerOrigin = getAuthorizationServerOrigin(origin);
|
|
|
|
const url = new URL(builderPath(link), authServerOrigin);
|
|
|
|
const fragments = url.host.split(".");
|
|
if (fragments.length <= 3) {
|
|
fragments.splice(0, 0, "p-" + projectId);
|
|
} else {
|
|
// staging | development branches
|
|
fragments[0] = "p-" + projectId + "-dot-" + fragments[0];
|
|
}
|
|
|
|
url.host = fragments.join(".");
|
|
|
|
return url.href;
|
|
};
|
|
|
|
export const dashboardPath = (
|
|
view: "templates" | "search" | "projects" = "projects"
|
|
) => {
|
|
if (view === "projects") {
|
|
return `/dashboard`;
|
|
}
|
|
return `/dashboard/${view}`;
|
|
};
|
|
|
|
export const dashboardUrl = (props: { origin: string }) => {
|
|
const authServerOrigin = getAuthorizationServerOrigin(props.origin);
|
|
|
|
return `${authServerOrigin}/dashboard`;
|
|
};
|
|
|
|
export const cloneProjectUrl = (props: {
|
|
origin: string;
|
|
sourceAuthToken: string;
|
|
}) => {
|
|
const authServerOrigin = getAuthorizationServerOrigin(props.origin);
|
|
|
|
const searchParams = new URLSearchParams();
|
|
searchParams.set("projectToCloneAuthToken", props.sourceAuthToken);
|
|
|
|
return `${authServerOrigin}/dashboard?${searchParams.toString()}`;
|
|
};
|
|
|
|
export const loginPath = (params: {
|
|
error?: (typeof AUTH_PROVIDERS)[keyof typeof AUTH_PROVIDERS];
|
|
message?: string;
|
|
returnTo?: string;
|
|
}) => `/login${searchParams(params)}`;
|
|
|
|
export const logoutPath = () => "/logout";
|
|
export const restLogoutPath = () => "/dashboard-logout";
|
|
|
|
export const planSubscriptionPath = (subscriptionId?: string) => {
|
|
const urlSearchParams = new URLSearchParams();
|
|
urlSearchParams.set("return_url", window.location.href);
|
|
if (subscriptionId) {
|
|
urlSearchParams.set("subscription", subscriptionId);
|
|
}
|
|
|
|
return `/builder-payments/billing-portal/sessions?${urlSearchParams.toString()}`;
|
|
};
|
|
|
|
export const authCallbackPath = ({
|
|
provider,
|
|
}: {
|
|
provider: "google" | "github";
|
|
}) => `/auth/${provider}/callback`;
|
|
|
|
export const authPath = ({
|
|
provider,
|
|
}: {
|
|
provider: "google" | "github" | "dev";
|
|
}) => `/auth/${provider}`;
|
|
|
|
export const restAssetsPath = () => {
|
|
return `/rest/assets`;
|
|
};
|
|
|
|
export const restAssetsUploadPath = ({
|
|
name,
|
|
width,
|
|
height,
|
|
}: {
|
|
name: string;
|
|
width?: number | undefined;
|
|
height?: number | undefined;
|
|
}) => {
|
|
const urlSearchParams = new URLSearchParams();
|
|
if (width !== undefined) {
|
|
urlSearchParams.set("width", String(width));
|
|
}
|
|
if (height !== undefined) {
|
|
urlSearchParams.set("height", String(height));
|
|
}
|
|
|
|
if (urlSearchParams.size > 0) {
|
|
return `/rest/assets/${name}?${urlSearchParams.toString()}`;
|
|
}
|
|
|
|
return `/rest/assets/${name}`;
|
|
};
|
|
|
|
export const getCanvasUrl = () => {
|
|
return `/canvas`;
|
|
};
|
|
|
|
export const restResourcesLoader = () => `/rest/resources-loader`;
|
|
|
|
export const marketplacePath = (method: string) =>
|
|
`/builder/marketplace/${method}`;
|