-
Notifications
You must be signed in to change notification settings - Fork 5
#397: Highlight States #413
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
ethanluc7
wants to merge
49
commits into
main
Choose a base branch
from
397-highlight-states
base: main
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.
+1,420
−78
Open
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
d968793
fix: update year to 2026
ethanluc7 3709c14
feat: add subtitle prop to modal component
ethanluc7 cc905ad
feat: create diagram view button
ethanluc7 1b0a3d5
feat: add dictionary view button to toolbar
ethanluc7 bd02d6b
fix: format fles
ethanluc7 f729b69
feat: implement entity relationship diagram
ethanluc7 2d61856
feat: add icons for diagram
ethanluc7 f840404
feat: add entity relationship diagram to diagram view button
ethanluc7 1479f36
feat: add entity relationship diagram story
ethanluc7 36476f5
Merge branch 'main' into 395-render-dictionary-schema
ethanluc7 2abb827
Merge branch 'main' into 395-render-dictionary-schema
ethanluc7 288d961
Merge branch '395-render-dictionary-schema' of https://github.com/ove…
ethanluc7 f66e39f
fix: removed unused imports
ethanluc7 d69ef67
fix: use empty dictionary instead of full dictionary
ethanluc7 1448234
feat: add separate file for schema node css
ethanluc7 e2ec2ed
fix: import types and components in one line
ethanluc7 6eba979
fix: remove spread
ethanluc7 7700a63
fix: remove type casting
ethanluc7 e083d73
fix: reduce height of modal to remove vertical scrolling on container
ethanluc7 04e0314
fix: remove unused type import
ethanluc7 ffb4767
refactor: remove max-height from nodes
ethanluc7 3a9efd9
docs: add docs for functions and props
ethanluc7 cb0e9d4
feat: add row hover states
ethanluc7 82b93f8
feat: add edge hover states
ethanluc7 0554d37
Merge branch 'main' into 396-field-edge-interactions
ethanluc7 a75c21e
feat: allow modal to take in reactnode as subtitle
ethanluc7 5c814cf
feat: add highlight states to schema node styles
ethanluc7 e53cac7
feat: add relationship provider to create relationship to determine h…
ethanluc7 2941455
feat: add diagram subtitle component to render scheam chain
ethanluc7 897ca27
feat: update schema node to activate / deactive edges on click
ethanluc7 f9c88f3
feat: add active and inactive marker
ethanluc7 f3d58d1
refactor: update index with new utils
ethanluc7 3ea658c
feat: add dictionaries for testing
ethanluc7 6fe4d87
Merge branch 'main' into 397-highlight-states
ethanluc7 8bafc25
test
ethanluc7 8349593
revert test
ethanluc7 52da977
fix: replace div element with fragment
ethanluc7 355fe54
refactor: use css selectors with hover text variable
ethanluc7 d67e0aa
fix: align schema title and rows text
ethanluc7 020ba8b
fix: remove union with null
ethanluc7 d5bdcc5
fix: use optional fields instead of union with null
ethanluc7 65f8ac3
fix: replace one line if statements
ethanluc7 cfdd84a
refactor: rename variable names for clarity
ethanluc7 6029fdb
fix: simplify conditional logic
ethanluc7 3a6160a
fix: change from null to undefined for now optional fields
ethanluc7 84f1b7a
refactor: remove isEvenRow property from rows
ethanluc7 1131100
refactor: move styling for marker outside of function
ethanluc7 46de40e
refactor: remove unnecessary duplicate check on sets
ethanluc7 27a6cb7
refactor: use useMemo to prevent extra re-renders
ethanluc7 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
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
126 changes: 126 additions & 0 deletions
126
packages/ui/src/viewer-table/EntityRelationshipDiagram/ActiveRelationshipContext.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,126 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2026 The Ontario Institute for Cancer Research. All rights reserved | ||
| * | ||
| * This program and the accompanying materials are made available under the terms of | ||
| * the GNU Affero General Public License v3.0. You should have received a copy of the | ||
| * GNU Affero General Public License along with this program. | ||
| * If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
| * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
| * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
| * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
| * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| * | ||
| */ | ||
|
|
||
| import { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from 'react'; | ||
| import { traceChain, type RelationshipMap } from './diagramUtils'; | ||
|
|
||
| type ActiveRelationshipState = { | ||
| edgeIds: Set<string>; | ||
| fieldKeys: Set<string>; | ||
| schemaChain: string[]; | ||
| }; | ||
|
|
||
| type ActiveRelationshipContextValue = { | ||
| activeEdgeIds?: Set<string>; | ||
| activeFieldKeys?: Set<string>; | ||
| activeSchemaNames?: Set<string>; | ||
| activeSchemaChain?: string[]; | ||
| activateRelationship: (chainStartingIndex: number) => void; | ||
| deactivateRelationship: () => void; | ||
| relationshipMap: RelationshipMap; | ||
| isFieldInActiveRelationship: (schemaName: string, fieldName: string) => boolean; | ||
| }; | ||
|
|
||
| const ActiveRelationshipContext = createContext<ActiveRelationshipContextValue | null>(null); | ||
|
|
||
| type ActiveRelationshipProviderProps = { | ||
| relationshipMap: RelationshipMap; | ||
| children: ReactNode; | ||
| }; | ||
|
|
||
| /** | ||
| * Provides active relationship state and actions to the ERD component tree. | ||
| * Wraps children with context that tracks which FK chain is currently highlighted, | ||
| * and exposes methods to activate/deactivate highlighting via traceChain. | ||
| * | ||
| * @param {RelationshipMap} relationshipMap — The FK adjacency graph used for chain tracing | ||
| * @param {ReactNode} children — Child components that can consume the active relationship context | ||
| */ | ||
| export function ActiveRelationshipProvider({ relationshipMap, children }: ActiveRelationshipProviderProps) { | ||
| const [activeState, setActiveState] = useState<ActiveRelationshipState | null>(null); | ||
|
|
||
| const activateRelationship = useCallback( | ||
| (chainStartingIndex: number) => { | ||
| const result = traceChain(chainStartingIndex, relationshipMap); | ||
| setActiveState(result); | ||
| }, | ||
| [relationshipMap], | ||
| ); | ||
|
|
||
| const deactivateRelationship = useCallback(() => { | ||
| setActiveState(null); | ||
| }, []); | ||
|
|
||
| const isFieldInActiveRelationship = useCallback( | ||
| (schemaName: string, fieldName: string): boolean => { | ||
| if (!activeState) { | ||
| return false; | ||
| } | ||
| return activeState.fieldKeys.has(`${schemaName}::${fieldName}`); | ||
| }, | ||
| [activeState], | ||
| ); | ||
|
|
||
| const activeSchemaNames = useMemo(() => { | ||
| if (!activeState) { | ||
| return undefined; | ||
| } | ||
| const names = new Set<string>(); | ||
| for (const key of activeState.fieldKeys) { | ||
| const schemaName = key.split('::')[0]; | ||
| if (schemaName) { | ||
| names.add(schemaName); | ||
| } | ||
| } | ||
| return names; | ||
| }, [activeState]); | ||
|
|
||
| return ( | ||
| <ActiveRelationshipContext.Provider | ||
| value={{ | ||
| activeEdgeIds: activeState?.edgeIds, | ||
| activeFieldKeys: activeState?.fieldKeys, | ||
| activeSchemaNames, | ||
| activeSchemaChain: activeState?.schemaChain, | ||
| activateRelationship, | ||
| deactivateRelationship, | ||
| relationshipMap, | ||
| isFieldInActiveRelationship, | ||
| }} | ||
| > | ||
| {children} | ||
| </ActiveRelationshipContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Consumes the active relationship context. Must be called from a component | ||
| * that is a descendant of ActiveRelationshipProvider. | ||
| * | ||
| * @returns {ActiveRelationshipContextValue} The current active relationship state and actions | ||
| */ | ||
| export function useActiveRelationship(): ActiveRelationshipContextValue { | ||
| const context = useContext(ActiveRelationshipContext); | ||
| if (!context) { | ||
| throw new Error('useActiveRelationship must be used within an ActiveRelationshipProvider'); | ||
| } | ||
| return context; | ||
| } |
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
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.
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.
👍