1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-13 11:17:26 +02:00

feat: show users with multiple parallel sessions (#8756)

This commit is contained in:
Tymoteusz Czech 2024-11-15 11:34:38 +01:00 committed by GitHub
parent f89bc33645
commit 9d5fceb5bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 78 additions and 8 deletions

View File

@ -0,0 +1,38 @@
import type { FC } from 'react';
import { IconCell } from 'component/common/Table/cells/IconCell/IconCell';
import WarningIcon from '@mui/icons-material/WarningAmber';
import { Tooltip } from '@mui/material';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { useVariant } from 'hooks/useVariant';
type UserSessionsCellProps = {
count?: number;
};
export const UserSessionsCell: FC<UserSessionsCellProps> = ({ count }) => {
const { uiConfig } = useUiConfig();
const minimumCountToShow = useVariant<number>(
uiConfig.flags.showUserDeviceCount,
);
if (!count || count < (minimumCountToShow ? minimumCountToShow : 5)) {
return null;
}
return (
<IconCell
icon={
<>
<Tooltip
title={`Multiple parallel browser sessions (${count})`}
>
<WarningIcon
aria-label='Multiple parallel browser sessions'
color='warning'
/>
</Tooltip>
</>
}
/>
);
};

View File

@ -39,6 +39,7 @@ import { StyledUsersLinkDiv } from '../Users.styles';
import { useUiFlag } from 'hooks/useUiFlag'; import { useUiFlag } from 'hooks/useUiFlag';
import useUiConfig from '../../../../hooks/api/getters/useUiConfig/useUiConfig'; import useUiConfig from '../../../../hooks/api/getters/useUiConfig/useUiConfig';
import { useScimSettings } from 'hooks/api/getters/useScimSettings/useScimSettings'; import { useScimSettings } from 'hooks/api/getters/useScimSettings/useScimSettings';
import { UserSessionsCell } from './UserSessionsCell/UserSessionsCell';
const UsersList = () => { const UsersList = () => {
const navigate = useNavigate(); const navigate = useNavigate();
@ -57,6 +58,8 @@ const UsersList = () => {
open: false, open: false,
}); });
const userAccessUIEnabled = useUiFlag('userAccessUIEnabled'); const userAccessUIEnabled = useUiFlag('userAccessUIEnabled');
const showUserDeviceCount = useUiFlag('showUserDeviceCount');
const { const {
settings: { enabled: scimEnabled }, settings: { enabled: scimEnabled },
} = useScimSettings(); } = useScimSettings();
@ -139,7 +142,7 @@ const UsersList = () => {
id: 'name', id: 'name',
Header: 'Name', Header: 'Name',
accessor: (row: any) => row.name || '', accessor: (row: any) => row.name || '',
minWidth: 200, minWidth: 180,
Cell: ({ row: { original: user } }: any) => ( Cell: ({ row: { original: user } }: any) => (
<HighlightCell <HighlightCell
value={user.name} value={user.name}
@ -148,6 +151,21 @@ const UsersList = () => {
), ),
searchable: true, searchable: true,
}, },
...(showUserDeviceCount
? [
{
id: 'warning',
Header: ' ',
accessor: (row: any) => row.name || '',
maxWidth: 40,
Cell: ({ row: { original: user } }: any) => (
<UserSessionsCell count={user.activeSessions} />
),
searchable: false,
disableSortBy: true,
},
]
: []),
{ {
id: 'role', id: 'role',
Header: 'Role', Header: 'Role',
@ -283,7 +301,7 @@ const UsersList = () => {
}, },
{ {
condition: isSmallScreen, condition: isSmallScreen,
columns: ['createdAt', 'last-login'], columns: ['createdAt', 'last-login', 'warning'],
}, },
], ],
setHiddenColumns, setHiddenColumns,
@ -356,7 +374,10 @@ const UsersList = () => {
} }
elseShow={ elseShow={
<TablePlaceholder> <TablePlaceholder>
No users available. Get started by adding one. <span data-loading>
No users available. Get started by adding
one.
</span>
</TablePlaceholder> </TablePlaceholder>
} }
/> />

View File

@ -93,6 +93,7 @@ export type UiFlags = {
'enterprise-payg'?: boolean; 'enterprise-payg'?: boolean;
simplifyProjectOverview?: boolean; simplifyProjectOverview?: boolean;
productivityReportEmail?: boolean; productivityReportEmail?: boolean;
showUserDeviceCount?: Variant;
flagOverviewRedesign?: boolean; flagOverviewRedesign?: boolean;
}; };

View File

@ -1,5 +1,5 @@
import { PayloadType, type Variant } from 'unleash-client'; import { PayloadType, type Variant } from 'unleash-client';
import { parseEnvVarBoolean } from '../util'; import { parseEnvVarBoolean, parseEnvVarNumber } from '../util';
import { getDefaultVariant } from 'unleash-client/lib/variant'; import { getDefaultVariant } from 'unleash-client/lib/variant';
export type IFlagKey = export type IFlagKey =
@ -289,10 +289,20 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_FLAG_OVERVIEW_REDESIGN, process.env.UNLEASH_EXPERIMENTAL_FLAG_OVERVIEW_REDESIGN,
false, false,
), ),
showUserDeviceCount: parseEnvVarBoolean( showUserDeviceCount: {
name: 'showUserDeviceCount',
enabled: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_SHOW_USER_DEVICE_COUNT, process.env.UNLEASH_EXPERIMENTAL_SHOW_USER_DEVICE_COUNT,
false, false,
), ),
payload: {
type: PayloadType.NUMBER,
value: `${parseEnvVarNumber(
process.env.UNLEASH_EXPERIMENTAL_WARN_ABOVE_SESSION_COUNT,
0,
)}`,
},
},
}; };
export const defaultExperimentalOptions: IExperimentalOptions = { export const defaultExperimentalOptions: IExperimentalOptions = {