Skip to content

Commit

Permalink
Good progress on data grid.
Browse files Browse the repository at this point in the history
  • Loading branch information
JSv4 committed Jun 4, 2024
1 parent 56881f5 commit 759fe91
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 141 deletions.
12 changes: 6 additions & 6 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="OpenContracts is an Apache2-licensed document annotation labelling and sharing platform designed to make it
easy to label pdfs and complex natural language documents. Based in part on Allen AI's PAWLs annotator, it's open,
extensible, and designed for teams and collaboration."
content="OpenContracts is an Apache2-licensed document analytics and sharing platform designed to make it
easy to query, analyze and label complex natural language documents. It's open, extensible, and designed for
teams and collaboration."
/>
<meta property="og:type" content="website" key="Type" />
<meta
Expand All @@ -19,9 +19,9 @@
/>
<meta
property="og:description"
content="OpenContracts is an Apache2-licensed document annotation labelling and sharing platform designed to make it
easy to label pdfs and complex natural language documents. Based in part on Allen AI's PAWLs annotator, it's open,
extensible, and designed for teams and collaboration."
content="OpenContracts is an Apache2-licensed document analytics and sharing platform designed to make it
easy to query, analyze and label complex natural language documents. It's open, extensible, and designed for
teams and collaboration."
key="Description"
/>
<meta
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/forms/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const editColumnForm_Schema = {
"Use agentic retrieval of referenced sections and definitions in returned text.",
},
},
required: [],
required: ["name", "outputType"],
};

export const editColumnForm_Ui_Schema = {
Expand Down
36 changes: 26 additions & 10 deletions frontend/src/components/widgets/CRUD/CRUDModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactNode, useEffect, useState } from "react";
import { Button, Modal, Icon } from "semantic-ui-react";
import _ from "lodash";
import _, { update } from "lodash";
import { CRUDWidget } from "./CRUDWidget";
import { CRUDProps, LooseObject } from "../../types";

