-
Notifications
You must be signed in to change notification settings - Fork 16
feat(Clusters): rework versions progress bar #2642
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f7a225
feat(Clusters): rework versions progress bar
artemmufazalov 52ee19c
fix: copilot review
artemmufazalov 91b1704
fix: copilot review 2
artemmufazalov 107d2e6
fix: copilot review 3
artemmufazalov e6a662b
fix: copilot review 4
artemmufazalov 09c80c5
fix: review
artemmufazalov 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@use '../../styles/mixins.scss'; | ||
|
||
.ydb-versions-bar { | ||
&__bar { | ||
width: 100%; | ||
height: 10px; | ||
} | ||
|
||
&__titles-wrapper { | ||
width: max-content; | ||
} | ||
|
||
&__title { | ||
overflow: hidden; | ||
|
||
text-overflow: ellipsis; | ||
|
||
color: var(--g-color-text-primary); | ||
|
||
@include mixins.body-1-typography(); | ||
} | ||
|
||
&__version { | ||
min-width: 10px; | ||
|
||
border-radius: var(--g-border-radius-xs); | ||
} | ||
|
||
&__title, | ||
&__version, | ||
&__version-icon { | ||
&_dimmed { | ||
opacity: 0.5; | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import React from 'react'; | ||
|
||
import {Button, Flex, Tooltip} from '@gravity-ui/uikit'; | ||
import {debounce} from 'lodash'; | ||
|
||
import {cn} from '../../utils/cn'; | ||
import type {PreparedVersion} from '../../utils/versions/types'; | ||
|
||
import i18n from './i18n'; | ||
|
||
import './VersionsBar.scss'; | ||
|
||
const b = cn('ydb-versions-bar'); | ||
|
||
const TRUNCATION_THRESHOLD = 4; | ||
// One more line for Show more / Hide button | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const MAX_DISPLAYED_VERSIONS = TRUNCATION_THRESHOLD - 1; | ||
|
||
const HOVER_DELAY = 200; | ||
const TOOLTIP_OPEN_DELAY = 200; | ||
|
||
interface VersionsBarProps { | ||
preparedVersions: PreparedVersion[]; | ||
} | ||
|
||
export function VersionsBar({preparedVersions}: VersionsBarProps) { | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const shouldTruncateVersions = preparedVersions.length > TRUNCATION_THRESHOLD; | ||
|
||
const [hoveredVersion, setHoveredVersion] = React.useState<string | undefined>(); | ||
const [allVersionsDisplayed, setAllVersionsDisplayed] = React.useState<boolean>(false); | ||
|
||
const displayedVersions = React.useMemo(() => { | ||
const total = preparedVersions.reduce((acc, item) => acc + (item.count || 0), 0); | ||
|
||
return preparedVersions.map((item) => { | ||
return { | ||
value: ((item.count || 0) / total) * 100, | ||
color: item.color, | ||
version: item.version, | ||
count: item.count, | ||
}; | ||
}); | ||
}, [preparedVersions]); | ||
|
||
const truncatedDisplayedVersions = React.useMemo(() => { | ||
if (allVersionsDisplayed) { | ||
return preparedVersions; | ||
} | ||
|
||
return shouldTruncateVersions | ||
? preparedVersions.slice(0, MAX_DISPLAYED_VERSIONS) | ||
: preparedVersions; | ||
}, [allVersionsDisplayed, preparedVersions, shouldTruncateVersions]); | ||
|
||
const handleShowAllVersions = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
setAllVersionsDisplayed(true); | ||
}; | ||
const handleHideAllVersions = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { | ||
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
artemmufazalov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
event.preventDefault(); | ||
event.stopPropagation(); | ||
setAllVersionsDisplayed(false); | ||
}; | ||
|
||
const renderButton = () => { | ||
if (!shouldTruncateVersions) { | ||
return null; | ||
} | ||
|
||
const truncatedVersionsCount = preparedVersions.length - MAX_DISPLAYED_VERSIONS; | ||
|
||
if (allVersionsDisplayed) { | ||
return ( | ||
<Button view="flat-secondary" size={'s'} onClick={handleHideAllVersions}> | ||
{i18n('action_hide', { | ||
count: truncatedVersionsCount, | ||
})} | ||
</Button> | ||
); | ||
} else { | ||
return ( | ||
<Button view="flat-secondary" size={'s'} onClick={handleShowAllVersions}> | ||
{i18n('action_show_more', { | ||
count: truncatedVersionsCount, | ||
})} | ||
</Button> | ||
); | ||
} | ||
}; | ||
|
||
const handleMouseEnter = React.useMemo(() => { | ||
return debounce((version: string) => { | ||
setHoveredVersion(version); | ||
}, HOVER_DELAY); | ||
}, []); | ||
|
||
const handleMouseLeave = () => { | ||
handleMouseEnter.cancel(); | ||
setHoveredVersion(undefined); | ||
}; | ||
|
||
const isDimmed = (version: string) => { | ||
return hoveredVersion && hoveredVersion !== version; | ||
}; | ||
|
||
return ( | ||
<Flex gap={2} direction={'column'} className={b(null)} wrap> | ||
<Flex className={b('bar')} grow={1} gap={0.5}> | ||
{displayedVersions.map((item) => ( | ||
<Tooltip | ||
key={item.version} | ||
content={ | ||
<React.Fragment> | ||
{i18n('tooltip_nodes', {count: item.count})} | ||
<br /> | ||
{item.version} | ||
</React.Fragment> | ||
} | ||
placement={'top-start'} | ||
openDelay={TOOLTIP_OPEN_DELAY} | ||
> | ||
<span | ||
onMouseEnter={() => { | ||
handleMouseEnter(item.version); | ||
}} | ||
onMouseLeave={handleMouseLeave} | ||
className={b('version', {dimmed: isDimmed(item.version)})} | ||
style={{backgroundColor: item.color, width: `${item.value}%`}} | ||
/> | ||
</Tooltip> | ||
))} | ||
</Flex> | ||
|
||
<Flex gap={0.5} direction={'column'}> | ||
{truncatedDisplayedVersions.map((item) => ( | ||
<Tooltip | ||
key={item.version} | ||
content={i18n('tooltip_nodes', {count: item.count})} | ||
placement={'bottom-end'} | ||
openDelay={TOOLTIP_OPEN_DELAY} | ||
> | ||
<Flex gap={1} alignItems={'center'} className={b('titles-wrapper')}> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="6" | ||
height="6" | ||
viewBox="0 0 6 6" | ||
fill="none" | ||
className={b('version-icon', {dimmed: isDimmed(item.version)})} | ||
> | ||
<circle cx="3" cy="3" r="3" fill={item.color} /> | ||
</svg> | ||
<div | ||
className={b('title', {dimmed: isDimmed(item.version)})} | ||
onMouseEnter={() => { | ||
handleMouseEnter(item.version); | ||
}} | ||
onMouseLeave={handleMouseLeave} | ||
> | ||
{item.version} | ||
</div> | ||
</Flex> | ||
</Tooltip> | ||
))} | ||
<Flex>{renderButton()}</Flex> | ||
</Flex> | ||
</Flex> | ||
); | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"action_show_more": "Show {{count}} more", | ||
"action_hide": "Hide {{count}}", | ||
"tooltip_nodes": { | ||
"one": "{{count}} Node", | ||
"other": "{{count}} Nodes" | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {registerKeysets} from '../../../utils/i18n'; | ||
|
||
import en from './en.json'; | ||
|
||
const COMPONENT = 'ydb-versions-bar'; | ||
|
||
export default registerKeysets(COMPONENT, {en}); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.