Skip to content

Commit 18409bb

Browse files
authored
refactor: fix system on non-home pages (#4893)
Tested forms only on home page. John caught the issue on other pages. Forms now submit system.search on non-home pages proeprly.
1 parent b798809 commit 18409bb

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ import {
2727
ROOT_FOLDER_ID,
2828
findParentFolderByChildId,
2929
ProjectNewRedirectPath,
30-
DataSource,
3130
isLiteralExpression,
32-
type System,
3331
documentTypes,
3432
isRootFolder,
3533
} from "@webstudio-is/sdk";
@@ -74,7 +72,6 @@ import {
7472
$instances,
7573
$pages,
7674
$dataSources,
77-
$dataSourceVariables,
7875
$publishedOrigin,
7976
$project,
8077
$userPlanFeatures,
@@ -112,6 +109,7 @@ import { useUnmount } from "~/shared/hook-utils/use-mount";
112109
import { Card } from "../marketplace/card";
113110
import { selectInstance } from "~/shared/awareness";
114111
import { computeExpression } from "~/shared/data-variables";
112+
import { $currentSystem } from "~/shared/system";
115113

116114
const fieldDefaultValues = {
117115
name: "Untitled",
@@ -579,7 +577,7 @@ const LanguageField = ({
579577
);
580578
};
581579

582-
const usePageUrl = (values: Values, systemDataSourceId?: DataSource["id"]) => {
580+
const usePageUrl = (values: Values) => {
583581
const pages = useStore($pages);
584582
const foldersPath =
585583
pages === undefined ? "" : getPagePath(values.parentFolderId, pages);
@@ -588,16 +586,10 @@ const usePageUrl = (values: Values, systemDataSourceId?: DataSource["id"]) => {
588586
.join("/")
589587
.replace(/\/+/g, "/");
590588

591-
const dataSourceVariables = useStore($dataSourceVariables);
592-
const storedSystem =
593-
systemDataSourceId === undefined
594-
? undefined
595-
: (dataSourceVariables.get(systemDataSourceId) as System);
596-
const pathParams = storedSystem?.params ?? {};
597-
589+
const system = useStore($currentSystem);
598590
const publishedOrigin = useStore($publishedOrigin);
599591
const tokens = tokenizePathnamePattern(path);
600-
const compiledPath = compilePathnamePattern(tokens, pathParams);
592+
const compiledPath = compilePathnamePattern(tokens, system.params);
601593
return `${publishedOrigin}${compiledPath}`;
602594
};
603595

@@ -705,13 +697,11 @@ const MarketplaceSection = ({
705697
};
706698

707699
const FormFields = ({
708-
systemDataSourceId,
709700
autoSelect,
710701
errors,
711702
values,
712703
onChange,
713704
}: {
714-
systemDataSourceId?: DataSource["id"];
715705
autoSelect?: boolean;
716706
errors: Errors;
717707
values: Values;
@@ -724,7 +714,7 @@ const FormFields = ({
724714
const { allowDynamicData } = useStore($userPlanFeatures);
725715
const { variableValues, scope, aliases } = useStore($pageRootScope);
726716

727-
const pageUrl = usePageUrl(values, systemDataSourceId);
717+
const pageUrl = usePageUrl(values);
728718

729719
if (pages === undefined) {
730720
return;
@@ -1656,12 +1646,7 @@ export const PageSettings = ({
16561646
}
16571647
}}
16581648
>
1659-
<FormFields
1660-
systemDataSourceId={page.systemDataSourceId}
1661-
errors={errors}
1662-
values={values}
1663-
onChange={handleChange}
1664-
/>
1649+
<FormFields errors={errors} values={values} onChange={handleChange} />
16651650
</PageSettingsView>
16661651
);
16671652
};

apps/builder/app/canvas/interceptor.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import { getPagePath, type System } from "@webstudio-is/sdk";
1+
import { getPagePath } from "@webstudio-is/sdk";
22
import {
33
compilePathnamePattern,
44
matchPathnamePattern,
55
tokenizePathnamePattern,
66
} from "~/builder/shared/url-pattern";
77
import { $selectedPage, selectPage } from "~/shared/awareness";
88
import {
9-
$dataSourceVariables,
109
$isPreviewMode,
1110
$pages,
1211
$selectedPageHash,
1312
} from "~/shared/nano-states";
14-
import { updateCurrentSystem } from "~/shared/system";
13+
import { $currentSystem, updateCurrentSystem } from "~/shared/system";
1514

1615
const isAbsoluteUrl = (href: string) => {
1716
try {
@@ -25,13 +24,10 @@ const isAbsoluteUrl = (href: string) => {
2524
const getSelectedPagePathname = () => {
2625
const pages = $pages.get();
2726
const page = $selectedPage.get();
28-
const dataSourceVariables = $dataSourceVariables.get();
29-
if (page?.systemDataSourceId && pages) {
30-
const system = dataSourceVariables.get(page.systemDataSourceId) as
31-
| undefined
32-
| System;
27+
if (page && pages) {
3328
const tokens = tokenizePathnamePattern(getPagePath(page.id, pages));
34-
return compilePathnamePattern(tokens, system?.params ?? {});
29+
const system = $currentSystem.get();
30+
return compilePathnamePattern(tokens, system.params);
3531
}
3632
};
3733

@@ -62,8 +58,8 @@ const switchPageAndUpdateSystem = (href: string, formData?: FormData) => {
6258
$selectedPageHash.set({ hash: pageHref.hash });
6359
selectPage(page.id);
6460
updateCurrentSystem({ params, search });
61+
break;
6562
}
66-
break;
6763
}
6864
};
6965

0 commit comments

Comments
 (0)