Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#524' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Feb 3, 2021
2 parents 5b48a2e + ed95f12 commit 99150c0
Show file tree
Hide file tree
Showing 12 changed files with 493 additions and 20 deletions.
2 changes: 1 addition & 1 deletion js/components/preview/viewerControls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ButtonGroup, Grid, makeStyles, Tooltip } from '@material-ui/core';
import { SettingControls } from './settingsControls';
import DisplayControls from './displayControls/';
import { MouseControls } from './mouseControls';
import { ActionCreators as UndoActionCreators } from 'redux-undo';
import { ActionCreators as UndoActionCreators } from '../../../undoredo/actions';
import {
undoAction,
redoAction,
Expand Down
3 changes: 3 additions & 0 deletions js/components/preview/viewerControls/settingsControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { setNglBckGrndColor, setNglClipNear, setNglClipFar, setNglClipDist, setN
import { NglContext } from '../../nglView/nglProvider';
import { VIEWS } from '../../../constants/constants';


const useStyles = makeStyles(theme => ({
root: {
width: '100%',
Expand Down Expand Up @@ -44,6 +45,8 @@ export const SettingControls = memo(({ open, onClose }) => {
}
};



return (
<Drawer title="Settings" open={open} onClose={onClose}>
<Grid container justify="flex-start" direction="column" className={classes.root} spacing={1}>
Expand Down
2 changes: 1 addition & 1 deletion js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ export const actionAnnotation = {
STAR: 'STAR'
};

export const NUM_OF_SECONDS_TO_IGNORE_MERGE = 5;
export const NUM_OF_SECONDS_TO_IGNORE_MERGE = 2;
26 changes: 17 additions & 9 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ import {
setIsActionsLoading,
setActionsList,
setSnapshotImageActionList,
setUndoRedoActionList
setUndoRedoActionList,
setPast
} from './actions';
import { api, METHOD } from '../../../js/utils/api';
import { base_url } from '../../components/routes/constants';
Expand Down Expand Up @@ -124,6 +125,7 @@ import {
setInspirationMoleculeDataList
} from '../../components/datasets/redux/actions';
import { selectVectorAndResetCompounds } from '../../../js/reducers/selection/dispatchActions';
import { ActionCreators as UndoActionCreators } from '../../undoredo/actions'

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

export const appendAndSendTrackingActions = trackAction => (dispatch, getState) => {
export const appendAndSendTrackingActions = trackAction => async (dispatch, getState) => {
const state = getState();
const isUndoRedoAction = state.trackingReducers.isUndoRedoAction;
dispatch(setIsActionTracking(true));

if (trackAction && trackAction !== null) {
const actionList = state.trackingReducers.track_actions_list;
const sendActionList = state.trackingReducers.send_actions_list;
const mergedActionList = mergeActions(trackAction, [...actionList]);
const mergedSendActionList = mergeActions(trackAction, [...sendActionList]);
dispatch(setActionsList(mergedActionList));
dispatch(setSendActionsList(mergedSendActionList));

dispatch(setActionsList(mergedActionList.list));
dispatch(setSendActionsList(mergedSendActionList.list));
if (isUndoRedoAction === false) {
const undoRedoActionList = state.trackingReducers.undo_redo_actions_list;
const mergedUndoRedoActionList = mergeActions(trackAction, [...undoRedoActionList]);
dispatch(setUndoRedoActionList(mergedUndoRedoActionList));
if (mergedActionList.merged) {
dispatch(setUndoRedoActionList(mergedUndoRedoActionList.list));
dispatch(UndoActionCreators.removeLastPast());
} else {
dispatch(setUndoRedoActionList(mergedUndoRedoActionList.list));
}
}
}
dispatch(setIsActionTracking(false));
dispatch(checkSendTrackingActions());
};

export const mergeActions = (trackAction, list) => {
let merged = false;
if (needsToBeMerged(trackAction)) {
let newList = [];
if (list.length > 0) {
Expand All @@ -2248,16 +2254,18 @@ export const mergeActions = (trackAction, list) => {
trackAction.oldSetting = lastEntry.oldSetting;
trackAction.text = trackAction.getText();
newList = [...list.slice(0, list.length - 1), trackAction];
merged = true;
} else {
newList = [...list, trackAction];
}
} else {
newList.push(trackAction);
}
return newList;
return {merged: merged, list: newList};
} else {
return [...list, trackAction];
return {merged: merged, list: [...list, trackAction]};
}
// return {merged: merged, list: [...list, trackAction]};
};

const needsToBeMerged = trackAction => {
Expand Down
12 changes: 6 additions & 6 deletions js/reducers/tracking/trackingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ export const findTrackAction = (action, state) => {
object_name: 'NGL',
oldSetting: oldSetting,
newSetting: newSetting,
text: `Color of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
text: `Color of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
};
} else if (action.type === nglConstants.SET_CLIP_NEAR) {
let oldSetting = action.payload.oldValue;
Expand All @@ -975,7 +975,7 @@ export const findTrackAction = (action, state) => {
this.newSetting
);
},
text: `Clip near of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
text: `Clip near of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
};
} else if (action.type === nglConstants.SET_CLIP_FAR) {
let oldSetting = action.payload.oldValue;
Expand All @@ -1001,7 +1001,7 @@ export const findTrackAction = (action, state) => {
this.newSetting
);
},
text: `Clip far of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
text: `Clip far of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
};
} else if (action.type === nglConstants.SET_CLIP_DIST) {
let oldSetting = action.payload.oldValue;
Expand All @@ -1027,7 +1027,7 @@ export const findTrackAction = (action, state) => {
this.newSetting
);
},
text: `Clip dist of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
text: `Clip dist of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
};
} else if (action.type === nglConstants.SET_FOG_NEAR) {
let oldSetting = action.payload.oldValue;
Expand All @@ -1053,7 +1053,7 @@ export const findTrackAction = (action, state) => {
this.newSetting
);
},
text: `For near of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
text: `Fog near of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
};
} else if (action.type === nglConstants.SET_FOG_FAR) {
let oldSetting = action.payload.oldValue;
Expand All @@ -1079,7 +1079,7 @@ export const findTrackAction = (action, state) => {
this.newSetting
);
},
text: `For far of NGL ${actionDescription.CHANGED} from value: ${oldSetting} to value: ${newSetting}`
text: `Fog far of NGL ${actionDescription.CHANGED} to value: ${newSetting}`
};
}
}
Expand Down
5 changes: 3 additions & 2 deletions js/reducers/tracking/trackingReducers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { constants } from './constants';
import undoable, { includeAction } from 'redux-undo';
import {undoable } from '../../undoredo/reducer';
import { includeAction } from '../../undoredo/helpers';

