Skip to content

Commit

Permalink
fix(TabletsStatistic): use tenant backend (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov authored Jun 20, 2023
1 parent 6378ca7 commit d290684
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
39 changes: 23 additions & 16 deletions src/components/TabletsStatistic/TabletsStatistic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import './TabletsStatistic.scss';

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

type ITablets = TFullTabletStateInfo[] | TComputeTabletStateInfo[];
type Tablets = TFullTabletStateInfo[] | TComputeTabletStateInfo[];

const prepareTablets = (tablets: ITablets) => {
const prepareTablets = (tablets: Tablets) => {
const res = tablets.map((tablet) => {
return {
label: getTabletLabel(tablet.Type),
Expand All @@ -28,25 +28,32 @@ const prepareTablets = (tablets: ITablets) => {
};

interface TabletsStatisticProps {
tablets: ITablets;
tablets: Tablets;
path: string | undefined;
nodeIds: string[] | number[];
backend?: string;
}

export const TabletsStatistic = ({tablets = [], path, nodeIds}: TabletsStatisticProps) => {
export const TabletsStatistic = ({tablets = [], path, nodeIds, backend}: TabletsStatisticProps) => {
const renderTabletInfo = (item: ReturnType<typeof prepareTablets>[number], index: number) => {
return (
<Link
to={createHref(routes.tabletsFilters, undefined, {
nodeIds,
state: item.state,
type: item.type,
path,
})}
key={index}
className={b('tablet', {state: item.state?.toLowerCase()})}
>
{item.label}: {item.count}
const tabletsPath = createHref(routes.tabletsFilters, undefined, {
nodeIds,
state: item.state,
type: item.type,
path,
backend,
});

const label = `${item.label}: ${item.count}`;
const className = b('tablet', {state: item.state?.toLowerCase()});

return backend ? (
<a href={tabletsPath} key={index} className={className}>
{label}
</a>
) : (
<Link to={tabletsPath} key={index} className={className}>
{label}
</Link>
);
};
Expand Down
30 changes: 21 additions & 9 deletions src/containers/Tenants/Tenants.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,19 @@ class Tenants extends React.Component {
const initialTenantGeneralTab = savedTenantInitialTab || TENANT_GENERAL_TABS[0].id;
const initialTenantInfoTab = TENANT_INFO_TABS[0].id;

const getTenantBackend = (tenant) => {
const backend = tenant.MonitoringEndpoint ?? tenant.backend;
return additionalTenantsInfo.tenantBackend
? additionalTenantsInfo.tenantBackend(backend)
: undefined;
};

const columns = [
{
name: 'Name',
header: 'Database',
render: ({value, row}) => {
const backend = row.MonitoringEndpoint ?? row.backend;
const tenantBackend = additionalTenantsInfo.tenantBackend
? additionalTenantsInfo.tenantBackend(backend)
: undefined;
const backend = getTenantBackend(row);
const isExternalLink = Boolean(backend);
return (
<div className={b('name-wrapper')}>
Expand All @@ -147,7 +151,7 @@ class Tenants extends React.Component {
hasClipboardButton
path={createHref(routes.tenant, undefined, {
name: value,
backend: tenantBackend,
backend,
[TenantTabsGroups.info]: initialTenantInfoTab,
[TenantTabsGroups.general]: initialTenantGeneralTab,
})}
Expand Down Expand Up @@ -287,12 +291,20 @@ class Tenants extends React.Component {
header: 'Tablets States',
sortable: false,
width: 430,
render: ({value, row}) =>
value ? (
<TabletsStatistic path={row.Name} tablets={value} nodeIds={row.NodeIds} />
render: ({value, row}) => {
const backend = getTenantBackend(row);

return value ? (
<TabletsStatistic
path={row.Name}
tablets={value}
nodeIds={row.NodeIds}
backend={backend}
/>
) : (
'—'
),
);
},
},
];

Expand Down

0 comments on commit d290684

Please sign in to comment.