Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
67dad84
fix: language picker when url templates are in use
briantstephan Oct 28, 2025
3ec61cb
add logging
briantstephan Oct 28, 2025
a8a26ec
merge profile with streamDocument
briantstephan Oct 28, 2025
25af5aa
Update component screenshots for visual-editor
github-actions[bot] Oct 28, 2025
fa4d327
Update component screenshots for visual-editor
github-actions[bot] Oct 28, 2025
32c5ba6
use correct locale
briantstephan Oct 28, 2025
201a346
Merge branch 'url-templates-locale' of https://github.com/yext/visual…
briantstephan Oct 28, 2025
5deaf7a
improve log
briantstephan Oct 28, 2025
46fda73
improve logging
briantstephan Oct 28, 2025
cac1835
determine primary locale
briantstephan Oct 28, 2025
de66912
set correct primary locale field
briantstephan Oct 28, 2025
6035852
remove logging from testing
briantstephan Oct 28, 2025
89cc812
Merge branch 'main' into url-templates-locale
briantstephan Oct 28, 2025
7bb57be
check for isPrimaryLocale on content endpoint response
briantstephan Oct 30, 2025
b20d557
Merge branch 'url-templates-locale' of https://github.com/yext/visual…
briantstephan Oct 30, 2025
c48ddb7
refactor resovleUrlTemplate into two functions
briantstephan Oct 31, 2025
7b353fa
fixed import
briantstephan Oct 31, 2025
1145fee
Update component screenshots for visual-editor
github-actions[bot] Oct 31, 2025
c8e55ca
Update component screenshots for visual-editor
github-actions[bot] Oct 31, 2025
6e9012a
Update component screenshots for visual-editor
github-actions[bot] Oct 31, 2025
52bdbc3
Update component screenshots for visual-editor
github-actions[bot] Oct 31, 2025
8f44135
Update component screenshots for visual-editor
github-actions[bot] Oct 31, 2025
d618b92
refactor resolveUrlTemplate functions
briantstephan Oct 31, 2025
769513c
Merge branch 'url-templates-locale' of https://github.com/yext/visual…
briantstephan Oct 31, 2025
9367b0e
remove conflicting screenshot
briantstephan Oct 31, 2025
8cbb9a3
remove conflicting screenshot
briantstephan Oct 31, 2025
545fe93
fix build
briantstephan Oct 31, 2025
c7a532e
Update component screenshots for visual-editor
github-actions[bot] Oct 31, 2025
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
4 changes: 2 additions & 2 deletions packages/visual-editor/src/components/Directory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
YextEntityField,
resolveComponentData,
HoursStatusAtom,
resolveUrlTemplate,
resolveUrlTemplateOfChild,
mergeMeta,
} from "@yext/visual-editor";
import { BreadcrumbsComponent } from "./pageSections/Breadcrumbs.tsx";
Expand Down Expand Up @@ -294,7 +294,7 @@ const DirectoryCard = ({
const { document: streamDocument, relativePrefixToRoot } = useTemplateProps();
const cardStyles: DirectoryProps["styles"]["cards"] = styles["cards"];

const resolvedUrl = resolveUrlTemplate(
const resolvedUrl = resolveUrlTemplateOfChild(
mergeMeta(profile, streamDocument),
relativePrefixToRoot,
puck.metadata?.resolveUrlTemplate
Expand Down
4 changes: 2 additions & 2 deletions packages/visual-editor/src/components/Locator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
useDocument,
YextField,
useTemplateProps,
resolveUrlTemplate,
resolveUrlTemplateOfChild,
mergeMeta,
HoursStatusAtom,
} from "@yext/visual-editor";
Expand Down Expand Up @@ -1112,7 +1112,7 @@ const LocationCard = React.memo(
"TAP_TO_CALL"
);

const resolvedUrl = resolveUrlTemplate(
const resolvedUrl = resolveUrlTemplateOfChild(
mergeMeta(location, streamDocument),
relativePrefixToRoot,
puck.metadata?.resolveUrlTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
BackgroundStyle,
Body,
fetchLocalesToPathsForEntity,
useDocument,
} from "@yext/visual-editor";
import {
Accordion,
Expand Down Expand Up @@ -43,6 +44,7 @@ export const LanguageDropdown: React.FC<LanguageDropdownProps> = ({
currentLocale,
background,
}) => {
const streamDocument = useDocument();
const scopedLocales = new Set<string>(locales);
const [validLocalesToPaths, setValidLocalesToPaths] = React.useState<
Record<string, string>
Expand Down Expand Up @@ -72,6 +74,7 @@ export const LanguageDropdown: React.FC<LanguageDropdownProps> = ({
contentEndpointId,
contentDeliveryAPIDomain,
entityId,
streamDocument,
});

const filtered: Record<string, string> = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
MaybeLink,
resolveComponentData,
Body,
resolveUrlTemplate,
resolvePageSetUrlTemplate,
useTemplateProps,
mergeMeta,
} from "@yext/visual-editor";
Expand Down Expand Up @@ -314,7 +314,7 @@ const LocationCard = ({
} = locationData;
const { document: streamDocument, relativePrefixToRoot } = useTemplateProps();

const resolvedUrl = resolveUrlTemplate(
const resolvedUrl = resolvePageSetUrlTemplate(
mergeMeta(locationData, streamDocument),
relativePrefixToRoot,
puck.metadata?.resolveUrlTemplate
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/visual-editor/src/docs/hybrid-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Various existing components require additional data from the hybrid-developer. T
This could look like:

```ts
function resolveUrlTemplate(
function resolveUrlTemplateOfChild(
streamDocument: any,
locale: string,
relativePrefixToRoot: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { normalizeSlug } from "../slugifier.ts";
import { normalizeLocale } from "../normalizeLocale.ts";
import { mergeMeta } from "../mergeMeta.ts";
import { StreamDocument } from "../applyTheme.ts";
import { normalizeLocale } from "../normalizeLocale.ts";
import { resolvePageSetUrlTemplate } from "../resolveUrlTemplate.ts";

const V_PARAM = "20250407";

Expand All @@ -10,12 +11,14 @@ export const fetchLocalesToPathsForEntity = async ({
contentEndpointId,
contentDeliveryAPIDomain,
entityId,
streamDocument,
}: {
businessId: string;
apiKey: string;
contentEndpointId: string;
contentDeliveryAPIDomain: string;
entityId: string;
streamDocument: StreamDocument;
}): Promise<Record<string, string>> => {
const url = new URL(
`${contentDeliveryAPIDomain}/v2/accounts/${businessId}/content/${contentEndpointId}`
Expand All @@ -34,9 +37,22 @@ export const fetchLocalesToPathsForEntity = async ({

try {
const json = await response.json();

for (const profile of json.response.docs) {
if (profile?.meta?.locale && getPath(profile)) {
localeToPath[normalizeLocale(profile.meta.locale)] = getPath(profile);
if (profile?.meta?.locale) {
try {
// Merge profile with streamDocument metadata
const mergedDocument = mergeMeta(profile, streamDocument);

// Use resolvePageSetUrlTemplate to get the URL based on the current page set template
const resolvedUrl = resolvePageSetUrlTemplate(mergedDocument, "");
localeToPath[normalizeLocale(profile.meta.locale)] = resolvedUrl;
} catch (e) {
console.warn(
`Failed to resolve URL template for locale ${profile.meta.locale}`,
e
);
}
}
}
} catch (e) {
Expand All @@ -45,22 +61,3 @@ export const fetchLocalesToPathsForEntity = async ({

return localeToPath;
};

// getPath assumes the user is using Visual Editor in-platform. This does not work with some hybrid cases.
// This should use the exact same logic as getPath in packages/visual-editor/src/vite-plugin/templates/main.tsx
// as that is the code all in-platform developers are using.
const getPath = (streamDocument: StreamDocument): string => {
if (streamDocument.slug) {
return streamDocument.slug;
}

const localePath =
streamDocument.meta?.locale !== "en"
? `${streamDocument.meta?.locale}/`
: "";
const path = streamDocument.address
? `${localePath}${streamDocument.address.region}/${streamDocument.address.city}/${streamDocument.address.line1}-${streamDocument.id}`
: `${localePath}${streamDocument.id}`;

return normalizeSlug(path);
};
20 changes: 18 additions & 2 deletions packages/visual-editor/src/utils/getSchema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { StreamDocument } from "./applyTheme.ts";
import { resolveUrlTemplate } from "./resolveUrlTemplate.ts";
import {
resolvePageSetUrlTemplate,
resolveUrlTemplateOfChild,
} from "./resolveUrlTemplate.ts";
import { resolveSchemaJson } from "./resolveYextEntityField.ts";

interface TemplateRenderProps {
Expand All @@ -19,7 +22,20 @@ export const getSchema = (data: TemplateRenderProps): Record<string, any> => {
document.path = data.path;
} else {
// TODO (SUMO-7941): Check that this resolves correctly for the schema drawer preview
document.path = resolveUrlTemplate(document, data.relativePrefixToRoot);
if (
document?.__?.codeTemplate === "directory" ||
document?.__?.codeTemplate === "locator"
) {
document.path = resolveUrlTemplateOfChild(
document,
data.relativePrefixToRoot
);
} else {
document.path = resolvePageSetUrlTemplate(
document,
data.relativePrefixToRoot
);
}
}

const layoutString = document?.__?.layout;
Expand Down
5 changes: 4 additions & 1 deletion packages/visual-editor/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export {
resolveYextStructField,
resolveSchemaJson,
} from "./resolveYextEntityField.ts";
export { resolveUrlTemplate } from "./resolveUrlTemplate.ts";
export {
resolveUrlTemplateOfChild,
resolvePageSetUrlTemplate,
} from "./resolveUrlTemplate.ts";
export {
createSearchAnalyticsConfig,
createSearchHeadlessConfig,
Expand Down
14 changes: 13 additions & 1 deletion packages/visual-editor/src/utils/mergeMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@
* @returns {Object}
*/
export function mergeMeta(profile: any, streamDocument: any): any {
const locale: string = profile?.meta?.locale || streamDocument?.locale;

let isPrimaryLocale: boolean;
if (profile?.meta?.isPrimaryLocale === true) {
isPrimaryLocale = true;
} else if (profile?.meta?.isPrimaryLocale === false) {
isPrimaryLocale = false;
} else {
isPrimaryLocale = locale === "en";
}

return {
locale: streamDocument?.locale,
locale: locale,
...profile,
meta: {
...streamDocument?.meta,
Expand All @@ -16,6 +27,7 @@ export function mergeMeta(profile: any, streamDocument: any): any {
__: {
...streamDocument.__,
...profile.__,
isPrimaryLocale: isPrimaryLocale,
},
_pageset: streamDocument._pageset,
};
Expand Down
Loading
Loading