fixing condition where entity has been created with empty label

This commit is contained in:
dswbx
2024-12-11 18:48:57 +01:00
parent 35959aaf6d
commit 25027429df
2 changed files with 11 additions and 9 deletions

View File

@@ -158,7 +158,7 @@ export class Entity<
} }
get label(): string { get label(): string {
return snakeToPascalWithSpaces(this.config.name ?? this.name); return snakeToPascalWithSpaces(this.config.name || this.name);
} }
field(name: string): Field | undefined { field(name: string): Field | undefined {

View File

@@ -1,5 +1,5 @@
import { typeboxResolver } from "@hookform/resolvers/typebox"; import { typeboxResolver } from "@hookform/resolvers/typebox";
import type { Static } from "core/utils"; import { type Static, objectCleanEmpty } from "core/utils";
import { type TAppDataEntityFields, entitiesSchema } from "data/data-schema"; import { type TAppDataEntityFields, entitiesSchema } from "data/data-schema";
import { mergeWith } from "lodash-es"; import { mergeWith } from "lodash-es";
import { useRef } from "react"; import { useRef } from "react";
@@ -20,13 +20,15 @@ export function StepEntityFields() {
const entity = state.entities?.create?.[0]!; const entity = state.entities?.create?.[0]!;
const defaultFields = { id: { type: "primary", name: "id" } } as const; const defaultFields = { id: { type: "primary", name: "id" } } as const;
const ref = useRef<EntityFieldsFormRef>(null); const ref = useRef<EntityFieldsFormRef>(null);
const initial = mergeWith(entity, { const initial = objectCleanEmpty(
fields: defaultFields, mergeWith(entity, {
config: { fields: defaultFields,
sort_field: "id", config: {
sort_dir: "asc" sort_field: "id",
} sort_dir: "asc"
}); }
})
);
const { const {
control, control,
formState: { isValid, errors }, formState: { isValid, errors },