import React, { useEffect } from 'react';
import { connect } from 'dva';
import { Redirect, history } from 'umi';
import JSONPretty from 'react-json-pretty';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Tabs, Card, Table, Typography, Spin } from 'antd';
import Masonry from 'react-masonry-css';
import { masonryBreakpointCols } from '@/pages/onnet-portal/core/utils/props';
import styles from './style.less';
const { Title, Text } = Typography;
const { TabPane } = Tabs;
const ZoneInfo = props => {
const { dispatch, settings, kz_login, kz_account = {}, kz_system_status = {}, location } = props;
useEffect(() => {
if (kz_account.data) {
if (!kz_account.data.superduper_admin) {
history.push('/int/dashboard');
}
}
}, [kz_account, kz_system_status]);
if (kz_system_status.data) {
if (!kz_system_status.data[location.state.zone]) {
console.log(
'Absent zone name. Redirecting to dashboard. kz_system_status: ',
kz_system_status,
);
return ;
}
} else {
dispatch({
type: 'kz_system_status/refresh',
payload: { account_id: kz_login.data.account_id },
});
return (
);
}
const kapps = Object.values(kz_system_status.data[location.state.zone].kazoo_apps);
const kamailios = kz_system_status.data[location.state.zone].kamailio
? Object.values(kz_system_status.data[location.state.zone].kamailio)
: [];
const list = kapps.concat(kamailios);
const getDataSource = item => {
if (item.node.includes('kamailio')) {
return [
{
key: '1',
name: 'Version',
value: item.version,
},
{
key: '2',
name: 'Memory Usage',
value: item.used_memory,
},
{
key: '3',
name: 'Broker',
value: item.broker,
},
{
key: '4',
name: 'Registrations',
value: item.roles.Registrar.Registrations,
},
{
key: '5',
name: 'Dispatcher',
value: ,
},
];
}
if (item.node.includes('kazoo_apps')) {
return [
{
key: '1',
name: 'Version',
value: item.version,
},
{
key: '2',
name: 'Memory Usage',
value: item.used_memory,
},
{
key: '3',
name: 'Processes',
value: item.processes,
},
{
key: '4',
name: 'Ports',
value: item.ports,
},
{
key: '5',
name: 'Broker',
value: item.broker,
},
{
key: '6',
name: 'Node Info',
// value: JSON.stringify(item.node_info, undefined, 2),
value: ,
},
{
key: '7',
name: 'Kapps',
value: item.kapps.map(kapp => `${kapp} `),
},
{
key: '8',
name: 'Registrations',
value: item.registrations,
},
];
}
if (item.node.includes('freeswitch')) {
return [];
}
return [];
};
const select_avatar_img = item => {
if (item.node.includes('kamailio')) {
return '/icons/kamailioicon.svg';
}
if (item.node.includes('freeswitch')) {
return '/icons/fsicon.svg';
}
return '/icons/2600hz.png';
};
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
},
{
title: 'Value',
dataIndex: 'value',
key: 'value',
},
];
function callback(e) {
history.push({ pathname: '/int/zone', state: { zone: e } });
}
const items = list.map(item => (
}
title={{item.node}}
description={
}
/>
));
return (
Zone details:
{location.state.zone}
}
extra={[
{kz_system_status.data
? Object.keys(kz_system_status.data)
.reverse()
.map(z => )
: null}
,
]}
>
{items}
);
};
export default connect(
({ settings, kz_login, kz_account, kz_system_status, kz_registrations_count }) => ({
settings,
kz_login,
kz_account,
kz_system_status,
kz_registrations_count,
}),
)(ZoneInfo);