()
| 17 | import { JSONHeroPath } from '@jsonhero/path'; |
| 18 | |
| 19 | export function PathBar() { |
| 20 | const [isEditable, setIsEditable] = useState(false); |
| 21 | const { selectedNodes, highlightedNodeId } = useJsonColumnViewState(); |
| 22 | const { goToNodeId } = useJsonColumnViewAPI(); |
| 23 | const [json] = useJson(); |
| 24 | |
| 25 | if (isEditable) { |
| 26 | return ( |
| 27 | <PathBarText |
| 28 | selectedNodes={selectedNodes} |
| 29 | onConfirm={(newPath) => { |
| 30 | setIsEditable(false); |
| 31 | const heroPath = new JSONHeroPath(newPath); |
| 32 | const node = heroPath.first(json); |
| 33 | if (node) { |
| 34 | goToNodeId(newPath, 'pathBar'); |
| 35 | } |
| 36 | }} |
| 37 | /> |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | return ( |
| 42 | <PathBarLink |
| 43 | selectedNodes={selectedNodes} |
| 44 | highlightedNodeId={highlightedNodeId} |
| 45 | enableEdit={() => setIsEditable(true)} |
| 46 | /> |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | export function PathBarText({ selectedNodes, onConfirm }: { selectedNodes: ColumnViewNode[], onConfirm: (newPath: string) => void; }) { |
| 51 | const [path, setPath] = useState(''); |
nothing calls this directly
no test coverage detected