Skip to content

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.

fix: widget fetch url

AykutSarac1445ba86d4f8
diff --git a/src/pages/widget.tsx b/src/pages/widget.tsx
index 6bfa2655..04e709b4 100644
--- a/src/pages/widget.tsx
+++ b/src/pages/widget.tsx
@@ -23,18 +23,18 @@ const Graph = dynamic(() => import("src/components/Graph").then(c => c.Graph), {
const WidgetPage = () => {
const { query, push, isReady } = useRouter();
const [theme, setTheme] = React.useState("dark");
- const fetchFile = useFile(state => state.fetchFile);
+ const checkEditorSession = useFile(state => state.checkEditorSession);
const setContents = useFile(state => state.setContents);
const setDirection = useGraph(state => state.setDirection);
const clearGraph = useGraph(state => state.clearGraph);
React.useEffect(() => {
if (isReady) {
- if (typeof query?.json === "string") fetchFile(query.json);
+ if (typeof query?.json === "string") checkEditorSession(query.json, true);
else clearGraph();
window.parent.postMessage(window.frameElement?.getAttribute("id"), "*");
}
- }, [clearGraph, fetchFile, isReady, push, query.json, query.partner]);
+ }, [clearGraph, checkEditorSession, isReady, push, query.json, query.partner]);
React.useEffect(() => {
const handler = (event: EmbedMessage) => {
diff --git a/src/store/useFile.ts b/src/store/useFile.ts
index d5b201af..1e9869ee 100644
--- a/src/store/useFile.ts
+++ b/src/store/useFile.ts
@@ -36,7 +36,7 @@ interface JsonActions {
clear: () => void;
setFile: (fileData: File) => void;
setJsonSchema: (jsonSchema: object | null) => void;
- checkEditorSession: (url: Query) => void;
+ checkEditorSession: (url: Query, widget?: boolean) => void;
}
export type File = {
@@ -155,15 +155,16 @@ const useFile = create<FileStates & JsonActions>()((set, get) => ({
toast.error("Failed to fetch document from URL!");
}
},
- checkEditorSession: url => {
+ checkEditorSession: (url, widget) => {
if (url && typeof url === "string") {
if (isURL(url)) return get().fetchUrl(url);
return get().fetchFile(url);
}
+ let contents = defaultJson;
const sessionContent = sessionStorage.getItem("content") as string | null;
const format = sessionStorage.getItem("format") as FileFormat | null;
- const contents = sessionContent ?? defaultJson;
+ if (sessionContent && !widget) contents = sessionContent;
if (format) set({ format });
get().setContents({ contents, hasChanges: false });