mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
check that a synonym does not already exist as a species
This commit is contained in:
@@ -7,9 +7,13 @@ import { EditingForm, EditingFormField } from '@/components/DetailView/common/Ed
|
|||||||
import { useNotify } from '@/hooks/notification'
|
import { useNotify } from '@/hooks/notification'
|
||||||
import { validateSynonym } from '@/shared/validators/synonym'
|
import { validateSynonym } from '@/shared/validators/synonym'
|
||||||
import { convertSynonymTaxonomyFields } from '@/util/taxonomyUtilities'
|
import { convertSynonymTaxonomyFields } from '@/util/taxonomyUtilities'
|
||||||
|
import { useGetAllSpeciesQuery } from '@/redux/speciesReducer'
|
||||||
|
import { skipToken } from '@reduxjs/toolkit/query'
|
||||||
|
import { CircularProgress } from '@mui/material'
|
||||||
|
|
||||||
export const SynonymTab = () => {
|
export const SynonymTab = () => {
|
||||||
const { mode, setEditData, editData } = useDetailContext<SpeciesDetailsType>()
|
const { mode, setEditData, editData } = useDetailContext<SpeciesDetailsType>()
|
||||||
|
const { data: speciesQueryData, isFetching } = useGetAllSpeciesQuery(mode.read ? skipToken : undefined)
|
||||||
const { notify } = useNotify()
|
const { notify } = useNotify()
|
||||||
|
|
||||||
const convertAndCheckNewSynonymTaxonomy = (newSynonym: EditDataType<SpeciesSynonym>) => {
|
const convertAndCheckNewSynonymTaxonomy = (newSynonym: EditDataType<SpeciesSynonym>) => {
|
||||||
@@ -43,6 +47,21 @@ export const SynonymTab = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const existingSpecies of speciesQueryData!) {
|
||||||
|
if (
|
||||||
|
convertedSynonym.syn_genus_name === existingSpecies.genus_name &&
|
||||||
|
convertedSynonym.syn_species_name === existingSpecies.species_name
|
||||||
|
) {
|
||||||
|
notify(
|
||||||
|
`${convertedSynonym.syn_genus_name} ${convertedSynonym.syn_species_name} \
|
||||||
|
has already been created as a separate species, adding it as a synonym is currently not allowed.`,
|
||||||
|
'error',
|
||||||
|
null
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return convertedSynonym
|
return convertedSynonym
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +107,8 @@ export const SynonymTab = () => {
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (isFetching) return <CircularProgress />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grouped title="Synonyms">
|
<Grouped title="Synonyms">
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ const isDuplicateTaxon = (newSpecies: EditDataType<Species>, existingSpecies: Sp
|
|||||||
newSpecies.species_name === existingSpecies.species_name &&
|
newSpecies.species_name === existingSpecies.species_name &&
|
||||||
newSpecies.unique_identifier === existingSpecies.unique_identifier
|
newSpecies.unique_identifier === existingSpecies.unique_identifier
|
||||||
) {
|
) {
|
||||||
|
console.log('joo')
|
||||||
|
console.log(newSpecies)
|
||||||
|
console.log(existingSpecies)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user