|
1 | 1 | import React, { useEffect, useRef, useState } from 'react'; |
2 | 2 | import CreatableSelect from 'react-select/creatable'; |
3 | | -import { Mutation, MutationList, VusObjList } from '../model/firebase/firebase.model'; |
| 3 | +import { MutationList, VusObjList } from '../model/firebase/firebase.model'; |
4 | 4 | import { parseAlterationName } from '../util/utils'; |
5 | 5 | import _ from 'lodash'; |
6 | 6 | import { notifyError } from 'app/oncokb-commons/components/util/NotificationUtils'; |
@@ -107,18 +107,33 @@ const AddVusModal = (props: IAddVusModalProps) => { |
107 | 107 | }; |
108 | 108 |
|
109 | 109 | const filterAlterationsAndNotify = (variant: string) => { |
110 | | - const currentVariants = variants.map(o => o.label.toLowerCase()); |
| 110 | + const result: string[] = []; |
111 | 111 | const alterations = parseAlterationName(variant); |
112 | | - const filteredAlterations = alterations.filter(alt => { |
113 | | - if (currentVariants.includes(alt.alteration.toLowerCase())) { |
114 | | - return false; |
| 112 | + // should only have a single alteration |
| 113 | + for (const { alteration } of alterations) { |
| 114 | + const dropdownAlreadyHasVariant = variants.some(({ label }) => { |
| 115 | + return label.toLowerCase() === alteration.toLowerCase(); |
| 116 | + }); |
| 117 | + |
| 118 | + const vusTableAlreadyHasVariant = Object.values(props.vusList ?? {}).some(({ name }) => { |
| 119 | + return name.toLowerCase() === alteration.toLowerCase(); |
| 120 | + }); |
| 121 | + |
| 122 | + const alreadyHasVariantInMutationList = Object.values(mutationList ?? {}).some(({ name }) => { |
| 123 | + return name.toLowerCase() === alteration.toLowerCase(); |
| 124 | + }); |
| 125 | + |
| 126 | + if (dropdownAlreadyHasVariant) { |
| 127 | + notifyError(new Error(`${alteration} is already selected. The duplicate alteration(s) was not added.`)); |
| 128 | + } else if (vusTableAlreadyHasVariant) { |
| 129 | + notifyError(new Error(`${alteration} is already in the VUS table. The duplicate alteration(s) was not added.`)); |
| 130 | + } else if (alreadyHasVariantInMutationList) { |
| 131 | + notifyError(new Error(`${alteration} is already in the Mutation List. The duplicate alteration(s) was not added.`)); |
| 132 | + } else { |
| 133 | + result.push(alteration); |
115 | 134 | } |
116 | | - return true; |
117 | | - }); |
118 | | - if (alterations.length !== filteredAlterations.length) { |
119 | | - notifyError(new Error('Duplicate alteration(s) removed')); |
120 | 135 | } |
121 | | - return filteredAlterations.map(a => a.alteration); |
| 136 | + return result; |
122 | 137 | }; |
123 | 138 |
|
124 | 139 | const selectComponent = ( |
|
0 commit comments