Skip to content

Commit 05c14ce

Browse files
committed
Added Flask woker and python code which works
1 parent e1971a0 commit 05c14ce

File tree

48 files changed

+1006
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1006
-241
lines changed

apps/dashboard-app/app/(dashboard)/[...dashboard]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export default async function Home() {
88
if (!session){
99
redirect('/auth/login')
1010
}else{
11-
redirect('/financial')
11+
redirect('/home')
1212
}
1313
}

apps/dashboard-app/app/(dashboard)/automations/_components/Workflow.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const Workflow = ({workflow}:any) => {
7777
</Label>
7878
<Switch id='airplane-mode' onClick={onToggle} defaultChecked={workflow.publish!} />
7979
</div>
80-
<Button size="lg" onClick={()=>router.push(`/workflows/editor/${workflow.id}`)}>Edit</Button>
80+
<Button size="lg" onClick={()=>router.push(`/automations/editor/${workflow.id}`)}>Edit</Button>
8181
</div>
8282
</CardFooter>
8383
</Card>

apps/dashboard-app/app/(dashboard)/automations/editor/[editorId]/_components/NodeModal.tsx

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
'use client'
22

33
import { Button } from '@repo/ui/atoms/shadcn/Button';
4-
import React, { useState } from 'react'
4+
import React, { useEffect, useState } from 'react'
55
import { Dialog, DialogTrigger, DialogContent, DialogTitle, DialogDescription } from '@repo/ui/molecules/shadcn/Dialog';
66
import 'reactflow/dist/style.css';
77
import DynamicIcon from '../../../../../../components/DynamicIcon';
8-
import { Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from '@repo/ui/molecules/shadcn/Sheet';
98
import NodeSheet from './NodeSheet';
9+
import { TRIGGER_TYPES,ACTION_TYPES } from '../../../../../../lib/constant';
10+
import { getActionTypesAction, getTriggerTypesAction } from '../../../../../actions/workflows/workflow';
1011

11-
const NodeModal = ({node, type, types}: any) => {
12+
const NodeModal = ({node, type}: any) => {
1213

1314
const [selectedType, setSelectedType] = useState<any>({})
15+
const [actionTypes, setActionTypes] = useState<any>([])
16+
const [triggerTypes, setTriggerTypes] = useState<any>([])
17+
18+
useEffect(() => {
19+
const setTypes = async () =>{
20+
const actionTypes = await getActionTypesAction()
21+
setActionTypes(actionTypes)
22+
const triggerTypes = await getTriggerTypesAction()
23+
setTriggerTypes(triggerTypes)
24+
}
25+
setTypes()
26+
},[])
1427

1528
const onTypeSelect = (type: any) => {
1629
setSelectedType(type)
@@ -26,11 +39,20 @@ const NodeModal = ({node, type, types}: any) => {
2639
<DialogContent className="w-1/2 max-w-3xl">
2740
<div className='flex w-full h-[50vh] '>
2841
<div className='flex flex-col w-1/3 overflow-auto border-border/30 border-r-2'>
29-
{types.map((type: any) => (
30-
<div onClick={() => onTypeSelect(type)} key={type.id}
42+
{type=="Action" && actionTypes.map((type: any) => (
43+
<div onClick={() => onTypeSelect(type)} key={type.name}
44+
className='flex justify-start items-center gap-2 p-2 mr-4 hover:bg-destructive/10 cursor-pointer'>
45+
<div>
46+
<DynamicIcon icon={type.icon}/>
47+
</div>
48+
<div>{type.name}</div>
49+
</div>
50+
))}
51+
{type=="Trigger" && triggerTypes.map((type: any) => (
52+
<div onClick={() => onTypeSelect(type)} key={type.name}
3153
className='flex justify-start items-center gap-2 p-2 mr-4 hover:bg-destructive/10 cursor-pointer'>
3254
<div>
33-
<DynamicIcon icon={type.icon} />
55+
<DynamicIcon icon={type.icon}/>
3456
</div>
3557
<div>{type.name}</div>
3658
</div>
@@ -44,7 +66,7 @@ const NodeModal = ({node, type, types}: any) => {
4466
<DialogDescription>{selectedType?.description}</DialogDescription>
4567
</div>
4668
{selectedType?.types?.map((subType: any) => (
47-
<NodeSheet key={subType.id} funcType="create" nodeType={type} type={selectedType} subType={subType} />
69+
<NodeSheet key={subType.name} funcType="create" nodeType={type} type={selectedType} subType={subType} />
4870
))}
4971
</>)
5072
}

apps/dashboard-app/app/(dashboard)/automations/editor/[editorId]/_components/Nodes.tsx

+2-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import React, { useContext, useEffect, useState } from 'react'
44

55
import 'reactflow/dist/style.css';
6-
import { Card,CardHeader,CardTitle,CardFooter,CardDescription,CardContent } from '@repo/ui/molecules/shadcn/Card';
76
import { useParams, useRouter, useSearchParams } from 'next/navigation';
87
import { deleteActionAction, deleteTriggerAction, editFlow, getActionTypesAction, getTriggerTypesAction, publishFlow, runWorkflow } from '../../../../../actions/workflows/workflow';
98
import { EditorContext } from '../../../../../../providers/editor-provider';
@@ -17,7 +16,6 @@ import NodeModal from './NodeModal';
1716
import NodeCard from './NodeCard';
1817
import { useToast } from '../../../../../../hooks/useToast';
1918
import { Button } from '@repo/ui/atoms/shadcn/Button';
20-
import { useSearchParam } from 'react-use';
2119

2220
const Nodes = () => {
2321
const params = useParams()
@@ -28,27 +26,13 @@ const Nodes = () => {
2826
const [toggle,setToggle] = useState(editor.publish || false)
2927
const router = useRouter();
3028
const [loading,setLoading] = useState(false)
31-
const [workflow,setWorkflow] = useState({});
32-
33-
const [triggerTypes, setTriggerTypes] = useState([]);
34-
const [actionTypes, setActionTypes] = useState([]);
3529
const {toast} = useToast();
3630

3731
const onToggle = async () =>{
3832
setToggle(!toggle)
3933
await publishFlow(editorId as string,!toggle)
4034
}
4135

42-
useEffect(() => {
43-
const fetchTypes = async () => {
44-
const triggerTypes:any = await getTriggerTypesAction();
45-
setTriggerTypes(triggerTypes);
46-
const actionTypes:any = await getActionTypesAction();
47-
setActionTypes(actionTypes);
48-
}
49-
fetchTypes();
50-
},[])
51-
5236
useEffect(() => {
5337
const refreshNodes = async () => {
5438
setLoading(true);
@@ -133,7 +117,7 @@ const Nodes = () => {
133117
<NodeCard funcType='edit' nodeType='Trigger' node={editor.trigger}
134118
type={editor.trigger.type.triggerType} subType={editor.trigger.type} handleDelete={handleDelete}/>
135119
):(
136-
<NodeModal node={[]} type='Trigger' types={triggerTypes}/>
120+
<NodeModal node={[]} type='Trigger'/>
137121
)}
138122
<ArrowBigDownDash/>
139123
{editor.actions.length > 0 && editor.actions?.map((action:any) => (
@@ -143,7 +127,7 @@ const Nodes = () => {
143127
<ArrowBigDownDash/>
144128
</>
145129
))}
146-
<NodeModal node={[]} type='Action' types={actionTypes}/>
130+
<NodeModal node={[]} type='Action'/>
147131
</>
148132
)
149133
}

apps/dashboard-app/app/(dashboard)/automations/editor/[editorId]/_components/SelectedForm.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import Schedule from './trigger-forms/schedule/Schedule'
33
import WebhookTrigger from './trigger-forms/webhook/WebhookTrigger'
44
import WebhookAction from './action-forms/webhook/WebhookAction'
5-
import { JavascriptCode } from './action-forms/code/JavascriptCode'
5+
import Code from './action-forms/code/Code'
66
import Notion from './action-forms/notion/Notion'
77

88
const SelectedForm = ({funcType, nodeType,type,subType,node}: any) => {
@@ -19,7 +19,7 @@ const SelectedForm = ({funcType, nodeType,type,subType,node}: any) => {
1919
return <WebhookAction funcType={funcType} type={type} subType={subType} node={node}/>
2020
}
2121
else if (type.name == 'Code'){
22-
return <JavascriptCode funcType={funcType} type={type} subType={subType} node={node}/>
22+
return <Code funcType={funcType} type={type} subType={subType} node={node}/>
2323
}
2424

2525
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
import {JavascriptCode} from './JavascriptCode';
3+
import {PythonCode} from './PythonCode';
4+
5+
const Code= ({funcType,nodeType,type,subType,node}:any) => {
6+
7+
if (subType.name === 'Javascript Code'){
8+
9+
return <JavascriptCode funcType={funcType} type={type} subType={subType} node={node}/>
10+
}else if (subType.name === 'Python Code'){
11+
return <PythonCode funcType={funcType} type={type} subType={subType} node={node}/>
12+
}
13+
}
14+
15+
export default Code

apps/dashboard-app/app/(dashboard)/automations/editor/[editorId]/_components/action-forms/code/JavascriptCode.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { useToast } from '../../../../../../../../hooks/useToast';
99
import { getSession } from 'next-auth/react';
1010
import { useParams, useRouter } from 'next/navigation';
1111
import { EditorContext } from '../../../../../../../../providers/editor-provider';
12-
import { createActionAction, updateActionAction } from '../../../../../../../actions/workflows/workflow';
13-
import { set } from 'date-fns';
12+
import { createActionAction, updateActionAction } from '../../../../../../../actions/workflows/workflow';;
1413

1514
export const JavascriptCode = ({funcType,nodeType,type,subType,node}: any) => {
1615
const {toast} = useToast();
@@ -59,9 +58,10 @@ export const JavascriptCode = ({funcType,nodeType,type,subType,node}: any) => {
5958
workflowId: editorId,
6059
actionId: subType.id,
6160
metadata,
62-
sortingOrder: editor.actions.length
61+
sortingOrder: editor.actions.length+1
6362
}
6463
let res;
64+
console.log('params',params)
6565
if (funcType == 'create'){
6666
res = await createActionAction(params)
6767
}
@@ -71,7 +71,7 @@ export const JavascriptCode = ({funcType,nodeType,type,subType,node}: any) => {
7171
if (res.success){
7272
toast({title: "Success", description: res?.success, variant: 'default'})
7373
router.refresh()
74-
router.push(`/workflows/editor/${editorId}`)
74+
router.push(`/automations/editor/${editorId}`)
7575
}
7676
else if (res.error){
7777
toast({title: "Error", description: res?.error, variant: 'destructive'})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import CodeMirror from '@uiw/react-codemirror';
2+
// @ts-ignore
3+
import { python } from '@codemirror/lang-python';
4+
import React from 'react';
5+
import { oneDark } from '@codemirror/theme-one-dark';
6+
import { useContext, useState } from 'react';
7+
import { Button } from '@repo/ui/atoms/shadcn/Button';
8+
import { Alert, AlertDescription } from '@repo/ui/atoms/shadcn/Alert';
9+
import { useToast } from '../../../../../../../../hooks/useToast';
10+
import { getSession } from 'next-auth/react';
11+
import { useParams, useRouter } from 'next/navigation';
12+
import { EditorContext } from '../../../../../../../../providers/editor-provider';
13+
import { createActionAction, updateActionAction } from '../../../../../../../actions/workflows/workflow';;
14+
15+
export const PythonCode = ({funcType,nodeType,type,subType,node}: any) => {
16+
const {toast} = useToast();
17+
const params = useParams();
18+
const editorId = params?.editorId
19+
const router = useRouter();
20+
const editor = useContext(EditorContext);
21+
const [code, setCode] = useState(node?.metadata?.code || '// Write your python code here');
22+
const [output, setOutput] = useState('');
23+
const [error, setError] = useState('');
24+
const [logs, setLogs] = useState('');
25+
const compileCode = () => {
26+
setError('');
27+
setOutput('');
28+
29+
try {
30+
// Create a new Function from the code string
31+
const compiledFunction = new Function(code);
32+
33+
// Capture console.log output
34+
const originalLog = console.log;
35+
let logs:any = [];
36+
console.log = (...args) => {
37+
logs.push(args.join(' '));
38+
};
39+
40+
// Execute the compiled function
41+
const res = compiledFunction();
42+
43+
// Restore original console.log
44+
console.log = originalLog;
45+
setOutput(res);
46+
47+
setLogs(logs.join('\n'));
48+
} catch (err:any) {
49+
setError(err.toString());
50+
}
51+
};
52+
const onSubmit = async () => {
53+
const session = await getSession()
54+
const userId = session?.user?.id
55+
let metadata = {
56+
code: code
57+
}
58+
const params = {
59+
workflowId: editorId,
60+
actionId: subType.id,
61+
metadata,
62+
sortingOrder: editor.actions.length+1
63+
}
64+
let res;
65+
console.log('params',params)
66+
if (funcType == 'create'){
67+
res = await createActionAction(params)
68+
}
69+
else{
70+
res = await updateActionAction({id:node.id, actionId:node.actionId, metadata:metadata })
71+
}
72+
if (res.success){
73+
toast({title: "Success", description: res?.success, variant: 'default'})
74+
router.refresh()
75+
router.push(`/automations/editor/${editorId}`)
76+
}
77+
else if (res.error){
78+
toast({title: "Error", description: res?.error, variant: 'destructive'})
79+
}
80+
}
81+
82+
const modifyCode = (value: string) => {
83+
if (typeof value === 'string') {
84+
setCode(value);
85+
}
86+
else if (typeof value === 'object') {
87+
setCode(JSON.stringify(value));
88+
}
89+
}
90+
91+
return (
92+
<div className='flex flex-col gap-4'>
93+
<CodeMirror
94+
value={code}
95+
onChange={(value) => modifyCode(value)}
96+
height="500px"
97+
theme="dark"
98+
extensions={[python()]}
99+
className="border rounded"
100+
/>
101+
<div className='flex w-full justify-center gap-4'>
102+
<Button size="lg" onClick={compileCode}>Compile and Run</Button>
103+
<Button size="lg" variant="default" type="submit" onClick={onSubmit} > Add Action</Button>
104+
</div>
105+
{output && (
106+
<Alert>
107+
<AlertDescription>
108+
<pre>{typeof output === 'object' ?
109+
JSON.stringify(output) : output }</pre>
110+
</AlertDescription>
111+
</Alert>
112+
)}
113+
{error && (
114+
<Alert variant="destructive">
115+
<AlertDescription>
116+
<pre>{error}</pre>
117+
</AlertDescription>
118+
</Alert>
119+
)}
120+
{logs && (
121+
<Alert variant="default">
122+
<AlertDescription>
123+
<pre>{logs}</pre>
124+
</AlertDescription>
125+
</Alert>
126+
)}
127+
</div>
128+
)
129+
}

apps/dashboard-app/app/(dashboard)/automations/editor/[editorId]/_components/action-forms/notion/CreatePage.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const CreatePage = ({funcType,nodeType,type,subType,node}:any) => {
3939
workflowId: editorId,
4040
actionId: subType.id,
4141
metadata,
42-
sortingOrder: editor.actions.length
42+
sortingOrder: editor.actions.length+1
4343
}
4444
let res;
4545
if (funcType == 'create'){
@@ -51,7 +51,7 @@ const CreatePage = ({funcType,nodeType,type,subType,node}:any) => {
5151
if (res.success){
5252
toast({title: "Success", description: res?.success, variant: 'default'})
5353
router.refresh()
54-
router.push(`/workflows/editor/${editorId}`)
54+
router.push(`/automations/editor/${editorId}`)
5555
}
5656
else if (res.error){
5757
toast({title: "Error", description: res?.error, variant: 'destructive'})

apps/dashboard-app/app/(dashboard)/automations/editor/[editorId]/_components/action-forms/notion/Notion.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import UpdatePage from './UpdatePage';
44
import AppendBlock from './AppendBlock';
55
import DeletePage from './DeletePage';
66
import QueryDatabase from './QueryDatabase';
7+
import NotionJavascriptCode from './NotionJavascriptCode';
78

89
const Notion = ({funcType,nodeType,type,subType,node}:any) => {
10+
console.log('Notion',funcType,nodeType,type,subType,node)
911
if (subType.name === 'Create Page'){
1012
return <CreatePage funcType={funcType} type={type} subType={subType} node={node}/>
1113
}else if (subType.name === 'Update Page'){
@@ -16,6 +18,10 @@ const Notion = ({funcType,nodeType,type,subType,node}:any) => {
1618
return<DeletePage funcType={funcType} type={type} subType={subType} node={node}/>
1719
}else if (subType.name === 'Query Database'){
1820
return <QueryDatabase funcType={funcType} type={type} subType={subType} node={node}/>
21+
}else if (subType.name === 'Notion Javascript Code'){
22+
return <NotionJavascriptCode funcType={funcType} type={type} subType={subType} node={node}/>
23+
}else if (subType.name === 'Notion Python Code'){
24+
return <NotionJavascriptCode funcType={funcType} type={type} subType={subType} node={node}/>
1925
}
2026
}
2127

0 commit comments

Comments
 (0)