Skip to content

Commit

Permalink
fix: fix reducers names
Browse files Browse the repository at this point in the history
  • Loading branch information
krosy1337 committed Oct 17, 2023
1 parent 5beab67 commit f8ccbba
Show file tree
Hide file tree
Showing 26 changed files with 272 additions and 447 deletions.
6 changes: 6 additions & 0 deletions src/components/UsageLabel/UsageLabel.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.ydb-usage-label {
&_overload {
color: var(--yc-color-text-light-primary);
background-color: var(--yc-color-base-danger-heavy);
}
}
18 changes: 18 additions & 0 deletions src/components/UsageLabel/UsageLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import cn from 'bem-cn-lite';

import {Label, type LabelProps} from '@gravity-ui/uikit';

const b = cn('ydb-usage-label');

interface UsageLabelProps extends LabelProps {
value: number | string;
overloadThreshold?: number;
}

export function UsageLabel({value, overloadThreshold = 90, theme}: UsageLabelProps) {
return (
<Label theme={theme} className={b({overload: Number(value) >= overloadThreshold})}>
{value || 0}%
</Label>
);
}
7 changes: 0 additions & 7 deletions src/containers/Nodes/Nodes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,4 @@
&__node_unavailable {
opacity: 0.6;
}

&__usage-label {
&_overload {
color: var(--yc-color-text-light-primary);
background-color: var(--yc-color-base-danger-heavy);
}
}
}
39 changes: 15 additions & 24 deletions src/containers/Nodes/getNodesColumns.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import cn from 'bem-cn-lite';

import DataTable, {type Column} from '@gravity-ui/react-data-table';
import {Label, Popover} from '@gravity-ui/uikit';
import {Popover} from '@gravity-ui/uikit';

import {PoolsGraph} from '../../components/PoolsGraph/PoolsGraph';
import {ProgressViewer} from '../../components/ProgressViewer/ProgressViewer';
import {TabletsStatistic} from '../../components/TabletsStatistic';
import {NodeHostWrapper} from '../../components/NodeHostWrapper/NodeHostWrapper';
import {formatBytesToGigabyte} from '../../utils/dataFormatters/dataFormatters';
import type {NodesPreparedEntity} from '../../store/reducers/nodes/types';
import type {NodeAddress} from '../../types/additionalProps';
import type {GetNodeRefFunc} from '../../types/additionalProps';
import {getLoadSeverityForNode} from '../../store/reducers/tenantOverview/topNodesByLoad/utils';

const b = cn('node');
import {UsageLabel} from '../../components/UsageLabel/UsageLabel';

