Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions apps/builder/app/builder/features/pages/page-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import {
ROOT_FOLDER_ID,
findParentFolderByChildId,
ProjectNewRedirectPath,
DataSource,
isLiteralExpression,
type System,
documentTypes,
isRootFolder,
} from "@webstudio-is/sdk";
Expand Down Expand Up @@ -74,7 +72,6 @@ import {
$instances,
$pages,
$dataSources,
$dataSourceVariables,
$publishedOrigin,
$project,
$userPlanFeatures,
Expand Down Expand Up @@ -112,6 +109,7 @@ import { useUnmount } from "~/shared/hook-utils/use-mount";
import { Card } from "../marketplace/card";
import { selectInstance } from "~/shared/awareness";
import { computeExpression } from "~/shared/data-variables";
import { $currentSystem } from "~/shared/system";

const fieldDefaultValues = {
name: "Untitled",
Expand Down Expand Up @@ -579,7 +577,7 @@ const LanguageField = ({
);
};

const usePageUrl = (values: Values, systemDataSourceId?: DataSource["id"]) => {
const usePageUrl = (values: Values) => {
const pages = useStore($pages);
const foldersPath =
pages === undefined ? "" : getPagePath(values.parentFolderId, pages);
Expand All @@ -588,16 +586,10 @@ const usePageUrl = (values: Values, systemDataSourceId?: DataSource["id"]) => {
.join("/")
.replace(/\/+/g, "/");

const dataSourceVariables = useStore($dataSourceVariables);
const storedSystem =
systemDataSourceId === undefined
? undefined
: (dataSourceVariables.get(systemDataSourceId) as System);
const pathParams = storedSystem?.params ?? {};

const system = useStore($currentSystem);
const publishedOrigin = useStore($publishedOrigin);
const tokens = tokenizePathnamePattern(path);
const compiledPath = compilePathnamePattern(tokens, pathParams);
const compiledPath = compilePathnamePattern(tokens, system.params);
return `${publishedOrigin}${compiledPath}`;
};

Expand Down Expand Up @@ -705,13 +697,11 @@ const MarketplaceSection = ({
};

const FormFields = ({
systemDataSourceId,
autoSelect,
errors,
values,
onChange,
}: {
systemDataSourceId?: DataSource["id"];
autoSelect?: boolean;
errors: Errors;
values: Values;
Expand All @@ -724,7 +714,7 @@ const FormFields = ({
const { allowDynamicData } = useStore($userPlanFeatures);
const { variableValues, scope, aliases } = useStore($pageRootScope);

const pageUrl = usePageUrl(values, systemDataSourceId);
const pageUrl = usePageUrl(values);

if (pages === undefined) {
return;
Expand Down Expand Up @@ -1656,12 +1646,7 @@ export const PageSettings = ({
}
}}
>
<FormFields
systemDataSourceId={page.systemDataSourceId}
errors={errors}
values={values}
onChange={handleChange}
/>
<FormFields errors={errors} values={values} onChange={handleChange} />
</PageSettingsView>
);
};
Expand Down
16 changes: 6 additions & 10 deletions apps/builder/app/canvas/interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { getPagePath, type System } from "@webstudio-is/sdk";
import { getPagePath } from "@webstudio-is/sdk";
import {
compilePathnamePattern,
matchPathnamePattern,
tokenizePathnamePattern,
} from "~/builder/shared/url-pattern";
import { $selectedPage, selectPage } from "~/shared/awareness";
import {
$dataSourceVariables,
$isPreviewMode,
$pages,
$selectedPageHash,
} from "~/shared/nano-states";
import { updateCurrentSystem } from "~/shared/system";
import { $currentSystem, updateCurrentSystem } from "~/shared/system";

const isAbsoluteUrl = (href: string) => {
try {
Expand All @@ -25,13 +24,10 @@ const isAbsoluteUrl = (href: string) => {
const getSelectedPagePathname = () => {
const pages = $pages.get();
const page = $selectedPage.get();
const dataSourceVariables = $dataSourceVariables.get();
if (page?.systemDataSourceId && pages) {
const system = dataSourceVariables.get(page.systemDataSourceId) as
| undefined
| System;
if (page && pages) {
const tokens = tokenizePathnamePattern(getPagePath(page.id, pages));
return compilePathnamePattern(tokens, system?.params ?? {});
const system = $currentSystem.get();
return compilePathnamePattern(tokens, system.params);
}
};

Expand Down Expand Up @@ -62,8 +58,8 @@ const switchPageAndUpdateSystem = (href: string, formData?: FormData) => {
$selectedPageHash.set({ hash: pageHref.hash });
selectPage(page.id);
updateCurrentSystem({ params, search });
break;
}
break;
}
};

Expand Down
Loading