Skip to content

Commit 99150c0

Browse files
Merge remote-tracking branch 'remotes/origin/#524' into allfunctionality
2 parents 5b48a2e + ed95f12 commit 99150c0

File tree

12 files changed

+493
-20
lines changed

12 files changed

+493
-20
lines changed

js/components/preview/viewerControls/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ButtonGroup, Grid, makeStyles, Tooltip } from '@material-ui/core';
1010
import { SettingControls } from './settingsControls';
1111
import DisplayControls from './displayControls/';
1212
import { MouseControls } from './mouseControls';
13-
import { ActionCreators as UndoActionCreators } from 'redux-undo';
13+
import { ActionCreators as UndoActionCreators } from '../../../undoredo/actions';
1414
import {
1515
undoAction,
1616
redoAction,

js/components/preview/viewerControls/settingsControls.js

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { setNglBckGrndColor, setNglClipNear, setNglClipFar, setNglClipDist, setN
88
import { NglContext } from '../../nglView/nglProvider';
99
import { VIEWS } from '../../../constants/constants';
1010

11+
1112
const useStyles = makeStyles(theme => ({
1213
root: {
1314
width: '100%',
@@ -44,6 +45,8 @@ export const SettingControls = memo(({ open, onClose }) => {
4445
}
4546
};
4647

48+
49+
4750
return (
4851
<Drawer title="Settings" open={open} onClose={onClose}>
4952
<Grid container justify="flex-start" direction="column" className={classes.root} spacing={1}>

js/reducers/tracking/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ export const actionAnnotation = {
125125
STAR: 'STAR'
126126
};
127127

128-
export const NUM_OF_SECONDS_TO_IGNORE_MERGE = 5;
128+
export const NUM_OF_SECONDS_TO_IGNORE_MERGE = 2;

js/reducers/tracking/dispatchActions.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ import {
9494
setIsActionsLoading,
9595
setActionsList,
9696
setSnapshotImageActionList,
97-
setUndoRedoActionList
97+
setUndoRedoActionList,
98+
setPast
9899
} from './actions';
99100
import { api, METHOD } from '../../../js/utils/api';
100101
import { base_url } from '../../components/routes/constants';
@@ -124,6 +125,7 @@ import {
124125
setInspirationMoleculeDataList
125126
} from '../../components/datasets/redux/actions';
126127
import { selectVectorAndResetCompounds } from '../../../js/reducers/selection/dispatchActions';
128+
import { ActionCreators as UndoActionCreators } from '../../undoredo/actions'
127129

128130
export const addCurrentActionsListToSnapshot = (snapshot, project, nglViewList) => async (dispatch, getState) => {
129131
let projectID = project && project.projectID;
@@ -2216,30 +2218,34 @@ export const getRedoActionText = () => (dispatch, getState) => {
22162218
return action?.text ?? '';
22172219
};
22182220

2219-
export const appendAndSendTrackingActions = trackAction => (dispatch, getState) => {
2221+
export const appendAndSendTrackingActions = trackAction => async (dispatch, getState) => {
22202222
const state = getState();
22212223
const isUndoRedoAction = state.trackingReducers.isUndoRedoAction;
22222224
dispatch(setIsActionTracking(true));
2223-
22242225
if (trackAction && trackAction !== null) {
22252226
const actionList = state.trackingReducers.track_actions_list;
22262227
const sendActionList = state.trackingReducers.send_actions_list;
22272228
const mergedActionList = mergeActions(trackAction, [...actionList]);
22282229
const mergedSendActionList = mergeActions(trackAction, [...sendActionList]);
2229-
dispatch(setActionsList(mergedActionList));
2230-
dispatch(setSendActionsList(mergedSendActionList));
2231-
2230+
dispatch(setActionsList(mergedActionList.list));
2231+
dispatch(setSendActionsList(mergedSendActionList.list));
22322232
if (isUndoRedoAction === false) {
22332233
const undoRedoActionList = state.trackingReducers.undo_redo_actions_list;
22342234
const mergedUndoRedoActionList = mergeActions(trackAction, [...undoRedoActionList]);
2235-
dispatch(setUndoRedoActionList(mergedUndoRedoActionList));
2235+
if (mergedActionList.merged) {
2236+
dispatch(setUndoRedoActionList(mergedUndoRedoActionList.list));
2237+
dispatch(UndoActionCreators.removeLastPast());
2238+
} else {
2239+
dispatch(setUndoRedoActionList(mergedUndoRedoActionList.list));
2240+
}
22362241
}
22372242
}
22382243
dispatch(setIsActionTracking(false));
22392244
dispatch(checkSendTrackingActions());
22402245
};
22412246

22422247
export const mergeActions = (trackAction, list) => {
2248+
let merged = false;
22432249
if (needsToBeMerged(trackAction)) {
22442250
let newList = [];
22452251
if (list.length > 0) {
@@ -2248,16 +2254,18 @@ export const mergeActions = (trackAction, list) => {
22482254
trackAction.oldSetting = lastEntry.oldSetting;
22492255
trackAction.text = trackAction.getText();
22502256
newList = [...list.slice(0, list.length - 1), trackAction];
2257+
merged = true;
22512258
} else {
22522259
newList = [...list, trackAction];
22532260
}
22542261
} else {
22552262
newList.push(trackAction);
22562263
}
2257-
return newList;
2264+
return {merged: merged, list: newList};
22582265
} else {
2259-
return [...list, trackAction];
2266+
return {merged: merged, list: [...list, trackAction]};
22602267
}
2268+
// return {merged: merged, list: [...list, trackAction]};
22612269
};
22622270

22632271
const needsToBeMerged = trackAction => {

js/reducers/tracking/trackingActions.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ export const findTrackAction = (action, state) => {
949949
object_name: 'NGL',
950950
oldSetting: oldSetting,
951951
newSetting: newSetting,
952-
text: `Color of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
952+
text: `Color of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
953953
};
954954
} else if (action.type === nglConstants.SET_CLIP_NEAR) {
955955
let oldSetting = action.payload.oldValue;
@@ -975,7 +975,7 @@ export const findTrackAction = (action, state) => {
975975
this.newSetting
976976
);
977977
},
978-
text: `Clip near of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
978+
text: `Clip near of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
979979
};
980980
} else if (action.type === nglConstants.SET_CLIP_FAR) {
981981
let oldSetting = action.payload.oldValue;
@@ -1001,7 +1001,7 @@ export const findTrackAction = (action, state) => {
10011001
this.newSetting
10021002
);
10031003
},
1004-
text: `Clip far of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
1004+
text: `Clip far of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
10051005
};
10061006
} else if (action.type === nglConstants.SET_CLIP_DIST) {
10071007
let oldSetting = action.payload.oldValue;
@@ -1027,7 +1027,7 @@ export const findTrackAction = (action, state) => {
10271027
this.newSetting
10281028
);
10291029
},
1030-
text: `Clip dist of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
1030+
text: `Clip dist of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
10311031
};
10321032
} else if (action.type === nglConstants.SET_FOG_NEAR) {
10331033
let oldSetting = action.payload.oldValue;
@@ -1053,7 +1053,7 @@ export const findTrackAction = (action, state) => {
10531053
this.newSetting
10541054
);
10551055
},
1056-
text: `For near of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
1056+
text: `Fog near of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
10571057
};
10581058
} else if (action.type === nglConstants.SET_FOG_FAR) {
10591059
let oldSetting = action.payload.oldValue;
@@ -1079,7 +1079,7 @@ export const findTrackAction = (action, state) => {
10791079
this.newSetting
10801080
);
10811081
},
1082-
text: `For far of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
1082+
text: `Fog far of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
10831083
};
10841084
}
10851085
}

