From 676d780d3ffb5258ca90502ca4f0dc7d9ccf771b Mon Sep 17 00:00:00 2001 From: Alejandro De Maria Antolinos Date: Tue, 19 Mar 2019 14:41:44 +0100 Subject: [PATCH] It fixes icat/E-DataPortal#117 --- .gitignore | 2 + .../Selection/MintSelectionContainer.js | 44 +++++++++++-------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 224f149..49f0d1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*~ + #ICAT+ configuration /src/config/icat/icatPlus.js /src/config/icat/icat.js diff --git a/src/containers/Selection/MintSelectionContainer.js b/src/containers/Selection/MintSelectionContainer.js index 59dedc0..d4efc54 100644 --- a/src/containers/Selection/MintSelectionContainer.js +++ b/src/containers/Selection/MintSelectionContainer.js @@ -3,8 +3,7 @@ import axios from "axios"; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; -import { getDatasetsById } from '../../api/icat/icat.js' -import { getUsersByInvestigationIds } from '../../api/icat/icatPlus.js' +import { getUsersByInvestigationIds, getDatasetsById } from '../../api/icat/icatPlus.js' import Loader from 'react-loader-advanced'; import { doSignIn } from '../../actions/login.js'; import { PERSPECTIVE } from '../../constants/Perspectives.js' @@ -31,7 +30,7 @@ class MintSelectionContainer extends Component { investigationUsers: [] } } - + /* groupBy = function (xs, key) { return xs.reduce(function (rv, x) { (rv[x[key]] = rv[x[key]] || []).push(x); @@ -50,7 +49,7 @@ class MintSelectionContainer extends Component { datasets[datasetId] = {}; } datasets[datasetId][key] = value; - /** Some metadata at level of dataset to be added as parameters of the dataset */ + datasets[datasetId]["id"] = param[0]; datasets[datasetId]["name"] = param[1]; datasets[datasetId]["startDate"] = param[2]; @@ -67,7 +66,7 @@ class MintSelectionContainer extends Component { } return array; }; - +*/ onLogbookButtonClicked() { this.setState({ @@ -82,13 +81,15 @@ class MintSelectionContainer extends Component { } - getUsersByInvestigationIds(investigationIds) { + getUsers(investigationIds) { this.setState({ fetching: true }); - + console.log(getUsersByInvestigationIds(this.state.sessionId, investigationIds)) + debugger axios.get(getUsersByInvestigationIds(this.state.sessionId, investigationIds)) .then(res => { + debugger let investigationUsers = res.data; this.setState({ investigationUsers: investigationUsers, @@ -98,6 +99,7 @@ class MintSelectionContainer extends Component { }) .catch((error) => { + debugger if (error.response) { if (error.response.status === 403) { this.props.doSignIn(); @@ -107,30 +109,35 @@ class MintSelectionContainer extends Component { } retrieveSelectedDatasetsFromDatabase() { - if (!this.state.fetching) { + /*if (!this.state.fetching) { this.setState({ fetching: true }); - } + }*/ if (this.props.selection.datasetIds.length > 0) { - axios.get(getDatasetsById(this.state.sessionId, this.state.username, this.props.selection.datasetIds)) + console.log(getDatasetsById(this.state.sessionId, this.props.selection.datasetIds)); + debugger + axios.get(getDatasetsById(this.state.sessionId, this.props.selection.datasetIds)) .then(res => { + debugger try { - let datasets = this.parametersToDatasetObject(this.groupBy(res.data, 0)); + let datasets = res.data; this.setState({ datasets: datasets, filtered: datasets, fetching: false, fetched: true }); - this.getUsersByInvestigationIds(_.uniq(datasets.map(function (o) { return o.investigationId }))); + debugger + this.getUsers(_.uniq(datasets.map(function (o) { return o.investigation.id }))); } catch (error) { - + debugger } }) .catch((error) => { + debugger if (error.response) { if (error.response.status === 403) { this.props.doLogOut(); @@ -147,15 +154,16 @@ class MintSelectionContainer extends Component { }); } } + + render() { - if (this.props.selection.datasetIds.length !== this.state.datasets.length) { + /*if (this.props.selection.datasetIds.length !== this.state.datasets.length) { this.retrieveSelectedDatasetsFromDatabase(); - } + }*/ - /** TODO: To be implemented */ - if (this.state.fetching) { - return null; + if ((!this.props.user) || (!this.props.user.sessionId)) { + return null; } const options = { -- 2.22.0