mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-01 12:18:12 +08:00
undo/redo cleanup (#1165)
* fix refactoring error which disabled annotation file clearing * fix undo behavior on add category label * fix various undo/redo bugs * remove logging * further refinement of annotation undo/redo and actions * address PR comment
This commit is contained in:
@@ -80,15 +80,6 @@ const Annotations = (
|
||||
isAddingNewLabel: false,
|
||||
categoryAddingNewLabel: null
|
||||
};
|
||||
/* this handles both cases, since at this point it's just a string */
|
||||
case "annotation: add new label to category":
|
||||
return {
|
||||
...state,
|
||||
isAddingNewLabel: false,
|
||||
categoryAddingNewLabel: null,
|
||||
isAddingNewLabelFromOntology: false,
|
||||
categoryAddingNewLabelFromOntology: null
|
||||
};
|
||||
case "annotation: activate category edit mode":
|
||||
return {
|
||||
...state,
|
||||
@@ -101,12 +92,6 @@ const Annotations = (
|
||||
isEditingCategoryName: false,
|
||||
categoryBeingEdited: null
|
||||
};
|
||||
case "annotation: category edited":
|
||||
return {
|
||||
...state,
|
||||
isEditingCategoryName: false,
|
||||
categoryBeingEdited: null
|
||||
};
|
||||
|
||||
/* LABEL */
|
||||
case "annotation: activate edit label mode":
|
||||
@@ -124,12 +109,6 @@ const Annotations = (
|
||||
isEditingLabelName: false,
|
||||
labelEditable: { category: null, label: null }
|
||||
};
|
||||
case "annotation: label edited":
|
||||
return {
|
||||
...state,
|
||||
isEditingLabelName: false,
|
||||
labelEditable: { category: null, label: null }
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,6 @@ const Undoable = (reducer, undoableKeys, options = {}) => {
|
||||
);
|
||||
const newPast = [...past];
|
||||
const newState = newPast.pop();
|
||||
const newStateFilterState = newState[filterStateKey];
|
||||
const newFuture = push(future, currentUndoableState);
|
||||
const nextState = {
|
||||
...currentState,
|
||||
@@ -94,7 +93,6 @@ const Undoable = (reducer, undoableKeys, options = {}) => {
|
||||
[futureKey]: newFuture,
|
||||
[pendingKey]: null
|
||||
};
|
||||
nextState[filterStateKey] = newStateFilterState;
|
||||
return nextState;
|
||||
}
|
||||
|
||||
@@ -139,12 +137,13 @@ const Undoable = (reducer, undoableKeys, options = {}) => {
|
||||
*/
|
||||
function skip(currentState, action, filterState) {
|
||||
const past = currentState[pastKey] || [];
|
||||
const future = currentState[futureKey] || [];
|
||||
const pending = currentState[pendingKey];
|
||||
const res = reducer(currentState, action);
|
||||
return {
|
||||
...res,
|
||||
[pastKey]: past,
|
||||
[futureKey]: [],
|
||||
[futureKey]: future,
|
||||
[filterStateKey]: filterState,
|
||||
[pendingKey]: pending
|
||||
};
|
||||
@@ -218,6 +217,7 @@ const Undoable = (reducer, undoableKeys, options = {}) => {
|
||||
},
|
||||
action
|
||||
) => {
|
||||
if (debug > 1) console.log("---- ACTION", action.type);
|
||||
const aType = action.type;
|
||||
switch (aType) {
|
||||
case "@@undoable/undo": {
|
||||
|
||||
@@ -35,18 +35,30 @@ const skipOnActions = new Set([
|
||||
"get single gene expression for coloring error",
|
||||
|
||||
"category value mouse hover start",
|
||||
"category value mouse hover end"
|
||||
"category value mouse hover end",
|
||||
|
||||
/* autosave annotations */
|
||||
"writable obs annotations - save complete",
|
||||
"writable obs annotations - save started",
|
||||
"writable obs annotations - save error",
|
||||
|
||||
/* annotation component action */
|
||||
"annotation: activate add new label mode",
|
||||
"annotation: activate add new ontology label mode",
|
||||
"annotation: disable add new ontology label mode",
|
||||
"annotation: disable add new label mode",
|
||||
"annotation: activate category edit mode",
|
||||
"annotation: disable category edit mode",
|
||||
"annotation: activate edit label mode",
|
||||
"annotation: cancel edit label mode",
|
||||
"set annotations collection name"
|
||||
]);
|
||||
|
||||
/*
|
||||
identical, repeated occurances of these action types will be debounced.
|
||||
Entire action must be identical (all keys).
|
||||
*/
|
||||
const debounceOnActions = new Set([
|
||||
"color by categorical metadata",
|
||||
"color by continuous metadata",
|
||||
"color by expression"
|
||||
]);
|
||||
const debounceOnActions = new Set([]);
|
||||
|
||||
/*
|
||||
history will be cleared when these actions occur
|
||||
@@ -91,7 +103,8 @@ const saveOnActions = new Set([
|
||||
"annotation: delete category",
|
||||
"annotation: label edited",
|
||||
"annotation: label current cell selection",
|
||||
"annotation: delete label"
|
||||
"annotation: delete label",
|
||||
"annotation: category edited"
|
||||
]);
|
||||
|
||||
/**
|
||||
@@ -172,8 +185,6 @@ const actionFilter = debug => (state, action, prevFilterState) => {
|
||||
}
|
||||
if (
|
||||
debounceOnActions.has(actionType) &&
|
||||
prevFilterState !== undefined &&
|
||||
prevFilterState.prevAction !== undefined &&
|
||||
shallowObjectEq(action, prevFilterState.prevAction)
|
||||
) {
|
||||
return { [actionKey]: "skip", [stateKey]: filterState };
|
||||
@@ -229,7 +240,12 @@ function shallowArrayEq(arrA, arrB) {
|
||||
}
|
||||
|
||||
/* configuration for the undoable meta reducer */
|
||||
const debug = false; // set truish for undoble debugging
|
||||
/*
|
||||
debug: set to any falsish value to disable logging of helpful debugging information.
|
||||
Set to true or 1 for base logging, high number for more verbosity (currently only 1/true
|
||||
or 2).
|
||||
*/
|
||||
const debug = false;
|
||||
const undoableConfig = {
|
||||
debug,
|
||||
historyLimit: 50, // maximum history size
|
||||
|
||||
Reference in New Issue
Block a user