Skip to content

Commit 0ec7144

Browse files
committed
fix: duplicate molecule names #2730
Squashed commit of the following: commit 6e45b0a Author: Adrian Herrmann <headri@web.de> Date: Mon Oct 27 14:22:22 2025 +0000 show desc and remove duplicates
1 parent 8367b8b commit 0ec7144

File tree

1 file changed

+24
-6
lines changed
  • app/javascript/src/apps/mydb/elements/details/samples/propertiesTab

1 file changed

+24
-6
lines changed

app/javascript/src/apps/mydb/elements/details/samples/propertiesTab/SampleForm.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,24 @@ export default class SampleForm extends React.Component {
353353
let moleculeNames = newMolecule ? [] : [mno];
354354
if (sample && mnos) { moleculeNames = moleculeNames.concat(mnos); }
355355

356-
const formattedOptions = moleculeNames.filter(name => name).map(name => {
356+
const formattedOptions = moleculeNames.filter((name) => name).map((name) => {
357357
if (typeof name === 'string') {
358-
return { label: name, value: name };
358+
return { label: name, value: name, type: '' };
359359
}
360360
return {
361361
label: name.label || name.value || name.name || String(name),
362-
value: name.value || name.label || name.name || String(name)
362+
value: name.value || name.label || name.name || String(name),
363+
type: name.desc || ''
363364
};
365+
}).filter((name, _, names) => {
366+
if (name.type === 'alternate' || name.type?.startsWith('defined by user')) {
367+
const hasMainVersion = names.some(
368+
(other) => other.label === name.label
369+
&& !(other.type === 'alternate' || other.type?.toLowerCase().startsWith('defined by user'))
370+
);
371+
return !hasMainVersion;
372+
}
373+
return true;
364374
});
365375

366376
return (
@@ -380,6 +390,12 @@ export default class SampleForm extends React.Component {
380390
this.setState({ moleculeNameInputValue: value });
381391
this.updateMolName(selectedOption);
382392
}}
393+
formatOptionLabel={(option, { context }) => {
394+
if (context === 'menu') {
395+
return option.type ? `${option.label}(${option.type})` : option.label;
396+
}
397+
return option.label;
398+
}}
383399
onInputChange={(inputValue, { action }) => {
384400
if (action === 'input-change') {
385401
this.setState({ moleculeNameInputValue: inputValue });
@@ -421,7 +437,7 @@ export default class SampleForm extends React.Component {
421437

422438
fetchNextInventoryLabel() {
423439
const { currentCollection } = UIStore.getState();
424-
if(this.matchSelectedCollection(currentCollection)) {
440+
if (this.matchSelectedCollection(currentCollection)) {
425441
InventoryFetcher.fetchInventoryOfCollection(currentCollection.id)
426442
.then((result) => {
427443
if (result && result.prefix && result.counter !== undefined) {
@@ -1056,7 +1072,9 @@ export default class SampleForm extends React.Component {
10561072
}
10571073

10581074
render() {
1059-
const { enableSampleDecoupled, sample = {}, customizableField, handleSampleChanged } = this.props;
1075+
const {
1076+
enableSampleDecoupled, sample = {}, customizableField, handleSampleChanged
1077+
} = this.props;
10601078
const isPolymer = (sample.molfile || '').indexOf(' R# ') !== -1;
10611079
const isDisabled = !sample.can_update;
10621080
const polyDisabled = isPolymer || isDisabled;
@@ -1194,7 +1212,7 @@ export default class SampleForm extends React.Component {
11941212

11951213
{selectedSampleType?.value === 'Mixture' && (
11961214
<>
1197-
<br/>
1215+
<br />
11981216
<h5>Mixture components:</h5>
11991217
<Row className="mb-4 g-2">
12001218
<Col xs={12} sm={6} lg={3}>

0 commit comments

Comments
 (0)