mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
96 lines
2.2 KiB
TypeScript
96 lines
2.2 KiB
TypeScript
import { Box, Center, Flex, Text } from '@chakra-ui/react';
|
|
import React from 'react';
|
|
|
|
import type { AxesConfigFn, TimeChartItem } from './types';
|
|
import type { Resolution } from '@blockscout/stats-types';
|
|
|
|
import { Link } from 'toolkit/chakra/link';
|
|
import { Skeleton } from 'toolkit/chakra/skeleton';
|
|
import { apos } from 'toolkit/utils/htmlEntities';
|
|
|
|
import ChartWatermarkIcon from './ChartWatermarkIcon';
|
|
import ChartWidgetGraph from './ChartWidgetGraph';
|
|
|
|
export type Props = {
|
|
items?: Array<TimeChartItem>;
|
|
title: string;
|
|
units?: string;
|
|
isLoading?: boolean;
|
|
isError?: boolean;
|
|
emptyText?: string;
|
|
zoomRange?: [ Date, Date ];
|
|
handleZoom: (range: [ Date, Date ]) => void;
|
|
isEnlarged?: boolean;
|
|
noAnimation?: boolean;
|
|
resolution?: Resolution;
|
|
axesConfig?: AxesConfigFn;
|
|
};
|
|
|
|
const ChartWidgetContent = ({
|
|
items,
|
|
title,
|
|
isLoading,
|
|
isError,
|
|
units,
|
|
emptyText,
|
|
zoomRange,
|
|
handleZoom,
|
|
isEnlarged,
|
|
noAnimation,
|
|
resolution,
|
|
axesConfig,
|
|
}: Props) => {
|
|
const hasItems = items && items.length > 2;
|
|
|
|
if (isError) {
|
|
return (
|
|
<Flex
|
|
alignItems="center"
|
|
justifyContent="center"
|
|
flexGrow={ 1 }
|
|
py={ 4 }
|
|
>
|
|
<Text
|
|
color="text.secondary"
|
|
fontSize="sm"
|
|
textAlign="center"
|
|
>
|
|
{ `The data didn${ apos }t load. Please, ` }
|
|
<Link href={ window.document.location.href }>try to reload the page.</Link>
|
|
</Text>
|
|
</Flex>
|
|
);
|
|
}
|
|
|
|
if (isLoading) {
|
|
return <Skeleton loading flexGrow={ 1 } w="100%"/>;
|
|
}
|
|
|
|
if (!hasItems) {
|
|
return (
|
|
<Center flexGrow={ 1 }>
|
|
<Text color="text.secondary" fontSize="sm">{ emptyText || 'No data' }</Text>
|
|
</Center>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Box flexGrow={ 1 } maxW="100%" position="relative" h="100%">
|
|
<ChartWidgetGraph
|
|
items={ items }
|
|
zoomRange={ zoomRange }
|
|
onZoom={ handleZoom }
|
|
title={ title }
|
|
units={ units }
|
|
isEnlarged={ isEnlarged }
|
|
noAnimation={ noAnimation }
|
|
resolution={ resolution }
|
|
axesConfig={ axesConfig }
|
|
/>
|
|
<ChartWatermarkIcon w="162px" h="15%"/>
|
|
</Box>
|
|
);
|
|
};
|
|
|
|
export default React.memo(ChartWidgetContent);
|