Skip to content

Commit

Permalink
Merge pull request #29 from anoopkarnik/main
Browse files Browse the repository at this point in the history
Get Variables with Code Node Sheet
  • Loading branch information
anoopkarnik authored Oct 14, 2024
2 parents ed5fcda + b3dfdc1 commit 1750f76
Show file tree
Hide file tree
Showing 14 changed files with 2,425 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ const EventComponent = () => {
};
fetchEvents();
}, [workflowId,userId]);
if (events.length==0) return null;

return (
<div className='flex flex-col h-[800px] border-x-2 border-border/50 pr-2 px-2 rounded-lg border bg-card text-card-foreground shadow-sm ml-4'>
<div className='text-xl font-medium text-center mb-4'>Events</div>
{events.slice(0,10).map((event) => (
<div key={event.id} className='flex items-center justify-between gap-4 border-b-2 border-border/40 text-xs'>
<div>{format(new Date(event.createdAt), 'HH:mm')}</div>
<div>{format(new Date(event.createdAt), 'ddMMM')}</div>
<div>{event.Workflows.name}</div>
<div>{event.status}</div>
</div>
))}
<div className= 'flex flex-col gap-4'>
<div className='rounded-lg border bg-card text-card-foreground shadow-sm ml-4'>
<div className='text-xl font-medium text-center mt-1 mb-2 '>Events</div>
</div>
<div className='flex flex-col border-x-2 border-border/50 p-4 rounded-lg border bg-card text-card-foreground shadow-sm ml-4'>
{events.slice(0,24).map((event) => (
<div key={event.id} className='flex items-center justify-between gap-4 border-b-2 border-border/40 text-xs'>
<div>{format(new Date(event.createdAt), 'HH:mm')}</div>
<div>{format(new Date(event.createdAt), 'ddMMM')}</div>
<div>{event.Workflows.name}</div>
<div>{event.status}</div>
</div>
))}
</div>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const NodeSheet = ({funcType,nodeType,type,subType,node}:any) => {
</Button>
</div>}
</SheetTrigger>
<SheetContent side='rightLarge'>
<SheetContent className="overflow-y-auto" side='rightLarge'>
<SheetHeader>
<SheetTitle>Create a {subType.name} </SheetTitle>
<SheetDescription>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import React, { useEffect, useState } from 'react'


import { Button } from '@repo/ui/atoms/shadcn/Button';
import { useSession } from 'next-auth/react';

import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@repo/ui/molecules/shadcn/Accordion';
import { Label } from '@repo/ui/atoms/shadcn/Label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@repo/ui/molecules/shadcn/Select';
import { getDatabases } from '../../../../../../../actions/notion/notion';
import { getNotionConnection } from '../../../../../../../actions/connections/notion-connections';
import SearchableSelect from '@repo/ui/molecules/custom/SearchableSelect';
import { getYoutubeConnection } from '../../../../../../../actions/connections/youtube-connections';
import { getOpenAIConnection } from '../../../../../../../actions/connections/openai-connections';
;
const GetVariables = () => {

//Notion Variables
const [notionAccounts, setNotionAccounts] = useState<any>([])
const [selectedNotionAccount, setSelectedNotionAccount] = useState('')
const [databases, setDatabases] = useState<any>([])
const [selectedDatabase, setSelectedDatabase] = useState('')

//Youtube Variables
const [youtubeAccounts, setYoutubeAccounts] = useState<any>([])
const [selectedYoutubeAccount, setSelectedYoutubeAccount] = useState('')
const youtubeClientId:any = process.env.NEXT_PUBLIC_YOUTUBE_CLIENT_ID;
const youtubeClientSecret:any = process.env.NEXT_PUBLIC_YOUTUBE_CLIENT_SECRET;

//OpenAI Variables
const [openAIAccounts, setOpenAIAccounts] = useState<any>([])
const [selectedOpenAIAccount, setSelectedOpenAIAccount] = useState('')

const [variable, setVariable] = useState<any>('');
const session = useSession();
const userId = session?.data?.user?.id;

useEffect(() => {
const fetchNotionDetails = async () => {
if (!userId) return;
const res:any = await getNotionConnection(userId);
setNotionAccounts(res);
if(!selectedNotionAccount) return;
const databases:any = await getDatabases(selectedNotionAccount);
setDatabases(databases);
}
const fetchYoutubeDetails = async () => {
if (!userId) return;
const res:any = await getYoutubeConnection(userId);
const youtubeClientId =
setYoutubeAccounts(res);
}
const fetchOpenAIDetails = async () => {
if (!userId) return;
const res:any = await getOpenAIConnection(userId);
setOpenAIAccounts(res);
console.log('openaiAccounts',res)
}
fetchNotionDetails()
fetchYoutubeDetails()
fetchOpenAIDetails()
},[userId, selectedNotionAccount,selectedDatabase,selectedYoutubeAccount,selectedOpenAIAccount])
return (
<div>
<Accordion type="single" collapsible className='w-full'>
<AccordionItem value="1">
<AccordionTrigger>Get Notion Variables</AccordionTrigger>
<AccordionContent>
<div className='flex flex-col gap-4 mt-4 ml-2 w-[80%]'>
<Label className='ml-2'>Notion Account</Label>
<Select onValueChange={(value) => setSelectedNotionAccount(value)} defaultValue={selectedNotionAccount}>
<SelectTrigger>
<SelectValue placeholder='Select Notion Account'/>
</SelectTrigger>
<SelectContent>
{notionAccounts?.map((account:any) => (
<SelectItem key={account.id} value={account.accessToken}>{account.name}</SelectItem>
))}
</SelectContent>
</Select>
</div>
{selectedNotionAccount &&
<div className='flex flex-col gap-4 mt-4 ml-2 w-[80%] '>
<Label className='ml-2'>Notion Databases</Label>
<SearchableSelect
name="Database"
options={databases || []}
selectedOption={selectedDatabase }
onChange={(value:any)=>{setSelectedDatabase(value)}}/>
</div>}
<div className='flex gap-2 mt-4 ml-2 items-center'>
{selectedNotionAccount &&
<Button size="sm" variant="outline" onClick={() => setVariable(selectedNotionAccount)}>
Get Access Token
</Button> }
{selectedDatabase &&
<Button size="sm" variant="outline" onClick={() => setVariable(JSON.parse(selectedDatabase).id.replaceAll("-",""))}>
Get Database ID
</Button>}
</div>
<div className='flex flex-col gap-2 '>

</div>
</AccordionContent>
</AccordionItem>
<AccordionItem value="2">
<AccordionTrigger>Get Youtube Variables</AccordionTrigger>
<AccordionContent>
<div className='flex flex-col gap-4 mt-4 ml-2 w-[80%]'>
<Label className='ml-2'>Youtube Account</Label>
<Select onValueChange={(value) => setSelectedYoutubeAccount(value)} defaultValue={selectedYoutubeAccount}>
<SelectTrigger>
<SelectValue placeholder='Select Youtube Account'/>
</SelectTrigger>
<SelectContent>
{youtubeAccounts?.map((account:any) => (
<SelectItem key={account.id} value={account.access_token}>{account.name}</SelectItem>
))}
</SelectContent>
</Select>
</div>

<div className='flex gap-2 mt-4 ml-2 items-center flex-wrap'>
{selectedYoutubeAccount &&
<Button size="sm" variant="outline" onClick={() => setVariable(selectedYoutubeAccount)}>
Get Refresh Token
</Button> }
<Button size="sm" variant="outline" onClick={() => setVariable(youtubeClientId)}>
Get Youtube Client ID
</Button>
<Button size="sm" variant="outline" onClick={() => setVariable(youtubeClientSecret)}>
Get Youtube Client Secret
</Button>
</div>
</AccordionContent>
</AccordionItem>
<AccordionItem value="3">
<AccordionTrigger>Get OpenAI Variables</AccordionTrigger>
<AccordionContent>
<div className='flex flex-col gap-4 mt-4 ml-2 w-[80%]'>
<Label className='ml-2'>OpenAI Account</Label>
<Select onValueChange={(value) => setSelectedOpenAIAccount(value)} defaultValue={selectedOpenAIAccount}>
<SelectTrigger>
<SelectValue placeholder='Select OpenAI Account'/>
</SelectTrigger>
<SelectContent>
{openAIAccounts?.map((account:any) => (
<SelectItem key={account.id} value={account.apiKey}>{account.name}</SelectItem>
))}
</SelectContent>
</Select>
</div>

<div className='flex gap-2 mt-4 ml-2 items-center'>
{selectedOpenAIAccount &&
<Button size="sm" variant="outline" onClick={() => setVariable(selectedOpenAIAccount)}>
Get Access Token
</Button> }
</div>
<div className='flex flex-col gap-2 '>

</div>
</AccordionContent>
</AccordionItem>
</Accordion>
<input className='p-2 mt-4 w-full' type="text" value={variable} placeholder='Variable Value' />
</div>
)
}

export default GetVariables
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import CodeMirror from '@uiw/react-codemirror';
// @ts-ignore
import { python } from '@codemirror/lang-python';
import React from 'react';
import React, { useEffect } from 'react';
import { oneDark } from '@codemirror/theme-one-dark';
import { useContext, useState } from 'react';
import { Button } from '@repo/ui/atoms/shadcn/Button';
import { Alert, AlertDescription } from '@repo/ui/atoms/shadcn/Alert';
import { useToast } from '../../../../../../../../hooks/useToast';
import { getSession } from 'next-auth/react';
import { getSession, useSession } from 'next-auth/react';
import { useParams, useRouter } from 'next/navigation';
import { EditorContext } from '../../../../../../../../providers/editor-provider';
import { createActionAction, updateActionAction } from '../../../../../../../actions/workflows/workflow';;
import { createActionAction, updateActionAction } from '../../../../../../../actions/workflows/workflow';import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@repo/ui/molecules/shadcn/Accordion';
import { Label } from '@repo/ui/atoms/shadcn/Label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@repo/ui/molecules/shadcn/Select';
import { getDatabases } from '../../../../../../../actions/notion/notion';
import { getNotionConnection } from '../../../../../../../actions/connections/notion-connections';
import SearchableSelect from '@repo/ui/molecules/custom/SearchableSelect';
import { Input } from '@repo/ui/atoms/shadcn/Input';
import GetVariables from './GetVariables';
;

export const PythonCode = ({funcType,nodeType,type,subType,node}: any) => {
const {toast} = useToast();
Expand All @@ -22,34 +30,8 @@ export const PythonCode = ({funcType,nodeType,type,subType,node}: any) => {
const [output, setOutput] = useState('');
const [error, setError] = useState('');
const [logs, setLogs] = useState('');
const compileCode = () => {
setError('');
setOutput('');

try {
// Create a new Function from the code string
const compiledFunction = new Function(code);

// Capture console.log output
const originalLog = console.log;
let logs:any = [];
console.log = (...args) => {
logs.push(args.join(' '));
};

// Execute the compiled function
const res = compiledFunction();

// Restore original console.log
console.log = originalLog;
setOutput(res);

setLogs(logs.join('\n'));
} catch (err:any) {
setError(err.toString());
}
};
const onSubmit = async () => {
const onSubmit = async () => {
const session = await getSession()
const userId = session?.user?.id
let metadata = {
Expand Down Expand Up @@ -88,8 +70,10 @@ export const PythonCode = ({funcType,nodeType,type,subType,node}: any) => {
}
}


return (
<div className='flex flex-col gap-4'>
<GetVariables/>
<CodeMirror
value={code}
onChange={(value) => modifyCode(value)}
Expand All @@ -99,8 +83,8 @@ export const PythonCode = ({funcType,nodeType,type,subType,node}: any) => {
className="border rounded"
/>
<div className='flex w-full justify-center gap-4'>
<Button size="lg" onClick={compileCode}>Compile and Run</Button>
<Button size="lg" variant="default" type="submit" onClick={onSubmit} > Add Action</Button>
<Button size="lg" variant="default" onClick={() => modifyCode('// Write your python code here')}>Clear</Button>
<Button size="lg" variant="default" type="submit" onClick={onSubmit} > Add / Edit Action</Button>
</div>
{output && (
<Alert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Schedule = ({funcType,nodeType,type,subType,node}:any) => {
if (res.success){
toast({title: "Success", description: res?.success, variant: 'default'})
router.refresh()
router.push(`/workflows/editor/${editorId}`)
router.push(`/automations/editor/${editorId}`)
}
else if (res.error){
toast({title: "Error", description: res?.error, variant: 'destructive'})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const WebhookTrigger = ({funcType,nodeType,type,subType,node}:any) => {
if (res.success){
toast({title: "Success", description: res?.success, variant: 'default'})
router.refresh()
router.push(`/workflows/editor/${editorId}`)
router.push(`/automations/editor/${editorId}`)
}
else if (res.error){
toast({title: "Error", description: res?.error, variant: 'destructive'})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import Image from 'next/image'
import React from 'react'
import React, { useEffect, useState } from 'react'
import { NotionRenderer } from 'react-notion-x'
import { getNotionPage } from '../../../actions/notion/common';

const Overview = () => {
const [recordMap, setRecordMap] = useState<any>();
// useEffect(() =>{
// const fetchPage = async () => {
// const pageId = 'Project-Management-System-1001d3faa0a0801a9c02fa551c57b0c0';
// const recordMap = await getNotionPage(pageId);
// setRecordMap(recordMap);
// }
// fetchPage();
// })
return (
<div className='h-screen flex flex-col items-center my-10 '>
<h1 className='text-4xl font-medium my-4 text-center'>Still In Construction</h1>
<Image src="/construction.gif" alt="Overview" width={500} height={500} />
{/* <h1 className='text-4xl font-medium my-4 text-center'>Still In Construction</h1>
<Image src="/construction.gif" alt="Overview" width={500} height={500} /> */}
{/* <NotionRenderer recordMap={recordMap} fullPage={true} darkMode={false} /> */}
<iframe src="https://v2-embednotion.com/1001d3faa0a0801a9c02fa551c57b0c0"
className='w-[90%] h-[80%] rounded-lg'>
</iframe>
</div>
)
}
Expand Down
7 changes: 7 additions & 0 deletions apps/dashboard-app/app/actions/notion/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ export const getDefaultDbFromContext = (name: string, context: any) => {
case 'Punishments': return context.notionNode?.punishmentsDb
default: return null
}
}
import {NotionAPI} from 'notion-client'

export const getNotionPage = async (pageId: string) => {
const notion = new NotionAPI()
const recordMap = await notion.getPage(pageId)
return recordMap
}
8 changes: 8 additions & 0 deletions apps/dashboard-app/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { SessionProviders } from "../providers/session-provider";
import { ConnectionsProvider } from "../providers/connections-provider";
import useConnection from "../hooks/useConnection";
import { Toaster } from "../components/Toaster";
// core styles shared by all of react-notion-x (required)
import 'react-notion-x/src/styles.css'

// used for code syntax highlighting (optional)
import 'prismjs/themes/prism-tomorrow.css'

// used for rendering equations (optional)
import 'katex/dist/katex.min.css'


const font = Roboto_Mono({
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard-app/lib/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const sidebarStartItems = [
},
{
title: "Systems",
icon: BrainIcon,
image: "/systems.png",
show: true,
subItems: [
{
Expand Down
Loading

0 comments on commit 1750f76

Please sign in to comment.