From 2c05e1a12090ae7c1a86edb07fddd3da2507056b Mon Sep 17 00:00:00 2001 From: Upendra Kumbham Date: Mon, 19 Feb 2024 17:22:13 +0000 Subject: [PATCH] Add empty object check and null, undefined function and update tab validations --- .../experiment-page/src/ExperimentPageRouter.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/javascript/bundles/experiment-page/src/ExperimentPageRouter.js b/app/src/main/javascript/bundles/experiment-page/src/ExperimentPageRouter.js index 9495c494c..45736a24c 100644 --- a/app/src/main/javascript/bundles/experiment-page/src/ExperimentPageRouter.js +++ b/app/src/main/javascript/bundles/experiment-page/src/ExperimentPageRouter.js @@ -30,6 +30,14 @@ function isThistabType(tab,tabType) { return tab.type === tabType; } +const isObjectEmpty = (objectName) => { + return ( + objectName && + Object.keys(objectName).length === 0 && + objectName.constructor === Object + ); +}; + function enableExperimentPageTab(tab) { const resultTab = 'results' const experimentDesignTab = 'experiment-design' @@ -37,22 +45,22 @@ function enableExperimentPageTab(tab) { const downloadTab = 'resources' if (isThistabType(tab, resultTab)) { - if (Array.isArray(tab.props.ks) && (tab.props.plotTypesAndOptions)) { + if (!isObjectEmpty(tab.props.ks) && Array.isArray(tab.props.ks) && !isObjectEmpty(tab.props.plotTypesAndOptions)) { tabTypeComponent.push({resultTab : TSnePlotViewRoute}) return tab.name; } } else if (isThistabType(tab, experimentDesignTab)) { - if (Array.isArray(tab.props.table.data)) { + if (!isObjectEmpty(tab.props.table.data) && Array.isArray(tab.props.table.data)) { tabTypeComponent.push({experimentDesignTab : ExperimentDesignRoute}) return tab.name; } } else if (isThistabType(tab, supplementaryInformationTab)) { - if (Array.isArray(tab.props.sections)) { + if (!isObjectEmpty(tab.props.sections) && Array.isArray(tab.props.sections)) { tabTypeComponent.push({supplementaryInformationTab : SupplementaryInformationRoute}) return tab.name; } } else if (isThistabType(tab, downloadTab)) { - if (Array.isArray(tab.props.data)) { + if (!isObjectEmpty(tab.props.data) && Array.isArray(tab.props.data)) { tabTypeComponent.push({'resources': DownloadsRoute}) return tab.name; }