diff --git a/Desktop/src/main/main.ts b/Desktop/src/main/main.ts index 0671eba24..216ce53b6 100644 --- a/Desktop/src/main/main.ts +++ b/Desktop/src/main/main.ts @@ -38,16 +38,16 @@ let dataFromParser = {}; console.log('---------------------------'); console.log(path.resolve(__dirname, 'test.yaml')); // eslint-disable-next-line @typescript-eslint/no-unused-vars -ipcMain.on('editor/visualizeRequest', (event, scenario, format) => { +ipcMain.handle('editor/visualizeRequest', (event, scenario, format) => { let scenarioParsed = {}; if (format === 'json') scenarioParsed = JSON.parse(scenario); else scenarioParsed = yamlParser.load(scenario); console.log(scenarioParsed); - Object.assign(tempScenarioSave, { ...scenario }); + Object.assign(tempScenarioSave, { ...scenarioParsed }); parserAndGenerator( - path.resolve(__dirname, 'test.yaml'), - path.resolve(__dirname, 'temp.json') + path.resolve(__dirname, 'save.yaml'), + path.resolve(__dirname, 'save.json') ) .then((res: any) => { dataFromParser = res; @@ -59,17 +59,12 @@ ipcMain.on('editor/visualizeRequest', (event, scenario, format) => { }); }); -ipcMain.on('editor/action', (_event, actionName) => { +ipcMain.handle('editor/action', async (_event, actionName) => { const managerInstance = requestManager(); - managerInstance - .createReqHandler(dataFromParser) - .then(() => { - managerInstance.startScenario(actionName); - }) - .catch((err: any) => { - console.log(err); - }); - console.log('Sending to manager'); + + await managerInstance.createReqHandler(); + + await managerInstance.startScenario(actionName); }); if (process.env.NODE_ENV === 'production') { diff --git a/Desktop/src/main/menu.js b/Desktop/src/main/menu.js new file mode 100644 index 000000000..1248be1c0 --- /dev/null +++ b/Desktop/src/main/menu.js @@ -0,0 +1,59 @@ +const { app, Menu } = require('electron'); + +const isMac = process.platform === 'darwin'; + +const template = [ + { + label: 'File', + submenu: [isMac ? { role: 'close' } : { role: 'quit' }], + }, + { + label: 'Edit', + submenu: [ + { role: 'undo' }, + { role: 'redo' }, + { type: 'separator' }, + { role: 'cut' }, + { role: 'copy' }, + { role: 'paste' }, + ], + }, + { + label: 'View', + submenu: [ + { role: 'reload' }, + { role: 'forcereload' }, + { role: 'toggledevtools' }, + { type: 'separator' }, + { role: 'resetzoom' }, + { role: 'zoomin' }, + { role: 'zoomout' }, + { type: 'separator' }, + { role: 'togglefullscreen' }, + ], + }, + { + label: 'Window', + submenu: [{ role: 'minimize' }, { role: 'zoom' }], + }, + { + role: 'help', + submenu: [ + { + label: 'Learn More', + click: async () => { + // eslint-disable-next-line global-require + const { shell } = require('electron'); + await shell.openExternal('https://electronjs.org'); + }, + }, + ], + }, +]; + +const MenuBuilder = Menu.buildFromTemplate(template); +Menu.setApplicationMenu(MenuBuilder); + +module.exports = { + MenuBuilder, +}; diff --git a/Desktop/src/main/renderer.js b/Desktop/src/main/renderer.js new file mode 100644 index 000000000..2a6f6ff3c --- /dev/null +++ b/Desktop/src/main/renderer.js @@ -0,0 +1,63 @@ +const { remote, ipcRenderer } = require('electron'); + +function getCurrentWindow() { + return remote.getCurrentWindow(); +} + +function openMenu(x, y) { + ipcRenderer.send(`display-app-menu`, { x, y }); +} + +function minimizeWindow(browserWindow = getCurrentWindow()) { + if (browserWindow.minimizable) { + // browserWindow.isMinimizable() for old electron versions + browserWindow.minimize(); + } +} + +function maxUnmaxWindow(browserWindow = getCurrentWindow()) { + if (browserWindow.isMaximized()) { + browserWindow.unmaximize(); + } else { + browserWindow.maximize(); + } +} + +function closeWindow(browserWindow = getCurrentWindow()) { + browserWindow.close(); +} + +function isWindowMaximized(browserWindow = getCurrentWindow()) { + return browserWindow.isMaximized(); +} + +window.addEventListener('DOMContentLoaded', () => { + const menuButton = document.getElementById('menu-btn'); + const minimizeButton = document.getElementById('minimize-btn'); + const maxUnmaxButton = document.getElementById('max-unmax-btn'); + const closeButton = document.getElementById('close-btn'); + + menuButton.addEventListener('click', (e) => { + openMenu(e.x, e.y); + }); + + minimizeButton.addEventListener('click', (e) => { + minimizeWindow(); + }); + + maxUnmaxButton.addEventListener('click', (e) => { + const icon = maxUnmaxButton.querySelector('i.far'); + + maxUnmaxWindow(); + if (isWindowMaximized()) { + icon.classList.remove('fa-square'); + icon.classList.add('fa-clone'); + } else { + icon.classList.add('fa-square'); + icon.classList.remove('fa-clone'); + } + }); + closeButton.addEventListener('click', (e) => { + closeWindow(); + }); +}); diff --git a/Desktop/src/main/setup.ts b/Desktop/src/main/setup.ts new file mode 100644 index 000000000..aad83f39f --- /dev/null +++ b/Desktop/src/main/setup.ts @@ -0,0 +1,71 @@ +import { ipcMain, BrowserWindow, WebContents } from 'electron'; + +const setupEventListener = ( + browserWindow: BrowserWindow, + sender: WebContents +) => { + browserWindow.addListener('maximize', () => { + sender.send( + 'electron-react-titlebar/maximunize/change', + true, + browserWindow.id + ); + }); + browserWindow.addListener('unmaximize', () => { + sender.send( + 'electron-react-titlebar/maximunize/change', + false, + browserWindow.id + ); + }); +}; + +// eslint-disable-next-line import/prefer-default-export +export const initialize = (): void => { + ipcMain.handle( + 'electron-react-titlebar/initialize', + (event, browserWindowId): number | undefined => { + const browserWindow = browserWindowId + ? BrowserWindow.fromId(browserWindowId) + : BrowserWindow.fromWebContents(event.sender); + if (browserWindow) { + setupEventListener(browserWindow, event.sender); + return browserWindow.id; + } + return undefined; + } + ); + + ipcMain.on( + 'electron-react-titlebar/maximumize/set', + (event, browserWindowId) => { + const browserWindow = browserWindowId + ? BrowserWindow.fromId(browserWindowId) + : BrowserWindow.fromWebContents(event.sender); + if (browserWindow?.isMaximizable()) { + if (browserWindow.isMaximized()) { + browserWindow.unmaximize(); + } else { + browserWindow.maximize(); + } + } + } + ); + + ipcMain.on( + 'electron-react-titlebar/minimumize/set', + (event, browserWindowId) => { + const browserWindow = browserWindowId + ? BrowserWindow.fromId(browserWindowId) + : BrowserWindow.fromWebContents(event.sender); + browserWindow?.minimize(); + } + ); + + ipcMain.on('electron-react-titlebar/close', (event, browserWindowId) => { + const browserWindow = browserWindowId + ? BrowserWindow.fromId(browserWindowId) + : BrowserWindow.fromWebContents(event.sender); + browserWindow?.close(); + }); +}; diff --git a/Desktop/src/main/temp.json b/Desktop/src/main/temp.json new file mode 100644 index 000000000..1f41906f3 --- /dev/null +++ b/Desktop/src/main/temp.json @@ -0,0 +1,52 @@ +{ + "version": "0.0.1", + "user-logs-on": { + "game/server/{serverId}/events/player/{playerId}/connect": { + "playerId": { + "min": 0, + "max": 2000 + }, + "serverId": { + "min": 0, + "max": 4 + } + } + }, + "user-gameLoop": { + "loop": { + "interval": 600, + "cycles": 5, + "game/server/{serverId}/events/player/{playerId}/hit": { + "serverId": "1", + "playerId": { + "regex": "^[\\w\\d]{1,22}$" + }, + "payload": { + "crit": 125, + "apDamage": 30 + } + }, + "game/server/{serverId}/events/player/{playerId}/item/{itemId}/pickup": { + "serverId": "1", + "playerId": { + "regex": "^[\\w\\d]{1,22}$" + }, + "itemId": { + "min": 0, + "max": 4 + } + }, + "game/server/{serverId}/events/player/{playerId}/chat": { + "serverId": "1", + "playerId": { + "regex": "^[\\w\\d]{1,22}$" + }, + "payload": "well played m8" + } + } + }, + "scenario-SimpleGame": [ + "user-logs-on", + "user-gameLoop" + ] +} diff --git a/Desktop/src/main/tempScenarioSave.js b/Desktop/src/main/tempScenarioSave.js new file mode 100644 index 000000000..52cf5fab9 --- /dev/null +++ b/Desktop/src/main/tempScenarioSave.js @@ -0,0 +1,94 @@ +/* eslint-disable */ +const fs = require('fs'); +const path = require('path'); + +const cache = {}; + +function autoSave(filename, onSave) { + const filepath = path.resolve(filename); + + if (filepath in cache) { + return cache[filepath]; + } + + const object = read(filepath); + let changed = false; + let writing = false; + + return (cache[filepath] = wrap(object, change)); + + function change() { + if (!changed) { + changed = true; + + if (!writing) { + setImmediate(save); + } + } + } + + function save() { + changed = false; + writing = true; + + const json = JSON.stringify(object, null, 2); + + if (typeof onSave === 'function') { + fs.writeFile(filepath, json, (err) => { + onSave(err); + + if (changed) { + setImmediate(save); + } else { + writing = false; + } + }); + } else { + fs.writeFileSync(filepath, json); + } + } +} + +function wrap(o, change) { + const innerCache = {}; + + return new Proxy(o, { + set(o, prop, v) { + if (typeof v === 'object') { + if (innerCache[prop] !== v) { + change(); + } + } else if (v !== o[prop]) { + change(); + } + + o[prop] = v; + + if (innerCache.hasOwnProperty(prop)) { + delete innerCache[prop]; + } + + return true; + }, + get(o, prop) { + if (o.hasOwnProperty(prop) && typeof o[prop] === 'object') { + if (prop in innerCache) { + return innerCache[prop]; + } + return (innerCache[prop] = wrap(o[prop], change)); + } + return o[prop]; + }, + }); +} + +function read(p) { + try { + const raw = fs.readFileSync(p); + return JSON.parse(raw); + } catch (err) { + return {}; + } +} + +module.exports = autoSave; diff --git a/Desktop/src/renderer/containers/Editor/index.tsx b/Desktop/src/renderer/containers/Editor/index.tsx index 745bb6573..3e80974b9 100644 --- a/Desktop/src/renderer/containers/Editor/index.tsx +++ b/Desktop/src/renderer/containers/Editor/index.tsx @@ -1,38 +1,43 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-nocheck -import React, { createContext, useEffect, useReducer } from 'react'; -import { EditorPropsType, DefaultEditorStateType } from './types'; +import React, { useReducer } from 'react'; +import { EditorPropsType } from './types'; import { editorReducer } from './reducers'; import { defaultEditorState } from './constants'; import { TitleBar } from '../TitleBar'; import template from '../TitleBar/menuTemplate'; import ScenarioWorkbench from '../Workbench'; import icon from '../../../../assets/icon.svg'; +import { EditorContext } from '../Workbench/reducers'; -const EditorContext = createContext<{ - state: DefaultEditorStateType; - dispatch: React.Dispatch; -}>({ - state: defaultEditorState, - dispatch: () => null, -}); function Editor(props: EditorPropsType): JSX.Element { - const [state, dispatch] = useReducer(editorReducer, defaultEditorState); + const [EditorState, dispatch] = useReducer(editorReducer, defaultEditorState); return ( - - -
- -
+ + + {({ state, dispatch }) => ( + <> + +
+ +
+ + )} +
); } diff --git a/Desktop/src/renderer/containers/TitleBar/menu.tsx b/Desktop/src/renderer/containers/TitleBar/menu.tsx index f92c5ea5c..10b0192e8 100644 --- a/Desktop/src/renderer/containers/TitleBar/menu.tsx +++ b/Desktop/src/renderer/containers/TitleBar/menu.tsx @@ -1,6 +1,3 @@ -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-nocheck - import React, { useCallback, useEffect, useRef, useState } from 'react'; import classnames from 'classnames'; import { reduxSet } from './utils'; @@ -81,7 +78,7 @@ export const MenuBar: React.FC = ({ menu: propMenu }) => { } else { let newMenu = [...menu]; const menuLength = menu[mainIndex].submenu.length; - for (let i = 0; i < menuLength; i++) { + for (let i = 0; i < menuLength; i += 1) { if (menu[mainIndex].submenu[i].type === 'radio') { newMenu = reduxSet( newMenu, @@ -105,9 +102,13 @@ export const MenuBar: React.FC = ({ menu: propMenu }) => { return ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events
onButtonMouseOver(i)} onClick={() => onButtonClick(i)} + onFocus={() => { + onButtonClick(); + }} onTouchStart={() => onTouchStart(i)} onMouseMove={() => onMouseMove(i)} ref={(ref) => ref && setRefs(ref, i)} diff --git a/Desktop/src/renderer/containers/Workbench/components/ScenarioEditor.tsx b/Desktop/src/renderer/containers/Workbench/components/ScenarioEditor.tsx deleted file mode 100644 index ef5269410..000000000 --- a/Desktop/src/renderer/containers/Workbench/components/ScenarioEditor.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import React, { useCallback, useContext, useEffect, useState } from 'react'; -import AceEditor from 'react-ace'; - -import 'ace-builds/src-noconflict/mode-java'; -import 'ace-builds/src-noconflict/theme-github'; -import { ipcRenderer } from 'electron'; -import { WorkBenchContext } from '..'; -import { DefaultWorkBenchStateType } from '../types'; -import { ACTIONS_IDS } from '../constants'; - -// Example style, you can use another -function ScenarioEditor(): JSX.Element { - const WBContext: { - state: DefaultWorkBenchStateType; - dispatch: (arg0: Record) => null; - } = useContext(WorkBenchContext); - - const [EditorContent, setContent] = useState('myScenario:'); - - const getContent = useCallback(() => { - return EditorContent; - }, [EditorContent]); - - const setUpForVisualization = useCallback( - (value) => { - WBContext.state.upForVisualization = value; - }, - [WBContext.state] - ); - - useEffect(() => { - function getCurrentScenario() { - return getContent(); - } - function updateVisualizationObj(_event: any, obj: any) { - WBContext.dispatch({ type: ACTIONS_IDS.setScenarioFile, payload: obj }); - } - console.log('effectara'); - if (WBContext.state.upForVisualization === true) { - ipcRenderer.on('editor/visualizationReady', updateVisualizationObj); - ipcRenderer.send('editor/visualizeRequest', getCurrentScenario()); - setUpForVisualization(false); - } - - // TODO add case for save scenario action - - return function onUnmount() { - ipcRenderer.removeListener( - 'editor/visualizationReady', - updateVisualizationObj - ); - }; - }, [ - setUpForVisualization, - getContent, - WBContext.state.upForVisualization, - WBContext, - ]); - return ( -
- - {() => ( - setContent(code)} - name="UNIQUE_ID_OF_DIV" - editorProps={{ $blockScrolling: true }} - /> - )} - -
- ); -} - -export default ScenarioEditor; diff --git a/Desktop/src/renderer/containers/Workbench/components/ScenarioVisualizer.tsx b/Desktop/src/renderer/containers/Workbench/components/ScenarioVisualizer.tsx deleted file mode 100644 index 035b22d8f..000000000 --- a/Desktop/src/renderer/containers/Workbench/components/ScenarioVisualizer.tsx +++ /dev/null @@ -1,126 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-nocheck -import React, { useContext, useEffect, useState } from 'react'; -import { ipcRenderer } from 'electron'; -// eslint-disable-next-line import/no-cycle,import/no-duplicates -// eslint-disable-next-line import/no-cycle -import { WorkBenchContext } from '..'; -import { ACTIONS_IDS } from '../constants'; - -function ScenarioVisualizer(props: any): JSX.Element { - const WBContext = useContext(WorkBenchContext); - - const [actionsRegister, updateRegister] = useState({ - pendingAction: null, - doneActions: {}, - }); - - // eslint-disable-next-line react/prop-types - function GenerateScenariosView({ scenarioObject }) { - console.log('GenerateScenariosView'); - console.log(scenarioObject); - - // eslint-disable-next-line react/prop-types - if (!scenarioObject.scenarios) { - return
; - } - return ( - <> -

Scenarios

- {/* eslint-disable-next-line react/prop-types */} - {Object.keys(scenarioObject.scenarios).map((scenarioName) => { - const name = scenarioName.match(new RegExp(/[^-]*$/, 'gm')); //NOSONAR - return ( -
-
- {name[0]} -
- {/* eslint-disable-next-line react/button-has-type */} - -
-
-
- ); - })} - - ); - } - - // eslint-disable-next-line react/prop-types - function GenerateOperationsView({ operationsObj }) { - console.log(operationsObj); - return

