Skip to content

Commit d290684

Browse files
fix(TabletsStatistic): use tenant backend (#429)
1 parent 6378ca7 commit d290684

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

src/components/TabletsStatistic/TabletsStatistic.tsx

+23-16
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import './TabletsStatistic.scss';
1212

1313
const b = cn('tablets-statistic');
1414

15-
type ITablets = TFullTabletStateInfo[] | TComputeTabletStateInfo[];
15+
type Tablets = TFullTabletStateInfo[] | TComputeTabletStateInfo[];
1616

17-
const prepareTablets = (tablets: ITablets) => {
17+
const prepareTablets = (tablets: Tablets) => {
1818
const res = tablets.map((tablet) => {
1919
return {
2020
label: getTabletLabel(tablet.Type),
@@ -28,25 +28,32 @@ const prepareTablets = (tablets: ITablets) => {
2828
};
2929

3030
interface TabletsStatisticProps {
31-
tablets: ITablets;
31+
tablets: Tablets;
3232
path: string | undefined;
3333
nodeIds: string[] | number[];
34+
backend?: string;
3435
}
3536

36-
export const TabletsStatistic = ({tablets = [], path, nodeIds}: TabletsStatisticProps) => {
37+
export const TabletsStatistic = ({tablets = [], path, nodeIds, backend}: TabletsStatisticProps) => {
3738
const renderTabletInfo = (item: ReturnType<typeof prepareTablets>[number], index: number) => {
38-
return (
39-
<Link
40-
to={createHref(routes.tabletsFilters, undefined, {
41-
nodeIds,
42-
state: item.state,
43-
type: item.type,
44-
path,
45-
})}
46-
key={index}
47-
className={b('tablet', {state: item.state?.toLowerCase()})}
48-
>
49-
{item.label}: {item.count}
39+
const tabletsPath = createHref(routes.tabletsFilters, undefined, {
40+
nodeIds,
41+
state: item.state,
42+
type: item.type,
43+
path,
44+
backend,
45+
});
46+
47+
const label = `${item.label}: ${item.count}`;
48+
const className = b('tablet', {state: item.state?.toLowerCase()});
49+
50+
return backend ? (
51+
<a href={tabletsPath} key={index} className={className}>
52+
{label}
53+
</a>
54+
) : (
55+
<Link to={tabletsPath} key={index} className={className}>
56+
{label}
5057
</Link>
5158
);
5259
};

src/containers/Tenants/Tenants.js

+21-9
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,19 @@ class Tenants extends React.Component {
126126
const initialTenantGeneralTab = savedTenantInitialTab || TENANT_GENERAL_TABS[0].id;
127127
const initialTenantInfoTab = TENANT_INFO_TABS[0].id;
128128

129+
const getTenantBackend = (tenant) => {
130+
const backend = tenant.MonitoringEndpoint ?? tenant.backend;
131+
return additionalTenantsInfo.tenantBackend
132+
? additionalTenantsInfo.tenantBackend(backend)
133+
: undefined;
134+
};
135+
129136
const columns = [
130137
{
131138
name: 'Name',
132139
header: 'Database',
133140
render: ({value, row}) => {
134-
const backend = row.MonitoringEndpoint ?? row.backend;
135-
const tenantBackend = additionalTenantsInfo.tenantBackend
136-
? additionalTenantsInfo.tenantBackend(backend)
137-
: undefined;
141+
const backend = getTenantBackend(row);
138142
const isExternalLink = Boolean(backend);
139143
return (
140144
<div className={b('name-wrapper')}>
@@ -147,7 +151,7 @@ class Tenants extends React.Component {
147151
hasClipboardButton
148152
path={createHref(routes.tenant, undefined, {
149153
name: value,
150-
backend: tenantBackend,
154+
backend,
151155
[TenantTabsGroups.info]: initialTenantInfoTab,
152156
[TenantTabsGroups.general]: initialTenantGeneralTab,
153157
})}
@@ -287,12 +291,20 @@ class Tenants extends React.Component {
287291
header: 'Tablets States',
288292
sortable: false,
289293
width: 430,
290-
render: ({value, row}) =>
291-
value ? (
292-
<TabletsStatistic path={row.Name} tablets={value} nodeIds={row.NodeIds} />
294+
render: ({value, row}) => {
295+
const backend = getTenantBackend(row);
296+
297+
return value ? (
298+
<TabletsStatistic
299+
path={row.Name}
300+
tablets={value}
301+
nodeIds={row.NodeIds}
302+
backend={backend}
303+
/>
293304
) : (
294305
'—'
295-
),
306+
);
307+
},
296308
},
297309
];
298310

0 commit comments

Comments
 (0)