-
Notifications
You must be signed in to change notification settings - Fork 118
FE-585: WIP petrinaut add hover + selected emphasis for nodes #8632
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
base: main
Are you sure you want to change the base?
Changes from all commits
0a7cc56
ef75ef1
3f3ece5
970d330
bbbcda1
b882182
f1f6ff2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import type { Transition } from "../core/types/sdcpn"; | ||
| import { generateArcId } from "../state/sdcpn-context"; | ||
| import type { SelectionMap } from "../state/selection"; | ||
|
|
||
| /** | ||
| * Given a list of transitions and a set of selected item IDs, | ||
| * returns a {@link SelectionMap} of all items (places, transitions, arcs) | ||
| * that are directly connected to any selected item via an arc. | ||
| * | ||
| * An item is included if it shares an arc with a selected item: | ||
| * - A selected place includes its connected transitions and arcs. | ||
| * - A selected transition includes its connected places and arcs. | ||
| * - A selected arc includes its source place and target transition. | ||
| */ | ||
| export function getNodeConnections( | ||
| transitions: readonly Transition[], | ||
| selectedIds: ReadonlySet<string>, | ||
| ): SelectionMap { | ||
| const connections: SelectionMap = new Map(); | ||
|
|
||
| for (const transition of transitions) { | ||
| const transitionSelected = selectedIds.has(transition.id); | ||
|
|
||
| for (const inputArc of transition.inputArcs) { | ||
| const arcId = generateArcId({ | ||
| inputId: inputArc.placeId, | ||
| outputId: transition.id, | ||
| }); | ||
| const placeSelected = selectedIds.has(inputArc.placeId); | ||
| const arcSelected = selectedIds.has(arcId); | ||
|
|
||
| if (transitionSelected || placeSelected || arcSelected) { | ||
| connections.set(inputArc.placeId, { | ||
| type: "place", | ||
| id: inputArc.placeId, | ||
| }); | ||
| connections.set(transition.id, { | ||
| type: "transition", | ||
| id: transition.id, | ||
| }); | ||
| connections.set(arcId, { type: "arc", id: arcId }); | ||
| } | ||
| } | ||
|
|
||
| for (const outputArc of transition.outputArcs) { | ||
| const arcId = generateArcId({ | ||
| inputId: transition.id, | ||
| outputId: outputArc.placeId, | ||
| }); | ||
| const placeSelected = selectedIds.has(outputArc.placeId); | ||
| const arcSelected = selectedIds.has(arcId); | ||
|
|
||
| if (transitionSelected || placeSelected || arcSelected) { | ||
| connections.set(outputArc.placeId, { | ||
| type: "place", | ||
| id: outputArc.placeId, | ||
| }); | ||
| connections.set(transition.id, { | ||
| type: "transition", | ||
| id: transition.id, | ||
| }); | ||
| connections.set(arcId, { type: "arc", id: arcId }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // The logic above adds items even if they are selected, so we now remove all selected items from the | ||
| // connected map. I suspect this approach is also faster than adding extra conditions to build the list | ||
| selectedIds.forEach((id) => connections.delete(id)); | ||
|
|
||
| return connections; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,12 @@ export type EditorActions = { | |
| setActiveBottomPanelTab: (tab: BottomPanelTab) => void; | ||
| /** Check whether a given ID is in the current selection. */ | ||
| isSelected: (id: string) => boolean; | ||
| /** Check whether a node/edge is connected to any selected item via an arc. */ | ||
| isSelectedConnection: (id: string) => boolean; | ||
| /** Check whether a node/edge is connected to any selected item via an arc. */ | ||
| isNotSelectedConnection: (id: string) => boolean; | ||
|
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. libs/@hashintel/petrinaut/src/state/editor-context.ts:66 — The JSDoc for Severity: low 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| /** Map of all items connected to the current selection, keyed by id. */ | ||
| selectedConnections: SelectionMap; | ||
| setSelection: ( | ||
| selection: SelectionMap | ((prev: SelectionMap) => SelectionMap), | ||
| ) => void; | ||
|
|
@@ -115,6 +121,9 @@ const DEFAULT_CONTEXT_VALUE: EditorContextValue = { | |
| setBottomPanelHeight: () => {}, | ||
| setActiveBottomPanelTab: () => {}, | ||
| isSelected: () => false, | ||
| isSelectedConnection: () => false, | ||
| isNotSelectedConnection: () => false, | ||
| selectedConnections: new Map(), | ||
| setSelection: () => {}, | ||
| selectItem: () => {}, | ||
| toggleItem: () => {}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ import { | |
| type EditorState, | ||
| initialEditorState, | ||
| } from "./editor-context"; | ||
| import { getNodeConnections } from "../lib/get-connections"; | ||
| import { SDCPNContext } from "./sdcpn-context"; | ||
| import type { SelectionItem, SelectionMap } from "./selection"; | ||
| import { useSyncEditorToSettings } from "./use-sync-editor-to-settings"; | ||
| import { UserSettingsContext } from "./user-settings-context"; | ||
|
|
@@ -16,6 +18,7 @@ export type EditorProviderProps = React.PropsWithChildren; | |
|
|
||
| export const EditorProvider: React.FC<EditorProviderProps> = ({ children }) => { | ||
| const userSettings = use(UserSettingsContext); | ||
| const { petriNetDefinition } = use(SDCPNContext); | ||
|
|
||
| const [state, setState] = useState<EditorState>(() => ({ | ||
| ...initialEditorState, | ||
|
|
@@ -79,7 +82,13 @@ export const EditorProvider: React.FC<EditorProviderProps> = ({ children }) => { | |
| }); | ||
| }; | ||
|
|
||
| const actions: Omit<EditorActions, "isSelected"> = { | ||
| const actions: Omit< | ||
| EditorActions, | ||
| | "isSelected" | ||
| | "isSelectedConnection" | ||
| | "isNotSelectedConnection" | ||
| | "selectedConnections" | ||
| > = { | ||
| setGlobalMode: (mode) => | ||
| setState((prev) => ({ ...prev, globalMode: mode })), | ||
| setEditionMode: (mode) => | ||
|
|
@@ -220,12 +229,24 @@ export const EditorProvider: React.FC<EditorProviderProps> = ({ children }) => { | |
| const { selection } = state; | ||
| const isSelected = (id: string) => selection.has(id); | ||
|
|
||
| const selectedConnections = getNodeConnections( | ||
| petriNetDefinition.transitions, | ||
| new Set(selection.keys()), | ||
| ); | ||
|
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. Expensive computation runs on every unrelated renderMedium Severity
Reviewed by Cursor Bugbot for commit f1f6ff2. Configure here. |
||
|
|
||
| const isSelectedConnection = (id: string) => selectedConnections.has(id); | ||
| const isNotSelectedConnection = (id: string) => | ||
| selection.size > 0 && !isSelected(id) && !selectedConnections.has(id); | ||
|
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. libs/@hashintel/petrinaut/src/state/editor-provider.tsx:239 — Severity: medium Other Locations
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. 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. Non-graph item selection fades entire graph unexpectedlyMedium Severity When a non-graph item (type, parameter, or differential equation) is selected from the sidebar, Additional Locations (1)Reviewed by Cursor Bugbot for commit f1f6ff2. Configure here. |
||
|
|
||
| const searchInputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| const contextValue: EditorContextValue = { | ||
| ...state, | ||
| ...actions, | ||
| isSelected, | ||
| isSelectedConnection, | ||
| isNotSelectedConnection, | ||
| selectedConnections, | ||
| searchInputRef, | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { css } from "@hashintel/ds-helpers/css"; | ||
| import { NOT_SELECTED_CONNECTION_OVERLAY_OPACITY } from "../styles/styling"; | ||
| import { | ||
| BaseEdge, | ||
| type EdgeProps, | ||
|
|
@@ -182,11 +183,14 @@ export const Arc: React.FC<EdgeProps<ArcEdgeType>> = ({ | |
| markerEnd, | ||
| }) => { | ||
| // Derive selected state from EditorContext | ||
| const { isSelected } = use(EditorContext); | ||
| const { isSelected, isNotSelectedConnection, isSelectedConnection } = | ||
| use(EditorContext); | ||
| const { arcRendering } = use(UserSettingsContext); | ||
|
|
||
| // Check if this arc is selected by its ID | ||
| const selected = isSelected(id); | ||
| const notSelectedConnection = isNotSelectedConnection(id); | ||
| const selectedConnection = isSelectedConnection(id); | ||
|
|
||
| const inhibitorMarkerId = `inhibitor-circle-${id}`; | ||
|
|
||
|
|
@@ -236,7 +240,19 @@ export const Arc: React.FC<EdgeProps<ArcEdgeType>> = ({ | |
| const strokeColor = style?.stroke ?? "#b1b1b7"; | ||
|
|
||
| return ( | ||
| <> | ||
| <g | ||
| style={ | ||
| selectedConnection | ||
| ? { | ||
| filter: `brightness(${0.8})`, | ||
| } | ||
| : notSelectedConnection | ||
| ? { | ||
| filter: `brightness(${1 + NOT_SELECTED_CONNECTION_OVERLAY_OPACITY})`, | ||
| } | ||
|
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. Arc brightness filter makes strokes completely invisibleMedium Severity The Additional Locations (1)Reviewed by Cursor Bugbot for commit f1f6ff2. Configure here. |
||
| : undefined | ||
| } | ||
| > | ||
| {/* Custom SVG marker definition for inhibitor arcs (empty circle) */} | ||
| {data?.arcType === "inhibitor" && ( | ||
| <defs> | ||
|
|
@@ -339,6 +355,6 @@ export const Arc: React.FC<EdgeProps<ArcEdgeType>> = ({ | |
| </g> | ||
| ) : null} | ||
| </g> | ||
| </> | ||
| </g> | ||
| ); | ||
| }; | ||


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.
libs/@hashintel/petrinaut/src/lib/get-connections.ts:13 — The docs say a selected arc includes its “source place and target transition”, but output arcs are transition→place as well. Consider rewording to “source and target nodes” to avoid confusion.
Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.