Skip to content

Commit

Permalink
Add note, made LinkElement type more lax to accept lazy component,
Browse files Browse the repository at this point in the history
export SmartLink from instance
  • Loading branch information
hanbyul-here committed Sep 20, 2024
1 parent b609402 commit e7065ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/scripts/components/common/card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { lazy, MouseEventHandler } from 'react';
import React, { lazy, MouseEventHandler, ComponentType } from 'react';
import styled, { css } from 'styled-components';
import { Link } from 'react-router-dom';
import { format } from 'date-fns';
import { CollecticonExpandTopRight } from '@devseed-ui/collecticons';
import { Link } from 'react-router-dom';
const SmartLink = lazy(() => import('../smart-link'));
import {
glsp,
Expand Down Expand Up @@ -221,7 +221,7 @@ export function ExternalLinkFlag() {
}

export interface LinkProperties {
LinkElement: JSX.Element | ((props: any) => JSX.Element);
LinkElement: JSX.Element | ((props: any) => JSX.Element) | ComponentType<any>;
pathAttributeKeyName: string;
onLinkClick?: MouseEventHandler;
}
Expand All @@ -247,6 +247,7 @@ export interface CardComponentBaseProps {
}

// @TODO: Consolidate these props when the instance adapts the new syntax
// Specifically: https://github.com/US-GHG-Center/veda-config-ghg/blob/develop/custom-pages/news-and-events/component.tsx#L108
export interface CardComponentPropsDeprecated extends CardComponentBaseProps {
linkTo: string;
onLinkClick?: MouseEventHandler;
Expand Down Expand Up @@ -278,7 +279,8 @@ function CardComponent(props: CardComponentPropsType) {
footerContent,
onCardClickCapture
} = props;

// @TODO: This process is not necessary once all the instances adapt the linkProperties syntax
// Consolidate them to use LinkProperties only
let linkProperties: LinkWithPathProperties;

if (hasLinkProperties(props)) {
Expand All @@ -291,7 +293,6 @@ function CardComponent(props: CardComponentPropsType) {
linkTo,
onLinkClick,
pathAttributeKeyName: 'to',
// @ts-expect-error SmartLink needs to be lazily loaded temporarily to prevent ui-library from loading react-router-dom
LinkElement: SmartLink
};
}
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import Hug from "$styles/hug";
import { Actions } from "$components/common/browse-controls/use-browse-controls";
import Image from "$components/common/blocks/images";

import SmartLink from "$components/common/smart-link";

export {
STORIES_PATH,
DATASETS_PATH,
Expand All @@ -67,6 +69,7 @@ export {
FoldProse,
Hug,
Image,
SmartLink,
Pill,
Tip,
VarHeading
Expand Down

0 comments on commit e7065ff

Please sign in to comment.