diff --git a/frontend/public/index.html b/frontend/public/index.html
index c7c1060d..61a285e5 100644
--- a/frontend/public/index.html
+++ b/frontend/public/index.html
@@ -7,9 +7,9 @@
{
+ 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,
@@ -92,7 +98,13 @@ export function CRUDModal({
}
return (
- onClose()}>
+ onClose()}
+ >
- 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);
+ }}
>
{mode === "EDIT" ? "Update" : "Create"}
diff --git a/frontend/src/components/widgets/modals/CreateColumnModal.tsx b/frontend/src/components/widgets/modals/CreateColumnModal.tsx
new file mode 100644
index 00000000..231bd886
--- /dev/null
+++ b/frontend/src/components/widgets/modals/CreateColumnModal.tsx
@@ -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 = ({
+ open,
+ onClose,
+ onSubmit,
+}) => {
+ const [objData, setObjData] = useState({});
+
+ const {
+ name,
+ query,
+ matchText,
+ outputType,
+ limitToLabel,
+ instructions,
+ agentic,
+ languageModelId,
+ } = objData;
+
+ const handleChange = (
+ event: React.ChangeEvent,
+ data: TextAreaProps | InputOnChangeData,
+ name: string
+ ) => {
+ setObjData({ ...objData, [name]: data.value });
+ };
+
+ const handleSubmit = () => {
+ console.log("Submit data", objData);
+ onSubmit(objData);
+ };
+
+ return (
+
+ "Create a New Column"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ setObjData({
+ ...objData,
+ agentic: data.checked || false,
+ })
+ }
+ />
+
+
+
+
+
+ setObjData({ ...objData, limitToLabel: value })
+ }
+ style={{ minWidth: "50vw important!" }}
+ />
+
+
+
+
+
+
+
+
+
+ );
+};
diff --git a/frontend/src/components/widgets/modals/EditExtractModal.tsx b/frontend/src/components/widgets/modals/EditExtractModal.tsx
index b95e1d93..204f5649 100644
--- a/frontend/src/components/widgets/modals/EditExtractModal.tsx
+++ b/frontend/src/components/widgets/modals/EditExtractModal.tsx
@@ -5,15 +5,29 @@ import {
Button,
Modal,
} from "semantic-ui-react";
-import { ExtractType } from "../../../graphql/types";
-import { useQuery } from "@apollo/client";
+import {
+ ColumnType,
+ DatacellType,
+ DocumentType,
+ ExtractType,
+} from "../../../graphql/types";
+import { useMutation, useQuery } from "@apollo/client";
import {
RequestGetExtractOutput,
- GetExtractsInput,
REQUEST_GET_EXTRACT,
RequestGetExtractInput,
} from "../../../graphql/queries";
import { DataGrid } from "../../../extracts/datagrid/DataGrid";
+import { useEffect, useState } from "react";
+import {
+ REQUEST_ADD_DOC_TO_EXTRACT,
+ REQUEST_REMOVE_DOC_FROM_EXTRACT,
+ RequestAddDocToExtractInputType,
+ RequestAddDocToExtractOutputType,
+ RequestRemoveDocFromExtractInputType,
+ RequestRemoveDocFromExtractOutputType,
+} from "../../../graphql/mutations";
+import { toast } from "react-toastify";
interface EditExtractModalProps {
extract: ExtractType | null;
@@ -26,21 +40,107 @@ export const EditExtractModal = ({
extract,
toggleModal,
}: EditExtractModalProps) => {
- const { loading, error, data, refetch } = useQuery<
- RequestGetExtractOutput,
- RequestGetExtractInput
- >(REQUEST_GET_EXTRACT, {
- variables: {
- id: extract ? extract.id : "",
+ const [cells, setCells] = useState([]);
+ const [rows, setRows] = useState([]);
+ const [columns, setColumns] = useState([]);
+
+ const [addDocsToExtract, { loading: add_docs_loading, data: add_docs_data }] =
+ useMutation<
+ RequestAddDocToExtractOutputType,
+ RequestAddDocToExtractInputType
+ >(REQUEST_ADD_DOC_TO_EXTRACT, {
+ onCompleted: (data) => {
+ console.log("Add data to ", data);
+ setRows((old_rows) => [
+ ...old_rows,
+ ...(data.addDocsToExtract.objs as DocumentType[]),
+ ]);
+ toast.success("SUCCESS! Added docs to extract.");
+ },
+ onError: (err) => {
+ toast.error("ERROR! Could not add docs to extract.");
+ },
+ });
+
+ const handleAddDocIdsToExtract = (
+ extractId: string,
+ documentIds: string[]
+ ) => {
+ addDocsToExtract({
+ variables: {
+ extractId,
+ documentIds,
+ },
+ });
+ };
+
+ const [
+ removeDocsFromExtract,
+ { loading: remove_docs_loading, data: remove_docs_data },
+ ] = useMutation<
+ RequestRemoveDocFromExtractOutputType,
+ RequestRemoveDocFromExtractInputType
+ >(REQUEST_REMOVE_DOC_FROM_EXTRACT, {
+ onCompleted: (data) => {
+ toast.success("SUCCESS! Removed docs from extract.");
+ console.log("Removed docs and return data", data);
+ setRows((old_rows) =>
+ old_rows.filter(
+ (item) => !data.removeDocsFromExtract.idsRemoved.includes(item.id)
+ )
+ );
+ },
+ onError: (err) => {
+ toast.error("ERROR! Could not remove docs from extract.");
},
});
+ const handleRemoveDocIdsFromExtract = (
+ extractId: string,
+ documentIds: string[]
+ ) => {
+ removeDocsFromExtract({
+ variables: {
+ extractId,
+ documentIdsToRemove: documentIds,
+ },
+ });
+ };
+
+ const {
+ loading,
+ error,
+ data: extract_data,
+ refetch,
+ } = useQuery(
+ REQUEST_GET_EXTRACT,
+ {
+ variables: {
+ id: extract ? extract.id : "",
+ },
+ }
+ );
+
+ useEffect(() => {
+ if (extract) {
+ refetch();
+ }
+ }, [extract]);
+
+ useEffect(() => {
+ if (extract_data) {
+ const { fullDatacellList, fullDocumentList, fieldset } =
+ extract_data.extract;
+ setCells(fullDatacellList ? fullDatacellList : []);
+ setRows(fullDocumentList ? fullDocumentList : []);
+ setColumns(fieldset?.fullColumnList ? fieldset.fullColumnList : []);
+ }
+ }, [extract_data]);
+
if (!extract || !extract.id) {
return <>>;
}
- console.log("Extract", data);
-
return (
Editing Extract {extract.name}
-
+