Skip to content

Commit

Permalink
hotfix(linkTitle): handle i18n link title in web
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Sep 27, 2024
1 parent 154e66f commit e63a2a7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/components/link/CustomLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ interface ICustomLink {

const CustomLink = ({ type = "link", link, isSelected }: ICustomLink) => {
const linkTitle = link.linkTitle;
// TODO: pick title based on selected language
const linkTitleValue =
(typeof linkTitle === "string" ? linkTitle : linkTitle[0].value) ?? "";
const href = getHref(link);
const newTab = link.newTab;
const target = newTab ? "_blank" : undefined;
Expand All @@ -34,7 +37,7 @@ const CustomLink = ({ type = "link", link, isSelected }: ICustomLink) => {
rel={rel}
aria-label={link.ariaLabel}
>
<span className={styles.span}>{linkTitle}</span>
<span className={styles.span}>{linkTitleValue}</span>
</Link>
<div className={styles.underline}></div>
</div>
Expand All @@ -46,7 +49,7 @@ const CustomLink = ({ type = "link", link, isSelected }: ICustomLink) => {
rel={rel}
aria-label={link.ariaLabel}
>
{linkTitle}
{linkTitleValue}
</Link>
);
};
Expand Down
9 changes: 7 additions & 2 deletions src/components/linkButton/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ const typeClassMap: { [key in LinkButtonType]: string } = {
const LinkButton = ({ isSmall, type = "primary", link }: IButton) => {
const className = `${styles.button} ${isSmall ? styles.small : ""} ${typeClassMap[type]}`;
const href = getHref(link);
const linkTitle = link.linkTitle;
// TODO: pick title based on selected language
const linkTitleValue =
typeof linkTitle === "string" ? linkTitle : linkTitle[0].value;
return (
href && (
href &&
linkTitleValue && (
<a className={className} href={href}>
{link.linkTitle}
{linkTitleValue}
</a>
)
);
Expand Down
7 changes: 7 additions & 0 deletions studio/lib/interfaces/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ export interface DocumentWithSlug {
slug: Slug;
_updatedAt: string;
}

export type InternationalizedString = InternationalizedStringValue[];

export interface InternationalizedStringValue {
_key: string;
value?: string;
}
4 changes: 3 additions & 1 deletion studio/lib/interfaces/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { InternationalizedString } from "./global";

export interface Navigation {
_id: string;
main: ILink[];
Expand All @@ -12,7 +14,7 @@ interface Reference {
export interface ILink {
_key: string;
_type: string;
linkTitle: string;
linkTitle: string | InternationalizedString;
linkType: LinkType;
internalLink?: Reference;
url?: string;
Expand Down

0 comments on commit e63a2a7

Please sign in to comment.