Test

; - } - - const [currentScenario, setScenario] = useState({}); - - // eslint-disable-next-line @typescript-eslint/no-redeclare - function setLocalState(scenario) { - console.log(scenario); - setScenario(scenario); - } - - useEffect(() => { - console.log('visualizer'); - - if (actionsRegister.pendingAction) { - ipcRenderer.send('editor/action', actionsRegister.pendingAction); - } - if (WBContext.state.scenarioUpdated === true) { - console.log('GENERATING'); - setLocalState(WBContext.state.currentValidScenario); - WBContext.dispatch({ - type: ACTIONS_IDS.visualizationGenerating, - }); - - // WBContext.dispatch({ type: ACTIONS_IDS.visualizationGenerating }); - } - - // TODO add case for save scenario action - - return function onUnmount() { - // WBContext.dispatch({ type: ACTIONS_IDS.visualizationGenerating }); - }; - }, [WBContext, WBContext.state, actionsRegister]); - - return ( -
- -
- ); -} - -export default ScenarioVisualizer; diff --git a/Desktop/src/renderer/containers/Workbench/components/SideBar.tsx b/Desktop/src/renderer/containers/Workbench/components/SideBar.tsx index 417a8eadd..36390596e 100644 --- a/Desktop/src/renderer/containers/Workbench/components/SideBar.tsx +++ b/Desktop/src/renderer/containers/Workbench/components/SideBar.tsx @@ -1,19 +1,14 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-nocheck -import React, { useContext, useEffect, useState } from 'react'; +import React, { useState } from 'react'; import { VscRunAll } from 'react-icons/vsc'; import { IconContext } from 'react-icons'; -import { ACTIONS_IDS } from '../constants'; -// eslint-disable-next-line import/no-cycle -import { WorkBenchContext } from '..'; -function SideBar(): JSX.Element { - const WBContext = useContext(WorkBenchContext); - - function VisualizeScenario() { - console.log('clicked'); - WBContext.dispatch({ type: ACTIONS_IDS.visualizeScenarioFile }); +function SideBar({ EditorState, dispatch }): JSX.Element { + async function VisualizeScenario() { + console.log(dispatch); } + const [RunIconStyle, SetRunStyle] = useState({ color: 'white', }); diff --git a/Desktop/src/renderer/containers/Workbench/components/test.d.ts b/Desktop/src/renderer/containers/Workbench/components/test.d.ts deleted file mode 100644 index 1847d9c63..000000000 --- a/Desktop/src/renderer/containers/Workbench/components/test.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type ArrayMetadata = { - length: number; - firstObject: any | undefined; -}; -export function getArrayMetadata(arr: any[]): ArrayMetadata; diff --git a/Desktop/src/renderer/containers/Workbench/components/test.js b/Desktop/src/renderer/containers/Workbench/components/test.js deleted file mode 100644 index a40336845..000000000 --- a/Desktop/src/renderer/containers/Workbench/components/test.js +++ /dev/null @@ -1,3 +0,0 @@ -const { getArrayMetadata } = require('./test/index'); - -getArrayMetadata(); diff --git a/Desktop/src/renderer/containers/Workbench/constants/index.ts b/Desktop/src/renderer/containers/Workbench/constants/index.ts index 4d8d81e22..54dde7749 100644 --- a/Desktop/src/renderer/containers/Workbench/constants/index.ts +++ b/Desktop/src/renderer/containers/Workbench/constants/index.ts @@ -1,20 +1,56 @@ import * as types from '../types'; export const ACTIONS_IDS = { - checkScenarioFile: 0, + checkScenarioSyntax: 0, visualizeScenarioFile: 1, - executeOperartion: 2, + executeOperation: 2, executeScenario: 3, - setScenarioFile: 4, - visualizationGenerating: 5, - visualizationGenerated: 6, - simulateAction: 7, - simpleInvocation: 8, + cancelExecution: 4, + setCurrentScenarioFile: 5, + scenarioUpdated: 6, }; export const defaultEditorState: types.DefaultWorkBenchStateType = { - currentValidScenario: {}, - upForVisualization: false, + currentScenario: {}, scenarioUpdated: false, - pendingActions: [], + pendingRequestExecutions: {}, + applicationActionsHistory: [], }; + +export const defaultScenario = `version: "0.0.1" +user-logs-on: + game/server/{serverId}/events/player/{playerId}/connect: + playerId : + min: 0 + max: 2000 + serverId: + min: 0 + max: 4 +user-gameLoop: + loop: + interval: + 600 + cycles: + 5 + game/server/{serverId}/events/player/{playerId}/hit: + serverId: '1' + playerId: + regex: '^[\\w\\d]{1,22}$' + + game/server/{serverId}/events/player/{playerId}/item/{itemId}/pickup: + serverId: '1' + playerId: + regex: '^[\\w\\d]{1,22}$' + itemId: + min: 0 + max: 4 + + game/server/{serverId}/events/player/{playerId}/chat: + serverId: '1' + playerId: + regex: '^[\\w\\d]{1,22}$' + payload: 'well played m8' + +scenario-SimpleGame: + - user-logs-on + - user-gameLoop`; diff --git a/Desktop/src/renderer/containers/Workbench/index.tsx b/Desktop/src/renderer/containers/Workbench/index.tsx index 60d1b1d09..86492d9d4 100644 --- a/Desktop/src/renderer/containers/Workbench/index.tsx +++ b/Desktop/src/renderer/containers/Workbench/index.tsx @@ -1,29 +1,13 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-nocheck -import React, { createContext, useMemo, useReducer } from 'react'; -import { WorkBenchReducer } from './reducers'; -import ScenarioEditor from './components/ScenarioEditor'; -import ScenarioVisualizer from './components/ScenarioVisualizer'; -import { defaultEditorState } from './constants'; +import React from 'react'; import SideBar from './components/SideBar'; -export const WorkBenchContext: any = createContext<>({ - state: defaultEditorState, - dispatch: () => null, -}); -function ScenarioWorkbench(): JSX.Element { - const [state, dispatch] = useReducer(WorkBenchReducer, defaultEditorState); - - const ScenarioEditorMemo = useMemo(() => { - console.log('memo'); - return ScenarioEditor; - }, []); +function ScenarioWorkbench({ EditorState, dispatch }): JSX.Element { return ( - - - - - + <> + + ); } diff --git a/Desktop/src/renderer/containers/Workbench/reducers/index.ts b/Desktop/src/renderer/containers/Workbench/reducers/index.tsx similarity index 57% rename from Desktop/src/renderer/containers/Workbench/reducers/index.ts rename to Desktop/src/renderer/containers/Workbench/reducers/index.tsx index 8822d7b86..bdf7fd444 100644 --- a/Desktop/src/renderer/containers/Workbench/reducers/index.ts +++ b/Desktop/src/renderer/containers/Workbench/reducers/index.tsx @@ -1,8 +1,9 @@ -import { ACTIONS_IDS } from '../constants'; +import React, { useReducer } from 'react'; +import { ACTIONS_IDS, defaultEditorState } from '../constants'; // eslint-disable-next-line import/prefer-default-export -export const WorkBenchReducer = (state: any, action: any) => { +const EditorReducer = (state: any, action: any) => { switch (action.type) { - case ACTIONS_IDS.simulateAction: + case ACTIONS_IDS.visualizeScenarioFile: console.log('test'); console.log(state.pendingActions); return { @@ -12,11 +13,8 @@ export const WorkBenchReducer = (state: any, action: any) => { { [action.payload.actionName]: action.payload.type }, ], }; - case ACTIONS_IDS.visualizeScenarioFile: - console.log('visualizeScenarioFile'); - return { ...state, upForVisualization: true }; - case ACTIONS_IDS.setScenarioFile: + case ACTIONS_IDS.setCurrentScenarioFile: console.log('setScenarioFile'); console.log(action); return { @@ -30,7 +28,7 @@ export const WorkBenchReducer = (state: any, action: any) => { scenarioFilepath: action.payload.operation, }; - case ACTIONS_IDS.visualizationGenerating: + case ACTIONS_IDS.visualizationChangeStatus: return { ...state, scenarioUpdated: false, @@ -39,3 +37,16 @@ export const WorkBenchReducer = (state: any, action: any) => { return state; } }; + +const EditorContext = React.createContext(defaultEditorState); + +function EditorStateProvider({ children }) { + const [state, dispatch] = useReducer(EditorReducer, defaultEditorState); + return ( + + {children} + + ); +} + +export { EditorStateProvider, EditorContext }; diff --git a/Desktop/src/renderer/containers/Workbench/types/index.ts b/Desktop/src/renderer/containers/Workbench/types/index.ts index 31fbc586e..3e1b97efb 100644 --- a/Desktop/src/renderer/containers/Workbench/types/index.ts +++ b/Desktop/src/renderer/containers/Workbench/types/index.ts @@ -3,11 +3,27 @@ import React from 'react'; // eslint-disable-next-line @typescript-eslint/no-empty-interface interface ScenarioObject {} +interface RequestCollection { + [id: string]: + | 'resolved' + | 'pendingInfo' + | { status: 'error'; description: string } + | { + status: 'inProgress'; + currentRequestIndex: number; + finalRequestIndex: number; + }; +} + +interface ApplicationAction { + type: 'newScenario' | 'undo' | 'redo'; +} + export type DefaultWorkBenchStateType = { - currentValidScenario: ScenarioObject; - upForVisualization: boolean; + currentScenario: ScenarioObject; scenarioUpdated: boolean; - pendingActions: Array; + pendingRequestExecutions: RequestCollection; + applicationActionsHistory: Array; }; export type WorkBenchContextType = React.Context<{