import * as React from 'react'; import { useTranslation, Trans } from 'react-i18next'; import { Alert, Button, HelperText, HelperTextItem, Stack, StackItem, } from '@patternfly/react-core'; import classNames from 'classnames'; import get from 'lodash/get'; import isEmpty from 'lodash/isEmpty'; import isString from 'lodash/isString'; import { TimeoutError } from '../../../k8s/error'; import * as restrictedSignImg from '../../assets/restricted-sign.svg'; import './StatusBox.scss'; export const Box: React.FC> = ({ children, className }) => (
{children}
); export const LoadError: React.FC> = ({ label, className, message, canRetry = true, }) => { const { t } = useTranslation(); return (
{isString(message) ? t('public~Error Loading {{label}}: {{message}}', { label, message, }) : t('public~Error Loading {{label}}', { label })}
{canRetry && (
Please{' '} .
)}
); }; LoadError.displayName = 'LoadError'; export const Loading: React.FC> = ({ className }) => (
); Loading.displayName = 'Loading'; export const LoadingInline: React.FC>> = () => ( ); LoadingInline.displayName = 'LoadingInline'; export const LoadingBox: React.FC> = ({ className, message, }) => ( {message &&
{message}
}
); LoadingBox.displayName = 'LoadingBox'; export const EmptyBox: React.FC> = ({ label }) => { return (
{label ? `No ${label} found` : 'Not found'}
); }; EmptyBox.displayName = 'EmptyBox'; export const MsgBox: React.FC> = ({ title, detail, className = '', }) => ( {title && (
{title}
)} {detail && ( {detail} )}
); MsgBox.displayName = 'MsgBox'; export const AccessDenied: React.FC> = ({ message }) => { const { t } = useTranslation(); return (
{isString(message) && ( {message} )}
); }; AccessDenied.displayName = 'AccessDenied'; const Data: React.FC> = ({ NoDataEmptyMsg, EmptyMsg, Toolbar, label, data, unfilteredData, children, }) => { if (NoDataEmptyMsg && isEmpty(unfilteredData)) { return (
{Toolbar} {NoDataEmptyMsg ? : }
); } if (!data || isEmpty(data)) { return (
{Toolbar} {EmptyMsg ? : }
); } return (
{Toolbar} {children}
); }; Data.displayName = 'Data'; export const StatusBox: React.FC> = (props) => { const { loadError, loaded, skeleton, ...dataProps } = props; const { t } = useTranslation(); if (loadError) { const status = get(loadError, 'response.status'); if (status === 404) { return (

{t('public~404: Not Found')}

); } if (status === 403) { return ; } if (loaded && loadError instanceof TimeoutError) { return (
{t('public~Timed out fetching new data. The data below is stale.')}
{props.Toolbar} {props.children}
); } return ( ); } if (!loaded) { if (props.Toolbar) { return ( {props.Toolbar} {skeleton ?? } ); } return skeleton ? <>{skeleton} : ; } return ; }; StatusBox.displayName = 'StatusBox'; type BoxProps = { children: React.ReactNode; className?: string; }; type LoadErrorProps = { label: string; className?: string; message?: string; canRetry?: boolean; }; type LoadingProps = { className?: string; }; type LoadingBoxProps = { className?: string; message?: string; }; type EmptyBoxProps = { label?: string; }; type MsgBoxProps = { title?: string; detail?: React.ReactNode; className?: string; }; type AccessDeniedProps = { message?: string; }; type DataProps = { NoDataEmptyMsg?: React.ComponentType>; EmptyMsg?: React.ComponentType>; Toolbar?: React.ReactNode; label?: string; unfilteredData?: unknown; data?: unknown; children?: React.ReactNode; }; type StatusBoxProps = { label?: string; loadError?: unknown; loaded?: boolean; data?: unknown; unfilteredData?: unknown; skeleton?: React.ReactNode; NoDataEmptyMsg?: React.ComponentType>; EmptyMsg?: React.ComponentType>; Toolbar?: React.ReactNode; children?: React.ReactNode; };