mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 21:06:04 +00:00
admin ui: improved relation description
This commit is contained in:
@@ -89,13 +89,13 @@ const modals = {
|
|||||||
initialPath: ["entities", "entity"],
|
initialPath: ["entities", "entity"],
|
||||||
initialState: { action: "entity" }
|
initialState: { action: "entity" }
|
||||||
}),
|
}),
|
||||||
createRelation: (rel: { source?: string; target?: string; type?: string }) =>
|
createRelation: (entity?: string) =>
|
||||||
bkndModals.open(bkndModals.ids.dataCreate, {
|
bkndModals.open(bkndModals.ids.dataCreate, {
|
||||||
initialPath: ["entities", "relation"],
|
initialPath: ["entities", "relation"],
|
||||||
initialState: {
|
initialState: {
|
||||||
action: "relation",
|
action: "relation",
|
||||||
relations: {
|
relations: {
|
||||||
create: [rel as any]
|
create: [{ source: entity, type: "n:1" } as any]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -111,10 +111,6 @@ export function StepCreate() {
|
|||||||
<SummaryItem key={i} {...item} state={states[i]} />
|
<SummaryItem key={i} {...item} state={states[i]} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
{/*<div>{submitting ? "submitting" : "idle"}</div>
|
|
||||||
<div>
|
|
||||||
{states.length}/{items.length}
|
|
||||||
</div>*/}
|
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter
|
<ModalFooter
|
||||||
nextLabel="Create"
|
nextLabel="Create"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { typeboxResolver } from "@hookform/resolvers/typebox";
|
import { typeboxResolver } from "@hookform/resolvers/typebox";
|
||||||
import { Select, Switch, TextInput } from "@mantine/core";
|
import { Switch, TextInput } from "@mantine/core";
|
||||||
import { TypeRegistry } from "@sinclair/typebox";
|
import { TypeRegistry } from "@sinclair/typebox";
|
||||||
|
import { IconDatabase } from "@tabler/icons-react";
|
||||||
import {
|
import {
|
||||||
type Static,
|
type Static,
|
||||||
StringEnum,
|
StringEnum,
|
||||||
@@ -66,6 +67,7 @@ type ComponentCtx<T extends FieldValues = FieldValues> = {
|
|||||||
export function StepRelation() {
|
export function StepRelation() {
|
||||||
const { config } = useBknd();
|
const { config } = useBknd();
|
||||||
const entities = config.data.entities;
|
const entities = config.data.entities;
|
||||||
|
const count = Object.keys(entities ?? {}).length;
|
||||||
const { nextStep, stepBack, state, path, setState } = useStepContext<TCreateModalSchema>();
|
const { nextStep, stepBack, state, path, setState } = useStepContext<TCreateModalSchema>();
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@@ -79,7 +81,6 @@ export function StepRelation() {
|
|||||||
defaultValues: (state.relations?.create?.[0] ?? {}) as Static<typeof schema>
|
defaultValues: (state.relations?.create?.[0] ?? {}) as Static<typeof schema>
|
||||||
});
|
});
|
||||||
const data = watch();
|
const data = watch();
|
||||||
console.log("data", { data, schema });
|
|
||||||
|
|
||||||
function handleNext() {
|
function handleNext() {
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
@@ -114,6 +115,11 @@ export function StepRelation() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{count < 2 && (
|
||||||
|
<div className="px-5 py-4 bg-red-100 text-red-900">
|
||||||
|
Not enough entities to create a relation.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<form onSubmit={handleSubmit(handleNext)}>
|
<form onSubmit={handleSubmit(handleNext)}>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<div className="grid grid-cols-3 gap-8">
|
<div className="grid grid-cols-3 gap-8">
|
||||||
@@ -226,6 +232,10 @@ function ManyToOne({ register, control, data: { source, target, config } }: Comp
|
|||||||
{source && target && config && (
|
{source && target && config && (
|
||||||
<Callout>
|
<Callout>
|
||||||
<>
|
<>
|
||||||
|
<pre className="mb-2 opacity-70 flex flex-row items-center gap-2">
|
||||||
|
<IconDatabase className="size-4" />
|
||||||
|
{source}.{config.mappedBy || target}_id {"→"} {target}
|
||||||
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
Many <Pre>{source}</Pre> will each have one reference to <Pre>{target}</Pre>.
|
Many <Pre>{source}</Pre> will each have one reference to <Pre>{target}</Pre>.
|
||||||
</p>
|
</p>
|
||||||
@@ -239,7 +249,7 @@ function ManyToOne({ register, control, data: { source, target, config } }: Comp
|
|||||||
</p>
|
</p>
|
||||||
{config.sourceCardinality ? (
|
{config.sourceCardinality ? (
|
||||||
<p>
|
<p>
|
||||||
<Pre>{source}</Pre> should not have more than{" "}
|
<Pre>{target}</Pre> should not have more than{" "}
|
||||||
<Pre>{config.sourceCardinality}</Pre> referencing entr
|
<Pre>{config.sourceCardinality}</Pre> referencing entr
|
||||||
{config.sourceCardinality === 1 ? "y" : "ies"} to <Pre>{source}</Pre>.
|
{config.sourceCardinality === 1 ? "y" : "ies"} to <Pre>{source}</Pre>.
|
||||||
</p>
|
</p>
|
||||||
@@ -283,6 +293,10 @@ function OneToOne({
|
|||||||
{source && target && (
|
{source && target && (
|
||||||
<Callout>
|
<Callout>
|
||||||
<>
|
<>
|
||||||
|
<pre className="mb-2 opacity-70 flex flex-row items-center gap-2">
|
||||||
|
<IconDatabase className="size-4" />
|
||||||
|
{source}.{mappedBy || target}_id {"↔"} {target}
|
||||||
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
A single entry of <Pre>{source}</Pre> will have a reference to{" "}
|
A single entry of <Pre>{source}</Pre> will have a reference to{" "}
|
||||||
<Pre>{target}</Pre>.
|
<Pre>{target}</Pre>.
|
||||||
@@ -341,6 +355,10 @@ function ManyToMany({ register, control, data: { source, target, config } }: Com
|
|||||||
{source && target && (
|
{source && target && (
|
||||||
<Callout>
|
<Callout>
|
||||||
<>
|
<>
|
||||||
|
<pre className="mb-2 opacity-70 flex flex-row items-center gap-2">
|
||||||
|
<IconDatabase className="size-4" />
|
||||||
|
{source} {"→"} {table} {"←"} {target}
|
||||||
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
Many <Pre>{source}</Pre> will have many <Pre>{target}</Pre>.
|
Many <Pre>{source}</Pre> will have many <Pre>{target}</Pre>.
|
||||||
</p>
|
</p>
|
||||||
@@ -383,6 +401,10 @@ function Polymorphic({ register, control, data: { type, source, target, config }
|
|||||||
{source && target && (
|
{source && target && (
|
||||||
<Callout>
|
<Callout>
|
||||||
<>
|
<>
|
||||||
|
<pre className="mb-2 opacity-70 flex flex-row items-center gap-2">
|
||||||
|
<IconDatabase className="size-4" />
|
||||||
|
{source} {"←"} {target}
|
||||||
|
</pre>
|
||||||
<p>
|
<p>
|
||||||
<Pre>{source}</Pre> will have many <Pre>{target}</Pre>.
|
<Pre>{source}</Pre> will have many <Pre>{target}</Pre>.
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -191,11 +191,7 @@ const EntityContextMenu = ({
|
|||||||
{
|
{
|
||||||
icon: IconCirclesRelation,
|
icon: IconCirclesRelation,
|
||||||
label: "Add relation",
|
label: "Add relation",
|
||||||
onClick: () =>
|
onClick: () => $data.modals.createRelation(entity.name)
|
||||||
$data.modals.createRelation({
|
|
||||||
target: entity.name,
|
|
||||||
type: "n:1"
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
!$data.system(entity.name).media && {
|
!$data.system(entity.name).media && {
|
||||||
icon: IconPhoto,
|
icon: IconPhoto,
|
||||||
|
|||||||
@@ -76,11 +76,7 @@ export function DataSchemaEntity({ params }) {
|
|||||||
{
|
{
|
||||||
icon: TbCirclesRelation,
|
icon: TbCirclesRelation,
|
||||||
label: "Add relation",
|
label: "Add relation",
|
||||||
onClick: () =>
|
onClick: () => $data.modals.createRelation(entity.name)
|
||||||
$data.modals.createRelation({
|
|
||||||
target: entity.name,
|
|
||||||
type: "n:1"
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: TbPhoto,
|
icon: TbPhoto,
|
||||||
@@ -207,10 +203,7 @@ const Fields = ({
|
|||||||
onClick: () => {
|
onClick: () => {
|
||||||
switch (i.type) {
|
switch (i.type) {
|
||||||
case "relation":
|
case "relation":
|
||||||
$data.modals.createRelation({
|
$data.modals.createRelation(entity.name);
|
||||||
target: entity.name,
|
|
||||||
type: "n:1"
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case "media":
|
case "media":
|
||||||
$data.modals.createMedia(entity.name);
|
$data.modals.createMedia(entity.name);
|
||||||
|
|||||||
Reference in New Issue
Block a user