Skip to content

Commit 84df8b6

Browse files
authored
fix: Tooltip not being displayed consistently in permission row (RocketChat#36870)
1 parent de54db1 commit 84df8b6

5 files changed

Lines changed: 26 additions & 23 deletions

File tree

.changeset/strong-cars-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes an issue with inconsistent tooltip display in the permission row

apps/meteor/client/views/admin/permissions/PermissionsTable/PermissionRow.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { IRole, IPermission } from '@rocket.chat/core-typings';
2-
import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
32
import type { TranslationKey } from '@rocket.chat/ui-contexts';
43
import type { TFunction } from 'i18next';
54
import type { ReactElement } from 'react';
6-
import { useState, memo } from 'react';
5+
import { memo } from 'react';
76
import { useTranslation } from 'react-i18next';
87

98
import RoleCell from './RoleCell';
@@ -36,28 +35,15 @@ type PermissionRowProps = {
3635
const PermissionRow = ({ permission, roleList, onGrant, onRemove }: PermissionRowProps): ReactElement => {
3736
const { t } = useTranslation();
3837
const { _id, roles } = permission;
39-
const [hovered, setHovered] = useState(false);
4038
const changeRole = useChangeRole({ onGrant, onRemove, permissionId: _id });
4139

42-
const onMouseEnter = useEffectEvent(() => setHovered(true));
43-
const onMouseLeave = useEffectEvent(() => setHovered(false));
44-
4540
return (
46-
<GenericTableRow key={_id} role='link' action tabIndex={0} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
41+
<GenericTableRow key={_id} role='link' action tabIndex={0}>
4742
<GenericTableCell maxWidth='x300' withTruncatedText title={t(`${_id}_description` as TranslationKey)}>
4843
{getName(t, permission)}
4944
</GenericTableCell>
5045
{roleList.map(({ _id, name, description }) => (
51-
<RoleCell
52-
key={_id}
53-
_id={_id}
54-
name={name}
55-
description={description}
56-
grantedRoles={roles}
57-
onChange={changeRole}
58-
lineHovered={hovered}
59-
permissionId={_id}
60-
/>
46+
<RoleCell key={_id} _id={_id} name={name} description={description} grantedRoles={roles} onChange={changeRole} permissionId={_id} />
6147
))}
6248
</GenericTableRow>
6349
);

apps/meteor/client/views/admin/permissions/PermissionsTable/PermissionsTable.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const PermissionsTable = ({ roleList, permissions, setFilter, total, paginationP
2525
const grantRole = useMethod('authorization:addPermissionToRole');
2626
const removeRole = useMethod('authorization:removeRoleFromPermission');
2727

28-
const fixedColumnStyle = css`
28+
const tableCustomStyle = css`
29+
// Makes the first column of the table sticky
2930
tr > th {
3031
&:first-child {
3132
position: sticky;
@@ -43,6 +44,18 @@ const PermissionsTable = ({ roleList, permissions, setFilter, total, paginationP
4344
z-index: 11;
4445
}
4546
}
47+
48+
tr:hover {
49+
td {
50+
&:first-child {
51+
background-color: ${Palette.surface['surface-hover']};
52+
}
53+
}
54+
td > :nth-child(2) {
55+
visibility: visible;
56+
opacity: 1;
57+
}
58+
}
4659
`;
4760

4861
return (
@@ -51,7 +64,7 @@ const PermissionsTable = ({ roleList, permissions, setFilter, total, paginationP
5164
{permissions?.length === 0 && <GenericNoResults />}
5265
{permissions?.length > 0 && (
5366
<>
54-
<GenericTable className={[fixedColumnStyle]} fixed={false}>
67+
<GenericTable className={[tableCustomStyle]} fixed={false}>
5568
<GenericTableHeader>
5669
<GenericTableHeaderCell width='x120'>{t('Name')}</GenericTableHeaderCell>
5770
{roleList?.map(({ _id, name, description }) => <RoleHeader key={_id} _id={_id} name={name} description={description} />)}

apps/meteor/client/views/admin/permissions/PermissionsTable/RoleCell.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ type RoleCellProps = {
1212
name: IRole['name'];
1313
description: IRole['description'];
1414
onChange: (roleId: IRole['_id'], granted: boolean) => Promise<boolean>;
15-
lineHovered: boolean;
1615
permissionId: string;
1716
grantedRoles: IRole['_id'][];
1817
};
1918

20-
const RoleCell = ({ _id, name, description, onChange, lineHovered, permissionId, grantedRoles = [] }: RoleCellProps): ReactElement => {
19+
const RoleCell = ({ _id, name, description, onChange, permissionId, grantedRoles = [] }: RoleCellProps): ReactElement => {
2120
const [granted, setGranted] = useState(() => !!grantedRoles.includes(_id));
2221
const [loading, setLoading] = useState(false);
2322

@@ -37,7 +36,7 @@ const RoleCell = ({ _id, name, description, onChange, lineHovered, permissionId,
3736
<Margins inline={2}>
3837
<CheckBox checked={granted} onChange={handleChange} disabled={isDisabled} />
3938
{!loading && (
40-
<Box display='inline' color='hint' invisible={!lineHovered}>
39+
<Box display='inline' color='hint' invisible>
4140
{description || name}
4241
</Box>
4342
)}

apps/meteor/client/views/admin/permissions/PermissionsTable/__snapshots__/PermissionsTable.spec.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exports[`renders Default without crashing 1`] = `
3838
class="rcx-box rcx-box--full rcx-table__wrapper"
3939
>
4040
<table
41-
class="rcx-box rcx-box--full rcx-table--sticky rcx-table rcx-css-1fepnl2"
41+
class="rcx-box rcx-box--full rcx-table--sticky rcx-table rcx-css-1l69a2k"
4242
>
4343
<thead
4444
class="rcx-box rcx-box--full rcx-table__head"

0 commit comments

Comments
 (0)