Skip to content

Commit

Permalink
fix: can't hide last attribute of collection (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
kswenson authored Jul 16, 2024
1 parent 2ab7e9b commit 388e8ac
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ const AttributeMenuListComp = forwardRef<HTMLDivElement, IProps>(
isClosable: true,
})
}

// can't hide last attribute of collection
const collection = data?.getCollectionForAttribute(columnId)
const visibleAttributes = collection?.attributes
.reduce((sum, attr) => attr && !caseMetadata?.isHidden(attr.id) ? sum + 1 : sum, 0) ?? 0
const disableHideAttribute = visibleAttributes <= 1

const handleHideAttribute = () => {
caseMetadata?.applyModelChange(
() => caseMetadata?.setIsHidden(column.key, true),
Expand Down Expand Up @@ -136,7 +143,7 @@ const AttributeMenuListComp = forwardRef<HTMLDivElement, IProps>(
<MenuItem onClick={() => handleMenuItemClick("Sort Descending")}>
{t("DG.TableController.headerMenuItems.sortDescending")}
</MenuItem>
<MenuItem onClick={handleHideAttribute}>
<MenuItem onClick={handleHideAttribute} isDisabled={disableHideAttribute}>
{t("DG.TableController.headerMenuItems.hideAttribute")}
</MenuItem>
<MenuItem onClick={() => handleDeleteAttribute()} isDisabled={disableDeleteAttribute}>
Expand Down

0 comments on commit 388e8ac

Please sign in to comment.