| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {ReactNode} from 'react'; |
| b69ab31 | | | 9 | import type {Dag, DagCommitInfo} from './dag/dag'; |
| b69ab31 | | | 10 | import type {ExtendedGraphRow} from './dag/render'; |
| b69ab31 | | | 11 | import type {HashSet} from './dag/set'; |
| b69ab31 | | | 12 | |
| b69ab31 | | | 13 | import React from 'react'; |
| b69ab31 | | | 14 | import {AnimatedReorderGroup} from './AnimatedReorderGroup'; |
| b69ab31 | | | 15 | import {AvatarPattern} from './Avatar'; |
| b69ab31 | | | 16 | import {YouAreHereLabel} from './YouAreHereLabel'; |
| b69ab31 | | | 17 | import {LinkLine, NodeLine, PadLine} from './dag/render'; |
| b69ab31 | | | 18 | |
| b69ab31 | | | 19 | import './RenderDag.css'; |
| b69ab31 | | | 20 | |
| b69ab31 | | | 21 | /* eslint no-bitwise: 0 */ |
| b69ab31 | | | 22 | |
| b69ab31 | | | 23 | export type RenderDagProps = { |
| b69ab31 | | | 24 | /** The dag to use */ |
| b69ab31 | | | 25 | dag: Dag; |
| b69ab31 | | | 26 | |
| b69ab31 | | | 27 | /** If set, render a subset. Otherwise, all commits are rendered. */ |
| b69ab31 | | | 28 | subset?: HashSet; |
| b69ab31 | | | 29 | |
| b69ab31 | | | 30 | /** Should "anonymous" parents (rendered as "~" in CLI) be ignored? */ |
| b69ab31 | | | 31 | ignoreAnonymousParents?: boolean; |
| b69ab31 | | | 32 | } & React.HTMLAttributes<HTMLDivElement> & |
| b69ab31 | | | 33 | RenderFunctionProps; |
| b69ab31 | | | 34 | |
| b69ab31 | | | 35 | type RenderFunctionProps = { |
| b69ab31 | | | 36 | /** |
| b69ab31 | | | 37 | * How to render a commit. |
| b69ab31 | | | 38 | * |
| b69ab31 | | | 39 | * To avoid re-rendering, pass a "static" (ex. not a closure) function, |
| b69ab31 | | | 40 | * then use hooks (ex. recoil selector) to trigger re-rendering inside |
| b69ab31 | | | 41 | * the static function. |
| b69ab31 | | | 42 | */ |
| b69ab31 | | | 43 | renderCommit?: (info: DagCommitInfo) => JSX.Element; |
| b69ab31 | | | 44 | |
| b69ab31 | | | 45 | /** |
| b69ab31 | | | 46 | * How to render extra stuff below a commit. Default: nothing. |
| b69ab31 | | | 47 | * |
| b69ab31 | | | 48 | * To avoid re-rendering, pass a "static" (ex. not a closure) function, |
| b69ab31 | | | 49 | * then use hooks (ex. recoil selector) to trigger re-rendering inside |
| b69ab31 | | | 50 | * the static function. |
| b69ab31 | | | 51 | */ |
| b69ab31 | | | 52 | renderCommitExtras?: (info: DagCommitInfo, row: ExtendedGraphRow) => null | JSX.Element; |
| b69ab31 | | | 53 | |
| b69ab31 | | | 54 | /** |
| b69ab31 | | | 55 | * How to render a "glyph" (ex. "o", "x", "@"). |
| b69ab31 | | | 56 | * This should return an SVG element. |
| b69ab31 | | | 57 | * The SVG viewbox is (-10,-10) to (10,10) (20px * 20px). |
| b69ab31 | | | 58 | * Default: defaultRenderGlyphSvg, draw a circle. |
| b69ab31 | | | 59 | * |
| b69ab31 | | | 60 | * To avoid re-rendering, pass a "static" (ex. not a closure) function, |
| b69ab31 | | | 61 | * then use hooks (ex. recoil selector) to trigger re-rendering inside |
| b69ab31 | | | 62 | * the static function. |
| b69ab31 | | | 63 | */ |
| b69ab31 | | | 64 | renderGlyph?: (info: DagCommitInfo) => RenderGlyphResult; |
| b69ab31 | | | 65 | |
| b69ab31 | | | 66 | /** |
| b69ab31 | | | 67 | * Get extra props for the DivRow for the given commit. |
| b69ab31 | | | 68 | * This can be used to tweak styles like selection background, border. |
| b69ab31 | | | 69 | * This should be a static-ish function to avoid re-rendering. Inside the function, |
| b69ab31 | | | 70 | * it can use hooks to fetch extra state. |
| b69ab31 | | | 71 | */ |
| b69ab31 | | | 72 | useExtraCommitRowProps?: (info: DagCommitInfo) => React.HTMLAttributes<HTMLDivElement> | void; |
| b69ab31 | | | 73 | }; |
| b69ab31 | | | 74 | |
| b69ab31 | | | 75 | /** |
| b69ab31 | | | 76 | * - 'inside-tile': Inside a <Tile />. Must be a svg element. Size decided by <Tile />. |
| b69ab31 | | | 77 | * - 'replace-tile': Replace the <Tile /> with the rendered result. Size decided by the |
| b69ab31 | | | 78 | * rendered result. Can be other elements not just svg. Useful for "You are here". |
| b69ab31 | | | 79 | */ |
| b69ab31 | | | 80 | export type RenderGlyphResult = ['inside-tile', JSX.Element] | ['replace-tile', JSX.Element]; |
| b69ab31 | | | 81 | |
| b69ab31 | | | 82 | /** |
| b69ab31 | | | 83 | * Renders a dag. Calculate and render the edges, aka. the left side: |
| b69ab31 | | | 84 | * |
| b69ab31 | | | 85 | * o +--------+ |
| b69ab31 | | | 86 | * | | commit | |
| b69ab31 | | | 87 | * | +--------+ |
| b69ab31 | | | 88 | * | |
| b69ab31 | | | 89 | * | o +--------+ |
| b69ab31 | | | 90 | * |/ | commit | |
| b69ab31 | | | 91 | * o +--------+ |
| b69ab31 | | | 92 | * :\ |
| b69ab31 | | | 93 | * : o +--------+ |
| b69ab31 | | | 94 | * : | commit | |
| b69ab31 | | | 95 | * : +--------+ |
| b69ab31 | | | 96 | * : |
| b69ab31 | | | 97 | * o +--------+ |
| b69ab31 | | | 98 | * | commit | |
| b69ab31 | | | 99 | * +--------+ |
| b69ab31 | | | 100 | * |
| b69ab31 | | | 101 | * The callsite can customize: |
| b69ab31 | | | 102 | * - What "dag" and what subset of commits to render. |
| b69ab31 | | | 103 | * - How to render each "commit" (the boxes above). |
| b69ab31 | | | 104 | * - How to render the glyph (the "o"). |
| b69ab31 | | | 105 | * |
| b69ab31 | | | 106 | * For a commit with `info.isYouAreHere` set, the "commit" body |
| b69ab31 | | | 107 | * will be positioned at the right of the "pad" line, not the |
| b69ab31 | | | 108 | * "node" line, and the default "o" rendering logic will render |
| b69ab31 | | | 109 | * a blue badge instead. |
| b69ab31 | | | 110 | * |
| b69ab31 | | | 111 | * See `DagListProps` for customization options. |
| b69ab31 | | | 112 | * |
| b69ab31 | | | 113 | * This component is intended to be used in multiple places, |
| b69ab31 | | | 114 | * ex. the main dag, "mutation dag", context-menu sub-dag, etc. |
| b69ab31 | | | 115 | * So it should avoid depending on Recoil states. |
| b69ab31 | | | 116 | */ |
| b69ab31 | | | 117 | export function RenderDag(props: RenderDagProps) { |
| b69ab31 | | | 118 | const { |
| b69ab31 | | | 119 | dag, |
| b69ab31 | | | 120 | subset, |
| b69ab31 | | | 121 | renderCommit, |
| b69ab31 | | | 122 | renderCommitExtras, |
| b69ab31 | | | 123 | renderGlyph = defaultRenderGlyph, |
| b69ab31 | | | 124 | useExtraCommitRowProps, |
| b69ab31 | | | 125 | className, |
| b69ab31 | | | 126 | ...restProps |
| b69ab31 | | | 127 | } = props; |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | const rows = dag.renderToRows(subset); |
| b69ab31 | | | 130 | const authors = new Set<string>( |
| b69ab31 | | | 131 | rows.flatMap(([info]) => (info.phase === 'draft' && info.author.length > 0 ? info.author : [])), |
| b69ab31 | | | 132 | ); |
| b69ab31 | | | 133 | |
| b69ab31 | | | 134 | const renderedRows: Array<JSX.Element> = rows.map(([info, row]) => { |
| b69ab31 | | | 135 | return ( |
| b69ab31 | | | 136 | <DagRow |
| b69ab31 | | | 137 | key={info.hash} |
| b69ab31 | | | 138 | row={row} |
| b69ab31 | | | 139 | info={info} |
| b69ab31 | | | 140 | renderCommit={renderCommit} |
| b69ab31 | | | 141 | renderCommitExtras={renderCommitExtras} |
| b69ab31 | | | 142 | renderGlyph={renderGlyph} |
| b69ab31 | | | 143 | useExtraCommitRowProps={useExtraCommitRowProps} |
| b69ab31 | | | 144 | /> |
| b69ab31 | | | 145 | ); |
| b69ab31 | | | 146 | }); |
| b69ab31 | | | 147 | |
| b69ab31 | | | 148 | const fullClassName = ((className ?? '') + ' render-dag').trimStart(); |
| b69ab31 | | | 149 | return ( |
| b69ab31 | | | 150 | <div className={fullClassName} {...restProps}> |
| b69ab31 | | | 151 | <SvgPatternList authors={authors} /> |
| b69ab31 | | | 152 | <AnimatedReorderGroup animationDuration={100}>{renderedRows}</AnimatedReorderGroup> |
| b69ab31 | | | 153 | </div> |
| b69ab31 | | | 154 | ); |
| b69ab31 | | | 155 | } |
| b69ab31 | | | 156 | |
| b69ab31 | | | 157 | function DivRow( |
| b69ab31 | | | 158 | props: { |
| b69ab31 | | | 159 | left?: JSX.Element | null; |
| b69ab31 | | | 160 | right?: JSX.Element | null; |
| b69ab31 | | | 161 | } & React.HTMLAttributes<HTMLDivElement> & {['data-commit-hash']?: string}, |
| b69ab31 | | | 162 | ) { |
| b69ab31 | | | 163 | const {className, left, right, ...restProps} = props ?? {}; |
| b69ab31 | | | 164 | const fullClassName = `render-dag-row ${className ?? ''}`; |
| b69ab31 | | | 165 | return ( |
| b69ab31 | | | 166 | <div {...restProps} className={fullClassName}> |
| b69ab31 | | | 167 | <div className="render-dag-row-left-side">{left}</div> |
| b69ab31 | | | 168 | <div className="render-dag-row-right-side">{right}</div> |
| b69ab31 | | | 169 | </div> |
| b69ab31 | | | 170 | ); |
| b69ab31 | | | 171 | } |
| b69ab31 | | | 172 | |
| b69ab31 | | | 173 | function DagRowInner(props: {row: ExtendedGraphRow; info: DagCommitInfo} & RenderFunctionProps) { |
| b69ab31 | | | 174 | const { |
| b69ab31 | | | 175 | row, |
| b69ab31 | | | 176 | info, |
| b69ab31 | | | 177 | renderGlyph = defaultRenderGlyph, |
| b69ab31 | | | 178 | renderCommit, |
| b69ab31 | | | 179 | renderCommitExtras, |
| b69ab31 | | | 180 | useExtraCommitRowProps, |
| b69ab31 | | | 181 | } = props; |
| b69ab31 | | | 182 | |
| b69ab31 | | | 183 | const {className = '', ...commitRowProps} = useExtraCommitRowProps?.(info) ?? {}; |
| b69ab31 | | | 184 | |
| b69ab31 | | | 185 | // Layout per commit: |
| b69ab31 | | | 186 | // |
| b69ab31 | | | 187 | // Each (regular) commit is rendered in 2 rows: |
| b69ab31 | | | 188 | // |
| b69ab31 | | | 189 | // ┌──Row1──────────────────────────────┐ |
| b69ab31 | | | 190 | // │┌─Left──────────┐┌Right────────────┐│ |
| b69ab31 | | | 191 | // ││┌PreNode*─────┐││ ││ |
| b69ab31 | | | 192 | // │││ | | │││ (commit body) ││ |
| b69ab31 | | | 193 | // ││├Node─────────┤││ ││ |
| b69ab31 | | | 194 | // │││ o | │││ ││ |
| b69ab31 | | | 195 | // ││├PostNode*────┤││ ││ |
| b69ab31 | | | 196 | // │││ | | │││ ││ |
| b69ab31 | | | 197 | // ││└─────────────┘││ ││ |
| b69ab31 | | | 198 | // │└───────────────┘└─────────────────┘│ |
| b69ab31 | | | 199 | // └────────────────────────────────────┘ |
| b69ab31 | | | 200 | // |
| b69ab31 | | | 201 | // ┌──Row2──────────────────────────────┐ |
| b69ab31 | | | 202 | // │┌─Left──────────┐┌Right────────────┐│ |
| b69ab31 | | | 203 | // ││┌PostNode*────┐││ ││ |
| b69ab31 | | | 204 | // │││ | | │││ ││ |
| b69ab31 | | | 205 | // ││├Term─────────┤││ ││ |
| b69ab31 | | | 206 | // │││ | | │││ (extras) ││ |
| b69ab31 | | | 207 | // │││ | ~ │││ ││ |
| b69ab31 | | | 208 | // ││├Padding──────┤││ ││ |
| b69ab31 | | | 209 | // │││ | │││ ││ |
| b69ab31 | | | 210 | // ││├Link─────────┤││ ││ |
| b69ab31 | | | 211 | // │││ |\ │││ ││ |
| b69ab31 | | | 212 | // │││ | | │││ ││ |
| b69ab31 | | | 213 | // ││├Ancestry─────┤││ ││ |
| b69ab31 | | | 214 | // │││ : | │││ ││ |
| b69ab31 | | | 215 | // │└───────────────┘└─────────────────┘│ |
| b69ab31 | | | 216 | // └────────────────────────────────────┘ |
| b69ab31 | | | 217 | // |
| b69ab31 | | | 218 | // Note: |
| b69ab31 | | | 219 | // - Row1 is used to highlight selection. The "node" line should be |
| b69ab31 | | | 220 | // at the center once selected. |
| b69ab31 | | | 221 | // - The "*" lines (PreNode, PostNode, PostAncestry) have a stretch |
| b69ab31 | | | 222 | // height based on the right-side content. |
| b69ab31 | | | 223 | // - Row2 can be hidden if there is no link line, no ":" ancestry, |
| b69ab31 | | | 224 | // and no "extras". |
| b69ab31 | | | 225 | // |
| b69ab31 | | | 226 | // Example of "You Are here" special case. "Row1" is split to two |
| b69ab31 | | | 227 | // rows: "Row0" and "Row1": |
| b69ab31 | | | 228 | // |
| b69ab31 | | | 229 | // ┌──Row0──────────────────────────────┐ |
| b69ab31 | | | 230 | // │┌─Left─────────────┐ │ |
| b69ab31 | | | 231 | // ││┌Node────────────┐│ │ |
| b69ab31 | | | 232 | // │││ | (YouAreHere) ││ │ |
| b69ab31 | | | 233 | // ││└────────────────┘│ │ |
| b69ab31 | | | 234 | // │└──────────────────┘ │ |
| b69ab31 | | | 235 | // └────────────────────────────────────┘ |
| b69ab31 | | | 236 | // ┌──Row1──────────────────────────────┐ |
| b69ab31 | | | 237 | // │┌─Left──────────┐┌Right────────────┐│ |
| b69ab31 | | | 238 | // ││┌PostNode*────┐││ ││ |
| b69ab31 | | | 239 | // │││ | | │││ (commit body) ││ |
| b69ab31 | | | 240 | // ││└─────────────┘││ ││ |
| b69ab31 | | | 241 | // │└───────────────┘└─────────────────┘│ |
| b69ab31 | | | 242 | // └────────────────────────────────────┘ |
| b69ab31 | | | 243 | // |
| b69ab31 | | | 244 | // Note: |
| b69ab31 | | | 245 | // - Row0's "left" side can have a larger width, to fit the |
| b69ab31 | | | 246 | // "irregular" "(YouAreHere)" element. |
| b69ab31 | | | 247 | // - Row2 is the same in this special case. |
| b69ab31 | | | 248 | // |
| b69ab31 | | | 249 | // Also check fbcode/eden/website/src/components/RenderDag.js |
| b69ab31 | | | 250 | const {linkLine, termLine, nodeLine, ancestryLine, isHead, isRoot, hasIndirectAncestor} = row; |
| b69ab31 | | | 251 | |
| b69ab31 | | | 252 | // By default, the glyph "o" is rendered in a fixed size "Tile". |
| b69ab31 | | | 253 | // With 'replace-tile' the glyph can define its own rendered element |
| b69ab31 | | | 254 | // (of dynamic size). |
| b69ab31 | | | 255 | // |
| b69ab31 | | | 256 | // 'replace-tile' also moves the "commit" element to the right of |
| b69ab31 | | | 257 | // pad line, not node line. |
| b69ab31 | | | 258 | const [glyphPosition, glyph] = renderGlyph(info); |
| b69ab31 | | | 259 | const isIrregular = glyphPosition === 'replace-tile'; |
| b69ab31 | | | 260 | // isYouAreHere practically matches isIrregular but we treat them as |
| b69ab31 | | | 261 | // separate concepts. isYouAreHere affects colors, and isIrregular |
| b69ab31 | | | 262 | // affects layout. |
| b69ab31 | | | 263 | const color = info.isYouAreHere ? YOU_ARE_HERE_COLOR : undefined; |
| b69ab31 | | | 264 | const nodeLinePart = ( |
| b69ab31 | | | 265 | <div className="render-dag-row-left-side-line node-line"> |
| b69ab31 | | | 266 | {nodeLine.map((l, i) => { |
| b69ab31 | | | 267 | if (isIrregular && l === NodeLine.Node) { |
| b69ab31 | | | 268 | return <React.Fragment key={i}>{glyph}</React.Fragment>; |
| b69ab31 | | | 269 | } |
| b69ab31 | | | 270 | // Need stretchY if "glyph" is not "Tile" and has a dynamic height. |
| b69ab31 | | | 271 | return ( |
| b69ab31 | | | 272 | <NodeTile |
| b69ab31 | | | 273 | key={i} |
| b69ab31 | | | 274 | line={l} |
| b69ab31 | | | 275 | isHead={isHead} |
| b69ab31 | | | 276 | isRoot={isRoot} |
| b69ab31 | | | 277 | aboveNodeColor={info.isDot ? YOU_ARE_HERE_COLOR : undefined} |
| b69ab31 | | | 278 | stretchY={isIrregular && l != NodeLine.Node} |
| b69ab31 | | | 279 | scaleY={isIrregular ? 0.5 : 1} |
| b69ab31 | | | 280 | glyph={glyph} |
| b69ab31 | | | 281 | /> |
| b69ab31 | | | 282 | ); |
| b69ab31 | | | 283 | })} |
| b69ab31 | | | 284 | </div> |
| b69ab31 | | | 285 | ); |
| b69ab31 | | | 286 | |
| b69ab31 | | | 287 | const preNodeLinePart = ( |
| b69ab31 | | | 288 | <div |
| b69ab31 | | | 289 | className="render-dag-row-left-side-line pre-node-line grow" |
| b69ab31 | | | 290 | data-nodecolumn={row.nodeColumn}> |
| b69ab31 | | | 291 | {row.preNodeLine.map((l, i) => { |
| b69ab31 | | | 292 | const c = i === row.nodeColumn ? (info.isDot ? YOU_ARE_HERE_COLOR : color) : undefined; |
| b69ab31 | | | 293 | return <PadTile key={i} line={l} scaleY={0.1} stretchY={true} color={c} />; |
| b69ab31 | | | 294 | })} |
| b69ab31 | | | 295 | </div> |
| b69ab31 | | | 296 | ); |
| b69ab31 | | | 297 | |
| b69ab31 | | | 298 | const postNodeLinePart = ( |
| b69ab31 | | | 299 | <div className="render-dag-row-left-side-line post-node-line grow"> |
| b69ab31 | | | 300 | {row.postNodeLine.map((l, i) => { |
| b69ab31 | | | 301 | const c = i === row.nodeColumn ? color : undefined; |
| b69ab31 | | | 302 | return <PadTile key={i} line={l} scaleY={0.1} stretchY={true} color={c} />; |
| b69ab31 | | | 303 | })} |
| b69ab31 | | | 304 | </div> |
| b69ab31 | | | 305 | ); |
| b69ab31 | | | 306 | |
| b69ab31 | | | 307 | const linkLinePart = linkLine && ( |
| b69ab31 | | | 308 | <div className="render-dag-row-left-side-line link-line"> |
| b69ab31 | | | 309 | {linkLine.map((l, i) => ( |
| b69ab31 | | | 310 | <LinkTile key={i} line={l} color={color} colorLine={row.linkLineFromNode?.[i]} /> |
| b69ab31 | | | 311 | ))} |
| b69ab31 | | | 312 | </div> |
| b69ab31 | | | 313 | ); |
| b69ab31 | | | 314 | |
| b69ab31 | | | 315 | const stackPaddingPart = linkLine && linkLine.length <= 2 && ( |
| b69ab31 | | | 316 | <div className="render-dag-row-left-side-line stack-padding"> |
| b69ab31 | | | 317 | {linkLine |
| b69ab31 | | | 318 | // one less than the extra indent added by the link line normally |
| b69ab31 | | | 319 | .slice(0, -1) |
| b69ab31 | | | 320 | .map((l, i) => ( |
| b69ab31 | | | 321 | <PadTile key={i} scaleY={0.3} color={color} line={PadLine.Parent} /> |
| b69ab31 | | | 322 | ))} |
| b69ab31 | | | 323 | </div> |
| b69ab31 | | | 324 | ); |
| b69ab31 | | | 325 | |
| b69ab31 | | | 326 | const termLinePart = termLine && ( |
| b69ab31 | | | 327 | <> |
| b69ab31 | | | 328 | <div className="render-dag-row-left-side-line term-line-pad"> |
| b69ab31 | | | 329 | {termLine.map((isTerm, i) => { |
| b69ab31 | | | 330 | const line = isTerm ? PadLine.Ancestor : (ancestryLine.at(i) ?? PadLine.Blank); |
| b69ab31 | | | 331 | return <PadTile key={i} scaleY={0.25} line={line} />; |
| b69ab31 | | | 332 | })} |
| b69ab31 | | | 333 | </div> |
| b69ab31 | | | 334 | <div className="render-dag-row-left-side-line term-line-term"> |
| b69ab31 | | | 335 | {termLine.map((isTerm, i) => { |
| b69ab31 | | | 336 | const line = ancestryLine.at(i) ?? PadLine.Blank; |
| b69ab31 | | | 337 | return isTerm ? <TermTile key={i} /> : <PadTile key={i} line={line} />; |
| b69ab31 | | | 338 | })} |
| b69ab31 | | | 339 | </div> |
| b69ab31 | | | 340 | </> |
| b69ab31 | | | 341 | ); |
| b69ab31 | | | 342 | |
| b69ab31 | | | 343 | const commitPart = renderCommit?.(info); |
| b69ab31 | | | 344 | const commitExtrasPart = renderCommitExtras?.(info, row); |
| b69ab31 | | | 345 | |
| b69ab31 | | | 346 | const ancestryLinePart = hasIndirectAncestor ? ( |
| b69ab31 | | | 347 | <div className="render-dag-row-left-side-line ancestry-line"> |
| b69ab31 | | | 348 | {ancestryLine.map((l, i) => ( |
| b69ab31 | | | 349 | <PadTile |
| b69ab31 | | | 350 | key={i} |
| b69ab31 | | | 351 | scaleY={0.6} |
| b69ab31 | | | 352 | strokeDashArray="0,2,3,0" |
| b69ab31 | | | 353 | line={l} |
| b69ab31 | | | 354 | color={row.parentColumns.includes(i) ? color : undefined} |
| b69ab31 | | | 355 | /> |
| b69ab31 | | | 356 | ))} |
| b69ab31 | | | 357 | </div> |
| b69ab31 | | | 358 | ) : null; |
| b69ab31 | | | 359 | |
| b69ab31 | | | 360 | // Put parts together. |
| b69ab31 | | | 361 | |
| b69ab31 | | | 362 | let row0: JSX.Element | null = null; |
| b69ab31 | | | 363 | let row1: JSX.Element | null = null; |
| b69ab31 | | | 364 | let row2: JSX.Element | null = null; |
| b69ab31 | | | 365 | if (isIrregular) { |
| b69ab31 | | | 366 | row0 = <DivRow className={className} {...commitRowProps} left={nodeLinePart} />; |
| b69ab31 | | | 367 | row1 = <DivRow left={postNodeLinePart} right={commitPart} />; |
| b69ab31 | | | 368 | } else { |
| b69ab31 | | | 369 | const left = ( |
| b69ab31 | | | 370 | <> |
| b69ab31 | | | 371 | {preNodeLinePart} |
| b69ab31 | | | 372 | {nodeLinePart} |
| b69ab31 | | | 373 | {postNodeLinePart} |
| b69ab31 | | | 374 | </> |
| b69ab31 | | | 375 | ); |
| b69ab31 | | | 376 | row1 = ( |
| b69ab31 | | | 377 | <DivRow |
| b69ab31 | | | 378 | className={`render-dag-row-commit ${className ?? ''}`} |
| b69ab31 | | | 379 | {...commitRowProps} |
| b69ab31 | | | 380 | left={left} |
| b69ab31 | | | 381 | right={commitPart} |
| b69ab31 | | | 382 | data-commit-hash={info.hash} |
| b69ab31 | | | 383 | /> |
| b69ab31 | | | 384 | ); |
| b69ab31 | | | 385 | } |
| b69ab31 | | | 386 | |
| b69ab31 | | | 387 | if ( |
| b69ab31 | | | 388 | linkLinePart != null || |
| b69ab31 | | | 389 | termLinePart != null || |
| b69ab31 | | | 390 | ancestryLinePart != null || |
| b69ab31 | | | 391 | postNodeLinePart != null || |
| b69ab31 | | | 392 | commitExtrasPart != null |
| b69ab31 | | | 393 | ) { |
| b69ab31 | | | 394 | const left = ( |
| b69ab31 | | | 395 | <> |
| b69ab31 | | | 396 | {commitExtrasPart && postNodeLinePart} |
| b69ab31 | | | 397 | {linkLinePart} |
| b69ab31 | | | 398 | {termLinePart} |
| b69ab31 | | | 399 | {stackPaddingPart} |
| b69ab31 | | | 400 | {ancestryLinePart} |
| b69ab31 | | | 401 | </> |
| b69ab31 | | | 402 | ); |
| b69ab31 | | | 403 | row2 = <DivRow left={left} right={commitExtrasPart} />; |
| b69ab31 | | | 404 | } |
| b69ab31 | | | 405 | |
| b69ab31 | | | 406 | return ( |
| b69ab31 | | | 407 | <div |
| b69ab31 | | | 408 | className="render-dag-row-group" |
| b69ab31 | | | 409 | data-reorder-id={info.hash} |
| b69ab31 | | | 410 | data-testid={`dag-row-group-${info.hash}`}> |
| b69ab31 | | | 411 | {row0} |
| b69ab31 | | | 412 | {row1} |
| b69ab31 | | | 413 | {row2} |
| b69ab31 | | | 414 | </div> |
| b69ab31 | | | 415 | ); |
| b69ab31 | | | 416 | } |
| b69ab31 | | | 417 | |
| b69ab31 | | | 418 | const DagRow = React.memo(DagRowInner, (prevProps, nextProps) => { |
| b69ab31 | | | 419 | return ( |
| b69ab31 | | | 420 | nextProps.info.equals(prevProps.info) && |
| b69ab31 | | | 421 | prevProps.row.valueOf() === nextProps.row.valueOf() && |
| b69ab31 | | | 422 | prevProps.renderCommit === nextProps.renderCommit && |
| b69ab31 | | | 423 | prevProps.renderCommitExtras === nextProps.renderCommitExtras && |
| b69ab31 | | | 424 | prevProps.renderGlyph === nextProps.renderGlyph && |
| b69ab31 | | | 425 | prevProps.useExtraCommitRowProps == nextProps.useExtraCommitRowProps |
| b69ab31 | | | 426 | ); |
| b69ab31 | | | 427 | }); |
| b69ab31 | | | 428 | |
| b69ab31 | | | 429 | export type TileProps = { |
| b69ab31 | | | 430 | /** Width. Default: defaultTileWidth. */ |
| b69ab31 | | | 431 | width?: number; |
| b69ab31 | | | 432 | /** Y scale. Default: 1. Decides height. */ |
| b69ab31 | | | 433 | scaleY?: number; |
| b69ab31 | | | 434 | /** |
| b69ab31 | | | 435 | * If true, set: |
| b69ab31 | | | 436 | * - CSS: height: 100% - take up the height of the (flexbox) parent. |
| b69ab31 | | | 437 | * - CSS: min-height: width * scaleY, i.e. scaleY affects min-height. |
| b69ab31 | | | 438 | * - SVG: preserveAspectRatio: 'none'. |
| b69ab31 | | | 439 | * Intended to be only used by PadLine. |
| b69ab31 | | | 440 | */ |
| b69ab31 | | | 441 | stretchY?: boolean; |
| b69ab31 | | | 442 | edges?: Edge[]; |
| b69ab31 | | | 443 | /** SVG children. */ |
| b69ab31 | | | 444 | children?: React.ReactNode; |
| b69ab31 | | | 445 | /** Line width. Default: strokeWidth. */ |
| b69ab31 | | | 446 | strokeWidth?: number; |
| b69ab31 | | | 447 | /** Dash array. Default: '3,2'. */ |
| b69ab31 | | | 448 | strokeDashArray?: string; |
| b69ab31 | | | 449 | }; |
| b69ab31 | | | 450 | |
| b69ab31 | | | 451 | /** |
| b69ab31 | | | 452 | * Represent a line within a box (-1,-1) to (1,1). |
| b69ab31 | | | 453 | * For example, x1=0, y1=-1, x2=0, y2=1 draws a vertical line in the middle. |
| b69ab31 | | | 454 | * Default x y values are 0. |
| b69ab31 | | | 455 | * Flag can be used to draw special lines. |
| b69ab31 | | | 456 | */ |
| b69ab31 | | | 457 | export type Edge = { |
| b69ab31 | | | 458 | x1?: number; |
| b69ab31 | | | 459 | y1?: number; |
| b69ab31 | | | 460 | x2?: number; |
| b69ab31 | | | 461 | y2?: number; |
| b69ab31 | | | 462 | flag?: number; |
| b69ab31 | | | 463 | color?: string; |
| b69ab31 | | | 464 | }; |
| b69ab31 | | | 465 | |
| b69ab31 | | | 466 | export enum EdgeFlag { |
| b69ab31 | | | 467 | Dash = 1, |
| b69ab31 | | | 468 | IntersectGap = 2, |
| b69ab31 | | | 469 | } |
| b69ab31 | | | 470 | |
| b69ab31 | | | 471 | const defaultTileWidth = 20; |
| b69ab31 | | | 472 | const defaultStrokeWidth = 2; |
| b69ab31 | | | 473 | |
| b69ab31 | | | 474 | /** |
| b69ab31 | | | 475 | * A tile is a rectangle with edges in it. |
| b69ab31 | | | 476 | * Children are in SVG. |
| b69ab31 | | | 477 | */ |
| b69ab31 | | | 478 | // eslint-disable-next-line prefer-arrow-callback |
| b69ab31 | | | 479 | function TileInner(props: TileProps) { |
| b69ab31 | | | 480 | const { |
| b69ab31 | | | 481 | scaleY = 1, |
| b69ab31 | | | 482 | width = defaultTileWidth, |
| b69ab31 | | | 483 | edges = [], |
| b69ab31 | | | 484 | strokeWidth = defaultStrokeWidth, |
| b69ab31 | | | 485 | strokeDashArray = '3,2', |
| b69ab31 | | | 486 | stretchY = false, |
| b69ab31 | | | 487 | } = props; |
| b69ab31 | | | 488 | const preserveAspectRatio = stretchY || scaleY < 1 ? 'none' : undefined; |
| b69ab31 | | | 489 | const height = width * scaleY; |
| b69ab31 | | | 490 | const style = stretchY ? {height: '100%', minHeight: height} : {}; |
| b69ab31 | | | 491 | // Fill the small caused by scaling, non-integer rounding. |
| b69ab31 | | | 492 | // When 'x' is at the border (abs >= 10) and 'y' is at the center, use the "gap fix". |
| b69ab31 | | | 493 | const getGapFix = (x: number, y: number) => |
| b69ab31 | | | 494 | y === 0 && Math.abs(x) >= 10 ? 0.5 * Math.sign(x) : 0; |
| b69ab31 | | | 495 | const paths = edges.map(({x1 = 0, y1 = 0, x2 = 0, y2 = 0, flag = 0, color}, i): JSX.Element => { |
| b69ab31 | | | 496 | // see getGapFix above. |
| b69ab31 | | | 497 | const fx1 = getGapFix(x1, y1); |
| b69ab31 | | | 498 | const fx2 = getGapFix(x2, y2); |
| b69ab31 | | | 499 | const fy1 = getGapFix(y1, x1); |
| b69ab31 | | | 500 | const fy2 = getGapFix(y2, x2); |
| b69ab31 | | | 501 | |
| b69ab31 | | | 502 | const sY = scaleY; |
| b69ab31 | | | 503 | const dashArray = flag & EdgeFlag.Dash ? strokeDashArray : undefined; |
| b69ab31 | | | 504 | let d; |
| b69ab31 | | | 505 | if (flag & EdgeFlag.IntersectGap) { |
| b69ab31 | | | 506 | // This vertical line intercects with a horizontal line visually but it does not mean |
| b69ab31 | | | 507 | // they connect. Leave a small gap in the middle. |
| b69ab31 | | | 508 | d = `M ${x1 + fx1} ${y1 * sY + fy1} L 0 -2 M 0 2 L ${x2 + fx2} ${y2 * sY + fy2}`; |
| b69ab31 | | | 509 | } else if (y1 === y2 || x1 === x2) { |
| b69ab31 | | | 510 | // Straight line (-----). |
| b69ab31 | | | 511 | d = `M ${x1 + fx1} ${y1 * sY + fy1} L ${x2 + fx2} ${y2 * sY + fy2}`; |
| b69ab31 | | | 512 | } else { |
| b69ab31 | | | 513 | // Curved line (towards center). |
| b69ab31 | | | 514 | d = `M ${x1 + fx1} ${y1 * sY + fy1} L ${x1} ${y1 * sY} Q 0 0 ${x2} ${y2 * sY} L ${x2 + fx2} ${ |
| b69ab31 | | | 515 | y2 * sY + fy2 |
| b69ab31 | | | 516 | }`; |
| b69ab31 | | | 517 | } |
| b69ab31 | | | 518 | return <path d={d} key={i} strokeDasharray={dashArray} stroke={color} />; |
| b69ab31 | | | 519 | }); |
| b69ab31 | | | 520 | return ( |
| b69ab31 | | | 521 | <svg |
| b69ab31 | | | 522 | className="render-dag-tile" |
| b69ab31 | | | 523 | viewBox={`-10 -${scaleY * 10} 20 ${scaleY * 20}`} |
| b69ab31 | | | 524 | height={height} |
| b69ab31 | | | 525 | width={width} |
| b69ab31 | | | 526 | style={style} |
| b69ab31 | | | 527 | preserveAspectRatio={preserveAspectRatio}> |
| b69ab31 | | | 528 | <g stroke="var(--foreground)" fill="none" strokeWidth={strokeWidth}> |
| b69ab31 | | | 529 | {paths} |
| b69ab31 | | | 530 | {props.children} |
| b69ab31 | | | 531 | </g> |
| b69ab31 | | | 532 | </svg> |
| b69ab31 | | | 533 | ); |
| b69ab31 | | | 534 | } |
| b69ab31 | | | 535 | const Tile = React.memo(TileInner); |
| b69ab31 | | | 536 | |
| b69ab31 | | | 537 | function NodeTile( |
| b69ab31 | | | 538 | props: { |
| b69ab31 | | | 539 | line: NodeLine; |
| b69ab31 | | | 540 | isHead: boolean; |
| b69ab31 | | | 541 | isRoot: boolean; |
| b69ab31 | | | 542 | glyph: JSX.Element; |
| b69ab31 | | | 543 | /** For NodeLine.Node, the color of the vertical edge above the circle. */ |
| b69ab31 | | | 544 | aboveNodeColor?: string; |
| b69ab31 | | | 545 | } & TileProps, |
| b69ab31 | | | 546 | ) { |
| b69ab31 | | | 547 | const {line, isHead, isRoot, glyph} = props; |
| b69ab31 | | | 548 | switch (line) { |
| b69ab31 | | | 549 | case NodeLine.Ancestor: |
| b69ab31 | | | 550 | return <Tile {...props} edges={[{y1: -10, y2: 10, flag: EdgeFlag.Dash}]} />; |
| b69ab31 | | | 551 | case NodeLine.Parent: |
| b69ab31 | | | 552 | // 10.5 is used instead of 10 to avoid small gaps when the page is zoomed. |
| b69ab31 | | | 553 | return <Tile {...props} edges={[{y1: -10, y2: 10.5}]} />; |
| b69ab31 | | | 554 | case NodeLine.Node: { |
| b69ab31 | | | 555 | const edges: Edge[] = []; |
| b69ab31 | | | 556 | if (!isHead) { |
| b69ab31 | | | 557 | edges.push({y1: -10.5, color: props.aboveNodeColor}); |
| b69ab31 | | | 558 | } |
| b69ab31 | | | 559 | if (!isRoot) { |
| b69ab31 | | | 560 | edges.push({y2: 10.5}); |
| b69ab31 | | | 561 | } |
| b69ab31 | | | 562 | return ( |
| b69ab31 | | | 563 | <Tile {...props} edges={edges}> |
| b69ab31 | | | 564 | {glyph} |
| b69ab31 | | | 565 | </Tile> |
| b69ab31 | | | 566 | ); |
| b69ab31 | | | 567 | } |
| b69ab31 | | | 568 | default: |
| b69ab31 | | | 569 | return <Tile {...props} edges={[]} />; |
| b69ab31 | | | 570 | } |
| b69ab31 | | | 571 | } |
| b69ab31 | | | 572 | |
| b69ab31 | | | 573 | function PadTile(props: {line: PadLine; color?: string} & TileProps) { |
| b69ab31 | | | 574 | const {line, color} = props; |
| b69ab31 | | | 575 | switch (line) { |
| b69ab31 | | | 576 | case PadLine.Ancestor: |
| b69ab31 | | | 577 | return <Tile {...props} edges={[{y1: -10, y2: 10, flag: EdgeFlag.Dash, color}]} />; |
| b69ab31 | | | 578 | case PadLine.Parent: |
| b69ab31 | | | 579 | return <Tile {...props} edges={[{y1: -10, y2: 10, color}]} />; |
| b69ab31 | | | 580 | default: |
| b69ab31 | | | 581 | return <Tile {...props} edges={[]} />; |
| b69ab31 | | | 582 | } |
| b69ab31 | | | 583 | } |
| b69ab31 | | | 584 | |
| b69ab31 | | | 585 | function TermTile(props: TileProps) { |
| b69ab31 | | | 586 | // "~" in svg. |
| b69ab31 | | | 587 | return ( |
| b69ab31 | | | 588 | <Tile {...props}> |
| b69ab31 | | | 589 | <path d="M 0 -10 L 0 -5" strokeDasharray="3,2" /> |
| b69ab31 | | | 590 | <path d="M -7 -5 Q -3 -8, 0 -5 T 7 -5" /> |
| b69ab31 | | | 591 | </Tile> |
| b69ab31 | | | 592 | ); |
| b69ab31 | | | 593 | } |
| b69ab31 | | | 594 | |
| b69ab31 | | | 595 | function LinkTile(props: {line: LinkLine; color?: string; colorLine?: LinkLine} & TileProps) { |
| b69ab31 | | | 596 | const edges = linkLineToEdges(props.line, props.color, props.colorLine); |
| b69ab31 | | | 597 | return <Tile {...props} edges={edges} />; |
| b69ab31 | | | 598 | } |
| b69ab31 | | | 599 | |
| b69ab31 | | | 600 | function linkLineToEdges(linkLine: LinkLine, color?: string, colorLine?: LinkLine): Edge[] { |
| b69ab31 | | | 601 | const bits = linkLine.valueOf(); |
| b69ab31 | | | 602 | const colorBits = colorLine?.valueOf() ?? 0; |
| b69ab31 | | | 603 | const edges: Edge[] = []; |
| b69ab31 | | | 604 | const considerEdge = (parentBits: number, ancestorBits: number, edge: Partial<Edge>) => { |
| b69ab31 | | | 605 | const present = (bits & (parentBits | ancestorBits)) !== 0; |
| b69ab31 | | | 606 | const useColor = (colorBits & (parentBits | ancestorBits)) !== 0; |
| b69ab31 | | | 607 | const dashed = (bits & ancestorBits) !== 0; |
| b69ab31 | | | 608 | if (present) { |
| b69ab31 | | | 609 | const flag = edge.flag ?? 0 | (dashed ? EdgeFlag.Dash : 0); |
| b69ab31 | | | 610 | edges.push({...edge, flag, color: useColor ? color : undefined}); |
| b69ab31 | | | 611 | } |
| b69ab31 | | | 612 | }; |
| b69ab31 | | | 613 | considerEdge(LinkLine.VERT_PARENT, LinkLine.VERT_ANCESTOR, { |
| b69ab31 | | | 614 | y1: -10, |
| b69ab31 | | | 615 | y2: 10, |
| b69ab31 | | | 616 | flag: bits & (LinkLine.HORIZ_PARENT | LinkLine.HORIZ_ANCESTOR) ? EdgeFlag.IntersectGap : 0, |
| b69ab31 | | | 617 | }); |
| b69ab31 | | | 618 | considerEdge(LinkLine.HORIZ_PARENT, LinkLine.HORIZ_ANCESTOR, {x1: -10, x2: 10}); |
| b69ab31 | | | 619 | considerEdge(LinkLine.LEFT_MERGE_PARENT, LinkLine.LEFT_MERGE_ANCESTOR, {x1: -10, y2: -10}); |
| b69ab31 | | | 620 | considerEdge(LinkLine.RIGHT_MERGE_PARENT, LinkLine.RIGHT_MERGE_ANCESTOR, {x1: 10, y2: -10}); |
| b69ab31 | | | 621 | considerEdge(LinkLine.LEFT_FORK_PARENT | LinkLine.LEFT_FORK_ANCESTOR, 0, {x1: -10, y2: 10}); |
| b69ab31 | | | 622 | considerEdge(LinkLine.RIGHT_FORK_PARENT | LinkLine.RIGHT_FORK_ANCESTOR, 0, {x1: 10, y2: 10}); |
| b69ab31 | | | 623 | return edges; |
| b69ab31 | | | 624 | } |
| b69ab31 | | | 625 | |
| b69ab31 | | | 626 | // Svg patterns for avatar backgrounds. Those patterns are referred later by `RegularGlyph`. |
| b69ab31 | | | 627 | function SvgPatternList(props: {authors: Iterable<string>}) { |
| b69ab31 | | | 628 | return ( |
| b69ab31 | | | 629 | <svg className="render-dag-svg-patterns" viewBox={`-10 -10 20 20`}> |
| b69ab31 | | | 630 | <defs> |
| b69ab31 | | | 631 | {[...props.authors].map(author => ( |
| b69ab31 | | | 632 | <SvgPattern author={author} key={author} /> |
| b69ab31 | | | 633 | ))} |
| b69ab31 | | | 634 | </defs> |
| b69ab31 | | | 635 | </svg> |
| b69ab31 | | | 636 | ); |
| b69ab31 | | | 637 | } |
| b69ab31 | | | 638 | |
| b69ab31 | | | 639 | function authorToSvgPatternId(author: string) { |
| b69ab31 | | | 640 | return 'avatar-pattern-' + author.replace(/[^A-Z0-9a-z]/g, '_'); |
| b69ab31 | | | 641 | } |
| b69ab31 | | | 642 | |
| b69ab31 | | | 643 | function SvgPatternInner(props: {author: string}) { |
| b69ab31 | | | 644 | const {author} = props; |
| b69ab31 | | | 645 | const id = authorToSvgPatternId(author); |
| b69ab31 | | | 646 | return ( |
| b69ab31 | | | 647 | <AvatarPattern |
| b69ab31 | | | 648 | size={DEFAULT_GLYPH_RADIUS * 2} |
| b69ab31 | | | 649 | username={author} |
| b69ab31 | | | 650 | id={id} |
| b69ab31 | | | 651 | fallbackFill="var(--foreground)" |
| b69ab31 | | | 652 | /> |
| b69ab31 | | | 653 | ); |
| b69ab31 | | | 654 | } |
| b69ab31 | | | 655 | |
| b69ab31 | | | 656 | const SvgPattern = React.memo(SvgPatternInner); |
| b69ab31 | | | 657 | |
| ab83ad3 | | | 658 | const YOU_ARE_HERE_COLOR = '#4d8a78'; |
| ab83ad3 | | | 659 | const DEFAULT_GLYPH_RADIUS = (defaultTileWidth * 3.5) / 20; |
| b69ab31 | | | 660 | |
| b69ab31 | | | 661 | function RegularGlyphInner({info}: {info: DagCommitInfo}) { |
| b69ab31 | | | 662 | const stroke = info.isDot ? YOU_ARE_HERE_COLOR : 'var(--foreground)'; |
| b69ab31 | | | 663 | const r = DEFAULT_GLYPH_RADIUS; |
| b69ab31 | | | 664 | const strokeWidth = defaultStrokeWidth * 0.9; |
| b69ab31 | | | 665 | const isObsoleted = info.successorInfo != null; |
| b69ab31 | | | 666 | let fill = 'var(--foreground)'; |
| b69ab31 | | | 667 | let extraSvgElement = null; |
| b69ab31 | | | 668 | if (info.phase === 'draft') { |
| b69ab31 | | | 669 | if (isObsoleted) { |
| b69ab31 | | | 670 | // "/" inside the circle (similar to "x" in CLI) to indicate "obsoleted". |
| b69ab31 | | | 671 | fill = 'var(--background)'; |
| b69ab31 | | | 672 | const pos = r / Math.sqrt(2) - strokeWidth; |
| b69ab31 | | | 673 | extraSvgElement = ( |
| b69ab31 | | | 674 | <path |
| b69ab31 | | | 675 | d={`M ${-pos} ${pos} L ${pos} ${-pos}`} |
| b69ab31 | | | 676 | stroke={stroke} |
| b69ab31 | | | 677 | strokeWidth={strokeWidth} |
| b69ab31 | | | 678 | strokeLinecap="round" |
| b69ab31 | | | 679 | /> |
| b69ab31 | | | 680 | ); |
| b69ab31 | | | 681 | } else if (info.author.length > 0) { |
| b69ab31 | | | 682 | // Avatar for draft, non-obsoleted commits. |
| b69ab31 | | | 683 | const id = authorToSvgPatternId(info.author); |
| b69ab31 | | | 684 | fill = `url(#${id})`; |
| b69ab31 | | | 685 | } |
| b69ab31 | | | 686 | } |
| b69ab31 | | | 687 | |
| ab83ad3 | | | 688 | if (info.isDot && !isObsoleted) { |
| ab83ad3 | | | 689 | return ( |
| ab83ad3 | | | 690 | <> |
| ab83ad3 | | | 691 | <circle cx={0} cy={0} r={r + strokeWidth * 2.5} fill={'var(--background)'} stroke="none" /> |
| ab83ad3 | | | 692 | <circle cx={0} cy={0} r={r + strokeWidth * 2} fill="none" stroke={YOU_ARE_HERE_COLOR} strokeWidth={strokeWidth} /> |
| e6f6bcb | | | 693 | <circle cx={0} cy={0} r={r} fill={YOU_ARE_HERE_COLOR} stroke="none" /> |
| ab83ad3 | | | 694 | </> |
| ab83ad3 | | | 695 | ); |
| ab83ad3 | | | 696 | } |
| ab83ad3 | | | 697 | |
| b69ab31 | | | 698 | return ( |
| b69ab31 | | | 699 | <> |
| b69ab31 | | | 700 | <circle cx={0} cy={0} r={r} fill={fill} stroke={stroke} strokeWidth={strokeWidth} /> |
| b69ab31 | | | 701 | {extraSvgElement} |
| b69ab31 | | | 702 | </> |
| b69ab31 | | | 703 | ); |
| b69ab31 | | | 704 | } |
| b69ab31 | | | 705 | |
| b69ab31 | | | 706 | export const RegularGlyph = React.memo(RegularGlyphInner, (prevProps, nextProps) => { |
| b69ab31 | | | 707 | const prevInfo = prevProps.info; |
| b69ab31 | | | 708 | const nextInfo = nextProps.info; |
| b69ab31 | | | 709 | return nextInfo.equals(prevInfo); |
| b69ab31 | | | 710 | }); |
| b69ab31 | | | 711 | |
| b69ab31 | | | 712 | /** |
| b69ab31 | | | 713 | * The default "You are here" glyph - render as a blue bubble. Intended to be used in |
| b69ab31 | | | 714 | * different `RenderDag` configurations. |
| b69ab31 | | | 715 | * |
| b69ab31 | | | 716 | * If you want to customize the rendering for the main graph, or introducing dependencies |
| b69ab31 | | | 717 | * that seem "extra" (like code review states, operation-related progress state), consider |
| b69ab31 | | | 718 | * passing the `renderGlyph` prop to `RenderDag` instead. See `CommitTreeList` for example. |
| b69ab31 | | | 719 | */ |
| b69ab31 | | | 720 | export function YouAreHereGlyph({info, children}: {info: DagCommitInfo; children?: ReactNode}) { |
| b69ab31 | | | 721 | return ( |
| b69ab31 | | | 722 | <YouAreHereLabel title={info.description} style={{marginLeft: -defaultStrokeWidth * 1.5}}> |
| b69ab31 | | | 723 | {children} |
| b69ab31 | | | 724 | </YouAreHereLabel> |
| b69ab31 | | | 725 | ); |
| b69ab31 | | | 726 | } |
| b69ab31 | | | 727 | |
| b69ab31 | | | 728 | export function defaultRenderGlyph(info: DagCommitInfo): RenderGlyphResult { |
| b69ab31 | | | 729 | if (info.isYouAreHere) { |
| b69ab31 | | | 730 | return ['replace-tile', <YouAreHereGlyph info={info} />]; |
| b69ab31 | | | 731 | } else { |
| b69ab31 | | | 732 | return ['inside-tile', <RegularGlyph info={info} />]; |
| b69ab31 | | | 733 | } |
| b69ab31 | | | 734 | } |