From 498c9c8baa18fb2dd085a95d0ae424ca35855c10 Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Mon, 27 Feb 2023 09:13:37 -0600 Subject: [PATCH] Convert 0 linkTypeIDs to null for the relationship dialog This fixes the underlying cause of MBS-12931 by converting link type IDs stored as 0 to null before constructing the relationship state sent to the dialog. It also adds some Sentry logging in case we see a link type of 0 in useRelationshipDialogContent again, though I think the previous fix for MBS-12931 (hiding the '+' button when there is no type) makes that very unlikely. --- .../components/RelationshipPhraseGroup.js | 8 +++++++- .../hooks/useRelationshipDialogContent.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/root/static/scripts/relationship-editor/components/RelationshipPhraseGroup.js b/root/static/scripts/relationship-editor/components/RelationshipPhraseGroup.js index c7c41e12d00..c1f5da93401 100644 --- a/root/static/scripts/relationship-editor/components/RelationshipPhraseGroup.js +++ b/root/static/scripts/relationship-editor/components/RelationshipPhraseGroup.js @@ -143,7 +143,13 @@ const RelationshipPhraseGroup = (React.memo(({ [backward ? 'entity1' : 'entity0']: source, attributes: newAttributesData, linkOrder: maxLinkOrder > 0 ? (maxLinkOrder + 1) : 0, - linkTypeID: linkTypeId, + /* + * The `typeId` on `RelationshipLinkTypeGroupT` stores empty types as + * `0` (which isn't a valid relationship type row ID anyway) for easier + * sorting. `RelationshipStateT` stores empty types as `null`. Convert + * `0` back to `null` here. + */ + linkTypeID: linkTypeId || null, }; }, [ canBeOrdered, diff --git a/root/static/scripts/relationship-editor/hooks/useRelationshipDialogContent.js b/root/static/scripts/relationship-editor/hooks/useRelationshipDialogContent.js index 7dd15d514a5..923d4643553 100644 --- a/root/static/scripts/relationship-editor/hooks/useRelationshipDialogContent.js +++ b/root/static/scripts/relationship-editor/hooks/useRelationshipDialogContent.js @@ -7,6 +7,7 @@ * later version: http://www.gnu.org/licenses/gpl-2.0.txt */ +import * as Sentry from '@sentry/browser'; import * as React from 'react'; import {createCoreEntityObject} from '../../common/entity2.js'; @@ -75,6 +76,17 @@ export default function useRelationshipDialogContent( user, } = options; + if (relationship.linkTypeID === 0) { + /* + * Empty link types should be stored as `null` on `RelationshipStateT`. + * We store them as `0` on `RelationshipLinkTypeGroupT`, so check to + * make sure those don't wind up here. (See MBS-12931.) + */ + Sentry.captureException( + new Error('relationship.linkTypeID is 0, but should be null'), + ); + } + return React.useCallback((closeAndReturnFocus) => { if (targetTypeOptions != null && !targetTypeOptions.length) { /*