({
nodes,
maxComponents,
enabled,
}: PathPreviewProps)
| 27 | type Component = ValueComponent | EllipsisComponent; |
| 28 | |
| 29 | export function PathPreview({ |
| 30 | nodes, |
| 31 | maxComponents, |
| 32 | enabled, |
| 33 | }: PathPreviewProps) { |
| 34 | const isEnabled = useMemo(() => { |
| 35 | if (enabled === undefined) { |
| 36 | return true; |
| 37 | } |
| 38 | return enabled; |
| 39 | }, [enabled]); |
| 40 | |
| 41 | const { goToNodeId } = useJsonColumnViewAPI(); |
| 42 | |
| 43 | const components = useMemo<Array<Component>>(() => { |
| 44 | if (maxComponents == null || nodes.length <= maxComponents) { |
| 45 | return nodes.map((n) => { |
| 46 | return { type: "value", id: n.id, title: n.title, icon: n.icon }; |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | let components = Array<Component>(); |
| 51 | |
| 52 | //add the elements up to the ellipsis |
| 53 | for (let index = 0; index < maxComponents - 1; index++) { |
| 54 | const node = nodes[index]; |
| 55 | components.push({ |
| 56 | type: "value", |
| 57 | id: node.id, |
| 58 | title: node.title, |
| 59 | icon: node.icon, |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | //add ellipsis |
| 64 | components.push({ type: "ellipsis", id: "ellipsis" }); |
| 65 | |
| 66 | //add final element |
| 67 | const lastNode = nodes[nodes.length - 1]; |
| 68 | components.push({ |
| 69 | type: "value", |
| 70 | id: lastNode.id, |
| 71 | title: lastNode.title, |
| 72 | icon: lastNode.icon, |
| 73 | }); |
| 74 | |
| 75 | return components; |
| 76 | }, [nodes, maxComponents]); |
| 77 | |
| 78 | return ( |
| 79 | <div |
| 80 | className={`flex select-none pl-7 ${ |
| 81 | isEnabled |
| 82 | ? `relative transition hover:bg-slate-200 hover:cursor-pointer dark:hover:bg-slate-600 after:transition after:absolute after:h-3 after:w-3 after:opacity-0 hover:after:opacity-100 after:top-1 after:left-1 after:content-[''] after:bg-[url('${eyeIcon}')] after:bg-no-repeat` |
| 83 | : "disabled" |
| 84 | }`} |
| 85 | onClick={() => |
| 86 | isEnabled && |
nothing calls this directly
no test coverage detected