fix(content): case-insensitive navigation and contract matching for module and template references
This commit is contained in:
parent
64fbc89b36
commit
6c796d765c
|
|
@ -19,8 +19,9 @@ export function useContentDetailScreen({
|
||||||
);
|
);
|
||||||
|
|
||||||
const moduleMismatch = useMemo(() => {
|
const moduleMismatch = useMemo(() => {
|
||||||
const contractModuleCode = contractQuery.data?.module_code?.trim();
|
const contractModuleCode = contractQuery.data?.module_code?.trim().toLowerCase();
|
||||||
return Boolean(contractModuleCode && contractModuleCode !== moduleCode.trim());
|
const currentModuleCode = moduleCode.trim().toLowerCase();
|
||||||
|
return Boolean(contractModuleCode && currentModuleCode && contractModuleCode !== currentModuleCode);
|
||||||
}, [contractQuery.data?.module_code, moduleCode]);
|
}, [contractQuery.data?.module_code, moduleCode]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ function TemplateScreenResolved({
|
||||||
return <ScreenError title="Template unavailable" message="The template contract response was empty." />;
|
return <ScreenError title="Template unavailable" message="The template contract response was empty." />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contract.template_code !== templateCode) {
|
if (contract.template_code.toLowerCase() !== templateCode.toLowerCase()) {
|
||||||
return (
|
return (
|
||||||
<ScreenError
|
<ScreenError
|
||||||
title="Template contract mismatch"
|
title="Template contract mismatch"
|
||||||
|
|
@ -91,7 +91,7 @@ function TemplateScreenResolved({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contract.module_code && contract.module_code !== moduleCode) {
|
if (contract.module_code && contract.module_code.toLowerCase() !== moduleCode.toLowerCase()) {
|
||||||
return (
|
return (
|
||||||
<ScreenError
|
<ScreenError
|
||||||
title="Template/module mismatch"
|
title="Template/module mismatch"
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ export function parseContentReference(value: unknown): ContentReference | null {
|
||||||
const target = asRecord(reference.target);
|
const target = asRecord(reference.target);
|
||||||
if (!target) return null;
|
if (!target) return null;
|
||||||
|
|
||||||
const moduleCode = nonBlankString(target.module_code);
|
const moduleCode = nonBlankString(target.module_code)?.toLowerCase();
|
||||||
const templateCode = nonBlankString(target.template_code);
|
const templateCode = nonBlankString(target.template_code)?.toLowerCase();
|
||||||
const contentId = nonBlankString(target.content_id);
|
const contentId = nonBlankString(target.content_id);
|
||||||
|
|
||||||
if (!moduleCode || !templateCode || !contentId) return null;
|
if (!moduleCode || !templateCode || !contentId) return null;
|
||||||
|
|
@ -58,8 +58,8 @@ export function parseTemplateReference(value: unknown): TemplateReference | null
|
||||||
const target = asRecord(reference.target);
|
const target = asRecord(reference.target);
|
||||||
if (!target) return null;
|
if (!target) return null;
|
||||||
|
|
||||||
const moduleCode = nonBlankString(target.module_code);
|
const moduleCode = nonBlankString(target.module_code)?.toLowerCase();
|
||||||
const templateCode = nonBlankString(target.template_code);
|
const templateCode = nonBlankString(target.template_code)?.toLowerCase();
|
||||||
if (!moduleCode || !templateCode) return null;
|
if (!moduleCode || !templateCode) return null;
|
||||||
|
|
||||||
const label = nonBlankString(reference.label);
|
const label = nonBlankString(reference.label);
|
||||||
|
|
@ -134,8 +134,8 @@ export function getSingleNavigableContentReference(value: unknown): NavigableCon
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildContentReferenceRoute(reference: NavigableContentReference): string {
|
export function buildContentReferenceRoute(reference: NavigableContentReference): string {
|
||||||
const moduleCode = encodeURIComponent(reference.target.module_code);
|
const moduleCode = encodeURIComponent(reference.target.module_code.toLowerCase());
|
||||||
const templateCode = encodeURIComponent(reference.target.template_code);
|
const templateCode = encodeURIComponent(reference.target.template_code.toLowerCase());
|
||||||
|
|
||||||
if (reference.type === "template_ref") {
|
if (reference.type === "template_ref") {
|
||||||
return `/modules/${moduleCode}/${templateCode}`;
|
return `/modules/${moduleCode}/${templateCode}`;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue