Skip to content

Fix ui suggestions #917

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
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/components/ForceGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,11 @@ export default function ForceGraph({
|| hoverElement && ("source" in hoverElement) && hoverElement.id === link.id)
|| (selectedElements.length > 0 && selectedElements.some(el => el.id === link.id && !("source" in el))) ? 2 : 1}
nodeCanvasObject={(node, ctx) => {
if (graph.Elements.nodes.length === 1) {
if (!node.x || !node.y) {
node.x = 0
node.y = 0
}

if (node.x === undefined || node.y === undefined) return

ctx.lineWidth = ((selectedElement && !("source" in selectedElement) && selectedElement.id === node.id)
|| (hoverElement && !("source" in hoverElement) && hoverElement.id === node.id)
|| (selectedElements.length > 0 && selectedElements.some(el => el.id === node.id && !("source" in el)))) ? 1 : 0.5
Expand Down Expand Up @@ -272,7 +270,13 @@ export default function ForceGraph({
const start = link.source;
const end = link.target;

if (!start.x || !start.y || !end.x || !end.y) return
if (!start.x || !start.y || !end.x || !end.y) {
start.x = 0
start.y = 0
end.x = 0
end.y = 0
}


let textX;
let textY;
Expand Down
34 changes: 18 additions & 16 deletions app/schema/SchemaCreateElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default function SchemaCreateElement({ onCreate, onExpand, selectedNodes,
description: "You must type a label",
variant: "destructive"
})

return
}

Expand All @@ -134,17 +134,17 @@ export default function SchemaCreateElement({ onCreate, onExpand, selectedNodes,
description: "You must select two nodes to create a relation",
variant: "destructive"
})

return
}
}

try {
setIsLoading(true)
const ok = await onCreate(attributes, label)

if (!ok) return

setAttributes([])
setAttribute(getDefaultAttribute())
setLabel([])
Expand Down Expand Up @@ -205,17 +205,19 @@ export default function SchemaCreateElement({ onCreate, onExpand, selectedNodes,
<ChevronRight size={20} />
</Button>
<ul className="flex flex-wrap gap-4 min-w-[10%]" onMouseEnter={() => setLabelsHover(true)} onMouseLeave={() => setLabelsHover(false)}>
{label.map((l) => (
<li key={l} className="flex gap-2 px-2 py-1 bg-foreground rounded-full items-center">
<p>{l}</p>
<Button
title="Remove"
onClick={() => handleRemoveLabel(l)}
>
<X size={15} />
</Button>
</li>
))}
{
label.map((l) => (
<li key={l} className="flex gap-2 px-2 py-1 bg-foreground rounded-full items-center">
<p>{l}</p>
<Button
title="Remove"
onClick={() => handleRemoveLabel(l)}
>
<X size={15} />
</Button>
</li>
))
}
<li className="h-8 flex flex-wrap gap-2">
{
(type ? (labelsHover || label.length === 0) && !isAddLabel : label.length < 1 && !isAddLabel) &&
Expand Down
156 changes: 76 additions & 80 deletions app/schema/SchemaDataPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export default function SchemaDataPanel({ obj, onExpand, onDeleteElement, schema
})
return
}

try {
setIsLabelLoading(true)

Expand Down Expand Up @@ -298,93 +299,88 @@ export default function SchemaDataPanel({ obj, onExpand, onDeleteElement, schema
>
<ChevronRight size={20} />
</Button>
{
"source" in obj ?
<p className="px-2 py-1 bg-foreground rounded-full">{label[0]}</p>
:
<ul className="flex flex-wrap gap-4 min-w-[10%]" onMouseEnter={() => setLabelsHover(true)} onMouseLeave={() => setLabelsHover(false)}>
{label.map((l) => (
<li key={l} className="flex gap-2 px-2 py-1 bg-foreground rounded-full items-center">
<p>{l}</p>
{
session?.user?.role !== "Read-Only" &&
<Button
indicator={indicator}
title="Remove"
onClick={() => handleRemoveLabel(l)}
isLoading={isRemoveLabelLoading}
>
<X size={15} />
</Button>
}
</li>
))}
<li className="h-8 flex flex-wrap gap-2">
<ul className="flex flex-wrap gap-4 min-w-[10%]" onMouseEnter={() => setLabelsHover(true)} onMouseLeave={() => setLabelsHover(false)}>
{label.map((l) => (
<li key={l} className="flex gap-2 px-2 py-1 bg-foreground rounded-full items-center">
<p>{l}</p>
{
session?.user?.role !== "Read-Only" &&
<Button
indicator={indicator}
title="Remove"
onClick={() => handleRemoveLabel(l)}
isLoading={isRemoveLabelLoading}
>
<X size={15} />
</Button>
}
</li>
))}
<li className="h-8 flex flex-wrap gap-2">
{
type && labelsHover && !labelsEditable && session?.user?.role !== "Read-Only" &&
<Button
className="p-2 text-xs justify-center border border-foreground"
variant="Secondary"
label="Add"
title="Add a new label"
onClick={() => setLabelsEditable(true)}
>
<Pencil size={15} />
</Button>
}
{
labelsEditable &&
<>
<Input
ref={ref => ref?.focus()}
className="max-w-[20dvw] h-full bg-foreground border-none text-white"
value={newLabel}
onChange={(e) => setNewLabel(e.target.value)}
onKeyDown={(e) => {

if (e.key === "Escape") {
e.preventDefault()
setLabelsEditable(false)
setNewLabel("")
}

if (e.key !== "Enter" || isLabelLoading || indicator === "offline") return

e.preventDefault()
handleAddLabel()
}}
/>
<Button
indicator={indicator}
className="p-2 text-xs justify-center border border-foreground"
variant="Secondary"
label="Save"
title="Save the new label"
onClick={() => handleAddLabel()}
isLoading={isLabelLoading}
>
<Check size={15} />
</Button>
{
labelsHover && !labelsEditable && session?.user?.role !== "Read-Only" &&
!isLabelLoading &&
<Button
className="p-2 text-xs justify-center border border-foreground"
variant="Secondary"
label="Add"
title="Add a new label"
onClick={() => setLabelsEditable(true)}
label="Cancel"
title="Discard the new label"
onClick={() => {
setLabelsEditable(false)
setNewLabel("")
}}
>
<Pencil size={15} />
<X size={15} />
</Button>
}
{
labelsEditable &&
<>
<Input
ref={ref => ref?.focus()}
className="max-w-[20dvw] h-full bg-foreground border-none text-white"
value={newLabel}
onChange={(e) => setNewLabel(e.target.value)}
onKeyDown={(e) => {

if (e.key === "Escape") {
e.preventDefault()
setLabelsEditable(false)
setNewLabel("")
}

if (e.key !== "Enter" || isLabelLoading || indicator === "offline") return

e.preventDefault()
handleAddLabel()
}}
/>
<Button
indicator={indicator}
className="p-2 text-xs justify-center border border-foreground"
variant="Secondary"
label="Save"
title="Save the new label"
onClick={() => handleAddLabel()}
isLoading={isLabelLoading}
>
<Check size={15} />
</Button>
{
!isLabelLoading &&
<Button
className="p-2 text-xs justify-center border border-foreground"
variant="Secondary"
label="Cancel"
title="Discard the new label"
onClick={() => {
setLabelsEditable(false)
setNewLabel("")
}}
>
<X size={15} />
</Button>
}
</>
}
</li>
</ul>
}
</>
}
</li>
</ul>
</div>
<p className="font-medium text-xl">{attributes.length}&ensp;Attributes</p>
</div>
Expand Down
Loading