Skip to content
Open
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
34 changes: 22 additions & 12 deletions src/app/(app)/shared/utils/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,7 @@ async function getAppConfigBase(

// Fetch English resource directory for fallback if not English locale
let englishResourceDirectory: ResourceDirectory | null = null;
if (
locale !== 'en' &&
(resourceDirectory.resource?.useCustomLayout ||
!resourceDirectory.search.cardLayout)
) {
if (locale !== 'en') {
englishResourceDirectory = await findResourceDirectoryByHost(host, 'en');
}

Expand Down Expand Up @@ -617,13 +613,27 @@ async function getAppConfigBase(
}),
),
},
alerts: activeAlerts.map((alert) => ({
text: alert.text,
buttonText: alert.buttonText ?? undefined,
target: alert.openInNewTab ? '_blank' : undefined,
url: alert.url ?? undefined,
variant: alert.variant ?? undefined,
})),
alerts: activeAlerts
.map((alert, index) => {
const englishAlerts = englishResourceDirectory?.common?.alert ?? [];
const fallbackAlert =
findFallbackById(alert, englishAlerts) ?? englishAlerts[index];
const text = alert.text || fallbackAlert?.text;

if (!text?.trim()) {
return null;
}

return {
text,
buttonText:
(alert.buttonText || fallbackAlert?.buttonText) ?? undefined,
target: alert.openInNewTab ? ('_blank' as const) : undefined,
url: alert.url ?? undefined,
variant: alert.variant ?? undefined,
};
})
.filter((alert): alert is NonNullable<typeof alert> => alert !== null),
heroUrl,
highlights: resourceDirectory.highlights
? {
Expand Down
48 changes: 48 additions & 0 deletions src/payload/utilities/getChangedLocalizedPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,54 @@ function deepLocalizedDiff(
}
});

// ALERTS (from common tab)

const beforeAlerts: NonNullable<
NonNullable<ResourceDirectory['common']>['alert']
> = get(before, 'common.alert', []);
const afterAlerts: NonNullable<
NonNullable<ResourceDirectory['common']>['alert']
> = get(after, 'common.alert', []);

const beforeAlertsMap = new Map(beforeAlerts.map((a) => [a.id, a]));
const afterAlertsMap = new Map(afterAlerts.map((a) => [a.id, a]));

afterAlerts.forEach((afterAlert, index) => {
const beforeAlert = beforeAlertsMap.get(afterAlert.id);

(['text', 'buttonText'] as const).forEach((field) => {
if (!beforeAlert) {
if (afterAlert[field]) {
changes.push({
path: `common.alert.${index}.${field}`,
before: undefined,
after: afterAlert[field],
});
}
} else if (beforeAlert[field] !== afterAlert[field]) {
changes.push({
path: `common.alert.${index}.${field}`,
before: beforeAlert[field],
after: afterAlert[field],
});
}
});
});

beforeAlerts.forEach((beforeAlert, index) => {
if (!afterAlertsMap.has(beforeAlert.id)) {
(['text', 'buttonText'] as const).forEach((field) => {
if (beforeAlert[field]) {
changes.push({
path: `common.alert.${index}.${field}`,
before: beforeAlert[field],
after: undefined,
});
}
});
}
});

// SEARCH FACETS

const beforeFacets: NonNullable<ResourceDirectory['search']['facets']> = get(
Expand Down
Loading