Expand Down Expand Up @@ -47,17 +47,23 @@ export function CRUDModal({

const can_write = mode !== "VIEW" && (mode === "CREATE" || mode === "EDIT");

// console.log("----------------------------")
// console.log("old_instance", old_instance);
// console.log("instance_obj", instance_obj);
console.log("---- CRUD MODAL ----");
console.log("old_instance", old_instance);
console.log("instance_obj", instance_obj);

useEffect(() => {
console.log("CRUD updated fields obj", updated_fields_obj);
}, [updated_fields_obj]);

useEffect(() => {
setInstanceObj(old_instance ? old_instance : {});
setUpdatedFields({ id: old_instance?.id ? old_instance.id : -1 });
if (old_instance.length >= 0 && old_instance.hasOwnProperty("id")) {
setUpdatedFields({ id: old_instance.id });
}
}, [old_instance]);

const handleModelChange = (updated_fields: LooseObject) => {
// console.log("HandleModelChange: ", updated_fields);
console.log("HandleModelChange: ", updated_fields);
setInstanceObj((instance_obj) => ({ ...instance_obj, ...updated_fields }));
setUpdatedFields((updated_fields_obj) => ({
...updated_fields_obj,
Expand Down Expand Up @@ -92,7 +98,13 @@ export function CRUDModal({
}

return (
<Modal size="large" closeIcon open={open} onClose={() => onClose()}>
<Modal
centered
size="large"
closeIcon
open={open}
onClose={() => onClose()}
>
<Modal.Content scrolling>
<CRUDWidget
mode={mode}
Expand All @@ -118,9 +130,13 @@ export function CRUDModal({
<Button
color="green"
inverted
onClick={() =>
onSubmit(mode === "EDIT" ? updated_fields_obj : instance_obj)
}
onClick={() => {
console.log(
"Submitting",
mode === "EDIT" ? updated_fields_obj : instance_obj
);
onSubmit(mode === "EDIT" ? updated_fields_obj : instance_obj);
}}
>
<Icon name="checkmark" /> {mode === "EDIT" ? "Update" : "Create"}
</Button>
Expand Down
181 changes: 181 additions & 0 deletions frontend/src/components/widgets/modals/CreateColumnModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import React, { useState } from "react";
import {
Modal,
Form,
FormInput,
TextArea,
FormGroup,
FormButton,
FormField,
TextAreaProps,
InputOnChangeData,
Checkbox,
Grid,
Button,
} from "semantic-ui-react";
import { LanguageModelDropdown } from "../selectors/LanguageModelDropdown";
import { LooseObject } from "../../types";

interface CreateColumnModalProps {
open: boolean;
onClose: () => void;
onSubmit: (data: any) => void;
}

export const CreateColumnModal: React.FC<CreateColumnModalProps> = ({
open,
onClose,
onSubmit,
}) => {
const [objData, setObjData] = useState<LooseObject>({});

const {
name,
query,
matchText,
outputType,
limitToLabel,
instructions,
agentic,
languageModelId,
} = objData;

const handleChange = (
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
data: TextAreaProps | InputOnChangeData,
name: string
) => {
setObjData({ ...objData, [name]: data.value });
};

const handleSubmit = () => {
console.log("Submit data", objData);
onSubmit(objData);
};

return (
<Modal open={open} onClose={onClose}>
<Modal.Header>"Create a New Column"</Modal.Header>
<Modal.Content>
<Grid centered divided>
<Grid.Column>
<Grid.Row>
<Form>
<FormGroup>
<FormInput
placeholder="Name"
name="name"
value={name}
onChange={(e, { value }) =>
setObjData({ ...objData, name: value })
}
style={{ minWidth: "50vw important!" }}
/>
<TextArea
rows={6}
name="outputType"
label="Output Type:"
placeholder="str"
value={outputType}
onChange={(
event: React.ChangeEvent<HTMLTextAreaElement>,
data: TextAreaProps
) => setObjData({ ...objData, outputType: data.value })}
/>
<FormField>
<label>Language Model</label>
<LanguageModelDropdown
onChange={(id: string) =>
setObjData({ ...objData, languageModelId: id })
}
languageModelId={languageModelId}
/>
</FormField>
</FormGroup>
</Form>
</Grid.Row>
<Grid.Row>
<Form>
<TextArea
rows={3}
name="query"
label="Query:"
placeholder="What is the title of the document?"
value={query}
onChange={(
event: React.ChangeEvent<HTMLTextAreaElement>,
data: TextAreaProps
) => handleChange(event, data, "query")}
/>
</Form>
<Form>
<TextArea
rows={3}
name="matchText"
placeh
label="Representative Example:"
placeholder="Place example of text containing relevant data here."
value={matchText}
onChange={(
event: React.ChangeEvent<HTMLTextAreaElement>,
data: TextAreaProps
) => handleChange(event, data, "matchText")}
/>
</Form>
<Form>
<TextArea
rows={3}
name="instructions"
placeh
label="Parser Instructions:"
placeholder="Provide detailed instructions for extracting object properties here..."
value={instructions}
onChange={(
event: React.ChangeEvent<HTMLTextAreaElement>,
data: TextAreaProps
) => handleChange(event, data, "matchText")}
/>
</Form>
</Grid.Row>
<Grid.Row>
<Grid columns={2}>
<Grid.Column>
<Grid.Row>
<Checkbox
label="Agentic"
checked={agentic}
onChange={(_, data) =>
setObjData({
...objData,
agentic: data.checked || false,
})
}
/>
</Grid.Row>
</Grid.Column>
<Grid.Column>
<Grid.Row>
<FormInput
placeholder="Label Name To Limit Search To"
name="limitToLabel"
value={limitToLabel}
onChange={(e, { value }) =>
setObjData({ ...objData, limitToLabel: value })
}
style={{ minWidth: "50vw important!" }}
/>
</Grid.Row>
</Grid.Column>
</Grid>
</Grid.Row>
</Grid.Column>
</Grid>
<Button
content="Submit"
style={{ marginTop: "1vh" }}
onClick={handleSubmit}
/>
</Modal.Content>
</Modal>
);
};
Loading

0 comments on commit 759fe91

Please sign in to comment.