Skip to content
Snippets Groups Projects
DatabaseComponent.jsx 1.88 KiB
Newer Older
  • Learn to ignore specific revisions
  • import React from 'react'
    import Container from '@src/js/components/common/form/Container.jsx'
    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() {
        const { object } = this.props
    
        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 samples = await openbis.getSamples(
            [new openbis.SamplePermId(object.id)],
            new openbis.SampleFetchOptions()
          )
          json = samples[object.id]
        } else if (object.type === objectType.DATA_SET) {
          const dataSets = await openbis.getDataSets(
            [new openbis.DataSetPermId(object.id)],
            new openbis.DataSetFetchOptions()
          )
          json = dataSets[object.id]
        }
    
        this.setState({
          json
        })
      }
    
      render() {
        logger.log(logger.DEBUG, 'DatabaseComponent.render')
    
        return (
          <Container>
            <pre>{JSON.stringify(this.state.json, null, 2)}</pre>
          </Container>
        )
      }
    }
    
    export default DatabaseComponent