-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(data-modeling): add lineage search result navigator #108501
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
Merged
+728
−76
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
befac46
feat(data-modeling): add lineage search result navigator
sakce c70094d
fix(data-modeling): retain lineage search focus
sakce 63bb8fc
feat(data-modeling): navigate lineage selector results
sakce 984f08f
fix(data-modeling): declare posthog-js for lineage search tracking
sakce 782848f
fix(data-modeling): let lineage search stories settle before asserting
sakce 1f6ce8b
fix(data-modeling): bound and correct the lineage search result panel
sakce 9913540
chore(visual): update storybook baselines
posthog[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
117 changes: 117 additions & 0 deletions
117
products/data_modeling/frontend/lineage/LineageSearchResults.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { useEffect, useRef } from 'react' | ||
|
|
||
| import { IconChevronRight } from '@posthog/icons' | ||
| import { LemonButton } from '@posthog/lemon-ui' | ||
|
|
||
| import { DataModelingNode } from '~/types' | ||
|
|
||
| import { LineageSearchMode } from './lineageSearch' | ||
| import { NodeTypeTag } from './NodeTypeTag' | ||
|
|
||
| const RENDERED_RESULT_LIMIT = 50 | ||
|
|
||
| export interface LineageSearchResultsProps { | ||
| results: DataModelingNode[] | ||
| selectedResultId?: string | ||
| anchorResultId?: string | ||
| mode: LineageSearchMode | ||
| onSelect: (nodeId: string) => void | ||
| onPrevious: () => void | ||
| onNext: () => void | ||
| } | ||
|
|
||
| export function LineageSearchResults({ | ||
| results, | ||
| selectedResultId, | ||
| anchorResultId, | ||
| mode, | ||
| onSelect, | ||
| onPrevious, | ||
| onNext, | ||
| }: LineageSearchResultsProps): JSX.Element { | ||
| const selectedOptionRef = useRef<HTMLDivElement>(null) | ||
| const selectedPosition = results.findIndex((node) => node.id === selectedResultId) + 1 | ||
| const resultCountLabel = | ||
| mode === 'search' | ||
| ? `${results.length} ${results.length === 1 ? 'result' : 'results'}` | ||
| : `${results.length} ${results.length === 1 ? 'model' : 'models'} · ${ | ||
| mode === 'both' ? 'both directions' : mode | ||
| }` | ||
|
|
||
| // A one-letter term matches most of a large warehouse, and only about eight rows fit. Render a | ||
| // window that holds the selection instead of one button per match, so arrow navigation still | ||
| // reaches every result and the list never mounts thousands of buttons. | ||
| const windowStart = Math.min( | ||
| Math.max(0, selectedPosition - 1 - Math.floor(RENDERED_RESULT_LIMIT / 2)), | ||
| Math.max(0, results.length - RENDERED_RESULT_LIMIT) | ||
| ) | ||
| const renderedResults = results.slice(windowStart, windowStart + RENDERED_RESULT_LIMIT) | ||
|
|
||
| useEffect(() => { | ||
| selectedOptionRef.current?.scrollIntoView({ block: 'nearest' }) | ||
| }, [selectedResultId]) | ||
|
|
||
| return ( | ||
| <div className="absolute top-3 left-3 z-10 w-80 max-w-[calc(100%-1.5rem)] rounded border bg-bg-light shadow-lg"> | ||
| <div className="flex items-center justify-between gap-2 border-b px-2 py-1.5 text-xs text-secondary"> | ||
| <span>{resultCountLabel}</span> | ||
| {results.length > 0 && ( | ||
| <div className="flex items-center gap-1"> | ||
| <span> | ||
| {selectedPosition} of {results.length} | ||
| </span> | ||
| <LemonButton | ||
| size="xsmall" | ||
| noPadding | ||
| icon={<IconChevronRight className="-rotate-90" />} | ||
| aria-label="Previous result" | ||
| tooltip="Previous result" | ||
| onClick={onPrevious} | ||
| data-attr="models-lineage-search-previous" | ||
| /> | ||
| <LemonButton | ||
| size="xsmall" | ||
| noPadding | ||
| icon={<IconChevronRight className="rotate-90" />} | ||
| aria-label="Next result" | ||
| tooltip="Next result" | ||
| onClick={onNext} | ||
| data-attr="models-lineage-search-next" | ||
| /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| <div className="max-h-56 overflow-y-auto p-1"> | ||
| {results.length === 0 ? ( | ||
| <div className="px-2 py-3 text-sm text-secondary">No matching models</div> | ||
| ) : ( | ||
| renderedResults.map((node) => ( | ||
| <div key={node.id} ref={node.id === selectedResultId ? selectedOptionRef : undefined}> | ||
| <LemonButton | ||
| fullWidth | ||
| size="small" | ||
| type="tertiary" | ||
| active={node.id === selectedResultId} | ||
| aria-current={node.id === selectedResultId} | ||
| className="justify-start" | ||
| onClick={() => onSelect(node.id)} | ||
| data-attr="models-lineage-search-result" | ||
| > | ||
| <span className="flex min-w-0 items-center gap-2"> | ||
| <NodeTypeTag type={node.type} /> | ||
| <span className="truncate">{node.name}</span> | ||
| {node.id === anchorResultId && ( | ||
| <span className="ml-auto shrink-0 text-xs text-secondary">Anchor</span> | ||
| )} | ||
| </span> | ||
| </LemonButton> | ||
| </div> | ||
| )) | ||
| )} | ||
| </div> | ||
| <div className="border-t px-2 py-1.5 text-[11px] text-secondary"> | ||
| ↑↓ to select · Enter to center · Esc to clear | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.