From 46379df81a91e8b7e2c296954b148106e379e321 Mon Sep 17 00:00:00 2001 From: allisonking Date: Wed, 22 Jan 2025 17:41:30 -0500 Subject: [PATCH] A few more fixes --- .../components/forms/AddRelatedPubsPanel.tsx | 1 + .../forms/elements/RelatedPubsElement.tsx | 18 ++++++++---------- core/lib/fields/richText.ts | 2 +- packages/db/src/public/PublicSchema.ts | 8 ++++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/app/components/forms/AddRelatedPubsPanel.tsx b/core/app/components/forms/AddRelatedPubsPanel.tsx index 0bf14d4eb..04dffa6dc 100644 --- a/core/app/components/forms/AddRelatedPubsPanel.tsx +++ b/core/app/components/forms/AddRelatedPubsPanel.tsx @@ -72,6 +72,7 @@ export const AddRelatedPubsPanel = ({ .map((selection) => selection[0] as PubsId); const selectedPubs = pubs.filter((p) => selectedPubIds.includes(p.id)); onAdd(selectedPubs); + onCancel(); }; return ( diff --git a/core/app/components/forms/elements/RelatedPubsElement.tsx b/core/app/components/forms/elements/RelatedPubsElement.tsx index 5bfd4a52f..f0773a323 100644 --- a/core/app/components/forms/elements/RelatedPubsElement.tsx +++ b/core/app/components/forms/elements/RelatedPubsElement.tsx @@ -85,7 +85,8 @@ export const InnerValue = ({ element, ...props }: PubFieldFormElementProps & { slug: string }) => { - const label = element.config.label || element.label || slug; + const configLabel = "label" in element.config ? element.config.label : undefined; + const label = configLabel || element.label || slug; return ; }; @@ -121,26 +122,23 @@ export const RelatedPubsElement = ({ ); }, [pubs]); + const linkedPubs = fields.map((f) => f.relatedPubId); + const linkablePubs = pubs + // do not allow linking to itself or any pubs it is already linked to + .filter((p) => p.id !== pubId && !linkedPubs.includes(p.id)); + return ( <> { - const linkedPubs = Array.isArray(field.value) - ? field.value.map((v: FieldValue) => v.relatedPubId) - : []; - const linkablePubs = pubs - // do not allow linking to itself or any pubs it is already linked to - .filter((p) => p.id !== pubId && !linkedPubs.includes(p.id)); - const handleAddPubs = (newPubs: GetPubsResult) => { const values = newPubs.map((p) => ({ relatedPubId: p.id, value: null })); for (const value of values) { append(value); } }; - return ( {showPanel && ( @@ -159,7 +157,7 @@ export const RelatedPubsElement = ({ disabled={!isEnabled} onAdd={() => setShowPanel(true)} > - {Array.isArray(field.value) ? ( + {fields.length ? (
{fields.map((item, index) => { const handleRemovePub = () => { diff --git a/core/lib/fields/richText.ts b/core/lib/fields/richText.ts index f5d44cb13..8753d168e 100644 --- a/core/lib/fields/richText.ts +++ b/core/lib/fields/richText.ts @@ -53,7 +53,7 @@ export const parseRichTextForPubFieldsAndRelatedPubs = ({ pubId: PubsId; values: Record; }) => { - const newValues = structuredClone(values); + const newValues: Record = structuredClone(values); const pubs: PubCreate[] = []; // Find a rich text value if one exists diff --git a/packages/db/src/public/PublicSchema.ts b/packages/db/src/public/PublicSchema.ts index 62eb7d16d..adcc4c177 100644 --- a/packages/db/src/public/PublicSchema.ts +++ b/packages/db/src/public/PublicSchema.ts @@ -33,6 +33,10 @@ import type { StagesTable } from "./Stages"; import type { UsersTable } from "./Users"; export interface PublicSchema { + membership_capabilities: MembershipCapabilitiesTable; + + pub_values_history: PubValuesHistoryTable; + _prisma_migrations: PrismaMigrationsTable; users: UsersTable; @@ -88,8 +92,4 @@ export interface PublicSchema { stage_memberships: StageMembershipsTable; form_memberships: FormMembershipsTable; - - membership_capabilities: MembershipCapabilitiesTable; - - pub_values_history: PubValuesHistoryTable; }