Skip to content

Commit 5a1234f

Browse files
committed
Restrict creeating Host Taxon
This restriction needs to be put into place until a proper fix for the Host Taxon relationship is implemented The issue is that any Host Taxon uploaded through the WorkBench or created using the '+' button on the QueryCombobox will always be created in the current collection. Related: #3240, #2675
1 parent b81643b commit 5a1234f

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

specifyweb/frontend/js_src/lib/components/DataModel/schemaOverrides.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ const globalFieldOverrides: {
110110
Attachment: {
111111
tableID: 'optional',
112112
},
113+
CollectingEventAttribute: {
114+
hostTaxon: 'readOnly',
115+
},
113116
Taxon: {
114117
parent: 'required',
115118
isAccepted: 'readOnly',

specifyweb/frontend/js_src/lib/components/FormFields/QueryComboBox.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function QueryComboBox({
6464
typeSearch: initialTypeSearch,
6565
forceCollection,
6666
relatedModel: initialRelatedModel,
67+
disableCanAdd = false,
6768
}: {
6869
readonly id: string | undefined;
6970
readonly resource: SpecifyResource<AnySchema> | undefined;
@@ -75,6 +76,7 @@ export function QueryComboBox({
7576
readonly typeSearch: Element | string | undefined;
7677
readonly forceCollection: number | undefined;
7778
readonly relatedModel?: SpecifyModel | undefined;
79+
readonly disableCanAdd: boolean;
7880
}): JSX.Element {
7981
React.useEffect(() => {
8082
if (resource === undefined || !resource.isNew()) return;
@@ -344,7 +346,8 @@ export function QueryComboBox({
344346

345347
const canAdd =
346348
!RESTRICT_ADDING.has(field.relatedModel.name) &&
347-
hasTablePermission(field.relatedModel.name, 'create');
349+
hasTablePermission(field.relatedModel.name, 'create') &&
350+
!disableCanAdd;
348351

349352
return (
350353
<div className="flex w-full min-w-[theme(spacing.40)] items-center sm:min-w-[unset]">

specifyweb/frontend/js_src/lib/components/FormPlugins/HostTaxon.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,29 @@ export function HostTaxon({
4444
.maybe(records[0], deserializeResource)
4545
?.rgetPromise('rightSideCollection')
4646
)
47-
.then((collection) => collection?.get('id')),
47+
.then((collection) => collection),
4848
[relationship]
4949
),
5050
false
5151
);
52-
return rightSideCollection === undefined ? (
52+
return rightSideCollection === null || rightSideCollection === undefined ? (
5353
<Input.Text isReadOnly />
5454
) : hasTreeAccess('Taxon', 'read') ? (
5555
<QueryComboBox
5656
field={schema.models.CollectingEventAttribute.strictGetRelationship(
5757
'hostTaxon'
5858
)}
59-
forceCollection={rightSideCollection}
59+
forceCollection={rightSideCollection.get('id')}
6060
formType={formType}
6161
id={id}
6262
isRequired={isRequired}
6363
mode={mode}
6464
relatedModel={schema.models.Taxon}
6565
resource={resource}
6666
typeSearch={hostTaxonTypeSearch}
67+
disableCanAdd={
68+
rightSideCollection.get('discipline') !== resource.get('discipline')
69+
}
6770
/>
6871
) : null;
6972
}

0 commit comments

Comments
 (0)