From cc8cf6947675eb7552b95c8916761eca0d35f80b Mon Sep 17 00:00:00 2001 From: Nathaniel Rindlaub Date: Fri, 8 Dec 2023 12:14:03 -0800 Subject: [PATCH] Wire up unlock menu item --- src/features/images/ImagesTable.jsx | 29 ++++++++++++++++++++++++ src/features/loupe/BoundingBox.jsx | 2 +- src/features/loupe/Loupe.jsx | 6 ++--- src/features/loupe/ValidationButtons.jsx | 2 +- src/features/review/objectMiddleware.js | 8 +++++-- src/features/review/undoMiddleware.js | 3 +-- 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/features/images/ImagesTable.jsx b/src/features/images/ImagesTable.jsx index 14682da9..3601240f 100644 --- a/src/features/images/ImagesTable.jsx +++ b/src/features/images/ImagesTable.jsx @@ -29,6 +29,7 @@ import { setFocus, labelsAdded, labelsValidated, + objectsManuallyUnlocked, selectFocusIndex, selectFocusChangeType } from '../review/reviewSlice'; @@ -457,6 +458,25 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => { dispatch(addLabelStart('from-image-table')); }; + // unlock all labels + const handleUnlockMenuItemClick = (e) => { + e.stopPropagation(); + let objects = []; + for (const image of selectedImages) { + const objectsToUnlock = image.objects + .filter((obj) => ( + obj.locked && obj.labels.some((lbl) => ( + lbl.validation === null || lbl.validation.validated + )) + )) + .map((obj) => ({ imgId: image._id, objId: obj._id })); + + objects = objects.concat(objectsToUnlock); + } + dispatch(objectsManuallyUnlocked({ objects })); + }; + + // TODO: double check that all the "disabled" conditions are consistent // across bounding-box context menu items, ImageReviewToolbar, and the // context menu items here @@ -533,6 +553,15 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => { Edit all labels ) } + + + + + Unlock + ); diff --git a/src/features/loupe/BoundingBox.jsx b/src/features/loupe/BoundingBox.jsx index 82d90d7b..2ea0f84b 100644 --- a/src/features/loupe/BoundingBox.jsx +++ b/src/features/loupe/BoundingBox.jsx @@ -255,7 +255,7 @@ const BoundingBox = ({ const handleUnlockMenuItemClick = (e) => { e.stopPropagation(); - dispatch(objectsManuallyUnlocked({ imgId, objIds: [object._id] })); + dispatch(objectsManuallyUnlocked({ objects: [{ imgId, objId: object._id }] })); }; return ( diff --git a/src/features/loupe/Loupe.jsx b/src/features/loupe/Loupe.jsx index d44509b1..b93c2029 100644 --- a/src/features/loupe/Loupe.jsx +++ b/src/features/loupe/Loupe.jsx @@ -229,14 +229,14 @@ const Loupe = () => { const handleCloseLoupe = () => dispatch(toggleOpenLoupe(false)); const handleUnlockAllButtonClick = () => { - const objIds = currImgObjects + const objects = currImgObjects .filter((obj) => ( obj.locked && obj.labels.some((lbl) => ( lbl.validation === null || lbl.validation.validated )) )) - .map((obj) => obj._id); - dispatch(objectsManuallyUnlocked({ imgId: image._id, objIds })); + .map((obj) => ({ imgId: image._id, objId: obj._id })); + dispatch(objectsManuallyUnlocked({ objects })); }; const handleIncrementClick = (delta) => { diff --git a/src/features/loupe/ValidationButtons.jsx b/src/features/loupe/ValidationButtons.jsx index caf5e256..2aae0222 100644 --- a/src/features/loupe/ValidationButtons.jsx +++ b/src/features/loupe/ValidationButtons.jsx @@ -33,7 +33,7 @@ const ValidationButtons = ({ const handleLockButtonClick = (e) => { e.stopPropagation(); - dispatch(objectsManuallyUnlocked({ imgId, objIds: [object._id] })); + dispatch(objectsManuallyUnlocked({ objects: [{ imgId, objId: object._id }] })); }; const handleValidationButtonClick = (e, validated) => { diff --git a/src/features/review/objectMiddleware.js b/src/features/review/objectMiddleware.js index b38d9b8d..8cd22452 100644 --- a/src/features/review/objectMiddleware.js +++ b/src/features/review/objectMiddleware.js @@ -55,8 +55,12 @@ export const objectMiddleware = store => next => action => { else if (objectsManuallyUnlocked.match(action)) { next(action); - const { imgId, objIds } = action.payload; - const objects = objIds.map((objId) => ({ imgId, objId, locked: false })); + console.log('objectMiddleware - objectsManuallyUnlocked: ', action.payload) + // const { imgId, objIds } = action.payload; + // const objects = objIds.map((objId) => ({ imgId, objId, locked: false })); + const objects = action.payload.objects.map(({ imgId, objId }) => ({ + imgId, objId, locked: false + })); store.dispatch(objectsLocked({ objects })); } diff --git a/src/features/review/undoMiddleware.js b/src/features/review/undoMiddleware.js index ebdbe757..ebb768b3 100644 --- a/src/features/review/undoMiddleware.js +++ b/src/features/review/undoMiddleware.js @@ -74,8 +74,7 @@ export const undoMiddleware = createUndoMiddleware({ [objectsManuallyUnlocked.toString()]: { action: (action) => { console.log("reverting objectsManuallyUnlocked with action: ", action); - const { imgId, objIds } = action.payload; - const objects = objIds.map((objId) => ({ imgId, objId, locked: true })); + const objects = action.payload.objects.map(({ imgId, objId }) => ({ imgId, objId, locked: true })); return objectsLocked({ objects }); }, },