From 3eba2b2677f110956d1398b3db6fa1a20b437de5 Mon Sep 17 00:00:00 2001 From: eireland Date: Mon, 18 Mar 2024 17:02:10 -0700 Subject: [PATCH] Updates table after sort. Only works for flat tables. WIP heirarchical tables. --- src/hooks/useCodapState.tsx | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/hooks/useCodapState.tsx b/src/hooks/useCodapState.tsx index 4a65300..fe4eefb 100644 --- a/src/hooks/useCodapState.tsx +++ b/src/hooks/useCodapState.tsx @@ -91,7 +91,7 @@ export const useCodapState = () => { const handleDataContextChangeNotice = (iMessage: any) => { if (iMessage.resource === `dataContextChangeNotice[${selectedDataSetName}]`) { const theValues = iMessage.values; - console.log("***** in handleDataContextChangeNotice theValues", theValues.operation); + console.log("***** in handleDataContextChangeNotice theValues", theValues); switch (theValues.operation) { case `selectCases`: case `updateCases`: @@ -112,7 +112,7 @@ export const useCodapState = () => { refreshDataSetInfo(); break; case `moveCases`: - handleUpdateTable(); + refreshTable(); break; case "createCases": case "createItems": @@ -127,10 +127,8 @@ export const useCodapState = () => { handleSetDataSet(selectedDataSetName); }; - const handleUpdateTable = () => { - console.log("***** in handleUpdateTable"); - setNumUpdates(numUpdates + 1); - refreshDataSetInfo(); + const refreshTable = () => { + handleUpdateTable(); }; const setUpNotifications = async () => { @@ -141,13 +139,34 @@ export const useCodapState = () => { setUpNotifications(); } - }, [numUpdates, selectedDataSetName]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [selectedDataSetName]); const updateCollections = useCallback(async () => { const colls = await getDataSetCollections(selectedDataSet.name); setCollections(colls); }, [selectedDataSet]); + const handleUpdateTable = useCallback(async() => { + console.log("***** in handleUpdateTable selectedDataSetName", selectedDataSetName); + + const fetchCases = async () => { + const itemRes: any = await codapInterface.sendRequest({ + "action": "get", + "resource": `dataContext[${selectedDataSetName}].collection[Mammals].caseSearch[*]` + }); + console.log("***** in fetchCases itemRes", itemRes); + const fetchedItems = itemRes.values.map((item: any) => item.values); + setItems(fetchedItems); + }; + + // if (dsName) { + fetchCases(); + // } + // setNumUpdates(numUpdates + 1); + // refreshDataSetInfo(); + }, [selectedDataSetName]); + useEffect(() => { if (selectedDataSet) { updateCollections();