js/reducers/tracking/trackingReducers.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { constants } from './constants';
2-
import undoable, { includeAction } from 'redux-undo';
2+
import {undoable } from '../../undoredo/reducer';
3+
import { includeAction } from '../../undoredo/helpers';
34

45
export const INITIAL_STATE = {
56
track_actions_list: [],
@@ -111,7 +112,7 @@ export function trackingReducers(state = INITIAL_STATE, action = {}) {
111112
return Object.assign({}, state, {
112113
trackingImageSource: action.payload
113114
});
114-
115+
115116
case constants.RESET_TRACKING_STATE:
116117
return INITIAL_STATE;
117118

js/undoredo/actions.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export const ActionTypes = {
2+
UNDO: '@@redux-undo/UNDO',
3+
REDO: '@@redux-undo/REDO',
4+
JUMP_TO_FUTURE: '@@redux-undo/JUMP_TO_FUTURE',
5+
JUMP_TO_PAST: '@@redux-undo/JUMP_TO_PAST',
6+
JUMP: '@@redux-undo/JUMP',
7+
CLEAR_HISTORY: '@@redux-undo/CLEAR_HISTORY',
8+
REMOVE_LAST_PAST: '@@redux-undo/REMOVE_LAST_PAST'
9+
}
10+
11+
export const ActionCreators = {
12+
undo () {
13+
return { type: ActionTypes.UNDO }
14+
},
15+
redo () {
16+
return { type: ActionTypes.REDO }
17+
},
18+
jumpToFuture (index) {
19+
return { type: ActionTypes.JUMP_TO_FUTURE, index }
20+
},
21+
jumpToPast (index) {
22+
return { type: ActionTypes.JUMP_TO_PAST, index }
23+
},
24+
jump (index) {
25+
return { type: ActionTypes.JUMP, index }
26+
},
27+
clearHistory () {
28+
return { type: ActionTypes.CLEAR_HISTORY }
29+
},
30+
removeLastPast() {
31+
return {type: ActionTypes.REMOVE_LAST_PAST}
32+
}
33+
}

js/undoredo/debug.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
let __DEBUG__
2+
let displayBuffer
3+
4+
const colors = {
5+
prevState: '#9E9E9E',
6+
action: '#03A9F4',
7+
nextState: '#4CAF50'
8+
}
9+
10+
/* istanbul ignore next: debug messaging is not tested */
11+
function initBuffer () {
12+
displayBuffer = {
13+
header: [],
14+
prev: [],
15+
action: [],
16+
next: [],
17+
msgs: []
18+
}
19+
}
20+
21+
/* istanbul ignore next: debug messaging is not tested */
22+
function printBuffer () {
23+
const { header, prev, next, action, msgs } = displayBuffer
24+
if (console.group) {
25+
console.groupCollapsed(...header)
26+
console.log(...prev)
27+
console.log(...action)
28+
console.log(...next)
29+
console.log(...msgs)
30+
console.groupEnd()
31+
} else {
32+
console.log(...header)
33+
console.log(...prev)
34+
console.log(...action)
35+
console.log(...next)
36+
console.log(...msgs)
37+
}
38+
}
39+
40+
/* istanbul ignore next: debug messaging is not tested */
41+
function colorFormat (text, color, obj) {
42+
return [
43+
`%c${text}`,
44+
`color: ${color}; font-weight: bold`,
45+
obj
46+
]
47+
}
48+
49+
/* istanbul ignore next: debug messaging is not tested */
50+
function start (action, state) {
51+
initBuffer()
52+
if (__DEBUG__) {
53+
if (console.group) {
54+
displayBuffer.header = ['%credux-undo', 'font-style: italic', 'action', action.type]
55+
displayBuffer.action = colorFormat('action', colors.action, action)
56+
displayBuffer.prev = colorFormat('prev history', colors.prevState, state)
57+
} else {
58+
displayBuffer.header = ['redux-undo action', action.type]
59+
displayBuffer.action = ['action', action]
60+
displayBuffer.prev = ['prev history', state]
61+
}
62+
}
63+
}
64+
65+
/* istanbul ignore next: debug messaging is not tested */
66+
function end (nextState) {
67+
if (__DEBUG__) {
68+
if (console.group) {
69+
displayBuffer.next = colorFormat('next history', colors.nextState, nextState)
70+
} else {
71+
displayBuffer.next = ['next history', nextState]
72+
}
73+
printBuffer()
74+
}
75+
}
76+
77+
/* istanbul ignore next: debug messaging is not tested */
78+
function log (...args) {
79+
if (__DEBUG__) {
80+
displayBuffer.msgs = displayBuffer.msgs
81+
.concat([...args, '\n'])
82+
}
83+
}
84+
85+
/* istanbul ignore next: debug messaging is not tested */
86+
function set (debug) {
87+
__DEBUG__ = debug
88+
}
89+
90+
export { set, start, end, log }

js/undoredo/helpers.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// parseActions helper: takes a string (or array)
2+
// and makes it an array if it isn't yet
3+
export function parseActions (rawActions, defaultValue = []) {
4+
if (Array.isArray(rawActions)) {
5+
return rawActions
6+
} else if (typeof rawActions === 'string') {
7+
return [rawActions]
8+
}
9+
return defaultValue
10+
}
11+
12+
// isHistory helper: check for a valid history object
13+
export function isHistory (history) {
14+
return typeof history.present !== 'undefined' &&
15+
typeof history.future !== 'undefined' &&
16+
typeof history.past !== 'undefined' &&
17+
Array.isArray(history.future) &&
18+
Array.isArray(history.past)
19+
}
20+
21+
// includeAction helper: whitelist actions to be added to the history
22+
export function includeAction (rawActions) {
23+
const actions = parseActions(rawActions)
24+
return (action) => actions.indexOf(action.type) >= 0
25+
}
26+
27+
// excludeAction helper: blacklist actions from being added to the history
28+
export function excludeAction (rawActions) {
29+
const actions = parseActions(rawActions)
30+
return (action) => actions.indexOf(action.type) < 0
31+
}
32+
33+
// combineFilters helper: combine multiple filters to one
34+
export function combineFilters (...filters) {
35+
return filters.reduce((prev, curr) =>
36+
(action, currentState, previousHistory) =>
37+
prev(action, currentState, previousHistory) &&
38+
curr(action, currentState, previousHistory)
39+
, () => true)
40+
}
41+
42+
export function groupByActionTypes (rawActions) {
43+
const actions = parseActions(rawActions)
44+
return (action) => actions.indexOf(action.type) >= 0 ? action.type : null
45+
}
46+
47+
export function newHistory (past, present, future, group = null) {
48+
return {
49+
past,
50+
present,
51+
future,
52+
group,
53+
_latestUnfiltered: present,
54+
index: past.length,
55+
limit: past.length + future.length + 1
56+
}
57+
}

js/undoredo/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export { ActionTypes, ActionCreators } from './actions'
2+
export {
3+
parseActions, isHistory,
4+
includeAction, excludeAction,
5+
combineFilters, groupByActionTypes, newHistory
6+
} from './helpers'
7+
8+
export { default } from './reducer'

0 commit comments

Comments
 (0)