Skip to content
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

Fix #296 fix add & delete entity #297

Merged
merged 3 commits into from
Aug 6, 2024
Merged
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
8 changes: 4 additions & 4 deletions app/api/graph/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,17 @@ export class Graph {
return newElements
}

public updateCategories(category: string, type: string) {
if (type === "node" && !this.elements.find(e => e.data.category === category)) {
public updateCategories(category: string, type: boolean) {
if (type && !this.elements.find(e => e.data.category === category)) {
const i = this.categories.findIndex(({ name }) => name === category)
this.categories.splice(i, 1)
this.categoriesMap.delete(category)
}

if (type === "edge" && !this.elements.find(e => e.data.label === category)) {
if (!type && !this.elements.find(e => e.data.label === category)) {
const i = this.labels.findIndex(({ name }) => name === category)
this.labels.splice(i, 1)
this.labelsMap.delete(category)
}
}
}
}
6 changes: 3 additions & 3 deletions app/graph/GraphView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,18 @@ const GraphView = forwardRef(({ graph, runQuery, historyQuery, setNodesCount, se
if (!result.ok) return

selectedElements.forEach((element) => {
const type = element.source ? "edge" : "node"
const type = !element.source
const { id } = getElementId(element)
graph.Elements.splice(graph.Elements.findIndex(e => e.data.id === id), 1)
chartRef.current?.remove(`#${id} `)

if (type === "node") {
if (type) {
setNodesCount(prev => prev - 1)
} else {
setEdgesCount(prev => prev - 1)
}

graph.updateCategories(type === "node" ? element.category : element.label, type)
graph.updateCategories(type ? element.category : element.label, type)
})

setSelectedElements([])
Expand Down
27 changes: 12 additions & 15 deletions app/schema/SchemaCreateElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface Props {
onExpand: () => void
selectedNodes: NodeDataDefinition[]
setSelectedNodes: Dispatch<SetStateAction<NodeDataDefinition[]>>
type: "node" | "edge"
type: boolean
}

const emptyAttribute = (): Attribute => [undefined, "", false, false]
Expand All @@ -26,10 +26,10 @@ export default function SchemaCreateElement({ onCreate, onExpand, selectedNodes,

const [attributes, setAttributes] = useState<[string, Attribute][]>([])
const [attribute, setAttribute] = useState<Attribute>(emptyAttribute())
const [newKey, setNewKey] = useState<string>()
const [newValue, setNewValue] = useState<string>()
const [label, setLabel] = useState<string>()
const [newLabel, setNewLabel] = useState<string>()
const [newKey, setNewKey] = useState<string>("")
const [newValue, setNewValue] = useState<string>("")
const [label, setLabel] = useState<string>("")
const [newLabel, setNewLabel] = useState<string>("")
const [labelEditable, setLabelEditable] = useState<boolean>(false)
const [editable, setEditable] = useState<string>("")
const [hover, setHover] = useState<string>("")
Expand Down Expand Up @@ -57,7 +57,7 @@ export default function SchemaCreateElement({ onCreate, onExpand, selectedNodes,
const handelSetAttribute = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.code === "Escape") {
e.preventDefault()
setNewValue(undefined)
setNewValue("")
setEditable("")
return
}
Expand All @@ -77,19 +77,16 @@ export default function SchemaCreateElement({ onCreate, onExpand, selectedNodes,
p[index][i] = newValue
return p
})
setNewValue(undefined)
setNewValue("")
}

const handelOnCreate = async () => {
if (!label && type === "edge") {
if (!label && !type) {
Toast("Please fill the label")
return
}
const ok = await onCreate(attributes, label)
if (!ok) {
Toast("")
return
}
if (!ok) return
setAttributes([])
setAttribute(emptyAttribute())
setLabel("")
Expand Down Expand Up @@ -182,7 +179,7 @@ export default function SchemaCreateElement({ onCreate, onExpand, selectedNodes,
ref={ref => ref?.focus()}
className="w-28"
variant="Small"
value={newKey === undefined ? key : newKey}
value={newKey === "" ? key : newKey}
onChange={(e) => setNewKey(e.target.value)}
onKeyDown={handelSetAttribute}
onBlur={() => handelCancel()}
Expand Down Expand Up @@ -226,7 +223,7 @@ export default function SchemaCreateElement({ onCreate, onExpand, selectedNodes,
ref={ref => ref?.focus()}
className="w-28"
variant="Small"
value={newValue === undefined ? val[1] : newValue}
value={newValue === "" ? val[1] : newValue}
onChange={(e) => setNewValue(e.target.value)}
onKeyDown={handelSetAttribute}
onBlur={() => setEditable("")}
Expand Down Expand Up @@ -342,7 +339,7 @@ export default function SchemaCreateElement({ onCreate, onExpand, selectedNodes,
</TableBody>
</Table>
{
type === "edge" &&
!type &&
<div className="w-full flex flex-col gap-4">
<div className="w-full flex justify-between p-8 items-center">
<div className={`flex h-16 w-16 rounded-full bg-[#57577B] justify-center items-center bg-${getCategoryColorNameFromValue(selectedNodes[0]?.color)}`}>
Expand Down
Loading
Loading