mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-02 16:16:02 +00:00
fix schema import path
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import type { ModalProps } from "@mantine/core";
|
||||
import type { ContextModalProps } from "@mantine/modals";
|
||||
import { entitiesSchema, fieldsSchema, relationsSchema } from "data/data-schema";
|
||||
import { useState } from "react";
|
||||
import { type Modal2Ref, ModalBody, ModalFooter, ModalTitle } from "ui/components/modal/Modal2";
|
||||
import { Step, Steps, useStepContext } from "ui/components/steps/Steps";
|
||||
@@ -10,52 +9,10 @@ import { StepEntityFields } from "./step.entity.fields";
|
||||
import { StepRelation } from "./step.relation";
|
||||
import { StepSelect } from "./step.select";
|
||||
import Templates from "./templates/register";
|
||||
import { s } from "core/object/schema";
|
||||
import type { TCreateModalSchema } from "./schema";
|
||||
|
||||
export type CreateModalRef = Modal2Ref;
|
||||
|
||||
export const ModalActions = ["entity", "relation", "media"] as const;
|
||||
|
||||
export const entitySchema = s.object({
|
||||
name: s.string(),
|
||||
...entitiesSchema.properties,
|
||||
});
|
||||
|
||||
// @todo: this union is not fully working, just "string"
|
||||
const schemaAction = s.anyOf([
|
||||
s.string({ enum: ["entity", "relation", "media"] }),
|
||||
s.string({ pattern: "^template-" }),
|
||||
]);
|
||||
export type TSchemaAction = s.Static<typeof schemaAction>;
|
||||
|
||||
const createFieldSchema = s.object({
|
||||
entity: s.string(),
|
||||
name: s.string(),
|
||||
field: s.array(fieldsSchema),
|
||||
});
|
||||
export type TFieldCreate = s.Static<typeof createFieldSchema>;
|
||||
|
||||
const createModalSchema = s.strictObject({
|
||||
action: schemaAction,
|
||||
initial: s.any().optional(),
|
||||
entities: s
|
||||
.object({
|
||||
create: s.array(entitySchema).optional(),
|
||||
})
|
||||
.optional(),
|
||||
relations: s
|
||||
.object({
|
||||
create: s.array(s.anyOf(relationsSchema)).optional(),
|
||||
})
|
||||
.optional(),
|
||||
fields: s
|
||||
.object({
|
||||
create: s.array(createFieldSchema).optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
export type TCreateModalSchema = s.Static<typeof createModalSchema>;
|
||||
|
||||
export function CreateModal({
|
||||
context,
|
||||
id,
|
||||
@@ -107,4 +64,4 @@ CreateModal.modalProps = {
|
||||
padding: 0,
|
||||
} satisfies Partial<ModalProps>;
|
||||
|
||||
export { ModalBody, ModalFooter, ModalTitle, useStepContext, relationsSchema };
|
||||
export { ModalBody, ModalFooter, ModalTitle, useStepContext };
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { s } from "bknd/core";
|
||||
import { entitiesSchema, fieldsSchema, relationsSchema } from "data/data-schema";
|
||||
|
||||
export const ModalActions = ["entity", "relation", "media"] as const;
|
||||
|
||||
export const entitySchema = s.object({
|
||||
name: s.string(),
|
||||
...entitiesSchema.properties,
|
||||
});
|
||||
|
||||
// @todo: this union is not fully working, just "string"
|
||||
const schemaAction = s.anyOf([
|
||||
s.string({ enum: ["entity", "relation", "media"] }),
|
||||
s.string({ pattern: "^template-" }),
|
||||
]);
|
||||
export type TSchemaAction = s.Static<typeof schemaAction>;
|
||||
|
||||
const createFieldSchema = s.object({
|
||||
entity: s.string(),
|
||||
name: s.string(),
|
||||
field: s.array(fieldsSchema),
|
||||
});
|
||||
export type TFieldCreate = s.Static<typeof createFieldSchema>;
|
||||
|
||||
const createModalSchema = s.strictObject({
|
||||
action: schemaAction,
|
||||
initial: s.any().optional(),
|
||||
entities: s
|
||||
.object({
|
||||
create: s.array(entitySchema).optional(),
|
||||
})
|
||||
.optional(),
|
||||
relations: s
|
||||
.object({
|
||||
create: s.array(s.anyOf(relationsSchema)).optional(),
|
||||
})
|
||||
.optional(),
|
||||
fields: s
|
||||
.object({
|
||||
create: s.array(createFieldSchema).optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
export type TCreateModalSchema = s.Static<typeof createModalSchema>;
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import {
|
||||
IconAlignJustified,
|
||||
IconAugmentedReality,
|
||||
IconBox,
|
||||
IconCirclesRelation,
|
||||
IconInfoCircle,
|
||||
@@ -15,7 +14,7 @@ import { IconButton, type IconType } from "ui/components/buttons/IconButton";
|
||||
import { JsonViewer } from "ui/components/code/JsonViewer";
|
||||
import { ModalBody, ModalFooter } from "ui/components/modal/Modal2";
|
||||
import { useStepContext } from "ui/components/steps/Steps";
|
||||
import type { TCreateModalSchema } from "ui/modules/data/components/schema/create-modal/CreateModal";
|
||||
import type { TCreateModalSchema } from "ui/modules/data/components/schema/create-modal/schema";
|
||||
|
||||
type ActionItem = SummaryItemProps & {
|
||||
run: () => Promise<boolean>;
|
||||
@@ -35,9 +34,9 @@ export function StepCreate() {
|
||||
action: "add",
|
||||
Icon: IconBox,
|
||||
type: "Entity",
|
||||
name: entity.name,
|
||||
name: entity.name!,
|
||||
json: entity,
|
||||
run: async () => await $data.actions.entity.add(entity.name, entity),
|
||||
run: async () => await $data.actions.entity.add(entity.name!, entity),
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
//import { typeboxResolver } from "@hookform/resolvers/typebox";
|
||||
import { objectCleanEmpty } from "core/utils";
|
||||
import { type TAppDataEntityFields, entitiesSchema } from "data/data-schema";
|
||||
import { mergeWith } from "lodash-es";
|
||||
@@ -10,12 +9,13 @@ import {
|
||||
EntityFieldsForm,
|
||||
type EntityFieldsFormRef,
|
||||
} from "ui/routes/data/forms/entity.fields.form";
|
||||
import { ModalBody, ModalFooter, type TCreateModalSchema, useStepContext } from "./CreateModal";
|
||||
import { ModalBody, ModalFooter, useStepContext } from "./CreateModal";
|
||||
import { useBkndData } from "ui/client/schema/data/use-bknd-data";
|
||||
import type { s } from "core/object/schema";
|
||||
import type { s } from "bknd/core";
|
||||
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
|
||||
import { entitySchema, type TCreateModalSchema } from "./schema";
|
||||
|
||||
const schema = entitiesSchema;
|
||||
const schema = entitySchema;
|
||||
type Schema = s.Static<typeof schema>;
|
||||
|
||||
export function StepEntityFields() {
|
||||
|
||||
@@ -2,30 +2,29 @@ import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
|
||||
import { TextInput, Textarea } from "@mantine/core";
|
||||
import { useFocusTrap } from "@mantine/hooks";
|
||||
import { useForm } from "react-hook-form";
|
||||
import {
|
||||
ModalBody,
|
||||
ModalFooter,
|
||||
type TCreateModalSchema,
|
||||
entitySchema,
|
||||
useStepContext,
|
||||
} from "./CreateModal";
|
||||
import { ModalBody, ModalFooter, useStepContext } from "./CreateModal";
|
||||
import { entitySchema, type TCreateModalSchema } from "./schema";
|
||||
import { s } from "bknd/core";
|
||||
import { cloneSchema } from "core/object/schema";
|
||||
|
||||
const schema = s.object({
|
||||
name: entitySchema.properties.name,
|
||||
config: entitySchema.properties.config.partial().optional(),
|
||||
});
|
||||
type Schema = s.Static<typeof schema>;
|
||||
|
||||
export function StepEntity() {
|
||||
const focusTrapRef = useFocusTrap();
|
||||
|
||||
const { nextStep, stepBack, state, setState } = useStepContext<TCreateModalSchema>();
|
||||
const { register, handleSubmit, formState, watch, control } = useForm({
|
||||
mode: "onTouched",
|
||||
resolver: standardSchemaResolver(entitySchema),
|
||||
defaultValues: state.entities?.create?.[0] ?? {},
|
||||
mode: "onChange",
|
||||
resolver: standardSchemaResolver(cloneSchema(schema)),
|
||||
defaultValues: (state.entities?.create?.[0] ?? {}) as Schema,
|
||||
});
|
||||
/*const data = watch();
|
||||
console.log("state", { isValid });
|
||||
console.log("schema", JSON.stringify(entitySchema));
|
||||
console.log("data", JSON.stringify(data));*/
|
||||
|
||||
function onSubmit(data: any) {
|
||||
console.log(data);
|
||||
console.log("onSubmit", data);
|
||||
setState((prev) => {
|
||||
const prevEntity = prev.entities?.create?.[0];
|
||||
if (prevEntity && prevEntity.name !== data.name) {
|
||||
@@ -45,6 +44,7 @@ export function StepEntity() {
|
||||
<>
|
||||
<form onSubmit={handleSubmit(onSubmit)} ref={focusTrapRef}>
|
||||
<ModalBody>
|
||||
<input type="hidden" {...register("type")} defaultValue="regular" />
|
||||
<TextInput
|
||||
data-autofocus
|
||||
required
|
||||
|
||||
@@ -10,8 +10,9 @@ import { MantineNumberInput } from "ui/components/form/hook-form-mantine/Mantine
|
||||
import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelect";
|
||||
import { useStepContext } from "ui/components/steps/Steps";
|
||||
import { useEvent } from "ui/hooks/use-event";
|
||||
import { ModalBody, ModalFooter, type TCreateModalSchema } from "./CreateModal";
|
||||
import { s, stringIdentifier } from "core/object/schema";
|
||||
import { ModalBody, ModalFooter } from "./CreateModal";
|
||||
import type { TCreateModalSchema } from "./schema";
|
||||
import { s, stringIdentifier } from "bknd/core";
|
||||
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
|
||||
|
||||
const Relations: {
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
import type { IconType } from "react-icons";
|
||||
import { TbBox, TbCirclesRelation, TbPhoto } from "react-icons/tb";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
import {
|
||||
type ModalActions,
|
||||
ModalBody,
|
||||
ModalFooter,
|
||||
type TCreateModalSchema,
|
||||
type TSchemaAction,
|
||||
useStepContext,
|
||||
} from "./CreateModal";
|
||||
import { ModalBody, ModalFooter, useStepContext } from "./CreateModal";
|
||||
import Templates from "./templates/register";
|
||||
import type { TCreateModalSchema, TSchemaAction } from "./schema";
|
||||
|
||||
export function StepSelect() {
|
||||
const { nextStep, stepBack, state, path, setState } = useStepContext<TCreateModalSchema>();
|
||||
|
||||
+3
-8
@@ -7,14 +7,9 @@ import { useBknd } from "ui/client/bknd";
|
||||
import { MantineNumberInput } from "ui/components/form/hook-form-mantine/MantineNumberInput";
|
||||
import { MantineRadio } from "ui/components/form/hook-form-mantine/MantineRadio";
|
||||
import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelect";
|
||||
import {
|
||||
ModalBody,
|
||||
ModalFooter,
|
||||
type TCreateModalSchema,
|
||||
type TFieldCreate,
|
||||
useStepContext,
|
||||
} from "../../CreateModal";
|
||||
import { s, stringIdentifier } from "core/object/schema";
|
||||
import { ModalBody, ModalFooter, useStepContext } from "../../CreateModal";
|
||||
import type { TCreateModalSchema, TFieldCreate } from "../../schema";
|
||||
import { s, stringIdentifier } from "bknd/core";
|
||||
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema";
|
||||
|
||||
const schema = s.object({
|
||||
|
||||
Reference in New Issue
Block a user