diff --git a/app/src/ui/components/canvas/layouts/index.ts b/app/src/ui/components/canvas/layouts/index.ts index 761aaee..c0b3c1c 100644 --- a/app/src/ui/components/canvas/layouts/index.ts +++ b/app/src/ui/components/canvas/layouts/index.ts @@ -25,12 +25,6 @@ export const layoutWithDagre = ({ nodes, edges, graph }: LayoutProps) => { const dagreGraph = new Dagre.graphlib.Graph(); dagreGraph.setDefaultEdgeLabel(() => ({})); dagreGraph.setGraph(graph || {}); - /*dagreGraph.setGraph({ - rankdir: "LR", - align: "UR", - nodesep: NODE_SEP, - ranksep: RANK_SEP - });*/ nodes.forEach((node) => { dagreGraph.setNode(node.id, { @@ -48,7 +42,11 @@ export const layoutWithDagre = ({ nodes, edges, graph }: LayoutProps) => { return { nodes: nodes.map((node) => { const position = dagreGraph.node(node.id); - return { ...node, x: position.x, y: position.y }; + return { + ...node, + x: position.x - (node.width ?? 0) / 2, + y: position.y - (node.height ?? 0) / 2 + }; }), edges }; diff --git a/app/src/ui/modules/data/components/canvas/DataSchemaCanvas.tsx b/app/src/ui/modules/data/components/canvas/DataSchemaCanvas.tsx index 7d055cf..cc893e6 100644 --- a/app/src/ui/modules/data/components/canvas/DataSchemaCanvas.tsx +++ b/app/src/ui/modules/data/components/canvas/DataSchemaCanvas.tsx @@ -69,15 +69,13 @@ export function DataSchemaCanvas() { const nodeLayout = layoutWithDagre({ nodes: nodes.map((n) => ({ id: n.id, - ...EntityTableNode.getSize(n) + ...EntityTableNode.getSize(n.data) })), edges, graph: { rankdir: "LR", - //align: "UR", - ranker: "network-simplex", - nodesep: 350, - ranksep: 50 + marginx: 50, + marginy: 50 } }); @@ -88,12 +86,6 @@ export function DataSchemaCanvas() { } }); - /*const _edges = edges.map((e) => ({ - ...e, - source: e.source + `-${e.target}_id`, - target: e.target + "-id" - }));*/ - return ( ; export function StepEntityFields() { const { nextStep, stepBack, state, setState } = useStepContext(); const entity = state.entities?.create?.[0]!; const defaultFields = { id: { type: "primary", name: "id" } } as const; const ref = useRef(null); + const initial = entity + ? entity + : { + fields: defaultFields, + config: { + sort_field: "id", + sort_dir: "asc" + } + }; const { control, formState: { isValid, errors }, getValues, handleSubmit, watch, - register, setValue } = useForm({ mode: "onTouched", resolver: typeboxResolver(schema), - defaultValues: { - ...entity, - fields: defaultFields, - config: { - sort_field: "id", - sort_dir: "asc" - } - } + defaultValues: initial as NonNullable }); const values = watch(); @@ -74,7 +77,11 @@ export function StepEntityFields() { Add fields to {entity.name}:

- +
@@ -82,7 +89,7 @@ export function StepEntityFields() {
name.length > 0)} + data={Object.keys(values.fields ?? {}).filter((name) => name.length > 0)} placeholder="Select field" name="config.sort_field" allowDeselect={false} @@ -102,7 +109,7 @@ export function StepEntityFields() {
{Object.entries(errors).map(([key, value]) => (

- {key}: {value.message} + {key}: {(value as any).message}

))}
diff --git a/app/src/ui/routes/data/forms/entity.fields.form.tsx b/app/src/ui/routes/data/forms/entity.fields.form.tsx index 2de36e2..3f70848 100644 --- a/app/src/ui/routes/data/forms/entity.fields.form.tsx +++ b/app/src/ui/routes/data/forms/entity.fields.form.tsx @@ -72,22 +72,16 @@ export const EntityFieldsForm = forwardRef< name, field })); - /*const entityFields = entity.fields.map((field) => ({ - name: field.name, - field: field.toJSON() - }));*/ const { control, formState: { isValid, errors }, getValues, - handleSubmit, watch, register, setValue, setError, - reset, - clearErrors + reset } = useForm({ mode: "all", resolver: typeboxResolver(schema), @@ -114,7 +108,6 @@ export const EntityFieldsForm = forwardRef< props?.onChange?.(toCleanValues(data)); }); } - //props?.onChange?.() }, []); useImperativeHandle(ref, () => ({ @@ -122,25 +115,9 @@ export const EntityFieldsForm = forwardRef< getValues: () => getValues(), getData: () => { return toCleanValues(getValues()); - /*return Object.fromEntries( - getValues().fields.map((field) => [field.name, objectCleanEmpty(field.field)]) - );*/ }, isValid: () => isValid })); - console.log("errors", errors.fields); - - /*useEffect(() => { - console.log("change", values); - onSubmit(values); - }, [values]);*/ - - function onSubmit(data: TFieldsFormSchema) { - console.log("submit", isValid, data, errors); - } - function onSubmitInvalid(a, b) { - console.log("submit invalid", a, b); - } function handleAppend(_type: keyof typeof fieldsSchemaObject) { const newField = { @@ -151,7 +128,6 @@ export const EntityFieldsForm = forwardRef< config: {} } }; - console.log("handleAppend", _type, newField); append(newField); } @@ -165,10 +141,7 @@ export const EntityFieldsForm = forwardRef< }; return ( <> -
+
{sortable ? ( @@ -220,9 +193,7 @@ export const EntityFieldsForm = forwardRef<
-
); });