Skip to content

Commit

Permalink
feat(Storage): add advanced disks view
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov committed Aug 30, 2024
1 parent cf5e090 commit 1282052
Show file tree
Hide file tree
Showing 24 changed files with 324 additions and 115 deletions.
7 changes: 4 additions & 3 deletions src/components/DiskStateProgressBar/DiskStateProgressBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
--progress-bar-border-color: var(--g-color-base-misc-heavy);
--progress-bar-background-color: var(--g-color-base-misc-light);
--progress-bar-fill-color: var(--g-color-base-misc-medium);
--progress-bar-height: var(--g-text-body-3-line-height);

position: relative;
z-index: 0;

min-width: 50px;
height: var(--g-text-body-3-line-height);
height: var(--progress-bar-height);

text-align: center;

Expand All @@ -23,8 +24,8 @@
background-color: var(--progress-bar-background-color);

&_compact {
--progress-bar-height: 12px;
min-width: 0;
height: 12px;

border-radius: 2px;
}
Expand Down Expand Up @@ -101,7 +102,7 @@

font-size: var(--g-text-body-1-font-size);
// bar height minus borders
line-height: calc(var(--g-text-body-3-line-height) - #{$border-width * 2});
line-height: calc(var(--progress-bar-height) - #{$border-width * 2});

color: inherit;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/PDiskPopup/PDiskPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const PDiskPopup = ({data, nodes, ...props}: PDiskPopupProps) => {
<Popup
contentClassName={b()}
placement={['top', 'bottom']}
hasArrow
// bigger offset for easier switching to neighbour nodes
// matches the default offset for popup with arrow out of a sense of beauty
offset={[0, 12]}
Expand Down
49 changes: 33 additions & 16 deletions src/components/VDisk/VDisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ import './VDisk.scss';

const b = cn('ydb-vdisk-component');

interface VDiskProps {
export interface VDiskProps {
data?: PreparedVDisk;
nodes?: NodesMap;
compact?: boolean;
showPopup?: boolean;
onShowPopup?: VoidFunction;
onHidePopup?: VoidFunction;
progressBarClassName?: string;
}

export const VDisk = ({data = {}, nodes, compact}: VDiskProps) => {
export const VDisk = ({
data = {},
nodes,
compact,
showPopup,
onShowPopup,
onHidePopup,
progressBarClassName,
}: VDiskProps) => {
const isFullData = isFullVDiskData(data);

const diskPagesAvailable = useDiskPagesAvailable();
Expand All @@ -32,12 +44,14 @@ export const VDisk = ({data = {}, nodes, compact}: VDiskProps) => {

const anchor = React.useRef(null);

const showPopup = () => {
const handleShowPopup = () => {
setIsPopupVisible(true);
onShowPopup?.();
};

const hidePopup = () => {
const handleHidePopup = () => {
setIsPopupVisible(false);
onHidePopup?.();
};

let vDiskPath: string | undefined;
Expand All @@ -62,23 +76,26 @@ export const VDisk = ({data = {}, nodes, compact}: VDiskProps) => {

return (
<React.Fragment>
<VDiskPopup data={data} nodes={nodes} anchorRef={anchor} open={isPopupVisible} />
<div className={b()} ref={anchor} onMouseEnter={showPopup} onMouseLeave={hidePopup}>
{vDiskPath ? (
<InternalLink to={vDiskPath} className={b('content')}>
<DiskStateProgressBar
diskAllocatedPercent={data.AllocatedPercent}
severity={data.Severity}
compact={compact}
/>
</InternalLink>
) : (
<VDiskPopup
data={data}
nodes={nodes}
anchorRef={anchor}
open={isPopupVisible || showPopup}
/>
<div
className={b()}
ref={anchor}
onMouseEnter={handleShowPopup}
onMouseLeave={handleHidePopup}
>
<InternalLink to={vDiskPath} className={b('content')}>
<DiskStateProgressBar
diskAllocatedPercent={data.AllocatedPercent}
severity={data.Severity}
compact={compact}
className={progressBarClassName}
/>
)}
</InternalLink>
</div>
</React.Fragment>
);
Expand Down
16 changes: 6 additions & 10 deletions src/components/VDisk/VDiskWithDonorsStack.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
import type {NodesMap} from '../../types/store/nodesList';
import {stringifyVdiskId} from '../../utils/dataFormatters/dataFormatters';
import {isFullVDiskData} from '../../utils/disks/helpers';
import type {PreparedVDisk} from '../../utils/disks/types';
import {Stack} from '../Stack/Stack';

import type {VDiskProps} from './VDisk';
import {VDisk} from './VDisk';

interface VDiskWithDonorsStackProps {
interface VDiskWithDonorsStackProps extends VDiskProps {
data?: PreparedVDisk;
nodes?: NodesMap;
compact?: boolean;
className?: string;
stackClassName?: string;
}

export function VDiskWithDonorsStack({
data,
nodes,
compact,
className,
stackClassName,
...restProps
}: VDiskWithDonorsStackProps) {
const donors = data?.Donors;

const content =
donors && donors.length > 0 ? (
<Stack className={stackClassName}>
<VDisk data={data} nodes={nodes} compact={compact} />
<VDisk data={data} {...restProps} />
{donors.map((donor) => {
const isFullData = isFullVDiskData(donor);

Expand All @@ -35,14 +32,13 @@ export function VDiskWithDonorsStack({
<VDisk
key={stringifyVdiskId(isFullData ? donor.VDiskId : donor)}
data={donor}
nodes={nodes}
compact={compact}
{...restProps}
/>
);
})}
</Stack>
) : (
<VDisk data={data} nodes={nodes} compact={compact} />
<VDisk data={data} {...restProps} />
);

return <div className={className}>{content}</div>;
Expand Down
1 change: 1 addition & 0 deletions src/components/VDiskPopup/VDiskPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const VDiskPopup = ({data, nodes, ...props}: VDiskPopupProps) => {
<Popup
contentClassName={b()}
placement={['top', 'bottom']}
hasArrow
// bigger offset for easier switching to neighbour nodes
// matches the default offset for popup with arrow out of a sense of beauty
offset={[0, 12]}
Expand Down
16 changes: 4 additions & 12 deletions src/containers/PDiskPage/PDiskGroups/PDiskGroups.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import React from 'react';

import {ResizeableDataTable} from '../../../components/ResizeableDataTable/ResizeableDataTable';
import {TableSkeleton} from '../../../components/TableSkeleton/TableSkeleton';
import {selectNodesMap} from '../../../store/reducers/nodesList';
import {pDiskApi} from '../../../store/reducers/pdisk/pdisk';
import {DEFAULT_TABLE_SETTINGS} from '../../../utils/constants';
import {useAutoRefreshInterval, useTypedSelector} from '../../../utils/hooks';
import {
STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY,
getDiskPageStorageColumns,
} from '../../Storage/StorageGroups/getStorageGroupsColumns';
import {useAutoRefreshInterval} from '../../../utils/hooks';
import {STORAGE_GROUPS_COLUMNS_WIDTH_LS_KEY} from '../../Storage/StorageGroups/getStorageGroupsColumns';
import {useGetDiskStorageColumns} from '../../Storage/StorageGroups/hooks';

interface PDiskGroupsProps {
nodeId: string | number;
pDiskId: string | number;
}

export function PDiskGroups({pDiskId, nodeId}: PDiskGroupsProps) {
const nodesMap = useTypedSelector(selectNodesMap);
const [autoRefreshInterval] = useAutoRefreshInterval();

const pDiskStorageQuery = pDiskApi.useGetStorageInfoQuery(
Expand All @@ -27,9 +21,7 @@ export function PDiskGroups({pDiskId, nodeId}: PDiskGroupsProps) {
const loading = pDiskStorageQuery.isFetching && pDiskStorageQuery.currentData === undefined;
const data = pDiskStorageQuery.currentData ?? [];

const pDiskStorageColumns = React.useMemo(() => {
return getDiskPageStorageColumns(nodesMap);
}, [nodesMap]);
const pDiskStorageColumns = useGetDiskStorageColumns();

if (loading) {
return <TableSkeleton />;
Expand Down
46 changes: 46 additions & 0 deletions src/containers/Storage/Disks/Disks.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.ydb-storage-disks {
display: flex;
flex-direction: row;
align-items: center;
gap: 20px;

width: max-content;

&__vdisks-wrapper {
display: flex;
flex-grow: 1;
flex-direction: row;
gap: 4px;

width: 300px;
}

&__pdisks-wrapper {
display: flex;
flex-direction: row;
justify-content: left;
gap: 6px;

width: max-content;
}

&__vdisk-item {
flex-basis: 8px;
flex-shrink: 0;
}
&__vdisk-progress-bar {
--progress-bar-height: 18px;

border-radius: 4px;
}

&__pdisk-item {
width: 80px;
}
&__pdisk-progress-bar {
--progress-bar-height: 20px;
padding-left: var(--g-spacing-2);

text-align: left;
}
}
76 changes: 76 additions & 0 deletions src/containers/Storage/Disks/Disks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';

import {VDiskWithDonorsStack} from '../../../components/VDisk/VDiskWithDonorsStack';
import type {NodesMap} from '../../../types/store/nodesList';
import {cn} from '../../../utils/cn';
import {stringifyVdiskId} from '../../../utils/dataFormatters/dataFormatters';
import type {PreparedVDisk} from '../../../utils/disks/types';
import {PDisk} from '../PDisk';

import './Disks.scss';

const b = cn('ydb-storage-disks');

interface DisksProps {
vDisks?: PreparedVDisk[];
nodes?: NodesMap;
}

export function Disks({vDisks = [], nodes}: DisksProps) {
const [highlightedVDisk, setHighlightedVDisk] = React.useState<string | undefined>();

return (
<div className={b(null)}>
<div className={b('vdisks-wrapper')}>
{vDisks?.map((vDisk) => {
// Do not show PDisk popup for VDisk
const vDiskToShow = {...vDisk, PDisk: undefined};

const vDiskId = stringifyVdiskId(vDisk.VDiskId);

return (
<div
key={stringifyVdiskId(vDisk.VDiskId)}
style={{
flexGrow: Number(vDisk.AllocatedSize) || 1,
}}
className={b('vdisk-item')}
>
<VDiskWithDonorsStack
data={vDiskToShow}
nodes={nodes}
compact={true}
showPopup={highlightedVDisk === vDiskId}
onShowPopup={() => setHighlightedVDisk(vDiskId)}
onHidePopup={() => setHighlightedVDisk(undefined)}
progressBarClassName={b('vdisk-progress-bar')}
/>
</div>
);
})}
</div>

<div className={b('pdisks-wrapper')}>
{vDisks?.map((vDisk) => {
const vDiskId = stringifyVdiskId(vDisk.VDiskId);

if (!vDisk.PDisk) {
return null;
}

return (
<PDisk
key={vDisk.PDisk.PDiskId}
className={b('pdisk-item')}
progressBarClassName={b('pdisk-progress-bar')}
data={vDisk.PDisk}
showPopup={highlightedVDisk === vDiskId}
onShowPopup={() => setHighlightedVDisk(vDiskId)}
onHidePopup={() => setHighlightedVDisk(undefined)}
/>
);
})}
</div>
</div>
);
}
6 changes: 4 additions & 2 deletions src/containers/Storage/PDisk/PDisk.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@

&__media-type {
position: absolute;
top: 0;
top: 50%;
right: 4px;

font-size: var(--g-text-body-1-font-size);
line-height: var(--g-text-body-3-line-height);
line-height: var(--g-text-body-1-line-height);

color: var(--g-color-text-secondary);

transform: translateY(-50%);
}
}
Loading

0 comments on commit 1282052

Please sign in to comment.