Skip to content

Commit

Permalink
Merge pull request #647 from FalkorDB/fix-create-graph
Browse files Browse the repository at this point in the history
Fix #646 fix create graph
  • Loading branch information
Anchel123 authored Feb 5, 2025
2 parents 175de4c + caf7470 commit c715c86
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions app/components/CreateGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export default function CreateGraph({

const handleCreateGraph = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
if (!graphName) {
const name = graphName.trim()
if (!name) {
toast({
title: "Error",
description: "Graph name cannot be empty",
Expand All @@ -45,13 +46,13 @@ export default function CreateGraph({
return
}
const q = 'RETURN 1'
const result = await securedFetch(`api/graph/${prepareArg(graphName)}/?query=${prepareArg(q)}`, {
const result = await securedFetch(`api/graph/${prepareArg(name)}/?query=${prepareArg(q)}`, {
method: "GET",
}, toast)

if (!result.ok) return

onSetGraphName(graphName)
onSetGraphName(name)
setGraphName("")
setOpen(false)
}
Expand Down
6 changes: 3 additions & 3 deletions app/components/ui/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ export default function Combobox({ isSelectGraph = false, disabled = false, inTa
{
options.map((option) => (
<SelectItem
value={option}
key={option}
value={!option ? '""' : option}
key={`key-${option}`}
>
{option}
{!option ? '""' : option}
</SelectItem>
))
}
Expand Down
5 changes: 3 additions & 2 deletions app/graph/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ export default function Selector({ onChange, graphName, setGraphName, queries, r
}

const handleOnChange = async (name: string) => {
const formattedName = name === '""' ? "" : name
if (runQuery) {
const q = 'MATCH (n)-[e]-(m) return n,e,m'
const result = await securedFetch(`api/graph/${prepareArg(name)}_schema/?query=${prepareArg(q)}&create=false&role=${session?.user.role}`, {
const result = await securedFetch(`api/graph/${prepareArg(formattedName)}_schema/?query=${prepareArg(q)}&create=false&role=${session?.user.role}`, {
method: "GET"
}, toast)

Expand All @@ -87,7 +88,7 @@ export default function Selector({ onChange, graphName, setGraphName, queries, r
setSchema(Graph.create(name, json.result, false, true))
}
}
onChange(name)
onChange(formattedName)
setSelectedValue(name)
}

Expand Down
2 changes: 1 addition & 1 deletion app/schema/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function Page() {

return (
<div className="Page">
<Header />
<Header onSetGraphName={setSchemaName}/>
<div className="h-1 grow p-8 px-10 flex flex-col gap-8">
<Selector
setGraphName={setSchemaName}
Expand Down

0 comments on commit c715c86

Please sign in to comment.