import * as React from 'react'; import { Flex, Icon, Popover, PopoverArrow, PopoverContent, PopoverTrigger, Text, Tooltip, useColorMode, } from '@chakra-ui/core'; import { MdLastPage } from '@meronex/icons/md'; import dayjs from 'dayjs'; import relativeTimePlugin from 'dayjs/plugin/relativeTime'; import utcPlugin from 'dayjs/plugin/utc'; import { useConfig } from 'app/context'; import { Table } from 'app/components'; dayjs.extend(relativeTimePlugin); dayjs.extend(utcPlugin); const isActiveColor = { true: { dark: 'green.300', light: 'green.500' }, false: { dark: 'gray.300', light: 'gray.500' }, }; const arrowColor = { true: { dark: 'blackAlpha.500', light: 'blackAlpha.500' }, false: { dark: 'whiteAlpha.300', light: 'blackAlpha.500' }, }; const rpkiIcon = ['not-allowed', 'check-circle', 'warning', 'question']; const rpkiColor = { true: { dark: ['red.500', 'green.600', 'yellow.500', 'gray.800'], light: ['red.500', 'green.500', 'yellow.500', 'gray.600'], }, false: { dark: ['red.300', 'green.300', 'yellow.300', 'gray.300'], light: ['red.400', 'green.500', 'yellow.400', 'gray.500'], }, }; const makeColumns = fields => { return fields.map(pair => { const [header, accessor, align] = pair; let columnConfig = { Header: header, accessor: accessor, align: align, hidden: false, }; if (align === null) { columnConfig.hidden = true; } return columnConfig; }); }; const MonoField = ({ v, ...props }) => ( {v} ); const Active = ({ isActive }) => { const { colorMode } = useColorMode(); return ( ); }; const Age = ({ inSeconds }) => { const now = dayjs.utc(); const then = now.subtract(inSeconds, 'seconds'); return ( {now.to(then, true)} ); }; const Weight = ({ weight, winningWeight }) => { const fixMeText = winningWeight === 'low' ? 'Lower Weight is Preferred' : 'Higher Weight is Preferred'; return ( {weight} ); }; const ASPath = ({ path, active }) => { const { colorMode } = useColorMode(); if (path.length === 0) { return ; } let paths = []; path.map((asn, i) => { const asnStr = String(asn); i !== 0 && paths.push( , ); paths.push( {asnStr} , ); }); return paths; }; const Communities = ({ communities }) => { const { colorMode } = useColorMode(); let component; communities.length === 0 ? (component = ( )) : (component = ( {communities.join('\n')} )); return component; }; const RPKIState = ({ state, active }) => { const { web } = useConfig(); const { colorMode } = useColorMode(); const stateText = [ web.text.rpki_invalid, web.text.rpki_valid, web.text.rpki_unknown, web.text.rpki_unverified, ]; return ( ); }; const Cell = ({ data, rawData, longestASN }) => { const component = { prefix: , active: , age: , weight: , med: , local_preference: , as_path: , communities: , next_hop: , source_as: , source_rid: , peer_rid: , rpki_state: , }; return component[data.column.id] ?? <> ; }; export const BGPTable = ({ children: data, ...props }) => { const config = useConfig(); const columns = makeColumns(config.parsed_data_fields); return ( } bordersHorizontal rowHighlightBg="green" /> ); };