-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Added ui feedback when adding type in typesync #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
unniznd
wants to merge
3
commits into
graphprotocol:main
Choose a base branch
from
unniznd:feat_ui_feedback_for_adding_type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+59
−4
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import { | |
import { createFormHook, useStore } from '@tanstack/react-form'; | ||
import { createFileRoute } from '@tanstack/react-router'; | ||
import { Array as EffectArray, String as EffectString, Option, pipe, Schema } from 'effect'; | ||
import { useState } from 'react'; | ||
import { useRef, useState } from 'react'; | ||
|
||
import { Arrow } from '@/Components/Arrow.tsx'; | ||
import { Checkbox } from '@/Components/Form/Checkbox.tsx'; | ||
|
@@ -113,6 +113,12 @@ function SchemaBuilderComponent() { | |
}); | ||
}, | ||
}); | ||
|
||
// Create a ref to store DOM references for each type | ||
const typeRefs = useRef<Map<number, HTMLDivElement>>(new Map()); | ||
// State to track the index of the newly added type | ||
const [_newTypeIndex, setNewTypeIndex] = useState<number | null>(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we aren't reading the state variable here: |
||
|
||
const appTypes = useStore(createSchemaForm.store, (state) => | ||
pipe( | ||
state.values.types, | ||
|
@@ -427,6 +433,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 +449,7 @@ function SchemaBuilderComponent() { | |
EffectArray.match(relationSchemaTypes, { | ||
onEmpty() { | ||
field.replaceValue(0, selectedMappedToType as never); | ||
newIndex = 0; | ||
}, | ||
onNonEmpty(mappedRelationTypes) { | ||
EffectArray.forEach(mappedRelationTypes, (mapped, idx) => { | ||
|
@@ -448,12 +459,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 +485,25 @@ 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 = typeRefs.current.get(newIndex); | ||
if (element) { | ||
element.scrollIntoView({ behavior: 'smooth', block: 'start' }); | ||
} | ||
}, 0); | ||
setNewTypeIndex(newIndex); | ||
toastManager.add({ | ||
title: 'Type added to schema', | ||
description: selected.name, | ||
type: 'success', | ||
}); | ||
return; | ||
}} | ||
/> | ||
|
@@ -495,6 +523,13 @@ function SchemaBuilderComponent() { | |
return ( | ||
<div | ||
key={typeEntryKey} | ||
ref={(el) => { | ||
if (el) { | ||
typeRefs.current.set(idx, el); | ||
} else { | ||
typeRefs.current.delete(idx); | ||
} | ||
}} | ||
className="border-l-2 border-indigo-600 dark:border-indigo-400 pl-2 py-2 flex flex-col gap-y-4" | ||
> | ||
<div className="flex items-start justify-between gap-x-3"> | ||
|
@@ -860,12 +895,25 @@ function SchemaBuilderComponent() { | |
<Toast.Root | ||
key={t.id} | ||
toast={t} | ||
className="pointer-events-auto w-full max-w-md rounded-lg bg-white shadow-lg outline-1 outline-black/5 transition data-closed:opacity-0 data-enter:transform data-enter:duration-300 data-enter:ease-out data-closed:data-enter:translate-y-2 data-leave:duration-100 data-leave:ease-in data-closed:data-enter:sm:translate-x-2 data-closed:data-enter:sm:translate-y-0 dark:bg-gray-800 dark:-outline-offset-1 dark:outline-white/10 p-4" | ||
className={classnames( | ||
'pointer-events-auto w-full max-w-md rounded-lg shadow-lg outline-1 transition data-closed:opacity-0 data-enter:transform data-enter:duration-300 data-enter:ease-out data-closed:data-enter:translate-y-2 data-leave:duration-100 data-leave:ease-in data-closed:data-enter:sm:translate-x-2 data-closed:data-enter:sm:translate-y-0 p-4', | ||
t.type === 'success' | ||
? 'bg-green-50 dark:bg-green-900 outline-green-500/20' | ||
: t.type === 'error' | ||
? 'bg-red-50 dark:bg-red-900 outline-red-500/20' | ||
: 'bg-white dark:bg-gray-800 outline-black/5 dark:outline-white/10', | ||
)} | ||
> | ||
<div className="p-4"> | ||
<div className="flex items-start"> | ||
<div className="shrink-0"> | ||
<WarningIcon aria-hidden="true" className="size-6 text-red-400" /> | ||
{t.type === 'success' ? ( | ||
<CheckIcon aria-hidden="true" className="size-6 text-green-400" /> | ||
) : t.type === 'error' ? ( | ||
<ExclamationMarkIcon aria-hidden="true" className="size-6 text-red-400" /> | ||
) : ( | ||
<WarningIcon aria-hidden="true" className="size-6 text-yellow-400" /> | ||
)} | ||
</div> | ||
<div className="ml-3 w-0 flex-1 pt-0.5"> | ||
<Toast.Title className="text-sm font-medium text-gray-900 dark:text-white" /> | ||
|
@@ -874,7 +922,14 @@ function SchemaBuilderComponent() { | |
<div className="ml-4 flex shrink-0"> | ||
<Toast.Close | ||
aria-label="Close" | ||
className="inline-flex rounded-md text-gray-400 hover:text-gray-500 focus:outline-2 focus:outline-offset-2 focus:outline-red-600 dark:hover:text-white dark:focus:outline-red-500" | ||
className={classnames( | ||
'inline-flex rounded-md focus:outline-2 focus:outline-offset-2', | ||
t.type === 'success' | ||
? 'text-green-400 hover:text-green-500 focus:outline-green-600 dark:focus:outline-green-500' | ||
: t.type === 'error' | ||
? 'text-red-400 hover:text-red-500 focus:outline-red-600 dark:focus:outline-red-500' | ||
: 'text-gray-400 hover:text-gray-500 focus:outline-gray-600 dark:hover:text-white dark:focus:outline-gray-500', | ||
)} | ||
> | ||
<XIcon className="size-4" aria-hidden="true" /> | ||
</Toast.Close> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still does not feel like the right answer to me. Especially not the way it is being set