Commit 3dd3ac34 authored by Michael Vrána's avatar Michael Vrána

Fixed undo/redo, added undo/redo buttons

parent 7e79994f
Pipeline #80130 failed with stages
in 4 minutes and 17 seconds
......@@ -49,5 +49,5 @@
"not ie <= 11",
"not op_mini all"
],
"proxy": "http://0.0.0.0:3001"
"proxy": "https://alt.fit.cvut.cz/webui/"
}
......@@ -12,6 +12,7 @@ import Edge from './Edge'
import { algorithmCanvasActions } from '../../../reducers/algorithmCanvas'
import { add } from '../../../interfaces/Position'
import { paramNodeRadius } from './ParamNode'
import AlgorithmNode, { emptyNode } from '../../../interfaces/AlgorithmNode'
interface Props {
/**Id of transition from data */
......@@ -39,8 +40,8 @@ const edgeSelector = (id: string) => (state: ReduxState) => {
return {
data: edge,
isSelected: state.algorithmCanvas.selectedEdge === id,
startNode: nodes.get(startNodeId),
endNode: nodes.get(endNodeId),
startNode: { ...nodes.get(startNodeId, emptyNode) } as AlgorithmNode,
endNode: { ...nodes.get(endNodeId, emptyNode) } as AlgorithmNode,
hasError:
state.algorithmData.present.cycleEdges.contains(id) ||
state.algorithmData.present.incompatibleEdges.contains(edge),
......
import React, { useCallback } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { makeStyles } from '@material-ui/core'
import { makeStyles, Paper } from '@material-ui/core'
import {
Close as CloseIcon,
Undo as UndoIcon,
Redo as RedoIcon
} from '@material-ui/icons'
import { saveAs } from 'file-saver'
import { CanvasToolbar } from '../../Toolbar/CanvasToolbar'
import { ReduxState } from '../../../reducers'
......@@ -13,9 +18,12 @@ import {
} from '../../../interfaces/AlgorithmGraph'
import { algorithmDataActions } from '../../../reducers/algorithmData'
import { useSnackbar } from 'notistack'
import ElementButton from '../../Toolbar/ElementButton'
import { Actions } from '../../../reducers'
const { toggleGrid, setCursorMode, zoom } = algorithmCanvasActions
const { importGraph } = algorithmDataActions
const { undoAlgorithm, redoAlgorithm } = Actions
const useStyles = makeStyles((theme) => ({
root: {
......@@ -114,6 +122,9 @@ export const AlgorithmCanvasToolbar = () => {
[dispatch, enqueueSnackbar]
)
const handleUndo = useCallback(() => dispatch(undoAlgorithm()), [dispatch])
const handleRedo = useCallback(() => dispatch(redoAlgorithm()), [dispatch])
return (
<div className={classes.root}>
<CanvasToolbar
......@@ -125,6 +136,18 @@ export const AlgorithmCanvasToolbar = () => {
onZoomOut={handleZoomOut}
onGrid={handleGridToggle}
/>
<Paper>
<ElementButton
Icon={UndoIcon}
label="Undo"
onAction={handleUndo}
></ElementButton>
<ElementButton
Icon={RedoIcon}
label="Redo"
onAction={handleRedo}
></ElementButton>
</Paper>
<AlgorithmImportExportToolbar
onExport={handleExport}
onImport={handleImport}
......
......@@ -54,6 +54,18 @@ export default interface AlgorithmNode {
value?: AlgorithmNodeValue
}
export const emptyNode = {
id: '',
nodeType: 'algorithm',
name: '',
position: {x: 0, y: 0},
height: 0,
width: 0,
params: [],
templateParams: [],
resultType: ''
}
export const isAlgorithmNode = (node: any): node is AlgorithmNode => {
if (!isString(node.id)) return false
if (!algorithmNodeTypes.includes(node.nodeType)) return false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment