From c6e2fab6d43bc1a44eed0b52745343b4defd2827 Mon Sep 17 00:00:00 2001 From: David Mendez <dmendez@ebi.ac.uk> Date: Fri, 11 Aug 2023 16:08:16 +0100 Subject: [PATCH] eubopen compound: refactor generation of report card structure by using async functions --- .../EubopenCompoundReportCard.vue | 145 ++++++++++-------- .../CompoundReportCardGenerator.js | 4 +- 2 files changed, 81 insertions(+), 68 deletions(-) diff --git a/components/report_cards/chemical_probe/EubopenCompoundReportCard.vue b/components/report_cards/chemical_probe/EubopenCompoundReportCard.vue index 44e580c..b675153 100644 --- a/components/report_cards/chemical_probe/EubopenCompoundReportCard.vue +++ b/components/report_cards/chemical_probe/EubopenCompoundReportCard.vue @@ -37,79 +37,94 @@ export default { return state[this.storeModuleName].reportCardStructure }, }), - mounted() { - const docSource = [ - 'pref_name', - '_metadata.eubopen.is_probe', - '_metadata.eubopen.is_control', - ] - const entityID = EntityNames.EubopenCompound.entityID - const indexName = IndexNames.getIndexNameFromEntityID(entityID) + async mounted() { + try { + const paramsFromCompound = await this.getOptionalSectionsParams() + const showCellHeatlhAndViabilityData = await this.hasCellHeatlhAndViabilityData() + const reportCardStructure = CompoundReportCardGenerator.generateReportCardStructure( + this.itemID, + paramsFromCompound.prefName, + { + isChemicalProbe: paramsFromCompound.isChemicalProbe, + isNegativeControl: paramsFromCompound.isNegativeControl, + showCellHeatlhAndViabilityData, + } + ) - ESProxyService.getESDocument(indexName, this.itemID, docSource) - .then((response) => { - const sourceObtained = response.data._source - const prefName = ObjectPropertyAccess.getPropertyPalue( - sourceObtained, - 'pref_name', - '', - false - ) + this.$store.dispatch( + `${this.storeModuleName}/setReportCardStructure`, + reportCardStructure + ) - const isChemicalProbe = ObjectPropertyAccess.getPropertyPalue( - sourceObtained, - '_metadata.eubopen.is_probe', - false - ) + this.$store.dispatch(`${this.storeModuleName}/setStructureReady`, true) + } catch (error) { + ErrorTracking.trackError(error, this) - const isNegativeControl = ObjectPropertyAccess.getPropertyPalue( - sourceObtained, - '_metadata.eubopen.is_control', - false - ) + RequestNotifications.dispatchRequestErrorNotification( + error, + this.$store.dispatch, + `There was an error while loading the page structure` + ) + } + }, + methods: { + async getOptionalSectionsParams() { + const docSource = [ + 'pref_name', + '_metadata.eubopen.is_probe', + '_metadata.eubopen.is_control', + ] + const entityID = EntityNames.EubopenCompound.entityID + const indexName = IndexNames.getIndexNameFromEntityID(entityID) + + const compoundData = await ESProxyService.getESDocument( + indexName, + this.itemID, + docSource + ) - const cellHeatlhAndViabilityDataPath = `/eubopen/visualisations/compound/cell_viability_and_health_data/${this.itemID}` + const prefName = ObjectPropertyAccess.getPropertyPalue( + compoundData, + 'pref_name', + '' + ) - ESProxyService.getGenericData(cellHeatlhAndViabilityDataPath) - .then((response) => { - const numDataPoints = response.data.num_datapoints - const showCellHeatlhAndViabilityData = numDataPoints > 0 - const reportCardStructure = CompoundReportCardGenerator.generateReportCardStructure( - this.itemID, - prefName, - isChemicalProbe, - isNegativeControl, - showCellHeatlhAndViabilityData - ) - this.$store.dispatch( - `${this.storeModuleName}/setReportCardStructure`, - reportCardStructure - ) + const isChemicalProbe = ObjectPropertyAccess.getPropertyPalue( + compoundData, + '_metadata.eubopen.is_probe', + false + ) - this.$store.dispatch( - `${this.storeModuleName}/setStructureReady`, - true - ) - }) - .catch((error) => { - ErrorTracking.trackError(error, this) + const isNegativeControl = ObjectPropertyAccess.getPropertyPalue( + compoundData, + '_metadata.eubopen.is_control', + false + ) - RequestNotifications.dispatchRequestErrorNotification( - error, - this.$store.dispatch, - `Target Classifications: There was an error while loading the Cell Viability and Health Data!` - ) - }) - }) - .catch((error) => { - ErrorTracking.trackError(error, this) + return { + prefName, + isChemicalProbe, + isNegativeControl, + } + }, + async hasCellHeatlhAndViabilityData() { + const chemblIDResponse = await ESProxyService.getESDocument( + IndexNames.getIndexNameFromEntityID( + EntityNames.EubopenCompound.entityID + ), + this.itemID, + ['molecule_chembl_id'] + ) + + const chemblID = chemblIDResponse.data._source.molecule_chembl_id + const cellHeatlhAndViabilityDataPath = `/eubopen/visualisations/compound/cell_viability_and_health_data/${chemblID}` + const cellHealthAndViabilityData = await ESProxyService.getGenericData( + cellHeatlhAndViabilityDataPath + ) - RequestNotifications.dispatchRequestErrorNotification( - error, - this.$store.dispatch, - `There was an error while loading the page structure` - ) - }) + const numDataPoints = cellHealthAndViabilityData.data.num_datapoints + return numDataPoints > 0 + }, }, } </script> diff --git a/report_cards_structure/CompoundReportCardGenerator.js b/report_cards_structure/CompoundReportCardGenerator.js index 1cd9928..39e60db 100644 --- a/report_cards_structure/CompoundReportCardGenerator.js +++ b/report_cards_structure/CompoundReportCardGenerator.js @@ -13,9 +13,7 @@ const methods = { generateReportCardStructure( itemID, prefName, - isChemicalProbe, - isNegativeControl, - showCellHeatlhAndViabilityData + { isChemicalProbe, isNegativeControl, showCellHeatlhAndViabilityData } ) { const basePageStructure = [ { -- GitLab