aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/UndoStack.tsx
blob: f07e38af10478827b3fdedbdcd152ce1c7681a2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Tooltip } from '@mui/material';
import { Popup, Type } from 'browndash-components';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { StrCast } from '../../fields/Types';
import { SettingsManager } from '../util/SettingsManager';
import { UndoManager } from '../util/UndoManager';
import './UndoStack.scss';

interface UndoStackProps {
    width?: number;
    height?: number;
    inline?: boolean;
}
@observer
export class UndoStack extends React.Component<UndoStackProps> {
    @observable static HideInline: boolean;
    @observable static Expand: boolean;
    render() {
        const background = UndoManager.batchCounter.get() ? 'yellow' : SettingsManager.userVariantColor;
        const color = UndoManager.batchCounter.get() ? 'black' : SettingsManager.userColor;
        return this.props.inline && UndoStack.HideInline ? null : (
            <Tooltip title={'undo stack (if it stays yellow, undo is broken - you should reload Dash)'}>
                <div>
                    <div className="undoStack-outerContainer">
                        <Popup
                            text="stack"
                            color={color}
                            background={background}
                            placement={`top-start`}
                            type={Type.TERT}
                            popup={
                                <div
                                    className="undoStack-commandsContainer"
                                    ref={r => r?.scroll({ behavior: 'auto', top: r?.scrollHeight + 20 })}
                                    style={{
                                        background,
                                        color,
                                    }}>
                                    {Array.from(UndoManager.undoStackNames).map((name, i) => (
                                        <div className="undoStack-resultContainer" key={i} 
                                             onClick={e => {
                                                const size = UndoManager.undoStackNames.length;
                                                for (let n = 0; n < size-i; n++ ) UndoManager.Undo();  } } 
                                            >
                                            <div className="undoStack-commandString">{StrCast(name).replace(/[^\.]*\./, '')}</div>
                                        </div>
                                    ))}
                                    {Array.from(UndoManager.redoStackNames)
                                        .reverse()
                                        .map((name, i) => (
                                            <div className="undoStack-resultContainer" key={i} onClick={e =>
                                                { for (let n = 0; n <= i; n++ ) UndoManager.Redo() }}>
                                                <div className="undoStack-commandString" style={{ fontWeight: 'bold', background: SettingsManager.userBackgroundColor, color: SettingsManager.userColor }}>
                                                    {StrCast(name).replace(/[^\.]*\./, '')}
                                                </div>
                                            </div>
                                        ))}
                                </div>
                            }
                        />
                    </div>
                </div>
            </Tooltip>
        );
    }
}