@@ -2,21 +2,6 @@ import describeTable from '../api/instance/describeTable';
22import searchByValue from '../api/instance/searchByValue' ;
33import 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-
205export 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