1616import { fromJS , List } from 'immutable' ;
1717import { ActionURL , Ajax , Filter , getServerContext , Query , Utils } from '@labkey/api' ;
1818
19- import { resolveKey , SchemaQuery } from '../public/SchemaQuery' ;
19+ import { SchemaQuery } from '../public/SchemaQuery' ;
2020
2121import { Actions } from '../public/QueryModel/withQueryModels' ;
2222
@@ -63,34 +63,33 @@ export function selectAll(
6363 } ) ;
6464}
6565
66- export function getGridIdsFromTransactionId (
66+ export async function getGridIdsFromTransactionId (
6767 transactionAuditId : number | string ,
6868 dataType : string ,
6969 containerPath ?: string
7070) : Promise < string [ ] > {
71- if ( ! transactionAuditId ) {
72- return ;
73- }
74- const failureMsg = 'There was a problem retrieving the ' + dataType + ' from the last action.' ;
75- return new Promise ( ( resolve , reject ) => {
76- Ajax . request ( {
77- url : ActionURL . buildURL ( 'audit' , 'getTransactionRowIds.api' ) ,
78- params : { transactionAuditId, dataType, containerFilter : getContainerFilterForFolder ( containerPath ) } ,
79- success : Utils . getCallbackWrapper ( response => {
80- if ( response . success ) {
81- // The server returns numbers, so we coerce to string; If we don't it can lead to bugs (and has).
82- resolve ( response . rowIds . map ( ( rowId : number ) => rowId . toString ( ) ) ) ;
83- } else {
84- console . error ( failureMsg + ' (transactionAuditId = ' + transactionAuditId + ')' , response ) ;
85- reject ( failureMsg ) ;
86- }
87- } ) ,
88- failure : Utils . getCallbackWrapper ( error => {
89- console . error ( failureMsg + ' (transactionAuditId = ' + transactionAuditId + ')' , error ) ;
90- reject ( failureMsg ) ;
91- } ) ,
92- } ) ;
71+ if ( ! transactionAuditId ) return ;
72+
73+ const failureMsg = `There was a problem retrieving the ${ dataType } from the last action.` ;
74+ const errorLogMsg = `${ failureMsg } (transactionAuditId = ${ transactionAuditId } )` ;
75+
76+ const response = await request < { rowIds : number [ ] ; success : boolean } > ( {
77+ url : ActionURL . buildURL ( 'audit' , 'getTransactionRowIds.api' ) ,
78+ params : {
79+ containerFilter : getContainerFilterForFolder ( containerPath ) ,
80+ dataType,
81+ transactionAuditId,
82+ } ,
83+ errorLogMsg,
9384 } ) ;
85+
86+ if ( ! response . success ) {
87+ console . error ( errorLogMsg , response ) ;
88+ throw new Error ( failureMsg ) ;
89+ }
90+
91+ // The server returns numbers, so we coerce to string; If we don't, it can lead to bugs (and has).
92+ return response . rowIds . map ( rowId => rowId . toString ( ) ) ;
9493}
9594
9695export async function selectGridIdsFromTransactionId (
@@ -404,7 +403,7 @@ export async function getSelectedDataDeprecated(
404403 viewName ?: string ,
405404 keyColumn = 'RowId'
406405) : Promise < GridResponse > {
407- const { models, orderedModels } = await selectRowsDeprecated ( {
406+ const { key , models, orderedModels } = await selectRowsDeprecated ( {
408407 schemaName,
409408 queryName,
410409 viewName,
@@ -415,11 +414,9 @@ export async function getSelectedDataDeprecated(
415414 offset : 0 ,
416415 } ) ;
417416
418- const dataKey = resolveKey ( schemaName , queryName ) ;
419-
420417 return {
421- data : fromJS ( models [ dataKey ] ) ,
422- dataIds : List ( orderedModels [ dataKey ] ) ,
418+ data : fromJS ( models [ key ] ) ,
419+ dataIds : orderedModels [ key ] ,
423420 } ;
424421}
425422
@@ -552,8 +549,7 @@ export async function fetchCharts(schemaQuery: SchemaQuery, containerPath?: stri
552549 const { queryName, schemaName } = schemaQuery ;
553550 const errorLogMsg = `Unable to get report info for schema/query: ${ schemaName } /${ queryName } ` ;
554551
555- // TODO: Improve typings
556- const response = await request < any > ( {
552+ const response = await request < { reports : Partial < DataViewInfo [ ] > ; success : boolean } > ( {
557553 url : ActionURL . buildURL ( 'reports' , 'getReportInfos.api' , containerPath , {
558554 schemaName,
559555 queryName,
@@ -562,6 +558,7 @@ export async function fetchCharts(schemaQuery: SchemaQuery, containerPath?: stri
562558 } ) ;
563559
564560 if ( ! response . success ) {
561+ console . error ( errorLogMsg , response ) ;
565562 throw new Error ( errorLogMsg ) ;
566563 }
567564
0 commit comments