Commit 92a743ac authored by Matija Obreza's avatar Matija Obreza

Merge branch '161-pasting-descriptors-for-search' into 'master'

Resolve "Pasting descriptors for search"

Closes #161

See merge request genesys-pgr/genesys-ui!161
parents c982ca17 8e80df7b
......@@ -749,8 +749,8 @@
},
"pastingTraits": {
"title": "Select descriptors in batch",
"matched": "Matched",
"noDescriptors": "No matching descriptors"
"parsed": "Parsed {{count, number}} descriptors",
"noDescriptors": "No descriptor definitions pasted"
},
"traits": "Browse and select descriptors",
"reorder": "Reorder descriptors",
......
......@@ -123,8 +123,8 @@
},
"pastingTraits": {
"title": "Select descriptors in batch",
"matched": "Matched",
"noDescriptors": "No matching descriptors"
"parsed": "Parsed {{count, number}} descriptors",
"noDescriptors": "No descriptor definitions pasted"
},
"traits": "Browse and select descriptors",
"reorder": "Reorder descriptors",
......
......@@ -11,6 +11,7 @@ import { PartnerLink } from 'ui/catalog/Links';
import { Properties, PropertiesItem } from 'ui/common/Properties';
import CropChips from 'crop/ui/c/CropChips';
import McpdDate from 'ui/common/time/McpdDate';
import Number from 'ui/common/Number';
interface IDatasetCardProps extends React.ClassAttributes<any> {
className?: string;
......@@ -53,10 +54,10 @@ class DatasetCard extends React.Component<IDatasetCardProps, any> {
<McpdDate value={ dataset.startDate }/> &mdash; <McpdDate value={ dataset.endDate }/>
</PropertiesItem>
<PropertiesItem title={ t('datasets.public.common.accessionsNumber') }>
{ dataset.accessionCount }
<Number value={ dataset.accessionCount } />
</PropertiesItem>
<PropertiesItem title={ t('datasets.public.common.traitsNumber') }>
{ dataset.descriptorCount }
<Number value={ dataset.descriptorCount } />
</PropertiesItem>
</Properties>
</CardContent>
......
......@@ -8,48 +8,61 @@ import Dataset from 'model/catalog/Dataset';
import Grid from '@material-ui/core/Grid';
import { log } from 'utilities/debug';
import { addDescriptorsToDataset } from 'datasets/actions/editor';
import { addDescriptorsToDataset, removeDescriptorsFromDataset } from 'datasets/actions/editor';
import { searchMatchingDescriptor } from 'descriptors/actions/editor';
import DescriptorParser from 'descriptors/ui/c/DescriptorParser';
import DescriptorCard from 'descriptors/ui/c/DescriptorCard';
import StepperTemplate from 'ui/common/stepper/StepperTemplate';
import Loading from 'ui/common/Loading';
interface IPastingDescriptorsStepProps extends React.ClassAttributes<any> {
addDescriptorsToDataset: (dataset: Dataset, descriptorUuids: string[]) => void;
removeDescriptorsFromDataset: (dataset: Dataset, descriptorUuids: string[]) => void;
searchMatchingDescriptor: (descriptor: Descriptor) => Promise<Descriptor[]>;
}
class PastingDescriptorsStep extends StepperTemplate<IPastingDescriptorsStepProps> {
public state = {
matchingDescriptors: [],
pastedDescriptors: null,
matchingDescriptors: new Map<number, Descriptor[]>(),
...super.state,
};
public renderContent = () => (
<DescriptorParser onHandleDescriptors={ this.searchDescriptors }>
{ this.state.matchingDescriptors ? (
<div style={ { marginTop: '23px' } }>
<h3>{ this.props.t('datasets.dashboard.p.stepper.pastingTraits.matched', { length: this.state.matchingDescriptors.length }) }</h3>
<Grid container spacing={ 24 }>
{ this.state.matchingDescriptors.map((descriptor, index) => (
<Grid item key={ index } xs={ 12 } md={ 6 } xl={ 4 }>
{ this.state.pastedDescriptors ? (
<div>
<h3>{ this.props.t('datasets.dashboard.p.stepper.pastingTraits.parsed', { count: this.state.pastedDescriptors.length }) }</h3>
{ this.state.pastedDescriptors.map((pasted, index) => (
<Grid container key={ pasted.id } spacing={ 24 }>
<Grid item xs={ 6 }>
<DescriptorCard
key={ descriptor.uuid }
className="ml-20 mr-20 mb-20"
descriptor={ descriptor }
compact
crop version
textRows={ 3 }
selectedProps={ {
selectable: true,
onSelect: this.addDescriptor,
disabled: this.props.item.descriptors.map((d) => d.uuid).indexOf(descriptor.uuid) !== -1,
} }
descriptor={ pasted }
/>
</Grid>
)) }
</Grid>
<Grid item xs={ 6 }>
<Grid container spacing={ 24 }>
{ !(this.state.matchingDescriptors && this.state.matchingDescriptors.get(pasted.id)) ?
<Grid item xs={ 12 }>
<Loading />
</Grid>
: this.state.matchingDescriptors.get(pasted.id).map((descriptor) => (
<Grid item xs={ 12 } key={ descriptor.uuid }>
<DescriptorCard
descriptor={ descriptor }
selectedProps={ {
selectable: this.props.item.descriptors.map((d) => d.uuid).indexOf(descriptor.uuid) === -1,
onSelect: this.addDescriptor,
onUnselect: this.removeDescriptor,
} }
/>
</Grid>
)) }
</Grid>
</Grid>
</Grid>
)) }
</div>
) : (
<h3>{ this.props.t('datasets.dashboard.p.stepper.pastingTraits.noDescriptors') }</h3>
......@@ -64,22 +77,27 @@ class PastingDescriptorsStep extends StepperTemplate<IPastingDescriptorsStepProp
log(`Adding descriptor ${descriptor.uuid}`);
addDescriptorsToDataset(dataset, [descriptor.uuid]);
}
private searchDescriptors = (d: Descriptor[]) => {
const { searchMatchingDescriptor } = this.props;
if (d && d.length > 0) {
for (const importedDescriptor of d) {
searchMatchingDescriptor(importedDescriptor)
.then((matches) => {
const descriptors = this.state.matchingDescriptors;
matches.filter((m) => m != null).forEach((matching) => {
const alreadyInList = descriptors.map((d) => d.uuid).indexOf(matching.uuid) !== -1;
protected removeDescriptor = (descriptor: Descriptor) => {
const { item: dataset, removeDescriptorsFromDataset } = this.props;
if (!alreadyInList) {
descriptors.push(matching);
}
});
this.setState({ ...this.state, matchingDescriptors: descriptors });
log(`Removing descriptor ${descriptor.uuid}`);
removeDescriptorsFromDataset(dataset, [descriptor.uuid]);
}
private searchDescriptors = (descriptors: Descriptor[]) => {
const { searchMatchingDescriptor } = this.props;
let tempId: number = 0;
descriptors.forEach((d) => d.id = ++tempId);
const matchingDescriptors = new Map<number, Descriptor[]>();
this.setState({ ...this.state, pastedDescriptors: descriptors, matchingDescriptors });
if (descriptors && descriptors.length > 0) {
for (const importedDescriptor of descriptors) {
searchMatchingDescriptor(importedDescriptor)
.then((matches) => {
matchingDescriptors.set(importedDescriptor.id, []);
matches.forEach((match) => matchingDescriptors.get(importedDescriptor.id).push(match));
this.setState({ ...this.state, matchingDescriptors });
})
.catch((error) => {
log(`Error`, error);
......@@ -94,6 +112,7 @@ const mapStateToProps = (state, ownProps) => ({});
const mapDispatchToProps = (dispatch) => bindActionCreators({
searchMatchingDescriptor,
addDescriptorsToDataset,
removeDescriptorsFromDataset,
}, dispatch);
export default translate()(connect(
......
......@@ -226,8 +226,8 @@ const DescriptorCard = ({ complete = true, compact, descriptor, classes, classNa
<Button
variant="contained"
onClick={ onClick(false) }
disabled={ selectedProps.disabled }
className={ classes.btnDefault }
disabled={ selectedProps.disabled }
>
{ t('descriptors.public.c.card.unselect') }
</Button>
......
......@@ -334,7 +334,7 @@ class WelcomePage extends React.Component<IWelcomeProps, any> {
</Grid>
<Grid item xs={ 12 } md={ 3 }>
<Stats>
<Link to="/a/">
<Link to="/datasets">
<span className={ classes.amount }><Number value={ serverInfo.datasetCount } /></span>
{ t('datasets.common.stats', { count: serverInfo.datasetCount }) }
</Link>
......@@ -366,7 +366,7 @@ class WelcomePage extends React.Component<IWelcomeProps, any> {
</Grid>
<Grid item xs={ 12 } md={ 3 }>
<Stats>
<Link to="/a/">
<Link to="/datasets">
{ t('datasets.common.stats', { count: serverInfo.datasetCount }) }
</Link>
</Stats>
......
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