From fc08108ee04383c951eeb5c1f66567f6e9a978ae Mon Sep 17 00:00:00 2001 From: dswbx Date: Sat, 18 Jan 2025 16:22:26 +0100 Subject: [PATCH] admin ui: improved relation description --- .../ui/client/schema/data/use-bknd-data.ts | 4 +-- .../schema/create-modal/step.create.tsx | 4 --- .../schema/create-modal/step.relation.tsx | 28 +++++++++++++++++-- app/src/ui/routes/data/_data.root.tsx | 6 +--- .../ui/routes/data/data.schema.$entity.tsx | 11 ++------ 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/app/src/ui/client/schema/data/use-bknd-data.ts b/app/src/ui/client/schema/data/use-bknd-data.ts index 0886fed..7ab5d9b 100644 --- a/app/src/ui/client/schema/data/use-bknd-data.ts +++ b/app/src/ui/client/schema/data/use-bknd-data.ts @@ -89,13 +89,13 @@ const modals = { initialPath: ["entities", "entity"], initialState: { action: "entity" } }), - createRelation: (rel: { source?: string; target?: string; type?: string }) => + createRelation: (entity?: string) => bkndModals.open(bkndModals.ids.dataCreate, { initialPath: ["entities", "relation"], initialState: { action: "relation", relations: { - create: [rel as any] + create: [{ source: entity, type: "n:1" } as any] } } }), diff --git a/app/src/ui/modules/data/components/schema/create-modal/step.create.tsx b/app/src/ui/modules/data/components/schema/create-modal/step.create.tsx index 470d214..b3996fc 100644 --- a/app/src/ui/modules/data/components/schema/create-modal/step.create.tsx +++ b/app/src/ui/modules/data/components/schema/create-modal/step.create.tsx @@ -111,10 +111,6 @@ export function StepCreate() { ))} - {/*
{submitting ? "submitting" : "idle"}
-
- {states.length}/{items.length} -
*/} = { export function StepRelation() { const { config } = useBknd(); const entities = config.data.entities; + const count = Object.keys(entities ?? {}).length; const { nextStep, stepBack, state, path, setState } = useStepContext(); const { register, @@ -79,7 +81,6 @@ export function StepRelation() { defaultValues: (state.relations?.create?.[0] ?? {}) as Static }); const data = watch(); - console.log("data", { data, schema }); function handleNext() { if (isValid) { @@ -114,6 +115,11 @@ export function StepRelation() { return ( <> + {count < 2 && ( +
+ Not enough entities to create a relation. +
+ )}
@@ -226,6 +232,10 @@ function ManyToOne({ register, control, data: { source, target, config } }: Comp {source && target && config && ( <> +
+                     
+                     {source}.{config.mappedBy || target}_id {"→"} {target}
+                  

Many

{source}
will each have one reference to
{target}
.

@@ -239,7 +249,7 @@ function ManyToOne({ register, control, data: { source, target, config } }: Comp

{config.sourceCardinality ? (

-

{source}
should not have more than{" "} +
{target}
should not have more than{" "}
{config.sourceCardinality}
referencing entr {config.sourceCardinality === 1 ? "y" : "ies"} to
{source}
.

@@ -283,6 +293,10 @@ function OneToOne({ {source && target && ( <> +
+                     
+                     {source}.{mappedBy || target}_id {"↔"} {target}
+                  

A single entry of

{source}
will have a reference to{" "}
{target}
. @@ -341,6 +355,10 @@ function ManyToMany({ register, control, data: { source, target, config } }: Com {source && target && ( <> +
+                     
+                     {source} {"→"} {table} {"←"} {target}
+                  

Many

{source}
will have many
{target}
.

@@ -383,6 +401,10 @@ function Polymorphic({ register, control, data: { type, source, target, config } {source && target && ( <> +
+                     
+                     {source} {"←"} {target}
+                  

{source}
will have many
{target}
.

diff --git a/app/src/ui/routes/data/_data.root.tsx b/app/src/ui/routes/data/_data.root.tsx index 543816c..f7281ef 100644 --- a/app/src/ui/routes/data/_data.root.tsx +++ b/app/src/ui/routes/data/_data.root.tsx @@ -191,11 +191,7 @@ const EntityContextMenu = ({ { icon: IconCirclesRelation, label: "Add relation", - onClick: () => - $data.modals.createRelation({ - target: entity.name, - type: "n:1" - }) + onClick: () => $data.modals.createRelation(entity.name) }, !$data.system(entity.name).media && { icon: IconPhoto, diff --git a/app/src/ui/routes/data/data.schema.$entity.tsx b/app/src/ui/routes/data/data.schema.$entity.tsx index 455b945..ba4d8c4 100644 --- a/app/src/ui/routes/data/data.schema.$entity.tsx +++ b/app/src/ui/routes/data/data.schema.$entity.tsx @@ -76,11 +76,7 @@ export function DataSchemaEntity({ params }) { { icon: TbCirclesRelation, label: "Add relation", - onClick: () => - $data.modals.createRelation({ - target: entity.name, - type: "n:1" - }) + onClick: () => $data.modals.createRelation(entity.name) }, { icon: TbPhoto, @@ -207,10 +203,7 @@ const Fields = ({ onClick: () => { switch (i.type) { case "relation": - $data.modals.createRelation({ - target: entity.name, - type: "n:1" - }); + $data.modals.createRelation(entity.name); break; case "media": $data.modals.createMedia(entity.name);