From 5d6eebdb94f2ab4928f9a2b2dd85bbfc432019da Mon Sep 17 00:00:00 2001 From: Luv Kapur Date: Wed, 13 Mar 2024 11:50:28 -0400 Subject: [PATCH] allow overriding lane comp url in changelog --- components/ui/version-block/version-block.tsx | 22 +++++++++++++------ .../changelog/ui/change-log-page.tsx | 3 +++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/components/ui/version-block/version-block.tsx b/components/ui/version-block/version-block.tsx index 6e4a45f0274d..bc5b51121ec1 100644 --- a/components/ui/version-block/version-block.tsx +++ b/components/ui/version-block/version-block.tsx @@ -16,17 +16,27 @@ export type VersionBlockProps = { isLatest: boolean; snap: LegacyComponentLog; isCurrent: boolean; + getLaneComponentUrl?: (laneId: string, componentId: string) => string; } & HTMLAttributes; /** * change log section * @name VersionBlock */ -export function VersionBlock({ isLatest, className, snap, componentId, isCurrent, ...rest }: VersionBlockProps) { +export function VersionBlock({ + isLatest, + className, + snap, + componentId, + isCurrent, + getLaneComponentUrl, + ...rest +}: VersionBlockProps) { const { username, email, message, tag, hash, date } = snap; const { lanesModel } = useLanes(); const currentLaneUrl = lanesModel?.isViewingNonDefaultLane() ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - `${LanesModel.getLaneUrl(lanesModel.viewedLane!.id)}${LanesModel.baseLaneComponentRoute}` + getLaneComponentUrl?.(lanesModel.viewedLane!.id.toString(), componentId) ?? + `${LanesModel.getLaneUrl(lanesModel.viewedLane!.id)}${LanesModel.baseLaneComponentRoute}/${componentId}` : ''; const version = tag || hash; @@ -42,16 +52,14 @@ export function VersionBlock({ isLatest, className, snap, componentId, isCurrent const { pathname } = location || {}; const testsUrl = currentLaneUrl - ? `${currentLaneUrl}/${componentId}/~tests?version=${version}` + ? `${currentLaneUrl}/~tests?version=${version}` : `${pathname?.replace('~changelog', '~tests')}?version=${version}`; const compositionsUrl = currentLaneUrl - ? `${currentLaneUrl}/${componentId}/~compositions?version=${version}` + ? `${currentLaneUrl}/~compositions?version=${version}` : `${pathname?.replace('~changelog', '~compositions')}?version=${version}`; - const versionUrl = currentLaneUrl - ? `${currentLaneUrl}/${componentId}?version=${version}` - : `${pathname}?version=${version}`; + const versionUrl = currentLaneUrl ? `${currentLaneUrl}?version=${version}` : `${pathname}?version=${version}`; return (
diff --git a/scopes/component/changelog/ui/change-log-page.tsx b/scopes/component/changelog/ui/change-log-page.tsx index 301bd6af03e9..e99b10660d01 100644 --- a/scopes/component/changelog/ui/change-log-page.tsx +++ b/scopes/component/changelog/ui/change-log-page.tsx @@ -18,11 +18,13 @@ import styles from './change-log-page.module.scss'; export type ChangeLogPageProps = { host?: string; useComponentLogs?: (id: string, host: string, filters?: Filters, skip?: boolean) => ComponentLogsResult; + getLaneComponentUrl?: (laneId: string, componentId: string) => string; } & HTMLAttributes; export function ChangeLogPage({ className, useComponentLogs = defaultUseComponentLogs, + getLaneComponentUrl, host = '', }: ChangeLogPageProps) { const component = useContext(ComponentContext); @@ -67,6 +69,7 @@ export function ChangeLogPage({ isLatest={isLatest} snap={snap} isCurrent={isCurrent} + getLaneComponentUrl={getLaneComponentUrl} /> ); })}