From d6595b4701926740c499fc6482df3405a77a391f Mon Sep 17 00:00:00 2001 From: JSv4 Date: Sun, 2 Jun 2024 15:38:34 -0700 Subject: [PATCH] added bunch of mutations and types for new column and row mutations. Also made DataGrid pass typescript checks subbing in some console.log statements for now. --- frontend/src/extracts/datagrid/DataGrid.tsx | 73 ++++++++++++++++++--- frontend/src/graphql/mutations.ts | 43 ++++++++++++ 2 files changed, 108 insertions(+), 8 deletions(-) diff --git a/frontend/src/extracts/datagrid/DataGrid.tsx b/frontend/src/extracts/datagrid/DataGrid.tsx index 20f9dd18..56980d5a 100644 --- a/frontend/src/extracts/datagrid/DataGrid.tsx +++ b/frontend/src/extracts/datagrid/DataGrid.tsx @@ -9,28 +9,42 @@ import { List, Dropdown, } from "semantic-ui-react"; -import { ColumnType, DatacellType, DocumentType } from "../../graphql/types"; +import { + ColumnType, + DatacellType, + DocumentType, + ExtractType, +} from "../../graphql/types"; import { useMutation } from "@apollo/client"; import { + REQUEST_ADD_DOC_TO_EXTRACT, REQUEST_DELETE_COLUMN, + REQUEST_REMOVE_DOC_FROM_EXTRACT, REQUEST_UPDATE_COLUMN, + RemoveDocTypeAnnotationInputType, + RemoveDocTypeAnnotationOutputType, + RequestAddDocToExtractInputType, + RequestAddDocToExtractOutputType, RequestDeleteColumnInputType, RequestDeleteColumnOutputType, + RequestRemoveDocFromExtractInputType, + RequestRemoveDocFromExtractOutputType, RequestUpdateColumnInputType, RequestUpdateColumnOutputType, } from "../../graphql/mutations"; import { toast } from "react-toastify"; interface DataGridProps { + extract: ExtractType; columns: ColumnType[]; rows: DocumentType[]; cells: DatacellType[]; } -export const DataGrid = ({ columns, rows, cells }: DataGridProps) => { +export const DataGrid = ({ columns, rows, cells, extract }: DataGridProps) => { const [isAddingColumn, setIsAddingColumn] = useState(false); const [showAddRowButton, setShowAddRowButton] = useState(false); - const []; + const [openAddRowModal, setOpenAddRowModal] = useState(false); const [ deleteColumn, @@ -70,6 +84,35 @@ export const DataGrid = ({ columns, rows, cells }: DataGridProps) => { } ); + // TODO - I think I need to do something in the cache here... + 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."); + }, + onError: (err) => { + toast.error("ERROR! Could not remove docs from extract."); + }, + }); + + const [addDocsToExtract, { loading: add_docs_loading, data: add_docs_data }] = + useMutation< + RequestAddDocToExtractOutputType, + RequestAddDocToExtractInputType + >(REQUEST_ADD_DOC_TO_EXTRACT, { + onCompleted: (data) => { + toast.success("SUCCESS! Added docs to extract."); + }, + onError: (err) => { + toast.error("ERROR! Could not add docs to extract."); + }, + }); + return (
{ editColumn(column)} + onClick={() => console.log("Edit", column)} /> { style={{ float: "right" }} > - editRow(row)} /> + console.log("Edit row ", row)} + /> removeRow(row.id)} + onClick={() => + removeDocsFromExtract({ + variables: { + extractId: extract.id, + documentIdsToRemove: [row.id], + }, + }) + } /> @@ -169,7 +222,7 @@ export const DataGrid = ({ columns, rows, cells }: DataGridProps) => { alignItems: "center", cursor: "pointer", }} - onClick={addColumn} + onClick={() => console.log("Add row")} >
@@ -188,7 +241,11 @@ export const DataGrid = ({ columns, rows, cells }: DataGridProps) => { alignItems: "center", }} > -