loadingError.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import styled from '@emotion/styled';
  2. import Alert from 'sentry/components/alert';
  3. import Button from 'sentry/components/button';
  4. import {Panel} from 'sentry/components/panels';
  5. import {t} from 'sentry/locale';
  6. type Props = {
  7. className?: string;
  8. message?: React.ReactNode;
  9. onRetry?: () => void;
  10. };
  11. /**
  12. * Renders an Alert box of type "error". Renders a "Retry" button only if a
  13. * `onRetry` callback is defined.
  14. */
  15. function LoadingError({
  16. className,
  17. onRetry,
  18. message = t('There was an error loading data.'),
  19. }: Props) {
  20. return (
  21. <StyledAlert
  22. type="error"
  23. data-test-id="loading-error"
  24. showIcon
  25. className={className}
  26. trailingItems={
  27. onRetry && (
  28. <Button onClick={onRetry} type="button" priority="default" size="sm">
  29. {t('Retry')}
  30. </Button>
  31. )
  32. }
  33. >
  34. {message}
  35. </StyledAlert>
  36. );
  37. }
  38. export default LoadingError;
  39. const StyledAlert = styled(Alert)`
  40. ${Panel} & {
  41. border-radius: 0;
  42. border-width: 1px 0;
  43. }
  44. `;