Skip to content
Snippets Groups Projects
Commit 3adc1f50 authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

NG_UI : plugins evaluation : SSDM-10431 - display additional information about...

NG_UI : plugins evaluation : SSDM-10431 - display additional information about entities in the autocompleter - $NAME property (for all entity kinds) and an owner (only for data sets)
parent 3b7b87d5
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import logger from '@src/js/common/logger.js' ...@@ -8,6 +8,7 @@ import logger from '@src/js/common/logger.js'
const styles = () => ({}) const styles = () => ({})
const ENTITY_NAME_PROPERTY = '$NAME'
const LOADED_OPTIONS_COUNT = 100 const LOADED_OPTIONS_COUNT = 100
class EntityAutocompleterField extends React.PureComponent { class EntityAutocompleterField extends React.PureComponent {
...@@ -124,21 +125,28 @@ class EntityAutocompleterField extends React.PureComponent { ...@@ -124,21 +125,28 @@ class EntityAutocompleterField extends React.PureComponent {
if (value && value.trim().length > 0) { if (value && value.trim().length > 0) {
//criteria.withCode().thatContains(value) //criteria.withCode().thatContains(value)
criteria.withIdentifier().thatContains(value) criteria.withIdentifier().thatContains(value)
criteria.withProperty('$NAME').thatContains(value) criteria.withProperty(ENTITY_NAME_PROPERTY).thatContains(value)
} }
const fo = new openbis.ExperimentFetchOptions() const fo = new openbis.ExperimentFetchOptions()
fo.withProperties()
fo.from(0).count(count) fo.from(0).count(count)
fo.sortBy().identifier().asc() fo.sortBy().identifier().asc()
const results = await openbis.searchExperiments(criteria, fo) const results = await openbis.searchExperiments(criteria, fo)
return { return {
options: results.getObjects().map(object => ({ options: results.getObjects().map(object => {
label: object.identifier.identifier, return {
entityKind: openbis.EntityKind.EXPERIMENT, label: this.createOptionLabel(openbis.EntityKind.EXPERIMENT, object),
entityId: object.identifier.identifier fullLabel: this.createOptionFullLabel(
})), openbis.EntityKind.EXPERIMENT,
object
),
entityKind: openbis.EntityKind.EXPERIMENT,
entityId: object.identifier.identifier
}
}),
totalCount: results.totalCount totalCount: results.totalCount
} }
} }
...@@ -150,21 +158,28 @@ class EntityAutocompleterField extends React.PureComponent { ...@@ -150,21 +158,28 @@ class EntityAutocompleterField extends React.PureComponent {
if (value && value.trim().length > 0) { if (value && value.trim().length > 0) {
//criteria.withCode().thatContains(value) //criteria.withCode().thatContains(value)
criteria.withIdentifier().thatContains(value) criteria.withIdentifier().thatContains(value)
criteria.withProperty('$NAME').thatContains(value) criteria.withProperty(ENTITY_NAME_PROPERTY).thatContains(value)
} }
const fo = new openbis.SampleFetchOptions() const fo = new openbis.SampleFetchOptions()
fo.withProperties()
fo.from(0).count(count) fo.from(0).count(count)
fo.sortBy().identifier().asc() fo.sortBy().identifier().asc()
const results = await openbis.searchSamples(criteria, fo) const results = await openbis.searchSamples(criteria, fo)
return { return {
options: results.getObjects().map(object => ({ options: results.getObjects().map(object => {
label: object.identifier.identifier, return {
entityKind: openbis.EntityKind.SAMPLE, label: this.createOptionLabel(openbis.EntityKind.SAMPLE, object),
entityId: object.identifier.identifier fullLabel: this.createOptionFullLabel(
})), openbis.EntityKind.SAMPLE,
object
),
entityKind: openbis.EntityKind.SAMPLE,
entityId: object.identifier.identifier
}
}),
totalCount: results.totalCount totalCount: results.totalCount
} }
} }
...@@ -175,24 +190,31 @@ class EntityAutocompleterField extends React.PureComponent { ...@@ -175,24 +190,31 @@ class EntityAutocompleterField extends React.PureComponent {
if (value && value.trim().length > 0) { if (value && value.trim().length > 0) {
criteria.withCode().thatContains(value) criteria.withCode().thatContains(value)
criteria.withProperty('$NAME').thatContains(value) criteria.withProperty(ENTITY_NAME_PROPERTY).thatContains(value)
} }
const fo = new openbis.MaterialFetchOptions() const fo = new openbis.MaterialFetchOptions()
fo.withProperties()
fo.from(0).count(count) fo.from(0).count(count)
fo.sortBy().code().asc() fo.sortBy().code().asc()
const results = await openbis.searchMaterials(criteria, fo) const results = await openbis.searchMaterials(criteria, fo)
return { return {
options: results.getObjects().map(object => ({ options: results.getObjects().map(object => {
label: object.permId.code + ' (' + object.permId.typeCode + ')', return {
entityKind: openbis.EntityKind.MATERIAL, label: this.createOptionLabel(openbis.EntityKind.MATERIAL, object),
entityId: { fullLabel: this.createOptionFullLabel(
code: object.permId.code, openbis.EntityKind.MATERIAL,
typeCode: object.permId.typeCode object
),
entityKind: openbis.EntityKind.MATERIAL,
entityId: {
code: object.permId.code,
typeCode: object.permId.typeCode
}
} }
})), }),
totalCount: results.totalCount totalCount: results.totalCount
} }
} }
...@@ -203,37 +225,97 @@ class EntityAutocompleterField extends React.PureComponent { ...@@ -203,37 +225,97 @@ class EntityAutocompleterField extends React.PureComponent {
if (value && value.trim().length > 0) { if (value && value.trim().length > 0) {
criteria.withCode().thatContains(value) criteria.withCode().thatContains(value)
criteria.withProperty('$NAME').thatContains(value) criteria.withProperty(ENTITY_NAME_PROPERTY).thatContains(value)
const experimentCriteria = criteria.withExperiment() const experimentCriteria = criteria.withExperiment()
experimentCriteria.withOrOperator() experimentCriteria.withOrOperator()
//experimentCriteria.withCode().thatContains(value) //experimentCriteria.withCode().thatContains(value)
experimentCriteria.withIdentifier().thatContains(value) experimentCriteria.withIdentifier().thatContains(value)
experimentCriteria.withProperty('$NAME').thatContains(value) experimentCriteria.withProperty(ENTITY_NAME_PROPERTY).thatContains(value)
const sampleCriteria = criteria.withSample() const sampleCriteria = criteria.withSample()
sampleCriteria.withOrOperator() sampleCriteria.withOrOperator()
//sampleCriteria.withCode().thatContains(value) //sampleCriteria.withCode().thatContains(value)
sampleCriteria.withIdentifier().thatContains(value) sampleCriteria.withIdentifier().thatContains(value)
sampleCriteria.withProperty('$NAME').thatContains(value) sampleCriteria.withProperty(ENTITY_NAME_PROPERTY).thatContains(value)
} }
const fo = new openbis.DataSetFetchOptions() const fo = new openbis.DataSetFetchOptions()
fo.withProperties()
fo.withExperiment()
fo.withSample()
fo.from(0).count(count) fo.from(0).count(count)
fo.sortBy().code().asc() fo.sortBy().code().asc()
const results = await openbis.searchDataSets(criteria, fo) const results = await openbis.searchDataSets(criteria, fo)
return { return {
options: results.getObjects().map(object => ({ options: results.getObjects().map(object => {
label: object.code, return {
entityKind: openbis.EntityKind.DATA_SET, label: this.createOptionLabel(openbis.EntityKind.DATA_SET, object),
entityId: object.code fullLabel: this.createOptionFullLabel(
})), openbis.EntityKind.DATA_SET,
object
),
entityKind: openbis.EntityKind.DATA_SET,
entityId: object.code
}
}),
totalCount: results.totalCount totalCount: results.totalCount
} }
} }
createOptionLabel(entityKind, object) {
if (
entityKind === openbis.EntityKind.EXPERIMENT ||
entityKind === openbis.EntityKind.SAMPLE
) {
return object.identifier.identifier
} else if (
entityKind === openbis.EntityKind.MATERIAL ||
entityKind === openbis.EntityKind.DATA_SET
) {
return object.code
}
}
createOptionFullLabel(entityKind, object) {
let name = object.properties[ENTITY_NAME_PROPERTY]
if (name && name.trim().length > 0) {
name = ' (' + name.trim() + ')'
} else {
name = ''
}
if (
entityKind === openbis.EntityKind.EXPERIMENT ||
entityKind === openbis.EntityKind.SAMPLE ||
entityKind === openbis.EntityKind.MATERIAL
) {
return this.createOptionLabel(entityKind, object) + name
} else if (entityKind === openbis.EntityKind.DATA_SET) {
let owner = null
if (object.experiment) {
owner = this.createOptionLabel(
openbis.EntityKind.EXPERIMENT,
object.experiment
)
} else if (object.sample) {
owner = this.createOptionLabel(openbis.EntityKind.SAMPLE, object.sample)
}
if (owner) {
owner = ' [owner: ' + owner + ']'
} else {
owner = ''
}
return this.createOptionLabel(entityKind, object) + name + owner
}
}
handleFocus() { handleFocus() {
this.load(this.state.inputValue) this.load(this.state.inputValue)
} }
...@@ -271,7 +353,11 @@ class EntityAutocompleterField extends React.PureComponent { ...@@ -271,7 +353,11 @@ class EntityAutocompleterField extends React.PureComponent {
} }
renderOption(option) { renderOption(option) {
return <span>{this.getOptionLabel(option)}</span> if (option) {
return option.fullLabel || option.label
} else {
return ''
}
} }
filterOptions(options) { filterOptions(options) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment