-
Notifications
You must be signed in to change notification settings - Fork 392
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
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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} /> | ||
))} | ||
</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}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here with unique id |
||
<UserCredentials origin={origin} /> | ||
</MenuItem> | ||
); | ||
})} | ||
</Menu> | ||
</> | ||
)} | ||
</Fragment>, | ||
); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 incorrectI believe it is better to give a unique id here with some
generateId
helper