Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mxerf committed May 28, 2024
1 parent 9c9a963 commit 09e2ea5
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 104 deletions.
7 changes: 7 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
};
42 changes: 29 additions & 13 deletions frontend/cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
describe("check run and edit flow", () => {
it("add run edit flow", () => {
cy.visit("http://localhost:8000/app/home")
cy.visit("http://localhost:5173/app/home")
cy.location("pathname").should("eq", "/app/home")
cy.get("[data-testid=create-flow-btn]").should("exist")
cy.get("[data-testid=create-flow-btn]").click()
cy.get("[data-testid=create-flow-btn]").click({ force: true })
cy.get("[data-testid=flow-name-input]").should("exist")
cy.get("[data-testid=flow-name-input]").click().type("flow1")
cy.get("[data-testid=flow-name-input]").click({ force: true }).type("flow1")
cy.get("[data-testid=flow-color-FFCC00]").should("exist")
cy.get("[data-testid=flow-color-FFCC00]").click()
cy.get("[data-testid=flow-color-FFCC00]").click({ force: true })
cy.wait(100)
cy.get("[data-testid=flow-save-btn").should("exist")
cy.get("[data-testid=flow-save-btn").click()
cy.get("[data-testid=flow-save-btn").click({ force: true })
cy.get("[data-testid=flow1-edit-btn]").should("exist")
cy.get("[data-testid=flow1-edit-btn]").click()
cy.get("[data-testid=flow1-edit-btn]").click({ force: true })
cy.location("pathname").should("eq", "/app/flow/flow1")
cy.get("[data-testid=flow-page]").should("exist")
cy.get("[data-testid=nodes-collapse-btn]").click()
cy.get("[data-testid=nodes-collapse-btn]").click({ force: true })
cy.wait(500)
cy.get("[data-testid=default_node-item]").should("exist")
let nodes: any[] = []
Expand All @@ -28,13 +28,31 @@ describe("check run and edit flow", () => {
cy.get("[data-testid=default_node-item]").trigger("dragstart", { dataTransfer })
cy.get("[data-testid=rf__wrapper]").trigger("drop", { dataTransfer })
cy.get("[data-testid=defaultnode-add-condition-btn]").should("exist")
cy.get("[data-testid=defaultnode-add-condition-btn]").click()
cy.get("[data-testid=defaultnode-add-condition-btn]").click({ force: true })
cy.wait(300)
cy.get("[data-testid=python-condition-editor]").should("exist")
cy.get("[data-testid=python-condition-editor]").type('if False: print("hello")')
cy.get("[data-testid=save-condition-button]").should("exist").click()
cy.get("[data-testid=save-condition-button]").should("exist").click({ force: true })
cy.get("[data-testid=rf__wrapper]").trigger("keydown", { ctrlKey: true, key: "s" })
cy.wait(500)
cy.get("[data-testid=build-btn]").should("exist")
cy.get("[data-testid=build-btn]").click()
cy.wait(4000)
cy.get("[data-testid=build-menu-open-btn]").should("exist")
cy.get("[data-testid=build-menu-open-btn]").click()
cy.wait(300)
cy.get("[data-testid=run-btn]").should("exist")
cy.get("[data-testid=run-btn]").click()
cy.wait(1000)
cy.get("[data-testid=chat-btn]").should("exist")
cy.get("[data-testid=chat-btn]").click()
cy.get("[data-testid=chat-input]").should("exist")
cy.get("[data-testid=chat-input]").click()
cy.get("[data-testid=chat-input]").type("hello")
cy.get("[data-testid=chat-send]").should("exist")
cy.get("[data-testid=chat-send]").click()
cy.wait(300)
cy.get("[data-testid=bot-message]").should("exist")
cy.wrap(null).then(() => {
let currNodes: any[] = []
cy.request("http://localhost:8000/api/v1/flows").then((response) => {
Expand All @@ -50,11 +68,9 @@ describe("check run and edit flow", () => {
currNodes = response.body.data.flows.find((flow) => flow.name === "flow1").data.nodes
expect(currNodes.length).to.eq(nodes.length)
})
// cy.get("[data-testid=logo]").should("exist")
// cy.get("[data-testid=logo]").click()
cy.visit("http://localhost:8000/app/home")
cy.visit("http://localhost:5173/app/home")
cy.get("[data-testid=flow1-delete-btn]").should("exist")
cy.get("[data-testid=flow1-delete-btn]").click()
cy.get("[data-testid=flow1-delete-btn]").click({ force: true })
cy.get("[data-testid=flow1-edit-btn]").should("not.exist")
})
})
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const Chat = () => {
className='h-[60vh] bg-chat border-b border-border px-2 py-2 overflow-y-scroll scrollbar-hide flex flex-col gap-2'>
{messagesT((style, m) => (
<a.div
data-testid={`${m.type}-message`}
style={style}
key={m.message + m.type + Math.random()}
className={`flex items-center ${
Expand Down Expand Up @@ -247,6 +248,7 @@ const Chat = () => {
</div>
</div>
<Button
data-testid='chat-send'
onClick={handleMessage}
variant='light'
isIconOnly>
Expand All @@ -255,6 +257,7 @@ const Chat = () => {
</div>
</div>
<Textarea
data-testid='chat-input'
value={messageValue}
onChange={(e) => setMessageValue(e.target.value)}
classNames={{
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/components/header/BuildMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const BuildMenu = () => {
return (
<div className={classNames("build-menu", !showBuildMenu && "build-menu-closed")}>
<Button
data-testid='build-menu-open-btn'
isIconOnly
className={
"bg-transparent border border-transparent hover:bg-header-btn-hover hover:border-border-darker rounded p-0 max-w-5 w-5 min-w-5 h-[34px]"
Expand All @@ -32,6 +33,7 @@ const BuildMenu = () => {
/>
</Button>
<Button
data-testid='run-btn'
isIconOnly
style={{}}
onClick={() => {
Expand Down Expand Up @@ -63,13 +65,14 @@ const BuildMenu = () => {
runStatus === "alive"
? "bg-emerald-500"
: runStatus === "stopped"
? "bg-transparent"
: "bg-red-500",
? "bg-transparent"
: "bg-red-500",
runPending && "bg-warning"
)}
/>
</Button>
<Button
data-testid='build-btn'
isIconOnly
spinner={
<Spinner
Expand All @@ -78,7 +81,7 @@ const BuildMenu = () => {
/>
}
style={{}}
onClick={() => buildStart({ wait_time: 4, end_status: "success" })}
onClick={() => buildStart({ wait_time: 1, end_status: "success" })}
isLoading={buildPending}
className={classNames("flex items-center justify-center build-menu-item")}>
<Wrench className='w-5 h-5' />
Expand All @@ -88,13 +91,14 @@ const BuildMenu = () => {
buildStatus === "completed"
? "bg-emerald-500"
: buildStatus === "stopped"
? "bg-transparent"
: "bg-red-500",
? "bg-transparent"
: "bg-red-500",
buildPending && "bg-warning"
)}
/>
</Button>
<Button
data-testid='chat-btn'
onClick={() => {
setSearchParams({
...parseSearchParams(searchParams),
Expand Down
20 changes: 15 additions & 5 deletions frontend/src/components/nodes/DefaultNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { Handle, Position } from "reactflow"
import "reactflow/dist/style.css"
import { workspaceContext } from "../../contexts/workspaceContext"
import EditNodeIcon from "../../icons/nodes/EditNodeIcon"
import FallbackNodeIcon from "../../icons/nodes/FallbackNodeIcon"
import GlobalNodeIcon from "../../icons/nodes/GlobalNodeIcon"
import LocalNodeIcon from "../../icons/nodes/LocalNodeIcon"
import StartNodeIcon from "../../icons/nodes/StartNodeIcon"
import "../../index.css"
import ConditionModal from "../../modals/ConditionModal/ConditionModal"
import NodeModal from "../../modals/NodeModal/NodeModal"
Expand All @@ -26,17 +30,19 @@ const DefaultNode = memo(({ data }: { data: NodeDataType }) => {
// console.log("111")
// }, [flows])

console.log(data)

return (
<>
<div id={data.id} data-testid={data.id} className='default_node'>
{data.flags?.includes("start") && (
<span className='-top-2 left-4 bg-green-500 absolute text-white text-xs font-medium rounded-small px-1.5 py-1.5 -z-20 transition-transform cursor-auto hover:-z-10 hover:-translate-y-4'>
S
<span className='-top-2 left-4 bg-[#e5faf5] border border-[#00cc99] absolute text-white text-xs font-medium rounded-small px-0.5 py-0.5 -z-20 transition-transform cursor-auto hover:-z-10 hover:-translate-y-4'>
<StartNodeIcon />
</span>
)}
{data.flags?.includes("fallback") && (
<span className='-top-2 left-7 bg-red-500 absolute text-white text-xs font-medium rounded-small px-1.5 py-1.5 -z-20 transition-transform cursor-auto hover:-z-10 hover:-translate-y-4'>
F
<span className='-top-2 left-14 bg-[#fde9e9] border border-[#ff3333] absolute text-white text-xs font-medium rounded-small px-0.5 py-0.5 -z-20 transition-transform cursor-auto hover:-z-10 hover:-translate-y-4'>
<FallbackNodeIcon />
</span>
)}
<div className=' w-full flex justify-between items-center bg-node-header border-b border-border rounded-t-node px-6 py-4'>
Expand All @@ -57,7 +63,11 @@ const DefaultNode = memo(({ data }: { data: NodeDataType }) => {
zIndex: 10,
}}
/>
<p className='font-medium text-medium'>{data.name}</p>
<p className='font-medium text-medium flex items-center gap-1'>
{data.id.includes('LOCAL_NODE') && <LocalNodeIcon />}
{data.id.includes('GLOBAL_NODE') && <GlobalNodeIcon />}
{data.name}
</p>
</div>
<button onClick={onNodeOpen}>
<EditNodeIcon />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/contexts/buildContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const BuildProvider = ({ children }: { children: React.ReactNode }) => {
console.log(status_res)
const status = status_res.status.toLowerCase()
console.log(status)
if (status !== "running") {
if (status !== "running" && status !== "alive") {
flag = false
setTimeout(async () => {
const build = await get_builds()
Expand Down
114 changes: 39 additions & 75 deletions frontend/src/contexts/runContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
runMinifyApiType,
run_start,
run_status,
run_stop
run_stop,
} from "../api/bot"
import { buildContext } from "./buildContext"

Expand Down Expand Up @@ -57,7 +57,7 @@ export const RunProvider = ({ children }: { children: React.ReactNode }) => {
const [runPending, setRunPending] = useState(false)
const [runStatus, setRunStatus] = useState<buildApiStatusType>("stopped")
const [runs, setRuns] = useState<localRunType[]>([])
const { setBuildsHandler } = useContext(buildContext)
const { setBuildsHandler, builds: context_builds } = useContext(buildContext)

const setRunsHandler = (runs: runMinifyApiType[]) => {
setRuns(runs.map((run) => ({ ...run, type: "run" })))
Expand Down Expand Up @@ -89,83 +89,47 @@ export const RunProvider = ({ children }: { children: React.ReactNode }) => {
setRunPending(() => true)
setRunStatus("running")
try {
const data = await run_start({ wait_time, end_status }, 43)
const { run_id } = await run_start({ wait_time, end_status }, context_builds[0].id)
console.log("run started")
await new Promise((resolve) => setTimeout(resolve, 5000))
const started_runs = await get_runs()
const started_run = started_runs.find((r) => r.id === data.run_id)!
setRun({ ...started_run, type: "run" })
console.log(started_run)
setRuns((prev) => [
...prev,
{
...started_run,
type: "run",
},
])
const builds = await get_builds()
setBuildsHandler(builds)
let flag = true
let timer = 0
const timerId = setInterval(() => timer++, 500)
while (flag) {
if (timer > 9999) {
setRunPending(() => false)
setRunStatus("failed")
toast.error("Run timeout error!")
return (flag = false)
console.log(started_runs)
const started_run = started_runs.find((r) => r.id === run_id)
console.log(run_id)
if (started_run) {
setRun({ ...started_run, type: "run" })
console.log(started_run)
setRuns((prev) => [
...prev,
{
...started_run,
type: "run",
},
])
const builds = await get_builds()
console.log(started_run)
setBuildsHandler(builds)
let flag = true
let timer = 0
const timerId = setInterval(() => timer++, 500)
while (flag) {
if (timer > 9999) {
setRunPending(() => false)
setRunStatus("failed")
toast.error("Run timeout error!")
return (flag = false)
}
const { status } = await run_status(started_run.id)
console.log(status)
if (status === "alive") {
flag = false
setRunPending(false)
setRunStatus("alive")
}
await new Promise((resolve) => setTimeout(resolve, 500))
}
const { status } = await run_status(started_run.id)
console.log(status)
if (status === "running") {
flag = false
setRunPending(false)
setRunStatus("alive")
}
// if (status !== "running") {
// flag = false
// const {
// data: { run },
// } = await get_runs()
// setRuns((prev) => run.map((run) => ({ ...run, type: "run" })))
// const { data: b } = await get_builds()
// setBuilds((prev) =>
// b.build.map((build) => ({
// ...build,
// type: "build",
// runs: build.runs.map((run) => ({ ...run, type: "run" })),
// }))
// )
// if (status === "completed") {
// setRunPending((prev) => false)
// setRunStatus("completed")
// setRun((prev) => false)
// toast.success("Run successfully closed!")
// } else if (status === "failed") {
// setRunPending((prev) => false)
// setRunStatus("failed")
// setRun((prev) => false)
// toast.error("Run failed!")
// }
// } else {
// const {
// data: { run },
// } = await get_runs()
// setRuns((prev) => run.map((run) => ({ ...run, type: "run" })))
// const { data: b } = await get_builds()
// setBuilds((prev) =>
// b.build.map((build) => ({
// ...build,
// type: "build",
// runs: build.runs.map((run) => ({ ...run, type: "run" })),
// }))
// )
// setRunPending((prev) => true)
// setRunStatus("running")
// setRun((prev) => true)
// }
await new Promise((resolve) => setTimeout(resolve, 500))
clearInterval(timerId)
}
clearInterval(timerId)
} catch (error) {
console.log(error)
} finally {
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/icons/PlusFlagIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react"

export const PlusFlagIcon = ({ fill="#00CC99", stroke="#00CC99", className }: React.SVGAttributes<SVGSVGElement>) => {
return (
<svg
width='24'
height='24'
viewBox='0 0 24 24'
fill='none'
xmlns='http://www.w3.org/2000/svg'>
<path
d='M10.708 5.83427C9.21009 4.88107 7.25 5.95706 7.25 7.73251V16.2675C7.25 18.0429 9.21009 19.1189 10.708 18.1657L17.414 13.8982C18.8034 13.0141 18.8034 10.9859 17.414 10.1018L10.708 5.83427Z'
fill={fill}
stroke={stroke}
stroke-width='1.5'
stroke-linecap='round'
stroke-linejoin='round'
/>
</svg>
)
}
Loading

0 comments on commit 09e2ea5

Please sign in to comment.