Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Components/Versions): display more columns of node types [YTFRON…
Browse files Browse the repository at this point in the history
…T-4406]
KostyaAvtushko committed Jan 30, 2025
1 parent b052987 commit 6b0b04f
Showing 3 changed files with 29 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import {getCluster} from '../../../../store/selectors/global';
import {ThunkAction} from 'redux-thunk';
import {RootState} from '../../../../store/reducers';
import {
HostType,
SummaryItem,
VersionHostInfo,
VersionSummaryItem,
@@ -24,7 +23,7 @@ export interface DiscoverVersionsData {
summary: Record<'total' | 'error' | string, VersionSummary>;
}

type VersionSummary = Record<HostType, SummaryItem>;
type VersionSummary = Record<string, SummaryItem>;

type NodesThunkAction<T = void> = ThunkAction<Promise<T>, RootState, unknown, any>;

@@ -97,7 +96,7 @@ function prepareGroup(group: VersionSummary, version: string) {
(acc, value, type) => {
const {total, banned, offline} = value;

const k = type as HostType;
const k = type;
acc[k] = total;
acc.banned += banned;
acc.offline += offline;
Original file line number Diff line number Diff line change
@@ -36,29 +36,18 @@ export interface SummaryItem {

export type VersionHostState = 'online' | 'offline' | 'banned';

export type HostType =
| 'controller_agent'
| 'primary_master'
| 'secondary_master'
| 'node'
| 'cluster_node'
| 'http_proxy'
| 'rpc_proxy'
| 'scheduler'
| 'job_proxy';

export interface VersionHostInfo {
address: string;
banned: boolean;
type: HostType;
type: string;
version: string;
start_time: string;
state: string;
offline: boolean;
error: unknown;
}

export type VersionSummaryItem = Partial<Record<HostType, number>> &
export type VersionSummaryItem = Partial<Record<string, number>> &
Record<'banned' | 'online' | 'offline', number> & {version: string};

const ephemeralState: VersionsState = {
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import {RootState} from '../../../../store/reducers';
import {FIX_MY_TYPE, SortState} from '../../../../types';
import {sortArrayBySortState} from '../../../../utils/sort-helpers';
import {VersionSummaryItem} from '../../../../store/reducers/components/versions/versions_v2';
import {isSupportedClusterNodeForVersions} from '../../../../store/selectors/thor/support';
import format from '../.../../../../../common/hammer/format';

export const getSummarySortState = (
state: RootState,
@@ -39,39 +39,33 @@ export const getVersionsSummaryData = createSelector(
},
);

export const getVersionsSummaryVisibleColumns = createSelector(
[getSummary, isSupportedClusterNodeForVersions],
(summary = [], useClusterNode) => {
const visibleTypes = new Set<string>();
const total = getTotalElementOfSummary(summary);
Object.keys(total ?? {}).forEach((k) => {
const key = k as keyof typeof total;
if (total?.[key]) {
visibleTypes.add(key);
}
});
const res: Array<{type: keyof VersionSummaryItem; name: string; shortName: string}> = [];
function tryToAdd(type: keyof VersionSummaryItem, name: string, shortName = '') {
if (visibleTypes.has(type)) {
res.push({type, name, shortName});
}
export const getVersionsSummaryVisibleColumns = createSelector([getSummary], (summary = []) => {
const visibleTypes = new Set<string>();
const total = getTotalElementOfSummary(summary);
Object.keys(total ?? {}).forEach((k) => {
const key = k as keyof typeof total;
if (total?.[key]) {
visibleTypes.add(key);
}
});
const res: Array<{type: keyof VersionSummaryItem; name: string; shortName: string}> = [];
function tryToAdd(type: keyof VersionSummaryItem, name: string, shortName = '') {
if (visibleTypes.has(type)) {
res.push({type, name, shortName});
}
}

tryToAdd('primary_master', 'Primary Masters', 'Pri Masters');
tryToAdd('secondary_master', 'Secondary masters', 'Sec Masters');
tryToAdd('scheduler', 'Schedulers');
tryToAdd('controller_agent', 'Controller Agents', 'CA');
tryToAdd(useClusterNode ? 'cluster_node' : 'node', 'Nodes');
tryToAdd('http_proxy', 'HTTP Proxies');
tryToAdd('rpc_proxy', 'RPC Proxies');
tryToAdd('job_proxy', 'Job Proxies');
tryToAdd('online', 'Online');
tryToAdd('offline', 'Offline');
tryToAdd('banned', 'Banned');
for (const key in summary[summary.length - 1]) {
if (['online', 'offline', 'banned', 'total'].includes(key)) continue;
tryToAdd(key, format.Readable(key));
}

return res;
},
);
tryToAdd('online', 'Online');
tryToAdd('offline', 'Offline');
tryToAdd('banned', 'Banned');

return res;
});

function getTotalElementOfSummary(summary: ReturnType<typeof getSummary>) {
return summary[summary.length - 1];

0 comments on commit 6b0b04f

Please sign in to comment.