Skip to content

Commit 5059116

Browse files
committed
fix that some actions were not applied because of allowUpdate==false
1 parent 51e08f1 commit 5059116

File tree

4 files changed

+66
-15
lines changed

4 files changed

+66
-15
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import update from "immutability-helper";
2+
import type { Action } from "viewer/model/actions/actions";
3+
import type { WebknossosState } from "viewer/store";
4+
5+
export const applyActionsOnReadOnlyVersion = (
6+
applyActions: (
7+
state: WebknossosState,
8+
actionGetters: Array<Action | ((s: WebknossosState) => Action)>,
9+
) => WebknossosState,
10+
state: WebknossosState,
11+
actionGetters: Array<Action | ((s: WebknossosState) => Action)>,
12+
) => {
13+
const readOnlyState = overrideAllowUpdateInState(state, false);
14+
const reappliedNewState = applyActions(readOnlyState, actionGetters);
15+
16+
return overrideAllowUpdateInState(reappliedNewState, true);
17+
};
18+
19+
function overrideAllowUpdateInState(state: WebknossosState, value: boolean) {
20+
return update(state, {
21+
annotation: {
22+
restrictions: {
23+
allowUpdate: {
24+
$set: value,
25+
},
26+
},
27+
},
28+
});
29+
}

frontend/javascripts/test/reducers/update_action_application/skeleton.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { sampleTracingLayer } from "test/fixtures/dataset_server_object";
44
import { initialState as defaultSkeletonState } from "test/fixtures/skeletontracing_object";
55
import { chainReduce } from "test/helpers/chainReducer";
66
import { withoutUpdateActiveItemTracing } from "test/helpers/saveHelpers";
7+
import { applyActionsOnReadOnlyVersion } from "test/helpers/utils";
78
import type { Vector3 } from "viewer/constants";
89
import {
910
enforceSkeletonTracing,
@@ -202,11 +203,15 @@ describe("Update Action Application for SkeletonTracing", () => {
202203
seenActionTypes.add(action.name);
203204
}
204205

205-
const reappliedNewState = applyActions(state2WithoutActiveState, [
206-
SkeletonTracingActions.applySkeletonUpdateActionsFromServerAction(updateActions),
207-
SkeletonTracingActions.setActiveNodeAction(null),
208-
setActiveUserBoundingBoxId(null),
209-
]);
206+
const reappliedNewState = applyActionsOnReadOnlyVersion(
207+
applyActions,
208+
state2WithoutActiveState,
209+
[
210+
SkeletonTracingActions.applySkeletonUpdateActionsFromServerAction(updateActions),
211+
SkeletonTracingActions.setActiveNodeAction(null),
212+
setActiveUserBoundingBoxId(null),
213+
],
214+
);
210215

211216
expect(reappliedNewState).toEqual(state3);
212217
});
@@ -237,7 +242,7 @@ describe("Update Action Application for SkeletonTracing", () => {
237242
),
238243
) as ApplicableSkeletonUpdateAction[];
239244

240-
const newState3 = applyActions(newState, [
245+
const newState3 = applyActionsOnReadOnlyVersion(applyActions, newState, [
241246
SkeletonTracingActions.applySkeletonUpdateActionsFromServerAction(updateActions),
242247
]);
243248

@@ -268,7 +273,7 @@ describe("Update Action Application for SkeletonTracing", () => {
268273
),
269274
) as ApplicableSkeletonUpdateAction[];
270275

271-
const newState3 = applyActions(newState, [
276+
const newState3 = applyActionsOnReadOnlyVersion(applyActions, newState, [
272277
SkeletonTracingActions.applySkeletonUpdateActionsFromServerAction(updateActions),
273278
]);
274279

frontend/javascripts/test/reducers/update_action_application/volume.spec.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
import { combinedReducer, type WebknossosState } from "viewer/store";
2121
import { makeBasicGroupObject } from "viewer/view/right-border-tabs/trees_tab/tree_hierarchy_view_helpers";
2222
import { afterAll, describe, expect, test } from "vitest";
23+
import { applyActionsOnReadOnlyVersion } from "test/helpers/utils";
2324

2425
const enforceVolumeTracing = (state: WebknossosState) => {
2526
const tracing = state.annotation.volumes[0];
@@ -179,11 +180,15 @@ describe("Update Action Application for VolumeTracing", () => {
179180
seenActionTypes.add(action.name);
180181
}
181182

182-
const reappliedNewState = applyActions(state2WithoutActiveState, [
183-
VolumeTracingActions.applyVolumeUpdateActionsFromServerAction(updateActions),
184-
VolumeTracingActions.setActiveCellAction(0),
185-
setActiveUserBoundingBoxId(null),
186-
]);
183+
const reappliedNewState = applyActionsOnReadOnlyVersion(
184+
applyActions,
185+
state2WithoutActiveState,
186+
[
187+
VolumeTracingActions.applyVolumeUpdateActionsFromServerAction(updateActions),
188+
VolumeTracingActions.setActiveCellAction(0),
189+
setActiveUserBoundingBoxId(null),
190+
],
191+
);
187192

188193
expect(reappliedNewState).toEqual(state3);
189194
});

frontend/javascripts/viewer/model/reducers/skeletontracing_reducer.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ import { getUserStateForTracing } from "../accessors/annotation_accessor";
5757
import { max, maxBy } from "../helpers/iterator_utils";
5858
import { applySkeletonUpdateActionsFromServer } from "./update_action_application/skeleton";
5959

60-
function SkeletonTracingReducer(state: WebknossosState, action: Action): WebknossosState {
60+
function SkeletonTracingReducer(
61+
state: WebknossosState,
62+
action: Action,
63+
ignoreAllowUpdate: boolean = false,
64+
): WebknossosState {
6165
if (action.type === "INITIALIZE_SKELETONTRACING") {
6266
const userState = getUserStateForTracing(
6367
action.tracing,
@@ -653,7 +657,13 @@ function SkeletonTracingReducer(state: WebknossosState, action: Action): Webknos
653657

654658
case "APPLY_SKELETON_UPDATE_ACTIONS_FROM_SERVER": {
655659
const { actions } = action;
656-
return applySkeletonUpdateActionsFromServer(SkeletonTracingReducer, actions, state);
660+
return applySkeletonUpdateActionsFromServer(
661+
// Pass a SkeletonTracingReducer that ignores allowUpdate because
662+
// we want to be able to apply updates even in read-only views.
663+
(state: WebknossosState, action: Action) => SkeletonTracingReducer(state, action, true),
664+
actions,
665+
state,
666+
);
657667
}
658668

659669
default: // pass
@@ -664,7 +674,9 @@ function SkeletonTracingReducer(state: WebknossosState, action: Action): Webknos
664674
*/
665675
const { restrictions } = state.annotation;
666676
const { allowUpdate } = restrictions;
667-
if (!allowUpdate) return state;
677+
if (!(allowUpdate || ignoreAllowUpdate)) {
678+
return state;
679+
}
668680

669681
switch (action.type) {
670682
case "CREATE_NODE": {

0 commit comments

Comments
 (0)