|
1 | | -import { Button, Stack, Tile } from "@carbon/react" |
2 | | -import { ServiceId } from "@carbon/react/icons" |
| 1 | +import { Tile } from "@carbon/react" |
| 2 | + |
3 | 3 | import { Handle, NodeProps, Position } from "reactflow" |
4 | 4 | import { EipNodeData, Layout } from "../../api/flow" |
5 | 5 | import { ConnectionType, EipRole } from "../../api/generated/eipComponentDef" |
6 | | -import { EipId } from "../../api/generated/eipFlow" |
7 | 6 | import { lookupEipComponent } from "../../singletons/eipDefinitions" |
8 | 7 | import getIconUrl from "../../singletons/eipIconCatalog" |
9 | | -import { |
10 | | - clearSelectedChildNode, |
11 | | - updateSelectedChildNode, |
12 | | -} from "../../singletons/store/appActions" |
| 8 | +import { clearSelectedChildNode } from "../../singletons/store/appActions" |
13 | 9 | import { |
14 | 10 | useGetEnabledChildren, |
15 | 11 | useGetLayout, |
16 | | - useGetSelectedChildNode, |
17 | 12 | } from "../../singletons/store/getterHooks" |
18 | 13 | import { getEipId } from "../../singletons/store/storeViews" |
19 | | -import { toTitleCase } from "../../utils/titleTransform" |
| 14 | +import { getNamespacedTitle } from "../../utils/titleTransform" |
| 15 | +import { ChildrenNavigationPopover } from "./ChildrenNavigationPopover" |
20 | 16 | import "./nodes.scss" |
21 | 17 |
|
22 | | -interface ChildrenIconsProps { |
23 | | - childIds: string[] |
24 | | -} |
25 | | - |
26 | | -interface ChildIconButtonProps { |
27 | | - id: string |
28 | | -} |
29 | | - |
30 | | -const DEFAULT_NAMESPACE = "integration" |
31 | 18 | const DEFAULT_NODE_LABEL = "New Node" |
32 | 19 |
|
33 | 20 | const renderHorizontalHandles = (connectionType: ConnectionType) => { |
@@ -91,64 +78,19 @@ const renderHandles = ( |
91 | 78 | ? renderHorizontalHandles(connectionType) |
92 | 79 | : renderVerticalHandles(connectionType) |
93 | 80 |
|
94 | | -const getNamespacedTitle = (eipId: EipId) => { |
95 | | - if (eipId.namespace === DEFAULT_NAMESPACE) { |
96 | | - return toTitleCase(eipId.name) |
97 | | - } |
98 | | - return toTitleCase(eipId.namespace) + " " + toTitleCase(eipId.name) |
99 | | -} |
100 | | - |
101 | 81 | const getClassNames = (props: NodeProps<EipNodeData>, role: EipRole) => { |
102 | 82 | const roleClsName = |
103 | 83 | role === "channel" ? "eip-channel-node" : "eip-endpoint-node" |
104 | 84 | const selectedClsName = props.selected ? "eip-node-selected" : "" |
105 | 85 | return ["eip-node", roleClsName, selectedClsName].join(" ") |
106 | 86 | } |
107 | 87 |
|
108 | | -const ChildIconButton = (props: ChildIconButtonProps) => { |
109 | | - const currSelection = useGetSelectedChildNode() |
110 | | - const isSelected = currSelection === props.id |
111 | | - |
112 | | - const clsNames = ["child-icon-button"] |
113 | | - isSelected && clsNames.push("child-icon-button-focused") |
114 | | - |
115 | | - const eipId = getEipId(props.id) |
116 | | - |
117 | | - return eipId ? ( |
118 | | - <Button |
119 | | - className={clsNames.join(" ")} |
120 | | - hasIconOnly |
121 | | - renderIcon={ServiceId} |
122 | | - iconDescription={eipId.name} |
123 | | - size="sm" |
124 | | - tooltipPosition="bottom" |
125 | | - kind="primary" |
126 | | - onClick={(ev) => { |
127 | | - ev.stopPropagation() |
128 | | - updateSelectedChildNode(props.id) |
129 | | - }} |
130 | | - /> |
131 | | - ) : null |
132 | | -} |
133 | | - |
134 | | -// TODO: Account for a large number of children to be displayed |
135 | | -// TODO: Create a mapping of children to icons (with a fallback option) |
136 | | -const ChildrenIcons = ({ childIds }: ChildrenIconsProps) => { |
137 | | - return ( |
138 | | - <Stack className="eip-node-children" orientation="horizontal" gap={2}> |
139 | | - {childIds.map((id) => ( |
140 | | - <ChildIconButton key={id} id={id} /> |
141 | | - ))} |
142 | | - </Stack> |
143 | | - ) |
144 | | -} |
145 | | - |
146 | 88 | // TODO: Consider separating into Endpoint and Channel custom node types |
147 | 89 | export const EipNode = (props: NodeProps<EipNodeData>) => { |
148 | 90 | // TODO: clearSelectedChildNode is used in too many different components. See if that can be reduced (or elimnated). |
149 | 91 | const layout = useGetLayout() |
150 | | - const childrenState = useGetEnabledChildren(props.id) |
151 | | - const hasChildren = childrenState.length > 0 |
| 92 | + const children = useGetEnabledChildren(props.id) |
| 93 | + const hasChildren = children.length > 0 |
152 | 94 |
|
153 | 95 | const eipId = getEipId(props.id) |
154 | 96 | const componentDefinition = eipId && lookupEipComponent(eipId) |
@@ -176,7 +118,7 @@ export const EipNode = (props: NodeProps<EipNodeData>) => { |
176 | 118 | > |
177 | 119 | <strong>{data.label || DEFAULT_NODE_LABEL}</strong> |
178 | 120 | </div> |
179 | | - {hasChildren && <ChildrenIcons childIds={childrenState} />} |
| 121 | + {hasChildren && <ChildrenNavigationPopover />} |
180 | 122 | {handles} |
181 | 123 | </Tile> |
182 | 124 | ) |
|
0 commit comments