-
Notifications
You must be signed in to change notification settings - Fork 12
Graph Navigator #603
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
Open
floscr
wants to merge
20
commits into
master
Choose a base branch
from
florian/graph-navigator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Graph Navigator #603
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c7828e7
Selector to collect nodes in the main graph
floscr 50652df
Add navigator panel
floscr 4e266e1
Make subgraphs navigateable
floscr 0eff226
Extract callback
floscr 52b3447
Silence ts innerGraph errors
floscr e9c7f66
Rename
floscr 0f39937
Hacky work-around for circular dependency
floscr 24cec3d
Highlight currently selected graph
floscr b994acc
Show root graph
floscr 5a4e5e6
Depth styling & Pretty title
floscr 242fe67
Show node count
floscr c0e6a98
Fix forgotten file
floscr 1e024af
Fix condition
floscr c373a86
Fix ts errors
floscr 8ce784d
Cleanup
floscr e2289c0
Lint
floscr ca62fba
Remove console.log
floscr f5e35f4
Restore css file
floscr ee5810d
Review changes
floscr 327c0f1
Review changes
floscr 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
38 changes: 38 additions & 0 deletions
38
packages/graph-editor/src/components/panels/navigation/index.module.css
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,38 @@ | ||
| .scrollWrapper { | ||
| height: 100%; | ||
| flex: 1; | ||
| padding: var(--component-spacing-md); | ||
| overflow: auto; | ||
| } | ||
|
|
||
| .componentSpacingWrapper { | ||
| padding: var(--component-spacing-md); | ||
| } | ||
|
|
||
| .listWrapper { | ||
| display: flex; | ||
| flex-direction: column; | ||
| font-size: var(--font-body-small-default); | ||
| gap: var(--component-spacing-xs); | ||
| list-style-type: none; | ||
| margin: 0; | ||
| padding: 0; | ||
| user-select: none; | ||
| } | ||
|
|
||
| .listItem { | ||
| cursor: pointer; | ||
| display: inline-flex; | ||
| gap: var(--component-spacing-sm); | ||
| padding-left: 0; | ||
| padding-left: calc(var(--tree-depth, 0px) * var(--component-spacing-xs, 1px)); | ||
| } | ||
|
|
||
| .listItemSelected { | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| .listItemCount { | ||
| color: var(--fg-subtle); | ||
| font-weight: normal; | ||
| } |
106 changes: 106 additions & 0 deletions
106
packages/graph-editor/src/components/panels/navigation/index.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,106 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { MAIN_GRAPH_ID } from '@/constants.js'; | ||
| import { Stack } from '@tokens-studio/ui'; | ||
| import { TreeNode, graphNodesSelector } from '@/redux/selectors/graph.js'; | ||
| import { currentPanelIdSelector } from '@/redux/selectors/graph.js'; | ||
| import { dockerSelector } from '@/redux/selectors/refs.js'; | ||
| import { flow, get, size } from 'lodash-es'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { useSubgraphExplorerCallback } from '@/hooks/useSubgraphExplorerCallback.js'; | ||
| import cx from 'classnames'; | ||
| import styles from './index.module.css'; | ||
|
|
||
| type ListItemProps = { | ||
| label: string; | ||
| count?: number; | ||
| isSelected?: boolean; | ||
| onClick?: () => void; | ||
| depth?: number; | ||
| }; | ||
|
|
||
| const ListItem = function ({ | ||
| label, | ||
| count, | ||
| isSelected, | ||
| onClick, | ||
| depth = 0, | ||
| }: ListItemProps) { | ||
| const style = { | ||
| '--tree-depth': depth, | ||
| } as React.CSSProperties; | ||
|
|
||
| return ( | ||
| <li | ||
| className={cx(styles.listItem, { | ||
| [styles.listItemSelected]: isSelected, | ||
| })} | ||
| onClick={onClick} | ||
| style={style} | ||
| > | ||
| <span>{label}</span> | ||
| {count && <span className={styles.listItemCount}>({count})</span>} | ||
| </li> | ||
| ); | ||
| }; | ||
|
|
||
| const SubgraphNodeItem = function ({ node, isSelected, depth }) { | ||
| const nodeType = node.factory.title || node.nodeType(); | ||
| const onNodeClick = useSubgraphExplorerCallback(node); | ||
| const childNodesCount = flow( | ||
| (x) => get(x, ['_innerGraph', 'nodes'], []), | ||
| size, | ||
| )(node); | ||
|
|
||
| return ( | ||
| <ListItem | ||
| label={nodeType} | ||
| onClick={onNodeClick} | ||
| isSelected={isSelected} | ||
| depth={depth} | ||
| count={childNodesCount > 0 && childNodesCount} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const RootGraphNodeItem = function () { | ||
| const dockerRef = useSelector(dockerSelector); | ||
| const activeGraphId = useSelector(currentPanelIdSelector); | ||
|
|
||
| return ( | ||
| <ListItem | ||
| label={'Root'} | ||
| isSelected={activeGraphId === MAIN_GRAPH_ID} | ||
| onClick={() => dockerRef.current.updateTab(MAIN_GRAPH_ID, null, true)} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export const NavigationPanel = () => { | ||
| const nodes = useSelector(graphNodesSelector); | ||
| const activeGraphId = useSelector(currentPanelIdSelector); | ||
|
|
||
| return ( | ||
| <Stack direction="column" gap={4} className={styles.scrollWrapper}> | ||
| <div className={styles.componentSpacingWrapper}> | ||
| <ul className={styles.listWrapper}> | ||
| <RootGraphNodeItem /> | ||
| {Object.values(nodes || {}).map(({ node, depth }: TreeNode) => { | ||
| const innerGraph = node['_innerGraph']; | ||
| if (!innerGraph) return null; | ||
| return ( | ||
| <SubgraphNodeItem | ||
| key={node.id} | ||
| isSelected={ | ||
| activeGraphId === innerGraph?.annotations['engine.id'] | ||
| } | ||
| node={node} | ||
| depth={depth} | ||
| /> | ||
| ); | ||
| })} | ||
| </ul> | ||
| </div> | ||
| </Stack> | ||
| ); | ||
| }; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export const version = '4.3.9'; | ||
| export const version = '4.3.6'; |
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 |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| import { EditorApp } from './graph.js'; | ||
| import { ErrorBoundary } from 'react-error-boundary'; | ||
| import { ErrorBoundaryContent } from '@/components/ErrorBoundaryContent.js'; | ||
| import { GraphEditorProps, ImperativeEditorRef } from './editorTypes.js'; | ||
| import { ReactFlowProvider } from 'reactflow'; | ||
| import React from 'react'; | ||
|
|
@@ -16,3 +18,15 @@ export const GraphEditor = React.forwardRef< | |
| </ReactFlowProvider> | ||
| ); | ||
| }); | ||
|
|
||
| // HACK: Workaround for circular dependency not allowed for nextjs | ||
| // E.g.: when trying to create a new graph editor instance as a tab | ||
| if (typeof window !== 'undefined') { | ||
| window['newGraphEditor'] = function (ref, id) { | ||
| return ( | ||
| <ErrorBoundary fallback={<ErrorBoundaryContent />}> | ||
| <GraphEditor ref={ref} id={id} /> | ||
| </ErrorBoundary> | ||
| ); | ||
| }; | ||
| } | ||
|
Comment on lines
+24
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NextJS was erroring because there's a circular dependency. |
||
47 changes: 47 additions & 0 deletions
47
packages/graph-editor/src/hooks/useSubgraphExplorerCallback.ts
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,47 @@ | ||
| import { ImperativeEditorRef } from '../index.js'; | ||
| import { title as annotatedTitle } from '@/annotations/index.js'; | ||
| import { dockerSelector } from '@/redux/selectors/refs.js'; | ||
| import { useCallback } from 'react'; | ||
| import { useSelector } from 'react-redux'; | ||
|
|
||
| export const useSubgraphExplorerCallback = (node) => { | ||
| const dockerRef = useSelector(dockerSelector); | ||
|
|
||
| const callback = useCallback(() => { | ||
| if (!dockerRef?.current) { | ||
| return; | ||
| } | ||
|
|
||
| let oneShot = false; | ||
| const innerGraph = node['_innerGraph']; | ||
| const graphId = innerGraph.annotations['engine.id']; | ||
| const title = | ||
| node.annotations[annotatedTitle] || | ||
| innerGraph.annotations['engine.title'] || | ||
| 'Subgraph'; | ||
| const existing = dockerRef.current.find(graphId); | ||
|
|
||
| if (!existing) { | ||
| const ref = (o: ImperativeEditorRef) => { | ||
| if (o && !oneShot) { | ||
| o.load(innerGraph); | ||
| oneShot = true; | ||
| } | ||
| }; | ||
|
|
||
| const newTab = { | ||
| cached: true, | ||
| closable: true, | ||
| id: graphId, | ||
| group: 'graph', | ||
| title, | ||
| content: window && window['newGraphEditor'](ref, graphId), | ||
| }; | ||
| dockerRef.current.dockMove(newTab, 'graphs', 'middle'); | ||
| } else { | ||
| dockerRef.current.updateTab(graphId, null, true); | ||
| } | ||
| }, [dockerRef, node['_innerGraph'], node.annotations]); | ||
|
|
||
| return callback; | ||
| }; |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how we can get this type out of
packages/graph-engine/src/nodes/generic/subgraph.tsso we can do a proper typescript type check.I would have liked to do a check like
but I'm not sure how importing for types/classes works for such packages