Commit c2aada9a authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added a path to EntryPage that uses a query and displays the first result.

parent 47254942
Pipeline #62452 failed with stages
in 32 minutes and 1 second
......@@ -433,6 +433,11 @@ export default class App extends React.Component {
}
}
},
'entry_query': {
exact: true,
path: '/entry/query',
render: props => <EntryPage {...props} query />
},
'dataset': {
path: '/dataset/id/:datasetId',
key: (props) => `dataset/id/${props.match.params.datasetId}`,
......
......@@ -4,6 +4,9 @@ import { withStyles, Tab, Tabs } from '@material-ui/core'
import ArchiveEntryView from './ArchiveEntryView'
import ArchiveLogView from './ArchiveLogView'
import RepoEntryView from './RepoEntryView'
import { withApi, DoesNotExist } from '../api'
import { compose } from 'recompose'
import qs from 'qs'
class EntryPage extends React.Component {
static styles = theme => ({
......@@ -18,47 +21,96 @@ class EntryPage extends React.Component {
static propTypes = {
classes: PropTypes.object.isRequired,
uploadId: PropTypes.string.isRequired,
calcId: PropTypes.string.isRequired
api: PropTypes.object.isRequired,
uploadId: PropTypes.string,
calcId: PropTypes.string,
location: PropTypes.object,
query: PropTypes.bool
}
state = {
viewIndex: 0
viewIndex: 0,
calcId: null,
uploadId: null
}
componentDidMount() {
this.update()
}
componentDidUpdate(prevProps) {
if (prevProps.query !== this.props.query
|| prevProps.location !== this.props.location
|| prevProps.uploadId !== this.props.uploadId
|| prevProps.calcId !== this.props.calcId
|| prevProps.api !== this.props.api) {
this.update()
}
}
update() {
const { calcId, uploadId, query, location } = this.props
if (query) {
let queryParams = null
if (location && location.search) {
queryParams = qs.parse(location.search.substring(1))
}
this.props.api.search({...queryParams}).then(data => {
if (data.results && data.results.length > 0) {
const { calc_id, upload_id } = data.results[0]
this.setState({uploadId: upload_id, calcId: calc_id})
} else {
this.props.raiseError(new DoesNotExist())
}
}).catch(this.props.raiseError)
} else {
if (calcId && uploadId) {
this.setState({calcId: calcId, uploadId: uploadId})
} else {
// this should be unreachable
this.props.raiseError(new DoesNotExist())
}
}
}
render() {
const { classes, ...calcProps } = this.props
const { viewIndex } = this.state
const { classes } = this.props
const { viewIndex, calcId, uploadId } = this.state
return (
<div className={classes.root}>
<Tabs
className={classes.tabs}
value={viewIndex}
onChange={(event, state) => this.setState({viewIndex: state})}
indicatorColor="primary"
textColor="primary"
variant="fullWidth"
>
<Tab label="Raw data" />
<Tab label="Archive" />
<Tab label="Logs" />
</Tabs>
if (calcId && uploadId) {
const calcProps = { calcId: calcId, uploadId: uploadId }
return (
<div className={classes.root}>
<Tabs
className={classes.tabs}
value={viewIndex}
onChange={(event, state) => this.setState({viewIndex: state})}
indicatorColor="primary"
textColor="primary"
variant="fullWidth"
>
<Tab label="Raw data" />
<Tab label="Archive" />
<Tab label="Logs" />
</Tabs>
<div className={classes.content}>
<div style={viewIndex !== 0 ? {display: 'none'} : {}} >
<RepoEntryView {...calcProps} />
</div>
<div style={viewIndex !== 1 ? {display: 'none'} : {}} >
<ArchiveEntryView {...calcProps} />
</div>
<div style={viewIndex !== 2 ? {display: 'none'} : {}} >
<ArchiveLogView {...calcProps} />
<div className={classes.content}>
<div style={viewIndex !== 0 ? {display: 'none'} : {}} >
<RepoEntryView {...calcProps} />
</div>
<div style={viewIndex !== 1 ? {display: 'none'} : {}} >
<ArchiveEntryView {...calcProps} />
</div>
<div style={viewIndex !== 2 ? {display: 'none'} : {}} >
<ArchiveLogView {...calcProps} />
</div>
</div>
</div>
</div>
)
)
} else {
return ''
}
}
}
export default withStyles(EntryPage.styles)(EntryPage)
export default compose(withApi(false, true), withStyles(EntryPage.styles))(EntryPage)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment