Skip to content

Commit

Permalink
Fix issue with context-menu state updates happening after it's unmounted
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielrindlaub committed Dec 14, 2023
1 parent 1465f02 commit e1d17d4
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/features/images/ImagesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,6 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => {
// TODO: look for opportunities to abstract some of this. Lots of overlap
// with ImageReviewToolbar and BoundingBox context-menu logic

// TODO: e.g. the category selector used in this context-menu, in BoundingBoxLabel,
// and ImageReviewToolbar might be able to abstract into its own component

// TODO: also, can we move this logic higher up the component tree?
// Seems crazy to stick it in every row component

Expand Down Expand Up @@ -493,6 +490,7 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => {
// validate all labels
const handleValidationMenuItemClick = (e, validated) => {
e.stopPropagation();
if (allObjectsLocked) return;
let labelsToValidate = [];
for (const image of selectedImages) {
const unlockedObjects = image.objects.filter((obj) => !obj.locked);
Expand All @@ -517,12 +515,14 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => {
const handleEditAllLabelsButtonClick = (e) => {
e.stopPropagation();
e.preventDefault();
if (allObjectsLocked) return;
dispatch(addLabelStart('from-image-table'));
};

// unlock all labels
const handleUnlockMenuItemClick = (e) => {
e.stopPropagation();
if (allObjectsUnlocked || !hasRenderedObjects) return;
let objects = [];
for (const image of selectedImages) {
const objectsToUnlock = image.objects
Expand Down Expand Up @@ -608,7 +608,7 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => {
>
<ContextMenuItem
onSelect={(e) => handleValidationMenuItemClick(e, true)}
disabled={isAddingLabel || allObjectsLocked}
disabled={isAddingLabel}
css={{
color: '$successText',
'&[data-highlighted]': {
Expand All @@ -624,7 +624,7 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => {
</ContextMenuItem>
<ContextMenuItem
onSelect={(e) => handleValidationMenuItemClick(e, false)}
disabled={isAddingLabel || allObjectsLocked}
disabled={isAddingLabel}
css={{
color: '$errorText',
'&[data-highlighted]': {
Expand All @@ -643,10 +643,7 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => {
css={{ width: '100%' }}
handleCategoryChange={handleCategoryChange}
/>)
: (<ContextMenuItem
onSelect={handleEditAllLabelsButtonClick}
disabled={allObjectsLocked}
>
: (<ContextMenuItem onSelect={handleEditAllLabelsButtonClick}>
<ContextMenuItemIconLeft>
<Pencil1Icon />
</ContextMenuItemIconLeft>
Expand All @@ -655,7 +652,7 @@ const ImagesTable = ({ workingImages, hasNext, loadNextPage }) => {
}
<ContextMenuItem
onSelect={handleUnlockMenuItemClick}
disabled={isAddingLabel || allObjectsUnlocked || !hasRenderedObjects}
disabled={isAddingLabel}
>
<ContextMenuItemIconLeft>
<LockOpen1Icon />
Expand Down

0 comments on commit e1d17d4

Please sign in to comment.