From 08bbd3475ec09a95528336fd73497e972acfd856 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Fri, 7 Mar 2025 10:23:03 -0800 Subject: [PATCH 1/6] Remove cat number format check in interaction dialog Fixes #6287 --- .../lib/components/Interactions/InteractionDialog.tsx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx index 13e6e6ec32f..c428913be08 100644 --- a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx +++ b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx @@ -206,17 +206,6 @@ export function InteractionDialog({ const parseResults = split(catalogNumbers).map((value) => parseValue(parser, inputRef.current ?? undefined, value) ); - const errorMessages = parseResults - .filter((result): result is InvalidParseResult => !result.isValid) - .map(({ reason, value }) => `${reason} (${value})`); - if (errorMessages.length > 0) { - setValidation(errorMessages); - setState({ - type: 'InvalidState', - invalid: errorMessages, - }); - return undefined; - } const parsed = f.unique( (parseResults as RA) From efa337f29c9ab69438d889563840feaf292d0b52 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Fri, 7 Mar 2025 10:32:18 -0800 Subject: [PATCH 2/6] Remove import --- .../js_src/lib/components/Interactions/InteractionDialog.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx index c428913be08..21b9b6e5c79 100644 --- a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx +++ b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx @@ -14,7 +14,6 @@ import { resolveParser, } from '../../utils/parser/definitions'; import type { - InvalidParseResult, ValidParseResult, } from '../../utils/parser/parse'; import { parseValue } from '../../utils/parser/parse'; @@ -100,7 +99,7 @@ export function InteractionDialog({ | State<'MainState'> >({ type: 'MainState' }); - const { validationRef, inputRef, setValidation } = + const { validationRef, inputRef } = useValidation(); const [catalogNumbers, setCatalogNumbers] = React.useState(''); From 1e860bc70fb4d97dfee5611914080913d2bf9929 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:08:45 -0700 Subject: [PATCH 3/6] Check if collection has several types --- .../Interactions/InteractionDialog.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx index 21b9b6e5c79..a5cead3e0f1 100644 --- a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx +++ b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx @@ -1,6 +1,7 @@ import React from 'react'; import type { State } from 'typesafe-reducer'; +import { useAsyncState } from '../../hooks/useAsyncState'; import { useValidation } from '../../hooks/useValidation'; import { commonText } from '../../localization/common'; import { interactionsText } from '../../localization/interactions'; @@ -30,11 +31,13 @@ import type { SerializedResource, } from '../DataModel/helperTypes'; import type { SpecifyResource } from '../DataModel/legacyTypes'; -import { getResourceViewUrl } from '../DataModel/resource'; +import { getResourceViewUrl, resourceFromUrl } from '../DataModel/resource'; +import { fetchContext as fetchDomain, schema } from '../DataModel/schema'; import type { LiteralField } from '../DataModel/specifyField'; import type { Collection, SpecifyTable } from '../DataModel/specifyTable'; import { tables } from '../DataModel/tables'; import type { + CollectionObjectType, DisposalPreparation, GiftPreparation, LoanPreparation, @@ -201,11 +204,23 @@ export function InteractionDialog({ })), }); + const [collectionHasSeveralTypes] = useAsyncState( + React.useCallback( + async () => + fetchDomain.then(async (schema) => Object.keys(schema.collectionObjectTypeCatalogNumberFormats).length > 1), + [] + ), + false + ); + function handleParse(): RA | undefined { const parseResults = split(catalogNumbers).map((value) => parseValue(parser, inputRef.current ?? undefined, value) ); + const form = parser.parser?.(split(catalogNumbers)[0]) + console.log(form) + const parsed = f.unique( (parseResults as RA) .filter(({ parsed }) => parsed !== null) From b54685d95a9164a97315c46e6f0baf995d0f69b8 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:42:55 -0700 Subject: [PATCH 4/6] Set error message for cat num format only for collections that have 1 COtype --- .../Interactions/InteractionDialog.tsx | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx index a5cead3e0f1..03e39c6dd90 100644 --- a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx +++ b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx @@ -15,6 +15,7 @@ import { resolveParser, } from '../../utils/parser/definitions'; import type { + InvalidParseResult, ValidParseResult, } from '../../utils/parser/parse'; import { parseValue } from '../../utils/parser/parse'; @@ -102,7 +103,7 @@ export function InteractionDialog({ | State<'MainState'> >({ type: 'MainState' }); - const { validationRef, inputRef } = + const { validationRef, inputRef, setValidation } = useValidation(); const [catalogNumbers, setCatalogNumbers] = React.useState(''); @@ -218,8 +219,28 @@ export function InteractionDialog({ parseValue(parser, inputRef.current ?? undefined, value) ); - const form = parser.parser?.(split(catalogNumbers)[0]) - console.log(form) + const errorMessages = parseResults + .filter((result): result is InvalidParseResult => !result.isValid) + .map(({ reason, value }) => `${reason} (${value})`); + + if (errorMessages.length > 0 && collectionHasSeveralTypes === false) { + setValidation(errorMessages); + setState({ + type: 'InvalidState', + invalid: errorMessages, + }); + return undefined; + } + + if (collectionHasSeveralTypes === true) { + const parsedCatNumber = (split(catalogNumbers).map((catalogNumber) => parser.parser?.(catalogNumber) ?? catalogNumber)) + + setCatalogNumbers(parsedCatNumber.join('\n')) + + setState({ type: 'MainState' }); + + return(parsedCatNumber.map((cat) => (cat as number | string).toString())) + } const parsed = f.unique( (parseResults as RA) @@ -227,6 +248,7 @@ export function InteractionDialog({ .map(({ parsed }) => (parsed as number | string).toString()) .sort(sortFunction(f.id)) ); + setCatalogNumbers(parsed.join('\n')); setState({ type: 'MainState' }); From d53183004a0c664f9407815d2eff5b235aaf8951 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:46:45 -0700 Subject: [PATCH 5/6] Remove import --- .../js_src/lib/components/Interactions/InteractionDialog.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx index 03e39c6dd90..3be69ce838c 100644 --- a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx +++ b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx @@ -32,13 +32,12 @@ import type { SerializedResource, } from '../DataModel/helperTypes'; import type { SpecifyResource } from '../DataModel/legacyTypes'; -import { getResourceViewUrl, resourceFromUrl } from '../DataModel/resource'; -import { fetchContext as fetchDomain, schema } from '../DataModel/schema'; +import { getResourceViewUrl } from '../DataModel/resource'; +import { fetchContext as fetchDomain } from '../DataModel/schema'; import type { LiteralField } from '../DataModel/specifyField'; import type { Collection, SpecifyTable } from '../DataModel/specifyTable'; import { tables } from '../DataModel/tables'; import type { - CollectionObjectType, DisposalPreparation, GiftPreparation, LoanPreparation, From c6b2ba9bae42fd9f56db7349890131ac6772d952 Mon Sep 17 00:00:00 2001 From: Caroline D <108160931+CarolineDenis@users.noreply.github.com> Date: Wed, 12 Mar 2025 09:08:06 -0700 Subject: [PATCH 6/6] Do not use parser.parser when sevral cotype --- .../lib/components/Interactions/InteractionDialog.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx index 3be69ce838c..d5df5d8f74f 100644 --- a/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx +++ b/specifyweb/frontend/js_src/lib/components/Interactions/InteractionDialog.tsx @@ -232,13 +232,12 @@ export function InteractionDialog({ } if (collectionHasSeveralTypes === true) { - const parsedCatNumber = (split(catalogNumbers).map((catalogNumber) => parser.parser?.(catalogNumber) ?? catalogNumber)) - - setCatalogNumbers(parsedCatNumber.join('\n')) - + const parsedCatNumber = split(catalogNumbers); + + setCatalogNumbers(parsedCatNumber.join('\n')); setState({ type: 'MainState' }); - - return(parsedCatNumber.map((cat) => (cat as number | string).toString())) + + return parsedCatNumber.map(String); } const parsed = f.unique(