fix: auto rotate gaph shape
This commit is contained in:
parent
31aed48cab
commit
3419f9c45b
3 changed files with 74 additions and 17 deletions
|
|
@ -70,6 +70,7 @@ export default function CrewAITrigger({ onData, onActivity }: CrewAITriggerProps
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onData(null);
|
||||||
setIsCrewAIRunning(true);
|
setIsCrewAIRunning(true);
|
||||||
|
|
||||||
return fetch("/v1/crewai/run", {
|
return fetch("/v1/crewai/run", {
|
||||||
|
|
@ -82,7 +83,6 @@ export default function CrewAITrigger({ onData, onActivity }: CrewAITriggerProps
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
onActivity([{ id: uuid4(), timestamp: Date.now(), activity: "Hiring crew agents made a decision" }]);
|
onActivity([{ id: uuid4(), timestamp: Date.now(), activity: "Hiring crew agents made a decision" }]);
|
||||||
onData(null);
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
onActivity([{ id: uuid4(), timestamp: Date.now(), activity: "Hiring crew agents had problems while executing" }]);
|
onActivity([{ id: uuid4(), timestamp: Date.now(), activity: "Hiring crew agents had problems while executing" }]);
|
||||||
|
|
@ -96,9 +96,6 @@ export default function CrewAITrigger({ onData, onActivity }: CrewAITriggerProps
|
||||||
return (
|
return (
|
||||||
<form className="w-full flex flex-col gap-4" onSubmit={handleRunCrewAI}>
|
<form className="w-full flex flex-col gap-4" onSubmit={handleRunCrewAI}>
|
||||||
<h1 className="text-2xl text-white">Cognee HR Crew Demo</h1>
|
<h1 className="text-2xl text-white">Cognee HR Crew Demo</h1>
|
||||||
<p className="text-white mb-4">
|
|
||||||
Cognee can help you build AI memory from any data. Here you can see how AI Agents can use cognee to compare two GitHub contributors.
|
|
||||||
</p>
|
|
||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">
|
||||||
<div className="flex flex-col w-full flex-1/2">
|
<div className="flex flex-col w-full flex-1/2">
|
||||||
<label className="block mb-1 text-white" htmlFor="username1">GitHub username</label>
|
<label className="block mb-1 text-white" htmlFor="username1">GitHub username</label>
|
||||||
|
|
@ -109,7 +106,7 @@ export default function CrewAITrigger({ onData, onActivity }: CrewAITriggerProps
|
||||||
<Input name="username2" type="text" placeholder="Github Username" required defaultValue="lxobr" />
|
<Input name="username2" type="text" placeholder="Github Username" required defaultValue="lxobr" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<CTAButton type="submit" className="whitespace-nowrap">
|
<CTAButton type="submit" disabled={isCrewAIRunning} className="whitespace-nowrap">
|
||||||
Start HR Crew Research
|
Start HR Crew Research
|
||||||
{isCrewAIRunning && <LoadingIndicator />}
|
{isCrewAIRunning && <LoadingIndicator />}
|
||||||
</CTAButton>
|
</CTAButton>
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,18 @@
|
||||||
|
|
||||||
import { v4 as uuid4 } from "uuid";
|
import { v4 as uuid4 } from "uuid";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { NodeObject } from "react-force-graph-2d";
|
import { NodeObject, LinkObject } from "react-force-graph-2d";
|
||||||
import { ChangeEvent, useEffect, useImperativeHandle, useState } from "react";
|
import { ChangeEvent, useEffect, useImperativeHandle, useRef, useState } from "react";
|
||||||
|
|
||||||
import { DeleteIcon } from "@/ui/Icons";
|
import { DeleteIcon } from "@/ui/Icons";
|
||||||
import { FeedbackForm } from "@/ui/Partials";
|
import { FeedbackForm } from "@/ui/Partials";
|
||||||
import { CTAButton, Input, NeutralButton, Select } from "@/ui/elements";
|
import { CTAButton, Input, NeutralButton, Select } from "@/ui/elements";
|
||||||
|
|
||||||
interface GraphControlsProps {
|
interface GraphControlsProps {
|
||||||
|
data?: {
|
||||||
|
nodes: NodeObject[];
|
||||||
|
links: LinkObject[];
|
||||||
|
};
|
||||||
isAddNodeFormOpen: boolean;
|
isAddNodeFormOpen: boolean;
|
||||||
ref: React.RefObject<GraphControlsAPI>;
|
ref: React.RefObject<GraphControlsAPI>;
|
||||||
onFitIntoView: () => void;
|
onFitIntoView: () => void;
|
||||||
|
|
@ -37,7 +41,30 @@ const formatter = new Intl.DateTimeFormat("en-GB", { dateStyle: "short", timeSty
|
||||||
|
|
||||||
const DEFAULT_GRAPH_SHAPE = "lr";
|
const DEFAULT_GRAPH_SHAPE = "lr";
|
||||||
|
|
||||||
export default function GraphControls({ isAddNodeFormOpen, onGraphShapeChange, onFitIntoView, ref }: GraphControlsProps) {
|
const GRAPH_SHAPES = [{
|
||||||
|
value: "none",
|
||||||
|
label: "None",
|
||||||
|
}, {
|
||||||
|
value: "td",
|
||||||
|
label: "Top-down",
|
||||||
|
}, {
|
||||||
|
value: "bu",
|
||||||
|
label: "Bottom-up",
|
||||||
|
}, {
|
||||||
|
value: "lr",
|
||||||
|
label: "Left-right",
|
||||||
|
}, {
|
||||||
|
value: "rl",
|
||||||
|
label: "Right-left",
|
||||||
|
}, {
|
||||||
|
value: "radialin",
|
||||||
|
label: "Radial-in",
|
||||||
|
}, {
|
||||||
|
value: "radialout",
|
||||||
|
label: "Radial-out",
|
||||||
|
}];
|
||||||
|
|
||||||
|
export default function GraphControls({ data, isAddNodeFormOpen, onGraphShapeChange, onFitIntoView, ref }: GraphControlsProps) {
|
||||||
const [selectedNode, setSelectedNode] = useState<NodeObject | null>(null);
|
const [selectedNode, setSelectedNode] = useState<NodeObject | null>(null);
|
||||||
const [nodeProperties, setNodeProperties] = useState<NodeProperty[]>([]);
|
const [nodeProperties, setNodeProperties] = useState<NodeProperty[]>([]);
|
||||||
const [newProperty, setNewProperty] = useState<NodeProperty>({
|
const [newProperty, setNewProperty] = useState<NodeProperty>({
|
||||||
|
|
@ -79,15 +106,51 @@ export default function GraphControls({ isAddNodeFormOpen, onGraphShapeChange, o
|
||||||
const [selectedTab, setSelectedTab] = useState("nodeDetails");
|
const [selectedTab, setSelectedTab] = useState("nodeDetails");
|
||||||
|
|
||||||
const handleGraphShapeControl = (event: ChangeEvent<HTMLSelectElement>) => {
|
const handleGraphShapeControl = (event: ChangeEvent<HTMLSelectElement>) => {
|
||||||
|
setIsAuthShapeChangeEnabled(false);
|
||||||
onGraphShapeChange(event.target.value);
|
onGraphShapeChange(event.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [isAuthShapeChangeEnabled, setIsAuthShapeChangeEnabled] = useState(true);
|
||||||
|
const shapeChangeTimeout = useRef<number | null>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onGraphShapeChange(DEFAULT_GRAPH_SHAPE);
|
onGraphShapeChange(DEFAULT_GRAPH_SHAPE);
|
||||||
|
|
||||||
|
const graphShapesNum = GRAPH_SHAPES.length;
|
||||||
|
|
||||||
|
function switchShape(shapeIndex: number) {
|
||||||
|
if (!isAuthShapeChangeEnabled || !data) {
|
||||||
|
if (shapeChangeTimeout.current) {
|
||||||
|
clearTimeout(shapeChangeTimeout.current);
|
||||||
|
shapeChangeTimeout.current = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
shapeChangeTimeout.current = setTimeout(() => {
|
||||||
|
const newValue = GRAPH_SHAPES[shapeIndex].value;
|
||||||
|
onGraphShapeChange(newValue);
|
||||||
|
const graphShapeSelectElement = document.getElementById("graph-shape-select") as HTMLSelectElement;
|
||||||
|
graphShapeSelectElement.value = newValue;
|
||||||
|
|
||||||
|
switchShape((shapeIndex + 1) % graphShapesNum);
|
||||||
|
}, 5000) as unknown as number;
|
||||||
|
};
|
||||||
|
|
||||||
|
switchShape(0);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
onFitIntoView();
|
onFitIntoView();
|
||||||
}, 500);
|
}, 500);
|
||||||
}, [onFitIntoView, onGraphShapeChange]);
|
|
||||||
|
return () => {
|
||||||
|
if (shapeChangeTimeout.current) {
|
||||||
|
clearTimeout(shapeChangeTimeout.current);
|
||||||
|
shapeChangeTimeout.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [data, isAuthShapeChangeEnabled, onFitIntoView, onGraphShapeChange]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -105,14 +168,10 @@ export default function GraphControls({ isAddNodeFormOpen, onGraphShapeChange, o
|
||||||
<>
|
<>
|
||||||
<div className="w-full flex flex-row gap-2 items-center mb-4">
|
<div className="w-full flex flex-row gap-2 items-center mb-4">
|
||||||
<label className="text-gray-300 whitespace-nowrap flex-1/5">Graph Shape:</label>
|
<label className="text-gray-300 whitespace-nowrap flex-1/5">Graph Shape:</label>
|
||||||
<Select defaultValue={DEFAULT_GRAPH_SHAPE} onChange={handleGraphShapeControl} className="flex-2/5">
|
<Select defaultValue={DEFAULT_GRAPH_SHAPE} onChange={handleGraphShapeControl} id="graph-shape-select" className="flex-2/5">
|
||||||
<option value="none">None</option>
|
{GRAPH_SHAPES.map((shape) => (
|
||||||
<option value="td">Top-down</option>
|
<option key={shape.value} value={shape.value}>{shape.label}</option>
|
||||||
<option value="bu">Bottom-up</option>
|
))}
|
||||||
<option value="lr">Left-right</option>
|
|
||||||
<option value="rl">Right-left</option>
|
|
||||||
<option value="radialin">Radial-in</option>
|
|
||||||
<option value="radialout">Radial-out</option>
|
|
||||||
</Select>
|
</Select>
|
||||||
<NeutralButton onClick={onFitIntoView} className="flex-2/5 whitespace-nowrap">Fit Graph into View</NeutralButton>
|
<NeutralButton onClick={onFitIntoView} className="flex-2/5 whitespace-nowrap">Fit Graph into View</NeutralButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ export default function GraphView() {
|
||||||
<div className="absolute top-2 right-2 flex flex-col gap-2 items-end">
|
<div className="absolute top-2 right-2 flex flex-col gap-2 items-end">
|
||||||
<div className="bg-gray-500 pt-4 pr-4 pb-4 pl-4 rounded-md w-110">
|
<div className="bg-gray-500 pt-4 pr-4 pb-4 pl-4 rounded-md w-110">
|
||||||
<GraphControls
|
<GraphControls
|
||||||
|
data={data}
|
||||||
ref={graphControls as MutableRefObject<GraphControlsAPI>}
|
ref={graphControls as MutableRefObject<GraphControlsAPI>}
|
||||||
isAddNodeFormOpen={isAddNodeFormOpen}
|
isAddNodeFormOpen={isAddNodeFormOpen}
|
||||||
onFitIntoView={() => graphRef.current!.zoomToFit(1000, 50)}
|
onFitIntoView={() => graphRef.current!.zoomToFit(1000, 50)}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue