From af7128e7142e971b40b3de94597a612e440c785f Mon Sep 17 00:00:00 2001 From: Austin Akers Date: Mon, 16 Dec 2024 23:01:59 -0800 Subject: [PATCH 1/5] fixed duplicate api call bug for describe_table --- .../instance/browse/BrowseDatatable.js | 6 +++-- src/components/instance/browse/index.js | 25 +++---------------- src/functions/instance/getTableData.js | 4 +++ 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/components/instance/browse/BrowseDatatable.js b/src/components/instance/browse/BrowseDatatable.js index 6fac83120..ea6cee0e8 100644 --- a/src/components/instance/browse/BrowseDatatable.js +++ b/src/components/instance/browse/BrowseDatatable.js @@ -18,7 +18,7 @@ let controller; let controller2; let controller3; -function BrowseDatatable({ tableState, setTableState, activeTable, tableDescriptionAttributes }) { +function BrowseDatatable({ tableState, setTableState, activeTable }) { const navigate = useNavigate(); const { compute_stack_id, schema, table, customer_id } = useParams(); const auth = useStoreState(instanceState, (s) => s.auth); @@ -74,6 +74,7 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript hashAttribute, dynamicAttributesFromDataTable, dataTableColumns, + schemaAttributes, error, } = await getTableData({ schema, @@ -114,6 +115,7 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript hashAttribute, dataTableColumns, dynamicAttributesFromDataTable, + schemaAttributes, error, }); } @@ -175,7 +177,7 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript columns={tableState.dataTableColumns || []} data={tableState.tableData || []} error={tableState.error} - tableDescriptionAttributes={tableDescriptionAttributes} + tableDescriptionAttributes={tableState.schemaAttributes} dynamicAttributesFromDataTable={tableState.dynamicAttributesFromDataTable} currentPage={tableState.page} pageSize={tableState.pageSize} diff --git a/src/components/instance/browse/index.js b/src/components/instance/browse/index.js index dda00d0d7..b1c7f4b9f 100644 --- a/src/components/instance/browse/index.js +++ b/src/components/instance/browse/index.js @@ -14,7 +14,7 @@ import EmptyPrompt from '../../shared/EmptyPrompt'; import buildInstanceStructure from '../../../functions/instance/browse/buildInstanceStructure'; import { clearTableDescriptionCache } from '../../../functions/instance/state/describeTableCache'; -const DataTable = lazy(() => import(/* webpackChunkName: "browse-datatable" */ './BrowseDatatable')); +const BrowseDatatable = lazy(() => import(/* webpackChunkName: "browse-datatable" */ './BrowseDatatable')); const EntityManager = lazy(() => import(/* webpackChunkName: "browse-entitymanager" */ './EntityManager')); const JSONEditor = lazy(() => import(/* webpackChunkName: "browse-jsonviewer" */ './JSONEditor')); const CSVUpload = lazy(() => import(/* webpackChunkName: "browse-csvupload" */ './CsvUpload')); @@ -40,7 +40,7 @@ function NoPrimaryKeyMessage({ table }) { No Primary Key - + The table {`'${table}'`} does not have a primary key. The HarperDB Studio does not currently support tables without a primary key defined. Please see the{' '} @@ -85,20 +85,6 @@ function BrowseIndex() { buildInstanceStructure({ auth, url }); }; - useEffect(() => { - const fetchDescribeTable = async () => { - if (table) { - try { - const result = await describeTable({ auth, url, schema, table }); - setTableDescription(result); - } catch (e) { - addError(e); - } - } - }; - fetchDescribeTable(); - }, [auth, url, schema, table]); - useEffect(() => { if (tableDescription) { setHasHashAttr(Boolean(tableDescription.hash_attribute)); @@ -198,12 +184,7 @@ function BrowseIndex() { ) : schema && table && action && entities.activeTable ? ( ) : schema && table && entities.activeTable ? ( - + ) : schema && table && !hasHashAttr ? ( ) : ( diff --git a/src/functions/instance/getTableData.js b/src/functions/instance/getTableData.js index d23e29cd9..919d21a80 100644 --- a/src/functions/instance/getTableData.js +++ b/src/functions/instance/getTableData.js @@ -29,6 +29,7 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p let newData = []; let allAttributes = false; let hashAttribute = false; + let schemaAttributes = []; let get_attributes = ['*']; let dynamicAttributesFromDataTable = []; const offset = page * pageSize; @@ -46,6 +47,7 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p } const { record_count, attributes, hash_attribute } = result; + schemaAttributes = attributes; allAttributes = attributes.map((a) => a.attribute); if (hash_attribute === undefined) { hashAttribute = '$id'; @@ -55,6 +57,7 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p } newTotalRecords = record_count; + schemaAttributes = attributes; newTotalPages = newTotalRecords && Math.ceil(newTotalRecords / pageSize); } catch (e) { fetchError = e.message; @@ -124,6 +127,7 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p newTotalRecords, newTotalPages, hashAttribute, + schemaAttributes, dataTableColumns, error: fetchError === 'table' ? `You are not authorized to view ${schema}:${table}` : fetchError, dynamicAttributesFromDataTable, From a9dda643fa14fa9ba6aff88735aa613eb0d936a0 Mon Sep 17 00:00:00 2001 From: Austin Akers Date: Tue, 17 Dec 2024 14:23:34 -0800 Subject: [PATCH 2/5] removed tableDescription state and replace it with tableState from Store --- src/components/instance/browse/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/instance/browse/index.js b/src/components/instance/browse/index.js index b1c7f4b9f..3d16a311d 100644 --- a/src/components/instance/browse/index.js +++ b/src/components/instance/browse/index.js @@ -5,7 +5,6 @@ import { useStoreState } from 'pullstate'; import { ErrorBoundary } from 'react-error-boundary'; import instanceState from '../../../functions/state/instanceState'; -import describeTable from '../../../functions/api/instance/describeTable'; import ErrorFallback from '../../shared/ErrorFallback'; import addError from '../../../functions/api/lms/addError'; @@ -68,7 +67,6 @@ function BrowseIndex() { const structure = useStoreState(instanceState, (s) => s.structure); const [entities, setEntities] = useState({ schemas: [], tables: [], activeTable: false }); const [tableState, setTableState] = useState(defaultTableState); - const [tableDescription, setTableDescription] = useState(null); const baseUrl = `/o/${customer_id}/i/${compute_stack_id}/browse`; const showForm = instanceAuths[compute_stack_id]?.super || instanceAuths[compute_stack_id]?.structure === true; const showTableForm = @@ -86,10 +84,10 @@ function BrowseIndex() { }; useEffect(() => { - if (tableDescription) { - setHasHashAttr(Boolean(tableDescription.hash_attribute)); + if (tableState) { + setHasHashAttr(Boolean(tableState.hashAttribute)); } - }, [tableDescription]); + }, [tableState]); const validate = () => { if (structure) { From c8e8cf21d9e95bec299c145acfbb9c843de6360e Mon Sep 17 00:00:00 2001 From: Austin Akers Date: Tue, 17 Dec 2024 14:44:36 -0800 Subject: [PATCH 3/5] only sync instance structure when navigating to a new table --- src/components/instance/browse/EntityManagerRow.js | 14 ++++++++++---- src/components/instance/browse/index.js | 6 ------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/instance/browse/EntityManagerRow.js b/src/components/instance/browse/EntityManagerRow.js index 81e210ba7..1a46c27d6 100644 --- a/src/components/instance/browse/EntityManagerRow.js +++ b/src/components/instance/browse/EntityManagerRow.js @@ -58,6 +58,9 @@ function EntityManagerRow({ item, itemType, baseUrl, isActive, toggleDropItem, i toggleConfirmDropItem(false); }; + const syncInstanceStructure = () => { + buildInstanceStructure({ auth, url }); + }; const handleSetActive = () => isActive || isDropping || isConfirmingDropItem ? false : navigate(`${baseUrl}/${item}`); @@ -66,7 +69,10 @@ function EntityManagerRow({ item, itemType, baseUrl, isActive, toggleDropItem, i key={item} title={`View${isActive ? 'ing' : ''} ${itemType} ${item}`} className={`item-row ${isActive ? 'active' : ''}`} - onClick={handleSetActive} + onClick={() => { + handleSetActive(); + syncInstanceStructure(); + }} tabIndex="0" > @@ -86,7 +92,7 @@ function EntityManagerRow({ item, itemType, baseUrl, isActive, toggleDropItem, i title={`confirm drop ${itemType} ${item}`} onClick={confirmItemForDrop} > - + ) : isDropping ? ( @@ -106,7 +112,7 @@ function EntityManagerRow({ item, itemType, baseUrl, isActive, toggleDropItem, i title={`Drop ${itemType} ${item}`} onClick={selectItemForDrop} > - + ) : isActive ? (