Skip to content

Commit

Permalink
Merge pull request #184 from FalkorDB/multiple-query-sections
Browse files Browse the repository at this point in the history
fix #175 add multiple graph sections
  • Loading branch information
AviAvni authored Apr 21, 2024
2 parents d5525df + b4a8146 commit ed40fa2
Show file tree
Hide file tree
Showing 8 changed files with 420 additions and 296 deletions.
48 changes: 3 additions & 45 deletions app/components/combobox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client"

import { useState, Dispatch, createRef } from "react"
import { Check, ChevronsUpDown, Trash2 } from "lucide-react"
import { Check, ChevronsUpDown } from "lucide-react"
import {
Dialog,
DialogContent,
Expand All @@ -26,32 +26,19 @@ import {
} from "@/components/ui/popover"
import { Separator } from "@/components/ui/separator"
import { Input } from "@/components/ui/input"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
AlertDialogFooter
} from "@/components/ui/alert-dialog"

/* eslint-disable react/require-default-props */
interface ComboboxProps {
className?: string,
type?: string,
options: string[],
addOption?: Dispatch<string> | null,
deleteOption?: (graphName :string) => void,
selectedValue: string,
setSelectedValue: Dispatch<string>
}

export default function Combobox({ className = '', type = '', options, addOption = null, deleteOption, selectedValue, setSelectedValue }: ComboboxProps) {
export default function Combobox({ className = '', type = 'Graph', options, addOption = null, selectedValue, setSelectedValue }: ComboboxProps) {
const [open, setOpen] = useState(false)
const [deleteGraph, setDeleteGraph] = useState<string>("")
const inputRef = createRef<HTMLInputElement>()

// read the text in the create input box and add it to the list of options
Expand All @@ -65,13 +52,6 @@ export default function Combobox({ className = '', type = '', options, addOption
}
}

const onDeleteOption = (graphName: string) => {
setOpen(false)
if (deleteOption) {
deleteOption(graphName)
}
}

const handleKeyDown = (event: React.KeyboardEvent) => {
if (event.key === "Enter") {
onAddOption();
Expand All @@ -80,7 +60,6 @@ export default function Combobox({ className = '', type = '', options, addOption

const entityType = type ?? ""
return (
<AlertDialog>
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
Expand All @@ -102,7 +81,7 @@ export default function Combobox({ className = '', type = '', options, addOption
<CommandGroup>
{options.map((option) => (
<CommandItem
className="w-full flex flex-row justify-between px-6"
className="w-full flex flex-row gap-2"
key={option}
onSelect={(currentValue) => {
if (currentValue !== selectedValue) {
Expand All @@ -111,21 +90,13 @@ export default function Combobox({ className = '', type = '', options, addOption
setOpen(false)
}}
>
<div className="flex flex-row">
<Check
className={cn(
"mr-2 h-4 w-4",
selectedValue === option ? "opacity-100" : "opacity-0"
)}
/>
{option}
</div>
{
deleteOption &&
<AlertDialogTrigger onClick={() => setDeleteGraph(option)}>
<Trash2 />
</AlertDialogTrigger>
}
</CommandItem>
))}
<Separator orientation="horizontal" />
Expand All @@ -149,18 +120,5 @@ export default function Combobox({ className = '', type = '', options, addOption
</Command>
</PopoverContent>
</Popover>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to delete {deleteGraph}?
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={() => onDeleteOption(deleteGraph)}>Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}
72 changes: 0 additions & 72 deletions app/graph/GraphList.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions app/graph/GraphView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const GraphView = forwardRef(({ graph, darkmode }: GraphViewProps, ref) => {
}

return (
<ResizablePanelGroup direction="horizontal">
<ResizablePanelGroup className="relative" direction="horizontal">
<ResizablePanel defaultSize={selectedObject ? 80 : 100} className="h-full flex flex-col">
<div className="flex flex-row justify-between">
<Toolbar className="" chartRef={chartRef} />
Expand Down Expand Up @@ -216,7 +216,7 @@ const GraphView = forwardRef(({ graph, darkmode }: GraphViewProps, ref) => {
<ResizableHandle />
{
selectedObject &&
<button title={isCollapsed ? "open" : "close"} type="button" onClick={() => onExpand()} className="fixed right-5 top-[50%]">
<button title={isCollapsed ? "open" : "close"} type="button" onClick={() => onExpand()} className="absolute top-1/2 right-0 transform -translate-y-1/2">
{!isCollapsed ? <ChevronRight /> : <ChevronLeft />}
</button>
}
Expand Down
76 changes: 76 additions & 0 deletions app/graph/graphSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { useTheme } from "next-themes"
import { useEffect, useRef, useState } from "react"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import SectionQuery, { GraphState } from "./sectionQuery"
import MetaDataView from "./metadataview"
import GraphView, { GraphViewRef } from "./GraphView"
import { TableView } from "./tableview"
import { Graph } from "./model"

export default function GraphSection({ onSubmit, queryState }: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onSubmit: (e: React.FormEvent<HTMLElement>, graphName: string, query: string) => Promise<any>,
queryState: GraphState,
}) {

const [graph, setGraph] = useState<Graph>(Graph.create(queryState.graphName, queryState.data))
const [value, setValue] = useState<string>()
const [metadata, setMetadata] = useState<string[]>(queryState.data.metadata)
const graphView = useRef<GraphViewRef>(null)
const showGraph = graph.Elements && graph.Elements.length > 0
const showTable = graph.Data && graph.Data.length > 0
const { theme, systemTheme } = useTheme()
const darkmode = theme === "dark" || (theme === "system" && systemTheme === "dark")

useEffect(() => {
if (showGraph) {
setValue("graph")
} else if (showTable) {
setValue("table")
}
}, [showTable, showGraph])

const handelSubmit = async (e: React.FormEvent<HTMLElement>, graphName: string, query: string) => {
const data = await onSubmit(e, graphName, query)
setGraph(Graph.create(graphName, data))
setMetadata(data.metadata)
graphView.current?.expand(graph.Elements)
}

return (
<div className="h-full flex flex-col gap-y-2">
<SectionQuery
queryState={queryState}
onSubmit={handelSubmit}
className="border rounded-lg border-gray-300 p-2"
/>
{
graph.Id &&
<>
<div className="grow border flex flex-col border-gray-300 rounded-lg p-2">
{
(showTable || showGraph) &&
<Tabs value={value} className="h-1 grow flex flex-row">
<div className="w-20 flex flex-row items-center">
<TabsList className="h-fit flex flex-col p-0">
{showGraph && <TabsTrigger className="w-full" value="graph" onClick={() => setValue("graph")}>Graph</TabsTrigger>}
{showTable && <TabsTrigger className="w-full" value="table" onClick={() => setValue("table")}>Table</TabsTrigger>}
</TabsList>
</div>
<TabsContent value="table" className="w-1 grow overflow-auto">
<TableView graph={graph} />
</TabsContent>
<TabsContent value="graph" className="w-1 grow">
<GraphView ref={graphView} graph={graph} darkmode={darkmode} />
</TabsContent>
</Tabs>
}
</div>
<div>
<MetaDataView metadata={metadata} />
</div>
</>
}
</div>
)
}
Loading

0 comments on commit ed40fa2

Please sign in to comment.