Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions QualityControl/public/object/QCObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ export default class QCObject extends BaseViewModel {
* Set the current selected object by user
* Search within `currentList`;
* @param {QCObject} object - object to be selected and loaded
* @returns {undefined}
* @param {object} [preloadedData] - optional object data already fetched
* @returns {undefined}
*/
async select(object) {
async select(object, preloadedData = null) {
let foundObject = this.currentList.find((obj) => obj.name === object.name);

if (foundObject && this.list && this.list.length > 0) {
Expand All @@ -340,7 +341,11 @@ export default class QCObject extends BaseViewModel {

this.selected = foundObject || object;
setBrowserTabTitle(this.selected.name);
await this.loadObjectByName(this.selected.name);
if (preloadedData) {
this.objects[this.selected.name] = RemoteData.success(preloadedData);
} else {
await this.loadObjectByName(this.selected.name);
}
this.notify();
}

Expand Down Expand Up @@ -549,15 +554,35 @@ export default class QCObject extends BaseViewModel {
restoreNodeState(this.tree);
}

/**
* Checks if the given object needs to be refreshed by comparing its ID
* @param {object} object - The object to check for refresh.
* @param {string} object.name - The name of the object to look up.
* @param {string|number} object.id - The current ID of the object being validated.
* @returns {Promise<boolean,RemoteData>} A promise that resolves to `true` if the object should be refreshed
*/
async checkIfRefreshObject(object) {
const fetchFn = async () =>
await this.model.services.object.getObjectByName(object.name, undefined, undefined, this);
const validateFn = (result) =>
result.isSuccess() && result.payload.id !== object.id;
return this.model.filterModel.refreshCheck(fetchFn, validateFn);
}

/**
* Function that reloads the object list with filters applied
* @returns {undefined}
*/
async triggerFilter() {
// don't clear selected object refreshing in run mode
if (!this.model.filterModel.isRunModeActivated || !this.model.filterModel.runsModeInterval) {
this.selected = null;
}
if (this.selected && this.selected.name) {
const { refreshNeeded, data } = await this.checkIfRefreshObject(this.objects[this.selected.name].payload);
if (refreshNeeded && data?.payload) {
this.select({ name: this.selected.name }, data.payload);
}
}
this.loadList();
}
}
16 changes: 9 additions & 7 deletions QualityControl/public/pages/objectView/ObjectViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ export default class ObjectViewModel extends BaseViewModel {
* @returns {undefined}
*/
async init(urlParams) {
this.selected = RemoteData.loading();
this.notify();

const { objectName, layoutId, objectId, id, ts = undefined } = urlParams;
if (objectName) {
this.updateObjectSelection({ objectName }, ts, id);
Expand All @@ -74,16 +71,21 @@ export default class ObjectViewModel extends BaseViewModel {
async updateObjectSelection(object, validFrom = undefined, id = '') {
const { objectName = undefined, objectId = undefined } = object;
const { params } = this.model.router;

if (!objectName && !objectId && !params.objectId && !params.objectName && !this.selected.isSuccess()) {
return; // This will permanently put the page in loading mode.
const { refreshNeeded, data } = await this.model.object.checkIfRefreshObject(this.selected.payload);
if (!refreshNeeded) {
return;
}

this._setParameters(objectName, objectId, params);
this.selected = RemoteData.loading();
this.notify();

if (!objectName && !objectId && !params.objectId && !params.objectName && !this.selected.isSuccess()) {
return; // This will permanently put the page in loading mode.
}

let currentParams = '?page=objectView';
this.selected = params.objectName
this.selected = data ?? params.objectName
? await this.model.services.object.getObjectByName(params.objectName, id, validFrom, this)
: await this.model.services.object.getObjectById(params.objectId, id, validFrom, this);

Expand Down
Loading