diagnostic-component.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React from 'react'
  2. import classnames from 'classnames'
  3. import type { ConnectionStatus } from './types'
  4. import { Badge, Button } from 'react-bootstrap'
  5. import OLNotification from '@/shared/components/ol/ol-notification'
  6. import MaterialIcon from '@/shared/components/material-icon'
  7. const variants = {
  8. connected: 'success',
  9. connecting: 'warning',
  10. disconnected: 'danger',
  11. }
  12. export const ConnectionBadge = ({ state }: { state: ConnectionStatus }) => (
  13. <Badge className="px-2 py-1" bg={variants[state]}>
  14. {state}
  15. </Badge>
  16. )
  17. export const DiagnosticItem = ({
  18. icon,
  19. label,
  20. value,
  21. type,
  22. }: {
  23. icon: string
  24. label: string
  25. value: React.ReactNode
  26. type?: 'success' | 'danger'
  27. }) => (
  28. <div
  29. className={classnames(
  30. 'py-2',
  31. type === 'success' && 'text-success',
  32. type === 'danger' && 'text-danger'
  33. )}
  34. >
  35. <div className="d-flex gap-2 fw-bold align-items-center">
  36. <MaterialIcon type={icon} />
  37. <span>{label}</span>
  38. </div>
  39. <div>{value}</div>
  40. </div>
  41. )
  42. export function ErrorAlert({ message }: { message: string }) {
  43. return <OLNotification type="error" content={message} className="mt-3" />
  44. }
  45. export function ActionButton({
  46. label,
  47. icon,
  48. onClick,
  49. disabled,
  50. }: {
  51. label: string
  52. icon: string
  53. onClick: () => void
  54. disabled?: boolean
  55. }) {
  56. return (
  57. <Button
  58. onClick={onClick}
  59. disabled={disabled}
  60. className="d-flex align-items-center"
  61. >
  62. <MaterialIcon className="me-2" type={icon} />
  63. <span>{label}</span>
  64. </Button>
  65. )
  66. }