Skip to content

Commit

Permalink
Wire up unlock menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielrindlaub committed Dec 8, 2023
1 parent fcf94bb commit cc8cf69
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
29 changes: 29 additions & 0 deletions src/features/images/ImagesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
setFocus,
labelsAdded,
labelsValidated,
objectsManuallyUnlocked,
selectFocusIndex,
selectFocusChangeType
} from '../review/reviewSlice';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -533,6 +553,15 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => {
Edit all labels
</ContextMenuItem>)
}
<ContextMenuItem
onSelect={handleUnlockMenuItemClick}
disabled={isAddingLabel}
>
<ContextMenuItemIconLeft>
<LockOpen1Icon />
</ContextMenuItemIconLeft>
Unlock
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
);
Expand Down
2 changes: 1 addition & 1 deletion src/features/loupe/BoundingBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 3 additions & 3 deletions src/features/loupe/Loupe.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/features/loupe/ValidationButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
8 changes: 6 additions & 2 deletions src/features/review/objectMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}

Expand Down
3 changes: 1 addition & 2 deletions src/features/review/undoMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
},
},
Expand Down

0 comments on commit cc8cf69

Please sign in to comment.