Skip to content

Commit 4ef3c14

Browse files
authored
Merge pull request #422 from HarperDB/revert-420-stage
Revert "[v4.8.0] Create Dynamic Columns from Dynamic Data & Form Field Fixes"
2 parents 3add1b7 + e4b9558 commit 4ef3c14

8 files changed

Lines changed: 35 additions & 91 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "harperdb-studio",
3-
"version": "4.8.0",
3+
"version": "4.7.1",
44
"description": "A UI for HarperDB",
55
"deploymentUrl": "studio.harperdb.io",
66
"private": true,

src/assets/styles/components/_react-table.scss

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
min-width: 100px;
1919
white-space: nowrap;
2020

21-
&.disabled-column {
22-
background-color: $lighter-grey-overlay !important;
23-
cursor: not-allowed;
24-
}
25-
2621
&.sorted {
2722
&.desc {
2823
box-shadow: inset 0 -2px 0 0 $lighter-grey-overlay;
@@ -31,6 +26,7 @@
3126
&.asc {
3227
box-shadow: inset 0 2px 0 0 $lighter-grey-overlay;
3328
}
29+
3430
}
3531
}
3632
}
@@ -133,6 +129,7 @@
133129
}
134130
}
135131

132+
136133
.paginator {
137134
align-items: center;
138135
display: flex;

src/components/auth/SignUp.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function SignUp() {
4444
<Input
4545
id="firstname"
4646
name="fname"
47-
maxLength={40}
4847
required
4948
autoComplete="given-name"
5049
type="text"
@@ -60,7 +59,6 @@ function SignUp() {
6059
<Input
6160
id="lastname"
6261
name="lname"
63-
maxLength={40}
6462
required
6563
autoComplete="family-name"
6664
type="text"
@@ -76,7 +74,6 @@ function SignUp() {
7674
<Input
7775
id="email"
7876
autoComplete="email"
79-
maxLength={40}
8077
name="email"
8178
required
8279
className="mb-2"

src/components/instance/browse/BrowseDatatable.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let controller;
1717
let controller2;
1818
let controller3;
1919

20-
function BrowseDatatable({ tableState, setTableState, activeTable, tableDescriptionAttributes }) {
20+
function BrowseDatatable({ tableState, setTableState, activeTable }) {
2121
const navigate = useNavigate();
2222
const { compute_stack_id, schema, table, customer_id } = useParams();
2323
const auth = useStoreState(instanceState, (s) => s.auth);
@@ -65,7 +65,7 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript
6565
}
6666
controller = new AbortController();
6767
controller2 = new AbortController();
68-
const { newData, newTotalRecords, newTotalPages, newEntityAttributes, hashAttribute, dataTableColumns, dynamicAttributesFromDataTable, error } = await getTableData({
68+
const { newData, newTotalRecords, newTotalPages, newEntityAttributes, hashAttribute, dataTableColumns, error } = await getTableData({
6969
schema,
7070
table,
7171
filtered: tableState.filtered,
@@ -103,7 +103,6 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript
103103
newEntityAttributes,
104104
hashAttribute,
105105
dataTableColumns,
106-
dynamicAttributesFromDataTable,
107106
error,
108107
});
109108
}
@@ -147,7 +146,6 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript
147146
<DataTable
148147
manual
149148
columns={tableState.dataTableColumns || []}
150-
tableDescriptionAttributes={tableDescriptionAttributes}
151149
data={tableState.tableData || []}
152150
error={tableState.error}
153151
currentPage={tableState.page}
@@ -156,7 +154,6 @@ function BrowseDatatable({ tableState, setTableState, activeTable, tableDescript
156154
showFilter={tableState.showFilter}
157155
sorted={tableState.sorted.length ? tableState.sorted : [{ id: tableState.hashAttribute, desc: false }]}
158156
loading={loading && !tableState.autoRefresh}
159-
dynamicAttributesFromDataTable={tableState.dynamicAttributesFromDataTable}
160157
onFilteredChange={(value) => {
161158
setTableState({ ...tableState, page: 0, filtered: value });
162159
}}

src/components/instance/browse/index.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,40 +64,32 @@ function BrowseIndex() {
6464
const structure = useStoreState(instanceState, (s) => s.structure);
6565
const [entities, setEntities] = useState({ schemas: [], tables: [], activeTable: false });
6666
const [tableState, setTableState] = useState(defaultTableState);
67-
const [tableDescription, setTableDescription] = useState(null);
6867
const baseUrl = `/o/${customer_id}/i/${compute_stack_id}/browse`;
6968
const showForm = instanceAuths[compute_stack_id]?.super || instanceAuths[compute_stack_id]?.structure === true;
7069
const showTableForm = showForm || (instanceAuths[compute_stack_id]?.structure && instanceAuths[compute_stack_id]?.structure?.includes(schema));
7170
const emptyPromptMessage = showForm
72-
? `Please ${(schema && entities.tables && !entities.tables.length) || !entities.schemas.length ? 'create' : 'choose'} a
73-
${schema ? 'table' : `${versionAsFloat >= 4.2 ? 'database' : 'schema'}`}`
71+
? `Please ${(schema && entities.tables && !entities.tables.length) || !entities.schemas.length ? 'create' : 'choose'} a ${
72+
schema ? 'table' : `${versionAsFloat >= 4.2 ? 'database' : 'schema'}`
73+
}`
7474
: "This user has not been granted access to any tables. A super-user must update this user's role.";
7575
const [hasHashAttr, setHasHashAttr] = useState(true);
7676

7777
const syncInstanceStructure = () => {
7878
buildInstanceStructure({ auth, url });
7979
};
8080

81-
const fetchDescribeTable = async () => {
82-
if (table) {
83-
try {
81+
const checkForHashAttribute = () => {
82+
async function check() {
83+
if (table) {
8484
const result = await describeTable({ auth, url, schema, table });
85-
setTableDescription(result);
86-
} catch (e) {
87-
addError(e);
85+
setHasHashAttr(Boolean(result.hash_attribute));
8886
}
8987
}
90-
};
9188

92-
useEffect(() => {
93-
fetchDescribeTable();
94-
}, [auth, url, schema, table]);
89+
check();
90+
};
9591

96-
useEffect(() => {
97-
if (tableDescription) {
98-
setHasHashAttr(Boolean(tableDescription.hash_attribute));
99-
}
100-
}, [tableDescription]);
92+
useEffect(checkForHashAttribute, [auth, url, schema, table]);
10193

10294
const validate = () => {
10395
if (structure) {
@@ -161,7 +153,7 @@ function BrowseIndex() {
161153
) : schema && table && action && entities.activeTable ? (
162154
<JSONEditor newEntityAttributes={tableState.newEntityAttributes} hashAttribute={tableState.hashAttribute} />
163155
) : schema && table && entities.activeTable ? (
164-
<DataTable activeTable={entities.activeTable} tableDescriptionAttributes={tableDescription?.attributes} tableState={tableState} setTableState={setTableState} />
156+
<DataTable activeTable={entities.activeTable} tableState={tableState} setTableState={setTableState} />
165157
) : schema && table && !hasHashAttr ? (
166158
<NoPrimaryKeyMessage />
167159
) : (

src/components/shared/DataTable.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ function DataTable({
7171
onRowClick,
7272
sorted,
7373
loading,
74-
dynamicAttributesFromDataTable,
75-
tableDescriptionAttributes,
7674
manual = false,
7775
}) {
7876
const { headerGroups, page, rows, prepareRow, state, setAllFilters, canPreviousPage, canNextPage, pageOptions, pageCount, gotoPage, nextPage, previousPage, setPageSize } =
@@ -112,8 +110,8 @@ function DataTable({
112110

113111
return (
114112
<ErrorBoundary onError={(err, componentStack) => addError({ error: { message: err.message, componentStack } })} FallbackComponent={ErrorFallback}>
115-
<div role="table" aria-label="Table Data" className="react-table-scroller">
116-
<DataTableHeader headerGroups={headerGroups} tableDescriptionAttributes={tableDescriptionAttributes} onSortedChange={onSortedChange} sorted={sorted} showFilter={showFilter} dynamicAttributesFromDataTable={dynamicAttributesFromDataTable} />
113+
<div className="react-table-scroller">
114+
<DataTableHeader headerGroups={headerGroups} onSortedChange={onSortedChange} sorted={sorted} showFilter={showFilter} />
117115
{loading || localLoading ? (
118116
<div className="centered text-center">
119117
<i className="fa fa-spinner fa-spin" />
Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,33 @@
11
import React from 'react';
22
import { Row, Col } from 'reactstrap';
33

4-
const DataTableHeader = ({ headerGroups, onSortedChange, sorted, showFilter, dynamicAttributesFromDataTable, tableDescriptionAttributes }) => {
5-
6-
const isIndexedAttribute = (columnId) => {
7-
let isIndexed = false;
8-
tableDescriptionAttributes.forEach((attr) => {
9-
if (attr.attribute === columnId && (attr.is_primary_key || attr.indexed)) {
10-
isIndexed = true;
11-
}
12-
});
13-
return isIndexed;
14-
}
15-
16-
return headerGroups.map((headerGroup) => {
4+
const DataTableHeader = ({ headerGroups, onSortedChange, sorted, showFilter }) =>
5+
headerGroups.map((headerGroup) => {
176
const { key, ...rest } = headerGroup.getHeaderGroupProps();
187
return (
198
<div key={key} {...rest}>
209
<Row className="header g-0">
2110
{headerGroup.headers.map((column) => (
2211
<Col
2312
key={column.id}
24-
onClick={() => {
25-
if (!dynamicAttributesFromDataTable.includes(column.id) && isIndexedAttribute(column.id)) {
26-
onSortedChange([{ id: column.id, desc: sorted[0]?.id === column.id ? !sorted[0]?.desc : false }])
27-
}
28-
}}
29-
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'}`}
13+
onClick={() => onSortedChange([{ id: column.id, desc: sorted[0]?.id === column.id ? !sorted[0]?.desc : false }])}
14+
className={`${sorted[0]?.id === column.id ? 'sorted' : ''} ${sorted[0]?.desc ? 'desc' : 'asc'} ${column.id.indexOf('hdb-narrow') !== -1 ? 'action' : ''} px-1`}
3015
>
3116
<div className="text-renderer">{column.render('Header')}</div>
3217
</Col>
3318
))}
3419
</Row>
35-
{
36-
showFilter && (
37-
<Row className="filter g-0">
38-
{headerGroup.headers.map((column) => (
39-
<Col key={column.id} className={column.id.indexOf('hdb-narrow') !== -1 ? 'action' : ''}>
40-
{column.render('Filter')}
41-
</Col>
42-
))}
43-
</Row>
44-
)
45-
}
46-
</div >
20+
{showFilter && (
21+
<Row className="filter g-0">
22+
{headerGroup.headers.map((column) => (
23+
<Col key={column.id} className={column.id.indexOf('hdb-narrow') !== -1 ? 'action' : ''}>
24+
{column.render('Filter')}
25+
</Col>
26+
))}
27+
</Row>
28+
)}
29+
</div>
4730
);
4831
});
49-
}
32+
5033
export default DataTableHeader;

src/functions/instance/getTableData.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ import describeTable from '../api/instance/describeTable';
22
import searchByValue from '../api/instance/searchByValue';
33
import searchByConditions from '../api/instance/searchByConditions';
44

5-
const getAttributesFromTableData = (tableData, existingAttributes) => {
6-
if (existingAttributes.length >= 8) return [];
7-
const existing = new Map(existingAttributes.map((value, index) => [value, index]));
8-
const extra = new Map();
9-
for (const dataRow of tableData) {
10-
for (const key of Object.keys(dataRow)) {
11-
if (!existing.has(key)) {
12-
const count = extra.get(key) || 0;
13-
extra.set(key, count + 1);
14-
}
15-
}
16-
}
17-
return Array.from(extra).sort(([, a], [, b]) => b - a).map(([key]) => key).slice(0, 8 - existingAttributes.length);
18-
}
19-
205
export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, page, auth, url, signal, signal2 }) => {
216
let fetchError = false;
227
let newTotalRecords = 0;
@@ -25,7 +10,6 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p
2510
let allAttributes = false;
2611
let hashAttribute = false;
2712
let get_attributes = ['*'];
28-
let dynamicAttributesFromDataTable = [];
2913
const offset = page * pageSize;
3014

3115
try {
@@ -92,12 +76,9 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p
9276
}
9377
}
9478

95-
dynamicAttributesFromDataTable = getAttributesFromTableData(newData, allAttributes)
96-
allAttributes.push(...dynamicAttributesFromDataTable);
97-
98-
// Keeps primary key / hash attribute first, and created and updated last.
79+
// sort columns, but keep primary key / hash attribute first, and created and updated last.
9980
// NOTE: __created__ and __updated__ might not exist in the schema, only include if they exist.
100-
const orderedColumns = allAttributes.filter((a) => ![hashAttribute, '__createdtime__', '__updatedtime__'].includes(a))
81+
const orderedColumns = allAttributes.filter((a) => ![hashAttribute, '__createdtime__', '__updatedtime__'].includes(a)).sort();
10182
const newEntityAttributes = orderedColumns.reduce((ac, a) => ({ ...ac, [a]: null }), {});
10283

10384
if (allAttributes.includes('__createdtime__')) orderedColumns.push('__createdtime__');
@@ -116,6 +97,5 @@ export default async ({ schema, table, filtered, pageSize, onlyCached, sorted, p
11697
hashAttribute,
11798
dataTableColumns,
11899
error: fetchError === 'table' ? `You are not authorized to view ${schema}:${table}` : fetchError,
119-
dynamicAttributesFromDataTable
120100
};
121101
};

0 commit comments

Comments
 (0)