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

Added id/hash quanities to the search interface.

parent 2d316303
Pipeline #61717 failed with stages
in 34 minutes and 3 seconds
......@@ -72,29 +72,39 @@ class DomainProviderBase extends React.Component {
code_runs: {
label: 'Entries',
tooltip: 'The statistics will show the number of database entry. Each set of input/output files that represents a code run is an entry.',
renderResultString: count => (<span><b>{count.toLocaleString()}</b> entries</span>)
renderResultString: count => (<span><b>{count.toLocaleString()}</b> entr{count === 1 ? 'y' : 'ies'}</span>)
},
unique_entries: {
label: 'Unique entries',
tooltip: 'Counts duplicates only once.',
renderResultString: count => (<span> and <b>{count.toLocaleString()}</b> unique entries</span>)
renderResultString: count => (<span> and <b>{count.toLocaleString()}</b> unique entr{count === 1 ? 'y' : 'ies'}</span>)
},
total_energies: {
label: 'Total energy calculations',
tooltip: 'Aggregates the number of total energy calculations as each entry can contain many calculations.',
renderResultString: count => (<span> with <b>{count.toLocaleString()}</b> total energy calculations</span>)
renderResultString: count => (<span> with <b>{count.toLocaleString()}</b> total energy calculation{count === 1 ? '' : 's'}</span>)
},
unique_geometries: {
label: 'Unique geometries',
tooltip: 'Aggregates the number of unique simulated system geometries in all entries.',
renderResultString: count => (<span> that simulate <b>{count.toLocaleString()}</b> unique geometries</span>)
renderResultString: count => (<span> that simulate <b>{count.toLocaleString()}</b> unique geometrie{count === 1 ? '' : 's'}</span>)
},
datasets: {
label: 'Datasets',
tooltip: 'Shows statistics in terms of datasets that entries belong to.',
renderResultString: count => (<span> curated in <b>{count.toLocaleString()}</b> datasets</span>)
renderResultString: count => (<span> curated in <b>{count.toLocaleString()}</b> dataset{count === 1 ? '' : 's'}</span>)
}
},
additionalSearchKeys: {
raw_id: {},
upload_id: {},
calc_id: {},
paths: {},
external_id: {},
pid: {},
mainfile: {},
calc_hash: {}
},
/**
* An dict where each object represents a column. Possible keys are label, render.
* Default render
......
......@@ -150,6 +150,7 @@ class RepoEntryView extends React.Component {
<Quantity quantity="calc_id" label={`${domain.entryLabel} id`} noWrap withClipboard {...quantityProps} />
<Quantity quantity='mainfile' loading={loading} noWrap {...quantityProps} withClipboard />
<Quantity quantity="calc_hash" label={`${domain.entryLabel} hash`} loading={loading} noWrap {...quantityProps} />
<Quantity quantity="raw_id" label='raw id' loading={loading} noWrap {...quantityProps} withClipboard />
<Quantity quantity="last_processing" label='last processing' loading={loading} placeholder="not processed" noWrap {...quantityProps}>
<Typography noWrap>
{new Date(calcData.last_processing * 1000).toLocaleString()}
......
......@@ -199,14 +199,18 @@ class Search extends React.Component {
const { searchValues } = searchState
const { pagination: { total }, statistics } = data
const helperText = <span>
There are {Object.keys(domain.searchMetrics).filter(key => statistics.total.all[key]).map(key => {
let helperText = <span>
There {total === 1 ? 'is' : 'are'} {Object.keys(domain.searchMetrics).filter(key => statistics.total.all[key]).map(key => {
return <span key={key}>
{domain.searchMetrics[key].renderResultString(!loading && statistics.total.all[key] !== undefined ? statistics.total.all[key] : '...')}
{domain.searchMetrics[key].renderResultString(!loading ? statistics.total.all[key] : '...')}
</span>
})}{Object.keys(searchValues).length ? ' left' : ''}.
</span>
if (total === 0) {
helperText = <span>There are no more entries matching your criteria.</span>
}
return (
<div className={classes.root}>
<div className={classes.searchContainer}>
......
......@@ -9,6 +9,9 @@ import Paper from '@material-ui/core/Paper'
import MenuItem from '@material-ui/core/MenuItem'
import { Chip } from '@material-ui/core'
import { repoPrimaryColor } from '../../config'
import { withDomain } from '../domains'
import { compose } from 'recompose'
function renderInput(inputProps) {
const { classes, autoFocus, value, onChange, onAdd, onDelete, chips, ref, ...other } = inputProps
......@@ -88,7 +91,8 @@ class SearchBar extends React.Component {
classes: PropTypes.object.isRequired,
data: PropTypes.object.isRequired,
searchValues: PropTypes.object.isRequired,
onChanged: PropTypes.func.isRequired
onChanged: PropTypes.func.isRequired,
domain: PropTypes.object.isRequired
}
static styles = theme => ({
......@@ -121,8 +125,15 @@ class SearchBar extends React.Component {
textFieldInput: ''
}
getSuggestions(value) {
value = value.toLowerCase()
constructor(props) {
super(props)
const { domain } = props
const reStr = `^(${Object.keys(domain.additionalSearchKeys).join('|')})=`
this.additionalSearchKeyRE = new RegExp(reStr)
}
getSuggestions(valueWithCase) {
const value = valueWithCase.toLowerCase()
const { data: { statistics } } = this.props
const suggestions = []
......@@ -148,6 +159,15 @@ class SearchBar extends React.Component {
})
})
// Add additional quantities to the end
const match = value.match(this.additionalSearchKeyRE)
if (match && this.props.domain.additionalSearchKeys[match[1]]) {
suggestions.push({
key: match[1],
value: valueWithCase.substring(match[0].length)
})
}
// Always add as comment to the end of suggestions
suggestions.push({
key: 'comment',
......@@ -198,7 +218,6 @@ class SearchBar extends React.Component {
this.setState({
textFieldInput: ''
})
this.props.onChanged(values)
}
......@@ -269,4 +288,4 @@ class SearchBar extends React.Component {
}
}
export default withStyles(SearchBar.styles)(SearchBar)
export default compose(withDomain, withStyles(SearchBar.styles))(SearchBar)
Markdown is supported
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