Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-4388 add credentials menu #2260

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,38 @@
* you may not use this file except in compliance with the License.
*/

.staticImage {
.hasMoreIndicator {
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
border-radius: 50%;
background-color: var(--theme-primary);
color: var(--theme-on-primary);
font-size: 12px;
font-weight: 700;

&:hover {
opacity: 0.8;
}
}

.staticImage,
.hasMoreIndicator {
width: 24px;
height: 24px;
}

.menu {
flex-direction: row !important;
}

.menuItem {
cursor: auto !important;
}

.menuButton {
padding: 0;
background: transparent;
outline: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
*/
import { observer } from 'mobx-react-lite';
import { Fragment } from 'react';
import { Menu, MenuButton, MenuItem, useMenuState } from 'reakit';
import styled from 'reshadow';

import { AUTH_PROVIDER_LOCAL_ID } from '@cloudbeaver/core-authentication';
import { PlaceholderComponent, s, StaticImage, useS, useTranslate } from '@cloudbeaver/core-blocks';
import { BASE_DROPDOWN_STYLES, PlaceholderComponent, s, StaticImage, useS, useTranslate } from '@cloudbeaver/core-blocks';
import type { ObjectOrigin } from '@cloudbeaver/core-sdk';

import type { IUserDetailsInfoProps } from '../UsersAdministrationService';
import style from './UserCredentialsList.m.css';

const MAX_VISIBLE_CREDENTIALS = 3;

interface IUserCredentialsProps {
origin: ObjectOrigin;
className?: string;
Expand All @@ -32,11 +36,43 @@ export const UserCredentials = observer<IUserCredentialsProps>(function UserCred
});

export const UserCredentialsList: PlaceholderComponent<IUserDetailsInfoProps> = observer(function UserCredentialsList({ user }) {
return (
const styles = useS(style);
const translate = useTranslate();
const menu = useMenuState({
placement: 'top',
gutter: 8,
});

const visibleCredentials = user.origins.slice(0, MAX_VISIBLE_CREDENTIALS);

return styled(BASE_DROPDOWN_STYLES)(
<Fragment key="user-credentials-list">
{user.origins.map(origin => (
{visibleCredentials.map(origin => (
<UserCredentials key={origin.type + origin.subType} origin={origin} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string concatenation can sometimes lead to unexpected results. it is better to use concat method. In this case subtype can be undefined so it will lead to something like: "originundefined". And if those keys are duplicated react can rerender incorrect

I believe it is better to give a unique id here with some generateId helper

))}
</Fragment>

{user.origins.length > MAX_VISIBLE_CREDENTIALS && (
<>
<MenuButton {...menu} className={s(styles, { menuButton: true })}>
<div className={s(styles, { hasMoreIndicator: true })}>
<span>+{user.origins.length - MAX_VISIBLE_CREDENTIALS}</span>
</div>
</MenuButton>

<Menu className={s(styles, { menu: true })} {...menu} modal>
{user.origins.slice(MAX_VISIBLE_CREDENTIALS).map(origin => {
const isLocal = origin.type === AUTH_PROVIDER_LOCAL_ID;
const title = isLocal ? translate('authentication_administration_user_local') : origin.displayName;

return (
<MenuItem key={origin.type + origin.subType} className={s(styles, { menuItem: true })} title={title}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with unique id

<UserCredentials origin={origin} />
</MenuItem>
);
})}
</Menu>
</>
)}
</Fragment>,
);
});
Loading