-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lanes: Lane Compare + SnapsDistance GQL API (#7011)
- Loading branch information
Showing
13 changed files
with
262 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 52 additions & 7 deletions
59
scopes/lanes/ui/compare/lane-compare-page/lane-compare-page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,71 @@ | ||
import React, { HTMLAttributes } from 'react'; | ||
import React, { HTMLAttributes, useState, useEffect, useMemo } from 'react'; | ||
import { LaneCompareProps } from '@teambit/lanes'; | ||
import { useLanes } from '@teambit/lanes.hooks.use-lanes'; | ||
import { LaneSelector } from '@teambit/lanes.ui.inputs.lane-selector'; | ||
import { LaneModel } from '@teambit/lanes.ui.models.lanes-model'; | ||
import { LaneId } from '@teambit/lane-id'; | ||
import { LaneIcon } from '@teambit/lanes.ui.icons.lane-icon'; | ||
|
||
import styles from './lane-compare-page.module.scss'; | ||
|
||
export type LaneComparePageProps = { | ||
getLaneCompare: (props: LaneCompareProps) => React.ReactNode; | ||
groupByScope?: boolean; | ||
} & HTMLAttributes<HTMLDivElement>; | ||
|
||
export function LaneComparePage({ getLaneCompare, ...rest }: LaneComparePageProps) { | ||
export function LaneComparePage({ getLaneCompare, groupByScope, ...rest }: LaneComparePageProps) { | ||
const { lanesModel } = useLanes(); | ||
const [base, setBase] = useState<LaneModel | undefined>(); | ||
const defaultLane = lanesModel?.getDefaultLane(); | ||
const compare = lanesModel?.viewedLane; | ||
const nonMainLanes = lanesModel?.getNonMainLanes(); | ||
useEffect(() => { | ||
if (!base && !compare?.id.isDefault() && defaultLane) { | ||
setBase(defaultLane); | ||
} | ||
if (!base && compare?.id.isDefault() && (nonMainLanes?.length ?? 0) > 0) { | ||
setBase(nonMainLanes?.[0]); | ||
} | ||
}, [defaultLane, compare?.id.toString(), nonMainLanes?.length]); | ||
|
||
if (!lanesModel) return null; | ||
const LaneCompareComponent = useMemo(() => { | ||
return getLaneCompare({ base, compare }); | ||
}, [base?.id.toString(), compare?.id.toString()]); | ||
|
||
const compare = lanesModel.getDefaultLane(); | ||
const base = lanesModel.getNonMainLanes()[0]; | ||
const lanes: Array<LaneId> = useMemo(() => { | ||
const mainLaneId = defaultLane?.id; | ||
const nonMainLaneIds = nonMainLanes?.map((lane) => lane.id) || []; | ||
const allLanes = (mainLaneId && [mainLaneId, ...nonMainLaneIds]) || nonMainLaneIds; | ||
return allLanes.filter((l) => l.toString() !== compare?.id.toString()); | ||
}, [base?.id.toString(), compare?.id.toString(), lanesModel?.lanes.length]); | ||
|
||
const LaneCompareComponent = getLaneCompare({ base, compare }); | ||
if (!lanesModel) return null; | ||
if (!lanesModel.viewedLane) return null; | ||
if (!base) return null; | ||
|
||
return ( | ||
<div {...rest} className={styles.laneComparePage}> | ||
{LaneCompareComponent} | ||
<div className={styles.top}> | ||
<div>Compare</div> | ||
<div className={styles.compareLane}> | ||
<LaneIcon className={styles.laneIcon} /> | ||
{compare?.id.name} | ||
</div> | ||
<div>with</div> | ||
<div className={styles.baseSelectorContainer}> | ||
<LaneSelector | ||
selectedLaneId={base.id} | ||
className={styles.baseSelector} | ||
lanes={lanes} | ||
groupByScope={groupByScope} | ||
getHref={() => ''} | ||
onLaneSelected={(laneId) => { | ||
setBase(lanesModel?.lanes.find((l) => l.id.toString() === laneId.toString())); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
<div className={styles.bottom}>{LaneCompareComponent}</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.