Skip to content

Commit

Permalink
Merge branch 'staging' into fix-create-graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Anchel123 authored Feb 5, 2025
2 parents 941c9f9 + 175de4c commit caf7470
Show file tree
Hide file tree
Showing 31 changed files with 612 additions and 430 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "22"
cache: ${{ steps.detect-package-manager.outputs.manager }}

- name: Restore cache
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

services:
falkordb:
image: falkordb/falkordb:latest
image: falkordb/falkordb:v4.4.1
ports:
- 6379:6379

Expand All @@ -34,9 +34,20 @@ jobs:
npm install
npm run build
NEXTAUTH_SECRET=SECRET npm start & npx playwright test --reporter=dot,list
- name: Ensure required directories exist
run: |
mkdir -p playwright-report
mkdir -p playwright-report/artifacts
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
- name: Upload failed test screenshots
if: always()
uses: actions/upload-artifact@v4
with:
name: failed-test-screenshots
path: playwright-report/artifacts/
retention-days: 30
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-alpine AS base
FROM node:22-alpine AS base

# Install dependencies only when needed
FROM base AS deps
Expand Down Expand Up @@ -68,4 +68,4 @@ ENV HOSTNAME "0.0.0.0"

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]
CMD ["node", "server.js"]
49 changes: 36 additions & 13 deletions app/api/graph/model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
/* eslint-disable one-var */
/* eslint-disable no-param-reassign */
/* eslint-disable @typescript-eslint/no-explicit-any */

import { EdgeDataDefinition, NodeDataDefinition } from 'cytoscape';
import { LinkObject, NodeObject } from 'react-force-graph-2d';

const getSchemaValue = (value: string): string[] => {
let unique, required, type, description
if (value.includes("!")) {
value = value.replace("!", "")
unique = "true"
} else {
unique = "false"
}
if (value.includes("*")) {
value = value.replace("*", "")
required = "true"
} else {
required = "false"
}
if (value.includes("-")) {
[type, description] = value.split("-")
} else {
type = "string"
description = ""
}
return [type, description, unique, required]
}

export type Node = NodeObject<{
id: number,
category: string[],
Expand Down Expand Up @@ -209,14 +233,14 @@ export class Graph {
return new Graph(graphName || "", [], [], { nodes: [], links: [] }, new Map<string, Category>(), new Map<string, Category>(), new Map<number, Node>(), new Map<number, Link>(), colors)
}

public static create(id: string, results: any, colors?: string[]): Graph {
public static create(id: string, results: { data: Data, metadata: any[] }, isCollapsed: boolean, isSchema: boolean, colors?: string[],): Graph {
const graph = Graph.empty(undefined, colors)
graph.extend(results)
graph.extend(results, isCollapsed, isSchema)
graph.id = id
return graph
}

public extendNode(cell: NodeCell, collapsed = false) {
public extendNode(cell: NodeCell, collapsed: boolean, isSchema: boolean) {
// check if category already exists in categories
const categories = this.createCategory(cell.labels.length === 0 ? [""] : cell.labels)
// check if node already exists in nodes or fake node was created
Expand All @@ -233,7 +257,7 @@ export class Graph {
data: {}
}
Object.entries(cell.properties).forEach(([key, value]) => {
node.data[key] = value as string;
node.data[key] = isSchema ? getSchemaValue(value) : value;
});
this.nodesMap.set(cell.id, node)
this.elements.nodes.push(node)
Expand All @@ -248,7 +272,7 @@ export class Graph {
currentNode.expand = false
currentNode.collapsed = collapsed
Object.entries(cell.properties).forEach(([key, value]) => {
currentNode.data[key] = value as string;
currentNode.data[key] = isSchema ? getSchemaValue(value) : value;
});

// remove empty category if there are no more empty nodes category
Expand All @@ -272,9 +296,8 @@ export class Graph {
return currentNode
}

public extendEdge(cell: LinkCell, collapsed = false) {
public extendEdge(cell: LinkCell, collapsed: boolean, isSchema: boolean) {
const label = this.createLabel(cell.relationshipType)

const currentEdge = this.linksMap.get(cell.id)

if (!currentEdge) {
Expand Down Expand Up @@ -369,7 +392,7 @@ export class Graph {
}

Object.entries(cell.properties).forEach(([key, value]) => {
link.data[key] = value as string;
link.data[key] = isSchema ? getSchemaValue(value) : value;
});

this.linksMap.set(cell.id, link)
Expand All @@ -381,7 +404,7 @@ export class Graph {
return currentEdge
}

public extend(results: { data: Data, metadata: any[] }, collapsed = false): (Node | Link)[] {
public extend(results: { data: Data, metadata: any[] }, collapsed = false, isSchema = false): (Node | Link)[] {
const newElements: (Node | Link)[] = []
const data = results?.data

Expand All @@ -399,15 +422,15 @@ export class Graph {
if (cell instanceof Object) {
if (cell.nodes) {
cell.nodes.forEach((node: any) => {
newElements.push(this.extendNode(node, collapsed))
newElements.push(this.extendNode(node, collapsed, isSchema))
})
cell.edges.forEach((edge: any) => {
newElements.push(this.extendEdge(edge, collapsed))
newElements.push(this.extendEdge(edge, collapsed, isSchema))
})
} else if (cell.relationshipType) {
newElements.push(this.extendEdge(cell, collapsed))
newElements.push(this.extendEdge(cell, collapsed, isSchema))
} else if (cell.labels) {
newElements.push(this.extendNode(cell, collapsed))
newElements.push(this.extendNode(cell, collapsed, isSchema))
}
}
})
Expand Down
Loading

0 comments on commit caf7470

Please sign in to comment.