Return

All tests / RenderManager index.tsx

100% Statements 11/11
100% Branches 6/6
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 529x 9x 9x 9x 9x                                       9x 26x   26x                   19x                         26x  
import React from 'react';
import Loading from './Loading';
import Error from './Error';
import Tooltip from '@/components/Tooltip';
import { useIntl } from 'react-intl';
 
type Props = {
    error: boolean;
    loading: boolean;
    errorTitle?: string;
    loadingTitle?: string;
    children: React.ReactNode;
};
 
/**
 * @description - Renders children or error/loading icon
 *
 * @param {error} boolean - error state
 * @param {loading} boolean - loading state
 * @param {errorTitle} string - Title for error icon
 * @param {loadingTitle} string - Title for loading icon
 * @param {children} React.ReactNode - Children to render
 * @returns {React.ReactNode} - Returns children or error/loading icon
 */
const RenderManager = ({ error, loading, errorTitle, loadingTitle, children }: Props) => {
    const { formatMessage: f } = useIntl();
 
    if (error) {
        return (
            <Tooltip>
                <Tooltip.Trigger>
                    <Error />
                </Tooltip.Trigger>
                <Tooltip.Content>{errorTitle ?? f({ id: 'rendermanager.error' })}</Tooltip.Content>
            </Tooltip>
        );
    }
    if (loading) {
        return (
            <Tooltip>
                <Tooltip.Trigger>
                    <Loading />
                </Tooltip.Trigger>
                <Tooltip.Content>{loadingTitle ?? f({ id: 'rendermanager.loading' })}</Tooltip.Content>
            </Tooltip>
        );
    }
    return <>{children}</>;
};
 
export default RenderManager;