Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
3 changes: 1 addition & 2 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
main: {
Expand Down Expand Up @@ -31,7 +30,7 @@ export default defineConfig({
'@renderer': resolve('src/renderer/src')
}
},
plugins: [react()],
plugins: [],
build: {
rollupOptions: {
output: {
Expand Down
3 changes: 2 additions & 1 deletion src/main/controllers/componentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export const parseAllComponents = (event, args, res) => {
component.children = arrayOfChildFilePaths;
})

console.log('components', components)
// console.log('components', components)
res.locals.components = components


Expand All @@ -299,6 +299,7 @@ export const getCode = async (event, args, res) => {
const decodedId = decodeURIComponent(id);

const fileCode = fs.readFileSync(decodedId, 'utf-8');

res.locals.componentCode = fileCode;
} catch(err) {
console.error(err);
Expand Down
1 change: 1 addition & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ ipcMain.handle('code', async (e, args) => {
let res = { locals: {componentCode: ''} };

await getCode(e, args, res)

return { status: 200, data: res.locals.componentCode }
} catch (err) {
console.error(err)
Expand Down
23 changes: 22 additions & 1 deletion src/preload/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import { ElectronAPI } from '@electron-toolkit/preload'
import { SendReturnObject, SendData } from '../renderer/src/interfaces/stateInterfaces';

declare global {
interface Window {
electron: ElectronAPI
api: unknown
api: {
openDialog: (action: string, config: DialogConfig) => Promise<OpenDialogResult>;
send: (route: string, data: SendData) => Promise<SendReturnObject>;
};
openExplorerModal: ExplorerModal;
}

}

interface OpenDialogResult {
filePaths: string[];
}

interface DialogConfig {
title: string;
buttonLabel: string;
properties: string[];
}

interface ExplorerModal {
close: () => void;
showModal: () => void;
}
5 changes: 4 additions & 1 deletion src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { contextBridge, ipcRenderer } from 'electron'
import { electronAPI } from '@electron-toolkit/preload'
import { SendReturnObject, SendData } from '../renderer/src/interfaces/stateInterfaces';

// type SendData = { id: string; filePath?: never } | { id: never; filePath: string; }

// Custom APIs for renderer
const api = {
openDialog: (method, config) => ipcRenderer.invoke("dialog", method, config),
send: (route, data) => {
send: (route: string, data: SendData): void | Promise<string | SendReturnObject> => {
let validRoutes = ['components', 'server', 'code'];
if (validRoutes.includes(route)) return ipcRenderer.invoke(route, data);
},
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import Header from './components/Header';
import Tree from './components/Tree';
import ProjectPathModal from './components/ProjectPathModal';
import Details from './components/Details';

import { RootState } from './interfaces/stateInterfaces'

function App(): JSX.Element {
const componentName = useSelector((state: any) => state.project.componentName)
const componentName = useSelector((state: RootState) => state.project.componentName)

return (
<div className="flex flex-col h-screen w-full">
Expand Down
7 changes: 3 additions & 4 deletions src/renderer/src/components/ComponentCode.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import {useEffect} from 'react';
import Prism from 'prismjs';
import '../assets/prism.css';
import { useSelector } from 'react-redux'

import { useSelector } from 'react-redux';
import { RootState } from '../interfaces/stateInterfaces';

const ComponentCode = () => {
const activeComponentCode = useSelector((state: any) => state.detail.activeComponentCode)
const activeComponentCode = useSelector((state: RootState) => state.detail.activeComponentCode)
useEffect(() => {
Prism.highlightAll();
}, [activeComponentCode])



return (
<div className='col-span-12 h-min bg-neutral p-4 rounded-xl'>
<h3 className="font-bold">Component Code</h3>
Expand Down
15 changes: 8 additions & 7 deletions src/renderer/src/components/Details.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { useState, useEffect } from 'react';
import { BrowserRouter as Router, Routes, Route, useLocation, useNavigate } from 'react-router-dom';
import { Routes, Route, useLocation, useNavigate } from 'react-router-dom';
import ModelPreview from './ModelPreview';
import MethodButtonContainer from '@renderer/containers/MethodButtonContainer';
import ComponentCode from './ComponentCode'
import { useSelector } from 'react-redux'
import ComponentCode from './ComponentCode';
import { useSelector } from 'react-redux';
import { RootState } from '../interfaces/stateInterfaces';

function Details(): JSX.Element {
const [height, setHeight] = useState<string | number>(0);
const navigate = useNavigate();
const location = useLocation();
const nodeInfo = useSelector((state: any) => state.project.nodeInfo);
const componentName = useSelector((state: any) => state.project.componentName)
const treeContainerClick = useSelector((state: any) => state.detail.treeContainerClick)
const nodeInfo = useSelector((state: RootState) => state.project.nodeInfo);
const componentName = useSelector((state: RootState) => state.project.componentName)
const treeContainerClick = useSelector((state: RootState) => state.detail.treeContainerClick)

useEffect(() => {
window.innerHeight > 800 ? setHeight('40vh') : setHeight('30vh');
Expand All @@ -23,7 +24,7 @@ function Details(): JSX.Element {
}, [treeContainerClick])


const handler = (mouseDownEvent) => {
const handler = () => {
// const startHeight = height;
// const startPosition = mouseDownEvent.pageY;
function onMouseMove(mouseMoveEvent) {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import dirUpload from '../assets/images/directory-black.svg';
import appLogo from '../assets/images/ReactRelay-logos/ReactRelay-logos_white.png';
import { useDispatch, useSelector } from 'react-redux';
import { setSearchValue, setShowSearch } from '../features/searchSlice';
import { RootState } from '../interfaces/stateInterfaces';


function Header({}): JSX.Element {
const dispatch = useDispatch();
const searchBar = useSelector((state: any) => state.search.searchValue);
const showSearch = useSelector((state: any) => state.search.showSearch);
const searchBar = useSelector((state: RootState) => state.search.searchValue);
const showSearch = useSelector((state: RootState) => state.search.showSearch);

const searchInputRef = useRef<HTMLInputElement | null>(null);

Expand All @@ -32,7 +33,6 @@ function Header({}): JSX.Element {
{showSearch && (
<input
ref={searchInputRef}
id="search-input"
className="input border p-3 input-sm"
type="text"
id='componentSearch'
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/src/components/ModelPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import Prism from 'prismjs';
import '../assets/prism.css';
import { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { RootState } from '../interfaces/stateInterfaces';

function ModelPreview() {
const serverSchemas = useSelector((state: any) => state.project.server);
const activeRoute = useSelector((state: any) => state.detail.activeRoute);
const serverSchemas = useSelector((state: RootState) => state.project.server);
const activeRoute = useSelector((state: RootState) => state.detail.activeRoute);

//use Prism API to highlight the displayed schemas
useEffect(() => {
Expand Down
18 changes: 9 additions & 9 deletions src/renderer/src/components/ProjectPathModal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useSelector, useDispatch } from 'react-redux';
import { addPath, setComponents, setServer } from '../features/projectSlice'

import { RootState } from '../interfaces/stateInterfaces';
function ProjectPathModal() {

const dispatch = useDispatch();
const componentPath = useSelector((state: any) => state.project.componentPath)
const serverPath = useSelector((state: any) => state.project.serverPath)
const componentPath = useSelector((state: RootState) => state.project.componentPath)
const serverPath = useSelector((state: RootState) => state.project.serverPath)

const dialogConfig = {
title: 'Select a project',
Expand All @@ -14,21 +14,21 @@ function ProjectPathModal() {
}
// window.api.openDialog returns the filepath when the filepath is chosen from the dialog
// should i add a case where user doesn't actually select a filepath
const openFileExplorer = async (pathType): Promise<any> => { //FIXME: add to type
const {filePaths} = await (window as any).api.openDialog('showOpenDialog', dialogConfig) //TODO: add to type
const openFileExplorer = async (pathType): Promise<void | null> => { //FIXME: add to type
const {filePaths} = await window.api.openDialog('showOpenDialog', dialogConfig) //TODO: add to type
// if user chooses cancel then don't do anything
if (filePaths[0] === '' || !filePaths[0]) return null;
dispatch(addPath([pathType, filePaths[0]]));
}

const postPath = async (pathType, path): Promise<any> => {
const postPath = async (pathType, path): Promise<void | null> => {
if (path === '' || !path) return null;
console.log('componentPath', pathType, path)
const endpoint = {
component: `components`,
server: `server`
}
const response = await (window as any).api.send(endpoint[pathType], { filePath: path }) // sends to the componentController or serverASTController the filepath
const response = await window.api.send(endpoint[pathType], { filePath: path }) // sends to the componentController or serverASTController the filepath
console.log('response', response)
if (response.status >=200 && response.status < 300) {
console.log('pathtype:', pathType, 'path:', path, 'res:', response.data)
Expand All @@ -41,7 +41,7 @@ function ProjectPathModal() {
console.log('component', componentPath)
postPath('component', componentPath);
postPath('server', serverPath);
(window as any).openExplorerModal.close();
window.openExplorerModal.close();
}

return (
Expand Down Expand Up @@ -79,7 +79,7 @@ function ProjectPathModal() {
<div className='flex justify-between items-end'>
<div className="modal-action">
{/* if there is a button in form, it will close the modal */}
<button className="btn bg-error" onClick={()=>(window as any).openExplorerModal.close()}>Cancel</button>
<button className="btn bg-error" onClick={()=> window.openExplorerModal.close()}>Cancel</button>
</div>
<div>
<button onClick={()=>onContinue()} className='btn bg-primary'>Continue</button>
Expand Down
20 changes: 8 additions & 12 deletions src/renderer/src/components/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import {
} from '../features/projectSlice';
import { setTreeContainerClick,
setActive,
setActiveComponentCode } from '../features/detailSlice'
setActiveComponentCode } from '../features/detailSlice';
import { RootState, Component } from '../interfaces/stateInterfaces';

const nodeTypes = {
CustomNode,
CustomNode2,
Expand Down Expand Up @@ -83,16 +85,10 @@ const getLayoutedElements = (nodes, edges, direction = 'LR') => {

// setting the types for different components

type Component = {
id: string;
data: any;
children: string[];
ajaxRequests: string[];
};

type Node = {
id: string;
data: any;
data: { label: string, active: boolean };
position: { x: number; y: number };
type: string;
};
Expand All @@ -110,8 +106,8 @@ type Edge = {
function Tree({}): JSX.Element {
const [nodes, setNodes, onNodesChange] = useNodesState([]);
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
const reactFlowComponents = useSelector((state: any) => state.project.components);
const active = useSelector((state: any) => state.detail.active);
const reactFlowComponents = useSelector((state: RootState) => state.project.components);
const active = useSelector((state: RootState) => state.detail.active);
const dispatch = useDispatch();
//components that are re-used are given unique id's by adding a number to the end of the AFP. this function converts that id back to the AFP (i.e. as it appears in reactFlowComponents), then return the object associated with this AFP key in reactFlowComponents.
const getComponentFromNodeId = (id: string): Component => {
Expand Down Expand Up @@ -164,7 +160,7 @@ function Tree({}): JSX.Element {
//filter for components that have no parent, then invoke 'gatherChildren' on each of them
// console.log('list of children and their id ---> ', listOfChildIds);
const roots = Object.values(reactFlowComponents).filter(
(obj: any): obj is Component => !listOfChildIds.has(obj.id)
(obj: Component) => !listOfChildIds.has(obj.id)
);
// console.log('ROOTS ----> ', roots);
if (roots.length) roots.forEach((root) => gatherChildren(root)); //iterate thru each root and gather it's children
Expand Down Expand Up @@ -259,7 +255,7 @@ function Tree({}): JSX.Element {
});
dispatch(setActive(element.id));
const encodedId = encodeURIComponent(component.id);
const componentCode = await (window as any).api.send('code', { id: encodedId });
const componentCode = await window.api.send('code', { id: encodedId });
// console.log(componentCode, 'componentCode');
// console.log('data', data)
dispatch(setActiveComponentCode(componentCode.data));
Expand Down
32 changes: 8 additions & 24 deletions src/renderer/src/components/custom-nodes/custom-node.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
// Path: src/renderer/src/components/CustomNodes.jsx
import React, { useMemo, useEffect, useState } from 'react';
import { Handle, Position } from 'reactflow';
import React from 'react';
import { Handle } from 'reactflow';
import 'tailwindcss/tailwind.css';
import { useSelector } from 'react-redux';

interface NodeProps {
data: {
label: string,
active: boolean,
};
sourcePosition: {
x: number,
y: number,
};
targetPosition: number,
}

const handleStyle = {
//why is this decalred but never read
left: 10,
style: 'bg-primary',
};
import { RootState } from '@renderer/interfaces/stateInterfaces';
import { NodeProps, Position } from 'reactflow';

const checkForSearchMatch = (label: string) => {
return useSelector((state: any) => {
return useSelector((state: RootState) => {
const searchValue = state.search.searchValue.toLowerCase();
return label.toLowerCase().includes(searchValue) ? searchValue : null;
}, (a,b) => a === b)
Expand All @@ -32,7 +16,7 @@ const checkForSearchMatch = (label: string) => {
const CustomNode = React.memo<NodeProps>(({ data, sourcePosition, targetPosition }) => {
const { label } = data;
const searchValue = checkForSearchMatch(label.toLowerCase());

console.log('sourcePosition', typeof sourcePosition, 'targetPos', targetPosition)

return (
<div
Expand All @@ -41,7 +25,7 @@ const CustomNode = React.memo<NodeProps>(({ data, sourcePosition, targetPosition
} cursor-pointer min-h-4 max-h-16 p-1 w-fit shadow-md bg-blend-normal rounded-lg border-2 border-slate-500`}
>
{/* Handle are the dotes on the edge of the node where the lines connect */}
<Handle type='target' position={targetPosition} />
<Handle type='target' position={targetPosition || Position.Left} />
<p
className={`custom-node flex flex-column items-center ${
data.active
Expand All @@ -53,7 +37,7 @@ const CustomNode = React.memo<NodeProps>(({ data, sourcePosition, targetPosition
</p>
<Handle
type='source'
position={sourcePosition}
position={sourcePosition || Position.Right}
id='a'
className='source-handle'
/>
Expand Down
Loading