mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-03 08:36:01 +00:00
initial refactor
This commit is contained in:
@@ -1,13 +1,5 @@
|
||||
import { typeboxResolver } from "@hookform/resolvers/typebox";
|
||||
import { Tabs, TextInput, Textarea, Tooltip, Switch } from "@mantine/core";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import {
|
||||
Default,
|
||||
type Static,
|
||||
StringIdentifier,
|
||||
objectCleanEmpty,
|
||||
ucFirstAllSnakeToPascalWithSpaces,
|
||||
} from "core/utils";
|
||||
import { objectCleanEmpty, omitKeys, ucFirstAllSnakeToPascalWithSpaces } from "core/utils";
|
||||
import {
|
||||
type TAppDataEntityFields,
|
||||
fieldsSchemaObject as originalFieldsSchemaObject,
|
||||
@@ -26,31 +18,25 @@ import { type SortableItemProps, SortableList } from "ui/components/list/Sortabl
|
||||
import { Popover } from "ui/components/overlay/Popover";
|
||||
import { type TFieldSpec, fieldSpecs } from "ui/modules/data/components/fields-specs";
|
||||
import { dataFieldsUiSchema } from "../../settings/routes/data.settings";
|
||||
import * as tbbox from "@sinclair/typebox";
|
||||
import { useRoutePathState } from "ui/hooks/use-route-path-state";
|
||||
import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelect";
|
||||
import type { TPrimaryFieldFormat } from "data/fields/PrimaryField";
|
||||
const { Type } = tbbox;
|
||||
import { s, stringIdentifier } from "core/object/schema";
|
||||
|
||||
const fieldsSchemaObject = originalFieldsSchemaObject;
|
||||
const fieldsSchema = Type.Union(Object.values(fieldsSchemaObject));
|
||||
const fieldsSchema = s.anyOf(Object.values(fieldsSchemaObject));
|
||||
|
||||
const fieldSchema = Type.Object(
|
||||
{
|
||||
name: StringIdentifier,
|
||||
new: Type.Optional(Type.Boolean({ const: true })),
|
||||
field: fieldsSchema,
|
||||
},
|
||||
{
|
||||
additionalProperties: false,
|
||||
},
|
||||
);
|
||||
type TFieldSchema = Static<typeof fieldSchema>;
|
||||
|
||||
const schema = Type.Object({
|
||||
fields: Type.Array(fieldSchema),
|
||||
const fieldSchema = s.strictObject({
|
||||
name: stringIdentifier,
|
||||
new: s.boolean({ const: true }).optional(),
|
||||
field: fieldsSchema,
|
||||
});
|
||||
type TFieldsFormSchema = Static<typeof schema>;
|
||||
type TFieldSchema = s.Static<typeof fieldSchema>;
|
||||
|
||||
const schema = s.strictObject({
|
||||
fields: s.array(fieldSchema),
|
||||
});
|
||||
type TFieldsFormSchema = s.Static<typeof schema>;
|
||||
|
||||
const fieldTypes = Object.keys(fieldsSchemaObject);
|
||||
const defaultType = fieldTypes[0];
|
||||
@@ -58,7 +44,9 @@ const commonProps = ["label", "description", "required", "fillable", "hidden", "
|
||||
|
||||
function specificFieldSchema(type: keyof typeof fieldsSchemaObject) {
|
||||
//console.log("specificFieldSchema", type);
|
||||
return Type.Omit(fieldsSchemaObject[type]?.properties.config, commonProps);
|
||||
return s.object(
|
||||
omitKeys(fieldsSchemaObject[type]?.properties.config.properties, commonProps as any),
|
||||
);
|
||||
}
|
||||
|
||||
export type EntityFieldsFormProps = {
|
||||
@@ -100,7 +88,8 @@ export const EntityFieldsForm = forwardRef<EntityFieldsFormRef, EntityFieldsForm
|
||||
reset,
|
||||
} = useForm({
|
||||
mode: "all",
|
||||
resolver: typeboxResolver(schema),
|
||||
// @todo: add resolver
|
||||
//resolver: typeboxResolver(schema),
|
||||
defaultValues: {
|
||||
fields: entityFields,
|
||||
} as TFieldsFormSchema,
|
||||
@@ -135,15 +124,14 @@ export const EntityFieldsForm = forwardRef<EntityFieldsFormRef, EntityFieldsForm
|
||||
}));
|
||||
|
||||
function handleAppend(_type: keyof typeof fieldsSchemaObject) {
|
||||
const newField = {
|
||||
append({
|
||||
name: "",
|
||||
new: true,
|
||||
field: {
|
||||
type: _type,
|
||||
config: Default(fieldsSchemaObject[_type]?.properties.config, {}) as any,
|
||||
config: fieldsSchemaObject[_type]?.properties.config.template() as any,
|
||||
},
|
||||
};
|
||||
append(newField);
|
||||
});
|
||||
}
|
||||
|
||||
const formProps = {
|
||||
|
||||
Reference in New Issue
Block a user