Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Changelog): override component url for lane component versions #8667

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
22 changes: 15 additions & 7 deletions components/ui/version-block/version-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@ export type VersionBlockProps = {
isLatest: boolean;
snap: LegacyComponentLog;
isCurrent: boolean;
getLaneComponentUrl?: (laneId: string, componentId: string) => string;
} & HTMLAttributes<HTMLDivElement>;
/**
* 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;
Expand All @@ -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 (
<div className={classNames(styles.versionWrapper, className)}>
Expand Down
3 changes: 3 additions & 0 deletions scopes/component/changelog/ui/change-log-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDivElement>;

export function ChangeLogPage({
className,
useComponentLogs = defaultUseComponentLogs,
getLaneComponentUrl,
host = '',
}: ChangeLogPageProps) {
const component = useContext(ComponentContext);
Expand Down Expand Up @@ -67,6 +69,7 @@ export function ChangeLogPage({
isLatest={isLatest}
snap={snap}
isCurrent={isCurrent}
getLaneComponentUrl={getLaneComponentUrl}
/>
);
})}
Expand Down