Skip to content

Commit

Permalink
fix: lineage render
Browse files Browse the repository at this point in the history
  • Loading branch information
saravmajestic committed Oct 24, 2024
1 parent f182728 commit 8519f62
Showing 1 changed file with 24 additions and 33 deletions.
57 changes: 24 additions & 33 deletions webview_panels/src/modules/lineage/LineageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import DemoButton from "./components/demo/DemoButton";

const LineageView = (): JSX.Element | null => {
const {
state: { theme },
state: { theme, isComponentsApiInitialized },
} = useAppContext();

const [isApiHelperInitialized, setIsApiHelperInitialized] = useState(false);
Expand All @@ -28,32 +28,14 @@ const LineageView = (): JSX.Element | null => {
MissingLineageMessage | undefined
>();

const render = (
_data: {
node?: Table;
aiEnabled: boolean;
missingLineageMessage?: MissingLineageMessage;
} & StaticLineageProps,
) => {
panelLogger.log("thisisiit", "render");
setMissingLineageMessage(_data.missingLineageMessage);
// const event = new CustomEvent("renderStartNode", {
// detail: data,
// });
// document.dispatchEvent(event);
setRenderNode(_data);
useEffect(() => {
if (!isComponentsApiInitialized) {
return;
}
panelLogger.info("LineageView updating components api helper");
// @ts-expect-error TODO: add type generic for executeRequestInSync
ApiHelper.get = async (url: string, data?: Record<string, unknown>) => {
panelLogger.log("thisisiit", "ApiHelper.get", url, data);
switch (url) {
case "init": {
const event = new CustomEvent("renderStartNode", {
detail: _data,
});
document.dispatchEvent(event);
return;
}
case "upstreamTables":
case "downstreamTables":
case "getExposureDetails":
Expand All @@ -62,6 +44,7 @@ const LineageView = (): JSX.Element | null => {
case "sendFeedback":
case "getLineageSettings":
case "persistLineageSettings":
case "init":
case "openFile":
case "openChat":
case "showInfoNotification":
Expand All @@ -76,6 +59,21 @@ const LineageView = (): JSX.Element | null => {
}
};
setIsApiHelperInitialized(true);
}, [isComponentsApiInitialized]);

const render = (
data: {
node?: Table;
aiEnabled: boolean;
missingLineageMessage?: MissingLineageMessage;
} & StaticLineageProps,
) => {
setMissingLineageMessage(data.missingLineageMessage);
const event = new CustomEvent("renderStartNode", {
detail: data,
});
document.dispatchEvent(event);
setRenderNode(data);
};

const columnLineage = ({ event }: { event: CllEvents }) => {
Expand All @@ -97,11 +95,6 @@ const LineageView = (): JSX.Element | null => {
(
event: MessageEvent<{ command: string; args: Record<string, unknown> }>,

Check warning

Code scanning / CodeQL

Missing origin verification in `postMessage` handler Medium

Postmessage handler has no origin check.
) => {
if (!event.origin.startsWith("vscode-webview://")) {
panelLogger.debug("invalid message ", event);
return;
}

panelLogger.log("lineage:message -> ", JSON.stringify(event.data));
const { command, args } = event.data;

Expand All @@ -119,14 +112,12 @@ const LineageView = (): JSX.Element | null => {
document.documentElement.classList.add(styles.lineageBody);
executeRequestInAsync("init", {});
}, []);
panelLogger.log("thisisiit", renderNode);

if (!isApiHelperInitialized) {
if (!isApiHelperInitialized || !renderNode) {
return null;
}

// const lineageType = renderNode.details ? "sql" : "dynamic";
const lineageType = "dynamic" as "dynamic" | "sql";
const lineageType = renderNode.details ? "sql" : "dynamic";

return (
<div className={styles.lineageView}>
Expand All @@ -143,7 +134,7 @@ const LineageView = (): JSX.Element | null => {
<div className={styles.lineageWrap}>
<Lineage
theme={theme}
dynamicLineage={{ aiEnabled: true }}
dynamicLineage={renderNode}
lineageType={lineageType}
sqlLineage={
lineageType === "sql"
Expand Down

0 comments on commit 8519f62

Please sign in to comment.