From 0c4d94a3e7b8c1163246c94f7668eb6915fad7fb Mon Sep 17 00:00:00 2001 From: checktheroads Date: Tue, 15 Dec 2020 01:18:04 -0700 Subject: [PATCH] continue typescript & chakra v1 migrations [skip ci] --- hyperglass/ui/components/Card/body.tsx | 2 +- hyperglass/ui/components/Table/main.tsx | 18 ++++++++---- hyperglass/ui/components/Table/row.tsx | 6 ++-- hyperglass/ui/components/output/cell.tsx | 4 --- hyperglass/ui/components/output/fields.tsx | 29 ++++++++++++++----- hyperglass/ui/components/output/table.tsx | 2 +- hyperglass/ui/components/results/header.tsx | 29 +++++++++++-------- .../ui/components/results/individual.tsx | 10 ++++--- hyperglass/ui/hooks/useOpposingColor.ts | 19 ++++++------ 9 files changed, 71 insertions(+), 48 deletions(-) diff --git a/hyperglass/ui/components/Card/body.tsx b/hyperglass/ui/components/Card/body.tsx index 6ecc5bc..dced6f6 100644 --- a/hyperglass/ui/components/Card/body.tsx +++ b/hyperglass/ui/components/Card/body.tsx @@ -11,7 +11,7 @@ export const CardBody = (props: ICardBody) => { (() => import('@meronex/icons/fa').then(i => i.FaChevronUp)); +const ChevronRight = dynamic(() => + import('@meronex/icons/fa').then(i => i.FaChevronRight), +); + +const ChevronLeft = dynamic(() => + import('@meronex/icons/fa').then(i => i.FaChevronLeft), +); const ChevronDown = dynamic(() => import('@meronex/icons/fa').then(i => i.FaChevronDown), @@ -105,7 +111,7 @@ export function Table(props: TTable) { - + {''} @@ -147,13 +153,13 @@ export function Table(props: TTable) { mr={2} onClick={() => gotoPage(0)} isDisabled={!canPreviousPage} - icon={} + icon={} /> previousPage()} isDisabled={!canPreviousPage} - icon={} + icon={} /> @@ -177,12 +183,12 @@ export function Table(props: TTable) { ml={2} onClick={nextPage} isDisabled={!canNextPage} - icon={} + icon={} /> } + icon={} onClick={() => gotoPage(pageCount ? pageCount - 1 : 1)} /> diff --git a/hyperglass/ui/components/Table/row.tsx b/hyperglass/ui/components/Table/row.tsx index 9ce7fa7..fa1def3 100644 --- a/hyperglass/ui/components/Table/row.tsx +++ b/hyperglass/ui/components/Table/row.tsx @@ -23,7 +23,6 @@ export const TableRow = (props: TTableRow) => { { borderTop: '1px', borderTopColor: 'whiteAlpha.100' }, ); let bg; - const color = useOpposingColor(bgStripe); if (highlight) { bg = `${highlightBg}.${alpha}`; @@ -31,14 +30,15 @@ export const TableRow = (props: TTableRow) => { } else if (doStripe && index % 2 !== 0) { bg = bgStripe; } - + const defaultBg = useColorValue('white', 'black'); + const color = useOpposingColor(bg ?? defaultBg); const borderProps = doHorizontalBorders && index !== 0 ? rowBorder : {}; return ( td': { color } }} fontWeight={highlight ? 'bold' : undefined} _hover={{ cursor: 'pointer', diff --git a/hyperglass/ui/components/output/cell.tsx b/hyperglass/ui/components/output/cell.tsx index 79a057e..db14c96 100644 --- a/hyperglass/ui/components/output/cell.tsx +++ b/hyperglass/ui/components/output/cell.tsx @@ -5,10 +5,6 @@ import type { TCell } from './types'; export const Cell = (props: TCell) => { const { data, rawData } = props; const cellId = data.column.id as keyof TRoute; - console.group(cellId); - console.dir(data); - console.dir(rawData); - console.groupEnd(); const component = { med: , age: , diff --git a/hyperglass/ui/components/output/fields.tsx b/hyperglass/ui/components/output/fields.tsx index 487149d..b93498d 100644 --- a/hyperglass/ui/components/output/fields.tsx +++ b/hyperglass/ui/components/output/fields.tsx @@ -1,3 +1,4 @@ +import { forwardRef } from 'react'; import { Icon, Text, Box, Tooltip, Menu, MenuButton, MenuList } from '@chakra-ui/react'; import { CgMoreO as More } from '@meronex/icons/cg'; import { BisError as Warning } from '@meronex/icons/bi'; @@ -9,6 +10,7 @@ import relativeTimePlugin from 'dayjs/plugin/relativeTime'; import utcPlugin from 'dayjs/plugin/utc'; import { useConfig, useColorValue } from '~/context'; import { If } from '~/components'; +import { useOpposingColor } from '~/hooks'; import type { TAge, @@ -76,8 +78,10 @@ export const Weight = (props: TWeight) => { export const ASPath = (props: TASPath) => { const { path, active } = props; const color = useColorValue( + // light: inactive, active ['blackAlpha.500', 'blackAlpha.500'], - ['blackAlpha.500', 'whiteAlpha.300'], + // dark: inactive, active + ['whiteAlpha.600', 'blackAlpha.700'], ); if (path.length === 0) { @@ -88,7 +92,10 @@ export const ASPath = (props: TASPath) => { path.map((asn, i) => { const asnStr = String(asn); - i !== 0 && paths.push(); + i !== 0 && + paths.push( + , + ); paths.push( {asnStr} @@ -130,10 +137,10 @@ export const Communities = (props: TCommunities) => { ); }; -export const RPKIState = (props: TRPKIState) => { +export const RPKIState = forwardRef((props, ref) => { const { state, active } = props; const { web } = useConfig(); - const color = useColorValue( + const bg = useColorValue( [ ['red.400', 'green.500', 'yellow.400', 'gray.500'], ['red.500', 'green.500', 'yellow.500', 'gray.600'], @@ -143,6 +150,7 @@ export const RPKIState = (props: TRPKIState) => { ['red.500', 'green.600', 'yellow.500', 'gray.800'], ], ); + const color = useOpposingColor(bg[+active][state]); const icon = [NotAllowed, Check, Warning, Question]; const text = [ @@ -153,8 +161,15 @@ export const RPKIState = (props: TRPKIState) => { ]; return ( - - + + + + ); -}; +}); diff --git a/hyperglass/ui/components/output/table.tsx b/hyperglass/ui/components/output/table.tsx index f062a05..1bb6e67 100644 --- a/hyperglass/ui/components/output/table.tsx +++ b/hyperglass/ui/components/output/table.tsx @@ -32,7 +32,7 @@ export const BGPTable = (props: TBGPTable) => { const columns = makeColumns(parsed_data_fields); return ( - + { const text = useStrf(web.text.complete_time, { seconds: runtime }, [runtime]); const label = useMemo(() => runtimeText(runtime, text), [runtime]); + const color = useOpposingColor(isError ? warning : defaultStatus); + return ( { placement="top" isDisabled={loading} label={isError ? errorMsg : label} - colorScheme={isError ? errorLevel : 'success'}> - {loading ? ( - - ) : ( - - )} + bg={isError ? warning : defaultStatus} + color={color}> + + {loading ? ( + + ) : ( + + )} + {title} diff --git a/hyperglass/ui/components/results/individual.tsx b/hyperglass/ui/components/results/individual.tsx index 4a97674..e8920bd 100644 --- a/hyperglass/ui/components/results/individual.tsx +++ b/hyperglass/ui/components/results/individual.tsx @@ -191,20 +191,22 @@ export const Result = forwardRef((props, ref) => { '-ms-overflow-style': { display: 'none' }, }}> - + {!isError && typeof data !== 'undefined' && ( <> - {isStructuredOutput(data) && tableComponent ? ( + {isStructuredOutput(data) && data.level === 'success' && tableComponent ? ( {data.output} - ) : isStringOutput(data) && !tableComponent ? ( + ) : isStringOutput(data) && data.level === 'success' && !tableComponent ? ( {data.output} + ) : isStringOutput(data) && data.level !== 'success' ? ( + ) : null} )} {isError && } - + ('inherit'); const isBlack = useIsDark(color); - const dark = useToken('colors', options?.dark ?? 'original.dark'); - const light = useToken('colors', options?.light ?? 'original.light'); - - isBlack && opposingColor !== dark && setOpposingColor(dark); - !isBlack && opposingColor !== light && setOpposingColor(light); - - return opposingColor; + return useMemo(() => { + if (isBlack) { + return options?.dark ?? 'black'; + } else { + return options?.light ?? 'white'; + } + }, [color]); } export function useOpposingToken(color: string, options?: TOpposingOptions): string { @@ -40,5 +39,5 @@ export function useOpposingToken(color: string, options?: TOpposingOptions): str isBlack && opposingColor !== dark && setOpposingColor(dark); !isBlack && opposingColor !== light && setOpposingColor(light); - return opposingColor; + return useMemo(() => opposingColor, [color]); }