@@ -122,7 +122,7 @@ export default class QCObject extends BaseViewModel {
122122 * @returns {undefined }
123123 */
124124 sortListByField ( listSource , field , order ) {
125- listSource . sort ( ( a , b ) => typeof a [ field ] === 'string' ?
125+ listSource ? .sort ( ( a , b ) => typeof a [ field ] === 'string' ?
126126 this . _compareStrings ( a [ field ] , b [ field ] , order ) :
127127 this . _compareNumbers ( a [ field ] , b [ field ] , order ) ) ;
128128 }
@@ -310,7 +310,8 @@ export default class QCObject extends BaseViewModel {
310310 await Promise . allSettled ( objectsName . map ( async ( objectName ) => {
311311 let fetchedData = null ;
312312 if ( this . objects [ objectName ] ?. isSuccess ( ) && this . objects [ objectName ] ?. payload ?. name ) {
313- const { refreshNeeded, data } = await this . checkIfRefreshObject ( this . objects [ objectName ] . payload ) ;
313+ const context = { objectName } ;
314+ const { refreshNeeded, data } = await this . checkIfRefreshObject ( this . objects [ objectName ] . payload , context ) ;
314315 fetchedData = data ;
315316 if ( ! refreshNeeded ) {
316317 return ;
@@ -571,11 +572,32 @@ export default class QCObject extends BaseViewModel {
571572 * @param {object } object - The object to check for refresh.
572573 * @param {string } object.name - The name of the object to look up.
573574 * @param {string|number } object.id - The current ID of the object being validated.
575+ * @param {object } context - Additional context to determine fetch method
576+ * @param {string } context.objectName - Object name from URL params
577+ * @param {string } context.objectId - Object ID from URL params
574578 * @returns {Promise<boolean,RemoteData> } A promise that resolves to `true` if the object should be refreshed
575579 */
576- async checkIfRefreshObject ( object ) {
577- const fetchFn = async ( ) =>
578- await this . model . services . object . getObjectByName ( object . name , undefined , undefined , this ) ;
580+ async checkIfRefreshObject ( object , context = { } ) {
581+ const { objectName, objectId } = context ;
582+
583+ const fetchFn = async ( ) => {
584+ if ( objectId ) {
585+ return await this . model . services . object . getObjectById (
586+ objectId ,
587+ undefined ,
588+ undefined ,
589+ this ,
590+ ) ;
591+ } else {
592+ return await this . model . services . object . getObjectByName (
593+ objectName || object . name ,
594+ undefined ,
595+ undefined ,
596+ this ,
597+ ) ;
598+ }
599+ } ;
600+
579601 const validateFn = ( result ) =>
580602 result . isSuccess ( ) && result . payload . id !== object . id ;
581603 return this . model . filterModel . refreshCheck ( fetchFn , validateFn ) ;
@@ -590,7 +612,9 @@ export default class QCObject extends BaseViewModel {
590612 this . selected = null ;
591613 }
592614 if ( this . selected && this . selected . name ) {
593- const { refreshNeeded, data } = await this . checkIfRefreshObject ( this . objects [ this . selected . name ] . payload ) ;
615+ const context = { objectName : this . selected . name } ;
616+ const { refreshNeeded, data } =
617+ await this . checkIfRefreshObject ( this . objects [ this . selected . name ] . payload , context ) ;
594618 if ( refreshNeeded && data ?. payload ) {
595619 this . select ( { name : this . selected . name } , data . payload ) ;
596620 }
0 commit comments