diff --git a/packages/typesync-studio/src/routes/index.tsx b/packages/typesync-studio/src/routes/index.tsx index e3eee174..bb8303b1 100644 --- a/packages/typesync-studio/src/routes/index.tsx +++ b/packages/typesync-studio/src/routes/index.tsx @@ -113,6 +113,7 @@ function SchemaBuilderComponent() { }); }, }); + const appTypes = useStore(createSchemaForm.store, (state) => pipe( state.values.types, @@ -427,6 +428,10 @@ function SchemaBuilderComponent() { } satisfies Typesync.TypesyncHypergraphSchemaTypeProperty; }), }); + + // Calculate the index where the new type will be added + let newIndex = field.state.value.length; + // if schema is currently empty, set as first type if (field.state.value.length === 1) { const initialType = field.state.value[0]; @@ -439,6 +444,7 @@ function SchemaBuilderComponent() { EffectArray.match(relationSchemaTypes, { onEmpty() { field.replaceValue(0, selectedMappedToType as never); + newIndex = 0; }, onNonEmpty(mappedRelationTypes) { EffectArray.forEach(mappedRelationTypes, (mapped, idx) => { @@ -448,12 +454,15 @@ function SchemaBuilderComponent() { knowledgeGraphId: mapped.knowledgeGraphId, properties: mapped.properties, } as never); + newIndex = 0; return; } field.pushValue(mapped as never); + newIndex = idx; }); // push selected type field.pushValue(selectedMappedToType as never); + newIndex = field.state.value.length - 1; }, }); return; @@ -471,11 +480,24 @@ function SchemaBuilderComponent() { knowledgeGraphId: mapped.knowledgeGraphId, properties: mapped.properties, } as never); + newIndex = field.state.value.length - 1; }); // push selected type field.pushValue(selectedMappedToType as never); + newIndex = field.state.value.length - 1; }, }); + setTimeout(() => { + const element = document.getElementById(`type-entry-${newIndex}`); + if (element) { + element.scrollIntoView({ behavior: 'smooth', block: 'start' }); + } + }, 0); + toastManager.add({ + title: 'Type added to schema', + description: selected.name, + type: 'success', + }); return; }} /> @@ -495,6 +517,7 @@ function SchemaBuilderComponent() { return (
@@ -860,12 +883,25 @@ function SchemaBuilderComponent() {
-
@@ -874,7 +910,14 @@ function SchemaBuilderComponent() {