export const INITIAL_STATE = {
track_actions_list: [],
Expand Down Expand Up @@ -111,7 +112,7 @@ export function trackingReducers(state = INITIAL_STATE, action = {}) {
return Object.assign({}, state, {
trackingImageSource: action.payload
});

case constants.RESET_TRACKING_STATE:
return INITIAL_STATE;

Expand Down
33 changes: 33 additions & 0 deletions js/undoredo/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export const ActionTypes = {
UNDO: '@@redux-undo/UNDO',
REDO: '@@redux-undo/REDO',
JUMP_TO_FUTURE: '@@redux-undo/JUMP_TO_FUTURE',
JUMP_TO_PAST: '@@redux-undo/JUMP_TO_PAST',
JUMP: '@@redux-undo/JUMP',
CLEAR_HISTORY: '@@redux-undo/CLEAR_HISTORY',
REMOVE_LAST_PAST: '@@redux-undo/REMOVE_LAST_PAST'
}

export const ActionCreators = {
undo () {
return { type: ActionTypes.UNDO }
},
redo () {
return { type: ActionTypes.REDO }
},
jumpToFuture (index) {
return { type: ActionTypes.JUMP_TO_FUTURE, index }
},
jumpToPast (index) {
return { type: ActionTypes.JUMP_TO_PAST, index }
},
jump (index) {
return { type: ActionTypes.JUMP, index }
},
clearHistory () {
return { type: ActionTypes.CLEAR_HISTORY }
},
removeLastPast() {
return {type: ActionTypes.REMOVE_LAST_PAST}
}
}
90 changes: 90 additions & 0 deletions js/undoredo/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
let __DEBUG__
let displayBuffer

const colors = {
prevState: '#9E9E9E',
action: '#03A9F4',
nextState: '#4CAF50'
}

/* istanbul ignore next: debug messaging is not tested */
function initBuffer () {
displayBuffer = {
header: [],
prev: [],
action: [],
next: [],
msgs: []
}
}

/* istanbul ignore next: debug messaging is not tested */
function printBuffer () {
const { header, prev, next, action, msgs } = displayBuffer
if (console.group) {
console.groupCollapsed(...header)
console.log(...prev)
console.log(...action)
console.log(...next)
console.log(...msgs)
console.groupEnd()
} else {
console.log(...header)
console.log(...prev)
console.log(...action)
console.log(...next)
console.log(...msgs)
}
}

/* istanbul ignore next: debug messaging is not tested */
function colorFormat (text, color, obj) {
return [
`%c${text}`,
`color: ${color}; font-weight: bold`,
obj
]
}

/* istanbul ignore next: debug messaging is not tested */
function start (action, state) {
initBuffer()
if (__DEBUG__) {
if (console.group) {
displayBuffer.header = ['%credux-undo', 'font-style: italic', 'action', action.type]
displayBuffer.action = colorFormat('action', colors.action, action)
displayBuffer.prev = colorFormat('prev history', colors.prevState, state)
} else {
displayBuffer.header = ['redux-undo action', action.type]
displayBuffer.action = ['action', action]
displayBuffer.prev = ['prev history', state]
}
}
}

/* istanbul ignore next: debug messaging is not tested */
function end (nextState) {
if (__DEBUG__) {
if (console.group) {
displayBuffer.next = colorFormat('next history', colors.nextState, nextState)
} else {
displayBuffer.next = ['next history', nextState]
}
printBuffer()
}
}

/* istanbul ignore next: debug messaging is not tested */
function log (...args) {
if (__DEBUG__) {
displayBuffer.msgs = displayBuffer.msgs
.concat([...args, '\n'])
}
}

/* istanbul ignore next: debug messaging is not tested */
function set (debug) {
__DEBUG__ = debug
}

export { set, start, end, log }
57 changes: 57 additions & 0 deletions js/undoredo/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// parseActions helper: takes a string (or array)
// and makes it an array if it isn't yet
export function parseActions (rawActions, defaultValue = []) {
if (Array.isArray(rawActions)) {
return rawActions
} else if (typeof rawActions === 'string') {
return [rawActions]
}
return defaultValue
}

// isHistory helper: check for a valid history object
export function isHistory (history) {
return typeof history.present !== 'undefined' &&
typeof history.future !== 'undefined' &&
typeof history.past !== 'undefined' &&
Array.isArray(history.future) &&
Array.isArray(history.past)
}

// includeAction helper: whitelist actions to be added to the history
export function includeAction (rawActions) {
const actions = parseActions(rawActions)
return (action) => actions.indexOf(action.type) >= 0
}

// excludeAction helper: blacklist actions from being added to the history
export function excludeAction (rawActions) {
const actions = parseActions(rawActions)
return (action) => actions.indexOf(action.type) < 0
}

// combineFilters helper: combine multiple filters to one
export function combineFilters (...filters) {
return filters.reduce((prev, curr) =>
(action, currentState, previousHistory) =>
prev(action, currentState, previousHistory) &&
curr(action, currentState, previousHistory)
, () => true)
}

export function groupByActionTypes (rawActions) {
const actions = parseActions(rawActions)
return (action) => actions.indexOf(action.type) >= 0 ? action.type : null
}

export function newHistory (past, present, future, group = null) {
return {
past,
present,
future,
group,
_latestUnfiltered: present,
index: past.length,
limit: past.length + future.length + 1
}
}
8 changes: 8 additions & 0 deletions js/undoredo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export { ActionTypes, ActionCreators } from './actions'
export {
parseActions, isHistory,
includeAction, excludeAction,
combineFilters, groupByActionTypes, newHistory
} from './helpers'

export { default } from './reducer'
Loading

0 comments on commit 99150c0

Please sign in to comment.