Skip to content

Commit

Permalink
Added ability to push feedback to server
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Oct 23, 2024
1 parent 59adac7 commit 5d10c70
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
29 changes: 29 additions & 0 deletions pages/integrations/xdd/feedback/@sourceTextID/lib/edit-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -68,6 +70,8 @@ export function useUpdatableTree(
return [state, handler];
}

const AppToaster = Toaster.create();

async function treeActionHandler(
action: TreeAsyncAction | TreeAction
): Promise<TreeAction> {
Expand All @@ -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;
Expand Down

0 comments on commit 5d10c70

Please sign in to comment.