Commit f55f8a6c authored by tom goriunov's avatar tom goriunov Committed by GitHub

Merge pull request #551 from blockscout/more-stats-fixes

more stats fixes
parents 19183786 14b1bd8f
...@@ -2,8 +2,6 @@ import _debounce from 'lodash/debounce'; ...@@ -2,8 +2,6 @@ import _debounce from 'lodash/debounce';
import type { LegacyRef } from 'react'; import type { LegacyRef } from 'react';
import React from 'react'; import React from 'react';
import useUpdateEffect from 'lib/hooks/useUpdateEffect';
export default function useClientRect<E extends Element>(): [ DOMRect | null, LegacyRef<E> | undefined ] { export default function useClientRect<E extends Element>(): [ DOMRect | null, LegacyRef<E> | undefined ] {
const [ rect, setRect ] = React.useState<DOMRect | null>(null); const [ rect, setRect ] = React.useState<DOMRect | null>(null);
const nodeRef = React.useRef<E>(); const nodeRef = React.useRef<E>();
...@@ -15,7 +13,7 @@ export default function useClientRect<E extends Element>(): [ DOMRect | null, Le ...@@ -15,7 +13,7 @@ export default function useClientRect<E extends Element>(): [ DOMRect | null, Le
nodeRef.current = node; nodeRef.current = node;
}, []); }, []);
useUpdateEffect(() => { React.useEffect(() => {
const content = window.document.querySelector('main'); const content = window.document.querySelector('main');
if (!content) { if (!content) {
return; return;
......
...@@ -25,6 +25,7 @@ const AddressCoinBalanceChart = ({ addressHash }: Props) => { ...@@ -25,6 +25,7 @@ const AddressCoinBalanceChart = ({ addressHash }: Props) => {
title="Balances" title="Balances"
items={ items } items={ items }
isLoading={ isLoading } isLoading={ isLoading }
h="250px"
/> />
); );
}; };
......
import { import {
Box, Box,
Center,
chakra,
Flex, Flex,
Grid, Grid,
Icon, Icon,
...@@ -36,13 +38,13 @@ type Props = { ...@@ -36,13 +38,13 @@ type Props = {
title: string; title: string;
description?: string; description?: string;
isLoading: boolean; isLoading: boolean;
chartHeight?: string; className?: string;
isError: boolean; isError: boolean;
} }
const DOWNLOAD_IMAGE_SCALE = 5; const DOWNLOAD_IMAGE_SCALE = 5;
const ChartWidget = ({ items, title, description, isLoading, chartHeight, isError }: Props) => { const ChartWidget = ({ items, title, description, isLoading, className, isError }: Props) => {
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
const [ isFullscreen, setIsFullscreen ] = useState(false); const [ isFullscreen, setIsFullscreen ] = useState(false);
const [ isZoomResetInitial, setIsZoomResetInitial ] = React.useState(true); const [ isZoomResetInitial, setIsZoomResetInitial ] = React.useState(true);
...@@ -111,10 +113,53 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro ...@@ -111,10 +113,53 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro
return <ChartWidgetSkeleton hasDescription={ Boolean(description) }/>; return <ChartWidgetSkeleton hasDescription={ Boolean(description) }/>;
} }
const hasItems = items && items.length > 2;
const content = (() => {
if (isError) {
return (
<Flex
alignItems="center"
justifyContent="center"
flexGrow={ 1 }
py={ 4 }
>
<Text
variant="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 (!hasItems) {
return (
<Center flexGrow={ 1 }>
<Text variant="secondary" fontSize="sm">No data</Text>
</Center>
);
}
return (
<Box h="100%" maxW="100%">
<ChartWidgetGraph
items={ items }
onZoom={ handleZoom }
isZoomResetInitial={ isZoomResetInitial }
title={ title }
/>
</Box>
);
})();
return ( return (
<> <>
<Box <Box
height={ chartHeight } height="100%"
display="flex" display="flex"
flexDirection="column" flexDirection="column"
ref={ ref } ref={ ref }
...@@ -122,6 +167,7 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro ...@@ -122,6 +167,7 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro
borderRadius="md" borderRadius="md"
border="1px" border="1px"
borderColor={ borderColor } borderColor={ borderColor }
className={ className }
> >
<Grid <Grid
gridTemplateColumns="auto auto 36px" gridTemplateColumns="auto auto 36px"
...@@ -167,7 +213,7 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro ...@@ -167,7 +213,7 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro
/> />
</Tooltip> </Tooltip>
{ !isError && ( { hasItems && (
<Menu> <Menu>
<MenuButton <MenuButton
gridColumn={ 3 } gridColumn={ 3 }
...@@ -216,36 +262,10 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro ...@@ -216,36 +262,10 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro
) } ) }
</Grid> </Grid>
{ items ? ( { content }
<Box h={ chartHeight || 'auto' } maxW="100%">
<ChartWidgetGraph
margin={{ bottom: 20 }}
items={ items }
onZoom={ handleZoom }
isZoomResetInitial={ isZoomResetInitial }
title={ title }
/>
</Box>
) : (
<Flex
alignItems="center"
justifyContent="center"
flexGrow={ 1 }
py={ 4 }
>
<Text
variant="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>
) }
</Box> </Box>
{ items && ( { hasItems && (
<FullscreenChartModal <FullscreenChartModal
isOpen={ isFullscreen } isOpen={ isFullscreen }
items={ items } items={ items }
...@@ -258,4 +278,4 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro ...@@ -258,4 +278,4 @@ const ChartWidget = ({ items, title, description, isLoading, chartHeight, isErro
); );
}; };
export default React.memo(ChartWidget); export default React.memo(chakra(ChartWidget));
...@@ -23,7 +23,7 @@ interface Props { ...@@ -23,7 +23,7 @@ interface Props {
items: Array<TimeChartItem>; items: Array<TimeChartItem>;
onZoom: () => void; onZoom: () => void;
isZoomResetInitial: boolean; isZoomResetInitial: boolean;
margin: ChartMargin; margin?: ChartMargin;
} }
const MAX_SHOW_ITEMS = 100; const MAX_SHOW_ITEMS = 100;
......
...@@ -3,10 +3,9 @@ import React from 'react'; ...@@ -3,10 +3,9 @@ import React from 'react';
interface Props { interface Props {
hasDescription: boolean; hasDescription: boolean;
chartHeight?: string;
} }
const ChartWidgetSkeleton = ({ hasDescription, chartHeight }: Props) => { const ChartWidgetSkeleton = ({ hasDescription }: Props) => {
return ( return (
<Box <Box
height="235px" height="235px"
...@@ -15,7 +14,7 @@ const ChartWidgetSkeleton = ({ hasDescription, chartHeight }: Props) => { ...@@ -15,7 +14,7 @@ const ChartWidgetSkeleton = ({ hasDescription, chartHeight }: Props) => {
<Skeleton w="75%" h="24px"/> <Skeleton w="75%" h="24px"/>
{ hasDescription && <Skeleton w="50%" h="18px" mt={ 1 }/> } { hasDescription && <Skeleton w="50%" h="18px" mt={ 1 }/> }
<Skeleton w="100%" h={ chartHeight || '150px' } mt={ 5 }/> <Skeleton w="100%" h="150px" mt={ 5 }/>
</Box> </Box>
); );
}; };
......
...@@ -45,7 +45,6 @@ const ChartWidgetContainer = ({ id, title, description, interval, onLoadingError ...@@ -45,7 +45,6 @@ const ChartWidgetContainer = ({ id, title, description, interval, onLoadingError
return ( return (
<ChartWidget <ChartWidget
chartHeight="100%"
isError={ isError } isError={ isError }
items={ items } items={ items }
title={ title } title={ title }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment