Skip to content

Commit

Permalink
A few more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonking committed Jan 23, 2025
1 parent 3178f14 commit 46379df
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions core/app/components/forms/AddRelatedPubsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
18 changes: 8 additions & 10 deletions core/app/components/forms/elements/RelatedPubsElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PubFieldFormElement {...props} element={element} slug={slug} label={label} />;
};
Expand Down Expand Up @@ -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 (
<>
<FormField
control={control}
name={slug}
render={({ field }) => {
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 (
<FormItem>
{showPanel && (
Expand All @@ -159,7 +157,7 @@ export const RelatedPubsElement = ({
disabled={!isEnabled}
onAdd={() => setShowPanel(true)}
>
{Array.isArray(field.value) ? (
{fields.length ? (
<div className="flex flex-col gap-2">
{fields.map((item, index) => {
const handleRemovePub = () => {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/fields/richText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const parseRichTextForPubFieldsAndRelatedPubs = <T extends JsonValue>({
pubId: PubsId;
values: Record<string, T>;
}) => {
const newValues = structuredClone(values);
const newValues: Record<string, T | string> = structuredClone(values);
const pubs: PubCreate[] = [];

// Find a rich text value if one exists
Expand Down
8 changes: 4 additions & 4 deletions packages/db/src/public/PublicSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,8 +92,4 @@ export interface PublicSchema {
stage_memberships: StageMembershipsTable;

form_memberships: FormMembershipsTable;

membership_capabilities: MembershipCapabilitiesTable;

pub_values_history: PubValuesHistoryTable;
}

0 comments on commit 46379df

Please sign in to comment.