From e4b955871f72c5871fc9e32beab1b265f86c3c25 Mon Sep 17 00:00:00 2001 From: Austin Akers Date: Wed, 20 Nov 2024 20:03:54 -0800 Subject: [PATCH] Revert "[v4.8.0] Create Dynamic Columns from Dynamic Data & Form Field Fixes" --- package.json | 2 +- .../styles/components/_react-table.scss | 7 +-- src/components/auth/SignUp.js | 3 -- .../instance/browse/BrowseDatatable.js | 7 +-- src/components/instance/browse/index.js | 30 +++++------- src/components/shared/DataTable.js | 6 +-- src/components/shared/DataTableHeader.js | 47 ++++++------------- src/functions/instance/getTableData.js | 24 +--------- 8 files changed, 35 insertions(+), 91 deletions(-) diff --git a/package.json b/package.json index 86e250cb..3a9ab3bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "harperdb-studio", - "version": "4.8.0", + "version": "4.7.1", "description": "A UI for HarperDB", "deploymentUrl": "studio.harperdb.io", "private": true, diff --git a/src/assets/styles/components/_react-table.scss b/src/assets/styles/components/_react-table.scss index aa272663..18e50438 100755 --- a/src/assets/styles/components/_react-table.scss +++ b/src/assets/styles/components/_react-table.scss @@ -18,11 +18,6 @@ min-width: 100px; white-space: nowrap; - &.disabled-column { - background-color: $lighter-grey-overlay !important; - cursor: not-allowed; - } - &.sorted { &.desc { box-shadow: inset 0 -2px 0 0 $lighter-grey-overlay; @@ -31,6 +26,7 @@ &.asc { box-shadow: inset 0 2px 0 0 $lighter-grey-overlay; } + } } } @@ -133,6 +129,7 @@ } } + .paginator { align-items: center; display: flex; diff --git a/src/components/auth/SignUp.js b/src/components/auth/SignUp.js index 4733dfff..1776acf7 100644 --- a/src/components/auth/SignUp.js +++ b/src/components/auth/SignUp.js @@ -44,7 +44,6 @@ function SignUp() { s.auth); @@ -65,7 +65,7 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript } controller = new AbortController(); controller2 = new AbortController(); - const { newData, newTotalRecords, newTotalPages, newEntityAttributes, hashAttribute, dataTableColumns, dynamicAttributesFromDataTable, error } = await getTableData({ + const { newData, newTotalRecords, newTotalPages, newEntityAttributes, hashAttribute, dataTableColumns, error } = await getTableData({ schema, table, filtered: tableState.filtered, @@ -103,7 +103,6 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript newEntityAttributes, hashAttribute, dataTableColumns, - dynamicAttributesFromDataTable, error, }); } @@ -147,7 +146,6 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript { setTableState({ ...tableState, page: 0, filtered: value }); }} diff --git a/src/components/instance/browse/index.js b/src/components/instance/browse/index.js index 6037fa37..34188dd3 100644 --- a/src/components/instance/browse/index.js +++ b/src/components/instance/browse/index.js @@ -64,13 +64,13 @@ 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 = showForm || (instanceAuths[compute_stack_id]?.structure && instanceAuths[compute_stack_id]?.structure?.includes(schema)); const emptyPromptMessage = showForm - ? `Please ${(schema && entities.tables && !entities.tables.length) || !entities.schemas.length ? 'create' : 'choose'} a - ${schema ? 'table' : `${versionAsFloat >= 4.2 ? 'database' : 'schema'}`}` + ? `Please ${(schema && entities.tables && !entities.tables.length) || !entities.schemas.length ? 'create' : 'choose'} a ${ + schema ? 'table' : `${versionAsFloat >= 4.2 ? 'database' : 'schema'}` + }` : "This user has not been granted access to any tables. A super-user must update this user's role."; const [hasHashAttr, setHasHashAttr] = useState(true); @@ -78,26 +78,18 @@ function BrowseIndex() { buildInstanceStructure({ auth, url }); }; - const fetchDescribeTable = async () => { - if (table) { - try { + const checkForHashAttribute = () => { + async function check() { + if (table) { const result = await describeTable({ auth, url, schema, table }); - setTableDescription(result); - } catch (e) { - addError(e); + setHasHashAttr(Boolean(result.hash_attribute)); } } - }; - useEffect(() => { - fetchDescribeTable(); - }, [auth, url, schema, table]); + check(); + }; - useEffect(() => { - if (tableDescription) { - setHasHashAttr(Boolean(tableDescription.hash_attribute)); - } - }, [tableDescription]); + useEffect(checkForHashAttribute, [auth, url, schema, table]); const validate = () => { if (structure) { @@ -161,7 +153,7 @@ function BrowseIndex() { ) : schema && table && action && entities.activeTable ? ( ) : schema && table && entities.activeTable ? ( - + ) : schema && table && !hasHashAttr ? ( ) : ( diff --git a/src/components/shared/DataTable.js b/src/components/shared/DataTable.js index d7445392..b3b3c451 100644 --- a/src/components/shared/DataTable.js +++ b/src/components/shared/DataTable.js @@ -71,8 +71,6 @@ function DataTable({ onRowClick, sorted, loading, - dynamicAttributesFromDataTable, - tableDescriptionAttributes, manual = false, }) { const { headerGroups, page, rows, prepareRow, state, setAllFilters, canPreviousPage, canNextPage, pageOptions, pageCount, gotoPage, nextPage, previousPage, setPageSize } = @@ -112,8 +110,8 @@ function DataTable({ return ( addError({ error: { message: err.message, componentStack } })} FallbackComponent={ErrorFallback}> -
- +
+ {loading || localLoading ? (
diff --git a/src/components/shared/DataTableHeader.js b/src/components/shared/DataTableHeader.js index ee3a1468..aa2f3374 100644 --- a/src/components/shared/DataTableHeader.js +++ b/src/components/shared/DataTableHeader.js @@ -1,19 +1,8 @@ import React from 'react'; import { Row, Col } from 'reactstrap'; -const DataTableHeader = ({ headerGroups, onSortedChange, sorted, showFilter, dynamicAttributesFromDataTable, tableDescriptionAttributes }) => { - - const isIndexedAttribute = (columnId) => { - let isIndexed = false; - tableDescriptionAttributes.forEach((attr) => { - if (attr.attribute === columnId && (attr.is_primary_key || attr.indexed)) { - isIndexed = true; - } - }); - return isIndexed; - } - - return headerGroups.map((headerGroup) => { +const DataTableHeader = ({ headerGroups, onSortedChange, sorted, showFilter }) => + headerGroups.map((headerGroup) => { const { key, ...rest } = headerGroup.getHeaderGroupProps(); return (
@@ -21,30 +10,24 @@ const DataTableHeader = ({ headerGroups, onSortedChange, sorted, showFilter, dyn {headerGroup.headers.map((column) => ( { - if (!dynamicAttributesFromDataTable.includes(column.id) && isIndexedAttribute(column.id)) { - onSortedChange([{ id: column.id, desc: sorted[0]?.id === column.id ? !sorted[0]?.desc : false }]) - } - }} - className={`${sorted[0]?.id === column.id ? 'sorted' : ''} ${sorted[0]?.desc ? 'desc' : 'asc'} ${column.id.indexOf('hdb-narrow') !== -1 ? 'action' : ''} px-1 ${!dynamicAttributesFromDataTable.includes(column.id) && isIndexedAttribute(column.id) ? '' : 'disabled-column'}`} + onClick={() => onSortedChange([{ id: column.id, desc: sorted[0]?.id === column.id ? !sorted[0]?.desc : false }])} + className={`${sorted[0]?.id === column.id ? 'sorted' : ''} ${sorted[0]?.desc ? 'desc' : 'asc'} ${column.id.indexOf('hdb-narrow') !== -1 ? 'action' : ''} px-1`} >
{column.render('Header')}
))} - { - showFilter && ( - - {headerGroup.headers.map((column) => ( - - {column.render('Filter')} - - ))} - - ) - } -
+ {showFilter && ( + + {headerGroup.headers.map((column) => ( + + {column.render('Filter')} + + ))} + + )} +
); }); -} + export default DataTableHeader; diff --git a/src/functions/instance/getTableData.js b/src/functions/instance/getTableData.js index 8f055fa9..4adeba9f 100644 --- a/src/functions/instance/getTableData.js +++ b/src/functions/instance/getTableData.js @@ -2,21 +2,6 @@ import describeTable from '../api/instance/describeTable'; import searchByValue from '../api/instance/searchByValue'; import searchByConditions from '../api/instance/searchByConditions'; -const getAttributesFromTableData = (tableData, existingAttributes) => { - if (existingAttributes.length >= 8) return []; - const existing = new Map(existingAttributes.map((value, index) => [value, index])); - const extra = new Map(); - for (const dataRow of tableData) { - for (const key of Object.keys(dataRow)) { - if (!existing.has(key)) { - const count = extra.get(key) || 0; - extra.set(key, count + 1); - } - } - } - return Array.from(extra).sort(([, a], [, b]) => b - a).map(([key]) => key).slice(0, 8 - existingAttributes.length); -} - export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, page, auth, url, signal, signal2 }) => { let fetchError = false; let newTotalRecords = 0; @@ -25,7 +10,6 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p let allAttributes = false; let hashAttribute = false; let get_attributes = ['*']; - let dynamicAttributesFromDataTable = []; const offset = page * pageSize; try { @@ -92,12 +76,9 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p } } - dynamicAttributesFromDataTable = getAttributesFromTableData(newData, allAttributes) - allAttributes.push(...dynamicAttributesFromDataTable); - - // Keeps primary key / hash attribute first, and created and updated last. + // sort columns, but keep primary key / hash attribute first, and created and updated last. // NOTE: __created__ and __updated__ might not exist in the schema, only include if they exist. - const orderedColumns = allAttributes.filter((a) => ![hashAttribute, '__createdtime__', '__updatedtime__'].includes(a)) + const orderedColumns = allAttributes.filter((a) => ![hashAttribute, '__createdtime__', '__updatedtime__'].includes(a)).sort(); const newEntityAttributes = orderedColumns.reduce((ac, a) => ({ ...ac, [a]: null }), {}); if (allAttributes.includes('__createdtime__')) orderedColumns.push('__createdtime__'); @@ -116,6 +97,5 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p hashAttribute, dataTableColumns, error: fetchError === 'table' ? `You are not authorized to view ${schema}:${table}` : fetchError, - dynamicAttributesFromDataTable }; };