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

Various minor fixes revolvig arround datasets. #303 #345

parent dff91c97
Pipeline #74720 passed with stages
in 21 minutes and 23 seconds
......@@ -3,8 +3,8 @@ import { errorContext } from './errors'
import { apiContext } from './api'
import Search from './search/Search'
import { Typography, makeStyles } from '@material-ui/core'
import { DatasetActions, DOI } from './search/DatasetList'
import { matchPath, useLocation, useHistory, useRouteMatch } from 'react-router'
import { matchPath, useLocation, useRouteMatch } from 'react-router'
import { DOI } from './search/DatasetList'
export const help = `
This page allows you to **inspect** and **download** NOMAD datasets. It alsow allows you
......@@ -31,7 +31,6 @@ export default function DatasetPage() {
const {raiseError} = useContext(errorContext)
const location = useLocation()
const match = useRouteMatch()
const history = useHistory()
const {datasetId} = matchPath(location.pathname, {
path: `${match.path}/:datasetId`
......@@ -56,18 +55,11 @@ export default function DatasetPage() {
})
}, [location.pathname, api])
const handleChange = dataset => {
if (dataset) {
setDataset({dataset: dataset})
} else {
history.goBack()
}
}
if (!dataset) {
return <div>loading...</div>
}
console.log('### DatasetPage', dataset)
return <div>
<div className={classes.header}>
<div className={classes.description}>
......@@ -76,18 +68,11 @@ export default function DatasetPage() {
dataset{dataset.doi ? <span>, with DOI <DOI doi={dataset.doi} /></span> : ''}
</Typography>
</div>
<div className={classes.actions}>
{dataset && dataset.example && <DatasetActions
dataset={dataset}
onChange={handleChange}/>
}
</div>
</div>
<Search
initialQuery={{owner: 'all'}}
query={{dataset_id: datasetId}}
query={{dataset_id: [datasetId]}}
ownerTypes={['all', 'public']}
initialResultTab="entries"
availableResultTabs={['entries', 'groups', 'datasets']}
......
......@@ -125,7 +125,7 @@ function handleApiError(e) {
let error = null
if (e.response) {
const body = e.response.body
const message = (body && (body.description || body.message)) || e.response.statusText
const message = (body && (body.message || body.description)) || e.response.statusText
const errorMessage = `${message} (${e.response.status})`
if (e.response.status === 404) {
error = new DoesNotExist(errorMessage)
......
......@@ -131,7 +131,7 @@ class DatasetActionsUnstyled extends React.Component {
const canAssignDOI = !doi
const canDelete = !doi
const query = {dataset_id: dataset.id}
const query = {dataset_id: [dataset.dataset_id]}
return <FormGroup row classes={{root: classes.group}}>
{search && <Tooltip title="Open a search page with entries from this dataset only.">
......@@ -180,6 +180,7 @@ class DatasetListUnstyled extends React.Component {
data: PropTypes.object,
total: PropTypes.number,
onChange: PropTypes.func.isRequired,
onEdit: PropTypes.func.isRequired,
history: PropTypes.any.isRequired,
datasets_after: PropTypes.string,
per_page: PropTypes.number,
......@@ -243,8 +244,8 @@ class DatasetListUnstyled extends React.Component {
}
renderEntryActions(entry) {
const {onChange} = this.props
return <DatasetActions search dataset={entry} onChange={() => onChange({})} />
const {onEdit} = this.props
return <DatasetActions search dataset={entry} onChange={onEdit} />
}
render() {
......
......@@ -21,7 +21,7 @@ export function Published(props) {
</Tooltip>
} else {
return <Tooltip title="not published yet">
<PrivateIcon color="secondary"/>
<PrivateIcon color="error"/>
</Tooltip>
}
}
......@@ -32,6 +32,7 @@ export class EntryListUnstyled extends React.Component {
data: PropTypes.object.isRequired,
query: PropTypes.object.isRequired,
onChange: PropTypes.func,
onEdit: PropTypes.func,
history: PropTypes.any.isRequired,
order_by: PropTypes.string.isRequired,
order: PropTypes.number.isRequired,
......@@ -236,7 +237,7 @@ export class EntryListUnstyled extends React.Component {
{(row.datasets || []).map(ds => (
<Typography key={ds.dataset_id}>
<Link component={RouterLink} to={`/dataset/id/${ds.dataset_id}`}>{ds.name}</Link>
{ds.doi ? <span>&nbsp; (<Link href={ds.doi}>{ds.doi}</Link>)</span> : <React.Fragment/>}
{ds.doi ? <span>&nbsp; (<Link href={`https://dx.doi.org/${ds.doi}`}>{ds.doi}</Link>)</span> : <React.Fragment/>}
</Typography>))}
</div>
</Quantity>
......@@ -321,7 +322,7 @@ export class EntryListUnstyled extends React.Component {
const createActions = (props, moreActions) => <React.Fragment>
{example && editable ? <EditUserMetadataDialog
example={example} total={selected === null ? totalNumber : selected.length}
onEditComplete={() => this.props.onChange()}
onEditComplete={() => this.props.onEdit()}
{...props}
/> : ''}
<DownloadButton
......
......@@ -549,13 +549,14 @@ const useScroll = (apiGroupName, afterParameterName) => {
}
function SearchEntryList(props) {
const {response, requestParameters, apiQuery} = useContext(searchContext)
const {response, requestParameters, apiQuery, update} = useContext(searchContext)
const setRequestParameters = usePagination()
return <EntryList
query={apiQuery}
editable={apiQuery.owner === 'staging' || apiQuery.owner === 'user'}
data={response}
onChange={setRequestParameters}
onEdit={update}
actions={
<React.Fragment>
<ReRunSearchButton/>
......@@ -568,9 +569,10 @@ function SearchEntryList(props) {
}
function SearchDatasetList(props) {
const {response} = useContext(searchContext)
const {response, update} = useContext(searchContext)
return <DatasetList
data={response}
onEdit={update}
actions={<ReRunSearchButton/>}
{...response} {...props} {...useScroll('datasets')}
/>
......@@ -586,8 +588,9 @@ function SearchGroupList(props) {
}
function SearchUploadList(props) {
const {response} = useContext(searchContext)
const {response, update} = useContext(searchContext)
return <UploadList data={response}
onEdit={update}
actions={<ReRunSearchButton/>}
{...response} {...props} {...useScroll('uploads')}
/>
......
......@@ -150,7 +150,7 @@ export default function SearchContext({initialRequest, initialQuery, query, chil
owner: owner,
...initialQuery,
...requestRef.current.query,
query
...query
}
if (dateHistogram) {
dateHistogramInterval = Dates.intervalSeconds(
......
......@@ -53,7 +53,7 @@ class UploadActionsUnstyled extends React.Component {
classes: PropTypes.object.isRequired,
upload: PropTypes.object.isRequired,
user: PropTypes.object,
onChange: PropTypes.func,
onEdit: PropTypes.func,
history: PropTypes.object.isRequired
}
......@@ -71,9 +71,9 @@ class UploadActionsUnstyled extends React.Component {
}
handleEdit() {
const {onChange, upload} = this.props
if (onChange) {
onChange(upload)
const {onEdit, upload} = this.props
if (onEdit) {
onEdit(upload)
}
}
......@@ -86,7 +86,7 @@ class UploadActionsUnstyled extends React.Component {
const editable = user && upload.example &&
upload.example.authors.find(author => author.user_id === user.sub)
const query = {upload_id: upload.example.upload_id}
const query = {upload_id: [upload.example.upload_id]}
return <FormGroup row classes={{root: classes.group}}>
<Tooltip title="Open this upload on the uploads page">
......@@ -112,6 +112,7 @@ class UploadListUnstyled extends React.Component {
data: PropTypes.object,
total: PropTypes.number,
onChange: PropTypes.func.isRequired,
onEdit: PropTypes.func.isRequired,
history: PropTypes.any.isRequired,
uploads_after: PropTypes.string,
actions: PropTypes.element
......@@ -176,8 +177,8 @@ class UploadListUnstyled extends React.Component {
}
renderEntryActions(entry) {
const {onChange} = this.props
return <UploadActions search upload={entry} onChange={() => onChange({})} />
const {onEdit} = this.props
return <UploadActions search upload={entry} onEdit={onEdit}/>
}
render() {
......
......@@ -171,7 +171,7 @@ class Upload extends React.Component {
cursor: 'pointer'
},
decideIcon: {
color: theme.palette.secondary.main
color: theme.palette.error.main
}
})
......@@ -605,12 +605,13 @@ class Upload extends React.Component {
return <EntryList
title={`Upload with ${data.pagination.total} detected entries`}
query={{upload_id: upload.upload_id}}
query={{upload_id: [upload.upload_id]}}
columns={columns}
selectedColumns={Upload.defaultSelectedColumns}
editable={tasks_status === 'SUCCESS'}
data={data}
onChange={this.handleChange}
onEdit={this.handleChange}
actions={actions}
showEntryActions={entry => entry.processed || !running}
{...this.state.params}
......@@ -634,7 +635,7 @@ class Upload extends React.Component {
} else if (upload.published) {
return render(<PublishedIcon size={32} color="primary"/>, 'This upload is published')
} else {
return render(<UnPublishedIcon size={32} color="secondary"/>, 'This upload is not published yet, and only visible to you')
return render(<UnPublishedIcon size={32} color="error"/>, 'This upload is not published yet, and only visible to you')
}
}
......
......@@ -554,7 +554,7 @@ class EditRepoCalcsResource(Resource):
# remove potentially empty old datasets
if removed_datasets is not None:
for dataset in removed_datasets:
if proc.Calc.objects(metadata__dataset_id=dataset).first() is None:
if proc.Calc.objects(metadata__datasets=dataset).first() is None:
Dataset.m_def.a_mongo.objects(dataset_id=dataset).delete()
return json_data, 200
......
......@@ -193,7 +193,7 @@ def chown(ctx, username, uploads):
search.refresh()
@uploads.command(help='Change the owner of the upload and all its calcs.')
@uploads.command(help='Reset the processing state.')
@click.argument('UPLOADS', nargs=-1)
@click.option('--with-calcs', is_flag=True, help='Also reset all calculations.')
@click.pass_context
......@@ -209,6 +209,7 @@ def reset(ctx, uploads, with_calcs):
dict(upload_id=upload.upload_id),
{'$set': proc.Calc.reset_pymongo_update()})
upload.process_status = None
upload.reset()
upload.save()
i += 1
......
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