1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00
Files
checktheroads-hyperglass/hyperglass/ui/components/ResultHeader.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-10-07 09:41:58 -07:00
import * as React from 'react';
import { forwardRef } from 'react';
import { AccordionIcon, Icon, Spinner, Stack, Text, Tooltip, useColorMode } from '@chakra-ui/core';
import format from 'string-format';
import { useConfig } from 'app/context';
2020-01-17 02:50:57 -07:00
2020-04-16 23:43:02 -07:00
format.extend(String.prototype, {});
const runtimeText = (runtime, text) => {
2020-04-18 12:09:16 -07:00
let unit;
if (runtime === 1) {
2020-10-07 09:41:58 -07:00
unit = 'second';
2020-04-18 12:09:16 -07:00
} else {
2020-10-07 09:41:58 -07:00
unit = 'seconds';
2020-04-18 12:09:16 -07:00
}
const fmt = text.format({ seconds: runtime });
return `${fmt} ${unit}`;
2020-04-16 23:43:02 -07:00
};
2020-10-07 09:41:58 -07:00
const statusColor = { dark: 'primary.300', light: 'primary.500' };
2020-04-16 23:43:02 -07:00
const warningColor = { dark: 300, light: 500 };
const defaultStatusColor = {
2020-10-07 09:41:58 -07:00
dark: 'success.300',
light: 'success.500',
2020-04-16 23:43:02 -07:00
};
export const ResultHeader = forwardRef(
2020-04-18 12:09:16 -07:00
({ title, loading, error, errorMsg, errorLevel, runtime }, ref) => {
2020-01-17 02:50:57 -07:00
const { colorMode } = useColorMode();
2020-04-16 23:43:02 -07:00
const config = useConfig();
2020-01-17 02:50:57 -07:00
return (
2020-04-18 12:09:16 -07:00
<Stack ref={ref} isInline alignItems="center" w="100%">
{loading ? (
<Spinner size="sm" mr={4} color={statusColor[colorMode]} />
) : error ? (
<Tooltip hasArrow label={errorMsg} placement="top">
<Icon
name="warning"
color={`${errorLevel}.${warningColor[colorMode]}`}
mr={4}
size={6}
/>
</Tooltip>
) : (
<Tooltip
hasArrow
label={runtimeText(runtime, config.web.text.complete_time)}
2020-10-07 09:41:58 -07:00
placement="top">
<Icon name="check" color={defaultStatusColor[colorMode]} mr={4} size={6} />
2020-04-18 12:09:16 -07:00
</Tooltip>
)}
<Text fontSize="lg">{title}</Text>
<AccordionIcon ml="auto" />
</Stack>
2020-01-17 02:50:57 -07:00
);
2020-10-07 09:41:58 -07:00
},
2020-04-18 12:09:16 -07:00
);