Newer
Older
piotr.kupczyk@id.ethz.ch
committed
import React from 'react'
import Container from '@src/js/components/common/form/Container.jsx'
import AppController from '@src/js/components/AppController.js'
piotr.kupczyk@id.ethz.ch
committed
import openbis from '@src/js/services/openbis.js'
import objectType from '@src/js/common/consts/objectType.js'
import logger from '@src/js/common/logger.js'
class DatabaseComponent extends React.PureComponent {
constructor(props) {
super(props)
this.state = {
json: null
}
}
async componentDidMount() {
try {
const { object } = this.props
piotr.kupczyk@id.ethz.ch
committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
let json = null
if (object.type === objectType.SPACE) {
const spaces = await openbis.getSpaces(
[new openbis.SpacePermId(object.id)],
new openbis.SpaceFetchOptions()
)
json = spaces[object.id]
} else if (object.type === objectType.PROJECT) {
const projects = await openbis.getProjects(
[new openbis.ProjectPermId(object.id)],
new openbis.ProjectFetchOptions()
)
json = projects[object.id]
} else if (object.type === objectType.COLLECTION) {
const experiments = await openbis.getExperiments(
[new openbis.ExperimentPermId(object.id)],
new openbis.ExperimentFetchOptions()
)
json = experiments[object.id]
} else if (object.type === objectType.OBJECT) {
const fetchOptions = new openbis.SampleFetchOptions()
fetchOptions.withSpace()
fetchOptions.withProject()
fetchOptions.withExperiment()
fetchOptions.withParents()
const samples = await openbis.getSamples(
[new openbis.SamplePermId(object.id)],
fetchOptions
)
json = samples[object.id]
} else if (object.type === objectType.DATA_SET) {
const fetchOptions = new openbis.DataSetFetchOptions()
fetchOptions.withExperiment()
fetchOptions.withSample()
fetchOptions.withParents()
const dataSets = await openbis.getDataSets(
[new openbis.DataSetPermId(object.id)],
fetchOptions
)
json = dataSets[object.id]
}
piotr.kupczyk@id.ethz.ch
committed
this.setState({
json
})
} catch (error) {
AppController.getInstance().errorChange(error)
piotr.kupczyk@id.ethz.ch
committed
}
}
render() {
logger.log(logger.DEBUG, 'DatabaseComponent.render')
return (
<Container>
<pre>{JSON.stringify(this.state.json || {}, null, 2)}</pre>
piotr.kupczyk@id.ethz.ch
committed
</Container>
)
}
}
export default DatabaseComponent