const NODES_COLUMNS_IDS = {
NodeId: 'NodeId',
Expand All @@ -25,11 +22,12 @@ const NODES_COLUMNS_IDS = {
CPU: 'CPU',
LoadAverage: 'LoadAverage',
Tablets: 'Tablets',
TopNodesLoadAverage: 'TopNodesLoadAverage',
};

interface GetNodesColumnsProps {
tabletsPath?: string;
getNodeRef?: (node?: NodeAddress) => string | null;
getNodeRef?: GetNodeRefFunc;
}

const nodeIdColumn: Column<NodesPreparedEntity> = {
Expand All @@ -41,7 +39,7 @@ const nodeIdColumn: Column<NodesPreparedEntity> = {
};

const getHostColumn = (
getNodeRef?: (node?: NodeAddress) => string | null,
getNodeRef?: GetNodeRefFunc,
fixedWidth = false,
): Column<NodesPreparedEntity> => ({
name: NODES_COLUMNS_IDS.Host,
Expand Down Expand Up @@ -154,21 +152,14 @@ const getTabletsColumn = (tabletsPath?: string): Column<NodesPreparedEntity> =>
});

const topNodesLoadAverageColumn: Column<NodesPreparedEntity> = {
name: NODES_COLUMNS_IDS.LoadAverage,
name: NODES_COLUMNS_IDS.TopNodesLoadAverage,
header: 'Load',
sortAccessor: ({LoadAverage = []}) =>
LoadAverage.slice(0, 1).reduce((acc, item) => acc + item, 0),
defaultOrder: DataTable.DESCENDING,
render: ({row}) =>
row.LoadAverage && row.LoadAverage.length > 0 ? (
<>
<Label
theme={getLoadSeverityForNode(row.LoadAverage[0])}
className={b('usage-label', {overload: row.LoadAverage[0] >= 90})}
>
{row.LoadAverage[0].toFixed()}%
</Label>
</>
<UsageLabel
value={row.LoadAverage[0].toFixed()}
theme={getLoadSeverityForNode(row.LoadAverage[0])}
/>
) : (
'—'
),
Expand All @@ -195,14 +186,14 @@ export function getNodesColumns({
];
}

export function getTopNodesColumns(
getNodeRef?: (node?: NodeAddress) => string | null,
export function getTopNodesByLoadColumns(
getNodeRef?: GetNodeRefFunc,
): Column<NodesPreparedEntity>[] {
return [topNodesLoadAverageColumn, nodeIdColumn, getHostColumn(getNodeRef), versionColumn];
}

export function getTopPoolsColumns(
getNodeRef?: (node?: NodeAddress) => string | null,
export function getTopNodesByCpuColumns(
getNodeRef?: GetNodeRefFunc,
): Column<NodesPreparedEntity>[] {
return [cpuColumn, nodeIdColumn, getHostColumn(getNodeRef)];
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {useSelector} from 'react-redux';

import type {AdditionalNodesProps} from '../../../../../types/additionalProps';
import type {EPathType, TEvDescribeSchemeResult} from '../../../../../types/api/schema';
import {TopNodesByLoad} from './TopNodesByLoad';
import {TopNodesByCpu} from './TopNodesByCpu';
import {TopShards} from './TopShards';
Expand All @@ -13,21 +10,10 @@ interface TenantCpuProps {
}

export function TenantCpu({path, additionalNodesProps}: TenantCpuProps) {
const {currentSchemaPath, currentSchema: currentItem = {}} = useSelector(
(state: any) => state.schema,
);
const {PathType: preloadedPathType} = useSelector(
(state: any) => state.schema.data[currentSchemaPath]?.PathDescription?.Self || {},
);
const {PathType: currentPathType} =
(currentItem as TEvDescribeSchemeResult).PathDescription?.Self || {};

const type: EPathType | undefined = preloadedPathType || currentPathType;

return (
<>
<TopNodesByLoad path={path} type={type} additionalNodesProps={additionalNodesProps} />
<TopNodesByCpu path={path} type={type} additionalNodesProps={additionalNodesProps} />
<TopNodesByLoad path={path} additionalNodesProps={additionalNodesProps} />
<TopNodesByCpu path={path} additionalNodesProps={additionalNodesProps} />
<TopShards path={path} />
<TopQueries path={path} />
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,89 +1,53 @@
import cn from 'bem-cn-lite';
import {useDispatch} from 'react-redux';
import {useCallback} from 'react';

import DataTable from '@gravity-ui/react-data-table';

import {
TENANT_OVERVIEW_TABLES_LIMIT,
TENANT_OVERVIEW_TABLES_SETTINGS,
} from '../../../../../utils/constants';
import {useAutofetcher, useTypedSelector} from '../../../../../utils/hooks';
import {
getTopComputeNodesByCpu,
getTopNodesByCpu,
selectTopNodesByCpu,
setDataWasNotLoaded,
} from '../../../../../store/reducers/tenantOverview/topNodesByCpu/topNodesByCpu';
import type {EPathType} from '../../../../../types/api/schema';
import type {AdditionalNodesProps} from '../../../../../types/additionalProps';
import {TableSkeleton} from '../../../../../components/TableSkeleton/TableSkeleton';
import {ResponseError} from '../../../../../components/Errors/ResponseError';
import {getTopPoolsColumns} from '../../../../Nodes/getNodesColumns';
import {isDatabaseEntityType} from '../../../utils/schema';
import {getTopNodesByCpuColumns} from '../../../../Nodes/getNodesColumns';
import {TenantOverviewTableLayout} from '../TenantOverviewTableLayout';

import i18n from '../i18n';
import './TenantCpu.scss';

const b = cn('tenant-overview-cpu');

interface TopNodesByCpuProps {
path?: string;
type?: EPathType;
path: string;
additionalNodesProps?: AdditionalNodesProps;
}

export function TopNodesByCpu({path, type, additionalNodesProps}: TopNodesByCpuProps) {
export function TopNodesByCpu({path, additionalNodesProps}: TopNodesByCpuProps) {
const dispatch = useDispatch();

const {wasLoaded, loading, error} = useTypedSelector((state) => state.topNodesByCpu);
const {autorefresh} = useTypedSelector((state) => state.schema);
const topNodes = useTypedSelector(selectTopNodesByCpu);
const columns = getTopPoolsColumns(additionalNodesProps?.getNodeRef);
const columns = getTopNodesByCpuColumns(additionalNodesProps?.getNodeRef);

const fetchNodes = useCallback(
(isBackground) => {
if (!isBackground) {
dispatch(setDataWasNotLoaded());
}

// For not DB entities we always use /compute endpoint instead of /nodes
// since /nodes can return data only for tenants
if (path && !isDatabaseEntityType(type)) {
dispatch(getTopComputeNodesByCpu({path}));
} else {
dispatch(getTopNodesByCpu({tenant: path}));
}
dispatch(getTopNodesByCpu({tenant: path}));
},
[dispatch, path, type],
[dispatch, path],
);

useAutofetcher(fetchNodes, [fetchNodes], autorefresh);

const renderContent = () => {
if (error) {
return <ResponseError error={error} />;
}

if (loading && !wasLoaded) {
return <TableSkeleton rows={TENANT_OVERVIEW_TABLES_LIMIT} />;
}

return (
<DataTable
theme="yandex-cloud"
data={topNodes || []}
columns={columns}
settings={TENANT_OVERVIEW_TABLES_SETTINGS}
emptyDataMessage={i18n('top-nodes.empty-data')}
/>
);
};

return (
<>
<div className={b('title')}>Top nodes by pools usage</div>
<div className={b('table')}>{renderContent()}</div>
</>
<TenantOverviewTableLayout
data={topNodes || []}
columns={columns}
title="Top nodes by pools usage"
loading={loading}
wasLoaded={wasLoaded}
error={error}
emptyDataMessage={i18n('top-nodes.empty-data')}
/>
);
}
Loading

0 comments on commit f8ccbba

Please sign in to comment.