From 5d10c7058fb989ecc7860aff98a92c28e97746b8 Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Wed, 23 Oct 2024 12:39:24 -0500 Subject: [PATCH] Added ability to push feedback to server --- packages/settings/index.ts | 5 ++++ .../feedback/@sourceTextID/lib/edit-state.ts | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/packages/settings/index.ts b/packages/settings/index.ts index d0c79280..55a50260 100644 --- a/packages/settings/index.ts +++ b/packages/settings/index.ts @@ -42,6 +42,11 @@ export const postgrestPrefix = getRuntimeConfig( apiDomain + "/api/pg" ); +export const knowledgeGraphAPIURL = getRuntimeConfig( + "XDD_KNOWLEDGE_GRAPH_API_URL", + apiDomain + "/api/knowledge-graph" +); + export const macrostratInstance = getRuntimeConfig("MACROSTRAT_INSTANCE"); export const elevationLayerURL = getRuntimeConfig("ELEVATION_LAYER_URL"); diff --git a/pages/integrations/xdd/feedback/@sourceTextID/lib/edit-state.ts b/pages/integrations/xdd/feedback/@sourceTextID/lib/edit-state.ts index 52513ea3..ff68d39d 100644 --- a/pages/integrations/xdd/feedback/@sourceTextID/lib/edit-state.ts +++ b/pages/integrations/xdd/feedback/@sourceTextID/lib/edit-state.ts @@ -2,6 +2,8 @@ import { TreeData } from "./types"; import { Dispatch, useCallback, useReducer } from "react"; import update, { Spec } from "immutability-helper"; import { EntityType } from "#/integrations/xdd/extractions/lib/data-service"; +import { knowledgeGraphAPIURL } from "@macrostrat-web/settings"; +import { Toaster } from "@blueprintjs/core"; interface TreeState { initialTree: TreeData[]; @@ -68,6 +70,8 @@ export function useUpdatableTree( return [state, handler]; } +const AppToaster = Toaster.create(); + async function treeActionHandler( action: TreeAsyncAction | TreeAction ): Promise { @@ -81,6 +85,31 @@ async function treeActionHandler( ); console.log(JSON.stringify(data, null, 2)); + try { + const response = await fetch(knowledgeGraphAPIURL + "/record_run", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); + console.log(response); + if (!response.ok) { + throw new Error("Failed to save model information"); + } + AppToaster.show({ + message: "Model information saved", + intent: "success", + }); + } catch (e) { + // Show the error in the toaster + console.error(e); + AppToaster.show({ + message: "Failed to save model information", + intent: "danger", + }); + } + return null; default: return action;