|
5 | 5 | QueryClientProvider, |
6 | 6 | } from '@tanstack/react-query' |
7 | 7 | import { useApiModels } from '@/api' |
8 | | -import LineageFlowProvider from '@/components/graph/context' |
| 8 | +import LineageFlowProvider, { useLineageFlow } from '@/components/graph/context' |
9 | 9 | import { ModelLineage } from '@/components/graph/ModelLineage' |
10 | 10 | import { useVSCode } from '@/hooks/vscode' |
11 | 11 | import React from 'react' |
@@ -108,9 +108,39 @@ export function LineageComponentFromWeb({ |
108 | 108 | handleError={handleError} |
109 | 109 | models={models} |
110 | 110 | showControls={false} |
111 | | - > |
112 | | - <ModelLineage model={model} /> |
| 111 | + > <UpdateLineageFocus> |
| 112 | + <ModelLineage model={model} /> |
| 113 | + </UpdateLineageFocus> |
113 | 114 | </LineageFlowProvider> |
114 | 115 | </div> |
115 | 116 | ) |
116 | 117 | } |
| 118 | + |
| 119 | +export function UpdateLineageFocus({ children }: { children: React.ReactNode }) { |
| 120 | + const lineageFlow = useLineageFlow() |
| 121 | + |
| 122 | + React.useEffect(() => { |
| 123 | + const handleMessage = (event: MessageEvent) => { |
| 124 | + // Ensure the message is from VSCode |
| 125 | + if (event.data && event.data.key === 'vscode_send') { |
| 126 | + const payload = event.data.payload |
| 127 | + switch (payload.key) { |
| 128 | + case 'changeFocusOnFile': |
| 129 | + console.log('Changing focus to file:', payload.payload.path) |
| 130 | + // Implement your focus change logic here |
| 131 | + // TODO NEED TO PASS THE FQN of the model not the path |
| 132 | + lineageFlow.setMainNode(payload.payload.path) |
| 133 | + break |
| 134 | + default: |
| 135 | + console.error('Unhandled message type in lineage page:', payload.key) |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + window.addEventListener('message', handleMessage) |
| 140 | + return () => { |
| 141 | + window.removeEventListener('message', handleMessage) |
| 142 | + } |
| 143 | + }, []) |
| 144 | + |
| 145 | + return children |
| 146 | +} |
0 commit comments