Skip to content

Commit

Permalink
Merge branch 'kg-updates'
Browse files Browse the repository at this point in the history
* kg-updates:
  Updated knowledge graph state management
  Better opening of selector
  Fixed entity styles
  • Loading branch information
davenquinn committed Oct 30, 2024
2 parents 5d10c70 + 8d8cf7d commit bdfea55
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 75 deletions.
21 changes: 18 additions & 3 deletions pages/integrations/xdd/extractions/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ export function ModelInfo({ data }) {
return h("p.model-name", ["Model: ", h("code.bp5-code", data.name)]);
}

export function EntityTag({ data, highlighted = true, active = false }) {
export function EntityTag({
data,
highlighted = true,
active = false,
onClickType,
}) {
const { name, type, match } = data;
const className = classNames(
{
Expand All @@ -130,8 +135,18 @@ export function EntityTag({ data, highlighted = true, active = false }) {
return h(Tag, { style, className }, [
h("span.entity-name", name),
" ",
h("code.entity-type.bp5-code", type.name),
h(Match, { data: match }),
h(
"code.entity-type.bp5-code",
{
onClick(evt) {
if (active && onClickType != null) {
onClickType(type);
evt.stopPropagation();
}
},
},
[type.name, h(Match, { data: match })]
),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion pages/integrations/xdd/extractions/lib/main.module.sass
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

.entity
margin: 0.2em 0 0.5em

padding-right: 3px
1 change: 1 addition & 0 deletions pages/integrations/xdd/feedback/+title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const title = "Feedback";
30 changes: 22 additions & 8 deletions pages/integrations/xdd/feedback/@sourceTextID/+Page.client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import h from "@macrostrat/hyper";
import { ContentPage } from "~/layouts";
import h from "./lib/feedback.module.sass";
import { ContentPage, FullscreenPage } from "~/layouts";
import { PageBreadcrumbs } from "~/components";
import { usePageContext } from "vike-react/usePageContext";
import { enhanceData } from "../../extractions/lib";
Expand All @@ -10,8 +10,16 @@ import {
} from "../../extractions/lib/data-service";
import { FeedbackComponent } from "./lib";
import { Intent, NonIdealState, OverlaysProvider } from "@blueprintjs/core";
import { ErrorBoundary, Pagination } from "@macrostrat/ui-components";
import {
Box,
ErrorBoundary,
FlexCol,
FlexRow,
Pagination,
Spacer,
} from "@macrostrat/ui-components";
import { useState } from "react";
import { AuthStatus } from "@macrostrat/auth-components";

/**
* Get a single text window for feedback purposes
Expand All @@ -20,10 +28,16 @@ import { useState } from "react";
export function Page() {
return h(
OverlaysProvider,
h(ContentPage, [
h(PageBreadcrumbs),
h("h1", "Feedback"),
h(ExtractionIndex),
h(FullscreenPage, [
h("div.feedback-main", [
h(PageBreadcrumbs),
h(FlexRow, { alignItems: "center" }, [
h("h1", "Feedback"),
h(Spacer),
h(AuthStatus),
]),
h(ExtractionIndex),
]),
])
);
}
Expand Down Expand Up @@ -57,7 +71,7 @@ function MultiFeedbackInterface({ data, models, entityTypes }) {
const currentData = data[ix];
const count = data.length;

return h("div.feedback", [
return h("div.feedback-interface", [
h.if(data.length > 1)([
h(NonIdealState, {
icon: "warning-sign",
Expand Down
38 changes: 34 additions & 4 deletions pages/integrations/xdd/feedback/@sourceTextID/lib/edit-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { TreeData } from "./types";
import { Dispatch, useCallback, useReducer } from "react";
import {
createContext,
Dispatch,
useCallback,
useContext,
useReducer,
} from "react";
import update, { Spec } from "immutability-helper";
import { EntityType } from "#/integrations/xdd/extractions/lib/data-service";
import { knowledgeGraphAPIURL } from "@macrostrat-web/settings";
Expand All @@ -12,6 +18,7 @@ interface TreeState {
entityTypesMap: Map<number, EntityType>;
selectedEntityType: EntityType;
lastInternalId: number;
isSelectingEntityType: boolean;
}

type TextRange = {
Expand All @@ -37,6 +44,8 @@ type TreeAction =
| { type: "toggle-node-selected"; payload: { ids: number[] } }
| { type: "create-node"; payload: TextRange }
| { type: "select-entity-type"; payload: EntityType }
| { type: "toggle-entity-type-selector"; payload?: boolean | null }
| { type: "deselect" }
| { type: "reset" };

export type TreeDispatch = Dispatch<TreeAction | TreeAsyncAction>;
Expand All @@ -55,6 +64,7 @@ export function useUpdatableTree(
entityTypesMap: entityTypes,
selectedEntityType: type,
lastInternalId: 0,
isSelectingEntityType: false,
});

const handler = useCallback(
Expand All @@ -72,6 +82,16 @@ export function useUpdatableTree(

const AppToaster = Toaster.create();

export const TreeDispatchContext = createContext<TreeDispatch | null>(null);

export function useTreeDispatch() {
const dispatch = useContext(TreeDispatchContext);
if (dispatch == null) {
throw new Error("No dispatch context available");
}
return dispatch;
}

async function treeActionHandler(
action: TreeAsyncAction | TreeAction
): Promise<TreeAction> {
Expand All @@ -93,7 +113,6 @@ async function treeActionHandler(
},
body: JSON.stringify(data),
});
console.log(response);
if (!response.ok) {
throw new Error("Failed to save model information");
}
Expand All @@ -117,6 +136,7 @@ async function treeActionHandler(
}

function treeReducer(state: TreeState, action: TreeAction) {
console.log(action);
switch (action.type) {
case "move-node":
// For each node in the tree, if the node is in the dragIds, remove it from the tree and collect it
Expand Down Expand Up @@ -160,8 +180,9 @@ function treeReducer(state: TreeState, action: TreeAction) {
),
};
case "select-node":
return { ...state, selectedNodes: action.payload.ids };

const { ids } = action.payload;
return { ...state, selectedNodes: ids };
// otherwise fall through to toggle-node-selected for a single ID
case "toggle-node-selected":
const nodesToAdd = action.payload.ids.filter(
(id) => !state.selectedNodes.includes(id)
Expand All @@ -188,6 +209,13 @@ function treeReducer(state: TreeState, action: TreeAction) {
selectedNodes: [newId],
lastInternalId: newId,
};

/** Entity type selection */
case "toggle-entity-type-selector":
return {
...state,
isSelectingEntityType: action.payload ?? !state.isSelectingEntityType,
};
case "select-entity-type": {
// For each selected node, update the type
let newTree2 = state.tree;
Expand All @@ -205,6 +233,8 @@ function treeReducer(state: TreeState, action: TreeAction) {
selectedEntityType: action.payload,
};
}
case "deselect":
return { ...state, selectedNodes: [] };
case "reset":
return {
...state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

.entity-panel
position: relative
padding: 1em

.control-panel
max-width: 15em
Expand All @@ -23,3 +22,31 @@
right: 1em
padding: 0.2em 0.5em


.feedback-main
display: flex
flex-direction: column
max-width: 70em
margin: 0 auto
position: relative
max-height: 100%

.feedback-interface
display: flex
flex-direction: column
flex: 1
min-height: 100px


.entity-panel
flex: 1
min-height: 100px
padding: 1em
background: var(--panel-secondary-background-color)
border-radius: 4px
// Inset box shadow
box-shadow: 0 0 0 1px var(--panel-border-color) inset

.selection-tree
margin: -1em 0
padding: 1em 0
Loading

0 comments on commit bdfea55

Please sign in to comment.