overwriteWidgetModal.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {Fragment} from 'react';
  2. import {css} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import type {ModalRenderProps} from 'sentry/actionCreators/modal';
  5. import {Button} from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import {Card} from 'sentry/views/dashboards/widgetBuilder/widgetLibrary/card';
  10. import type {WidgetTemplate} from 'sentry/views/dashboards/widgetLibrary/data';
  11. export type OverwriteWidgetModalProps = {
  12. iconColor: string;
  13. onConfirm: () => void;
  14. widget: WidgetTemplate;
  15. };
  16. type Props = ModalRenderProps & OverwriteWidgetModalProps;
  17. const MODAL_DESCRIPTION = t(
  18. "You've already started building this widget and will lose unsaved changes. Are you sure you want to overwrite this widget with the template values?"
  19. );
  20. function OverwriteWidgetModal({
  21. Header,
  22. Body,
  23. Footer,
  24. closeModal,
  25. onConfirm,
  26. widget,
  27. iconColor,
  28. }: Props) {
  29. function handleConfirm() {
  30. onConfirm();
  31. closeModal();
  32. }
  33. return (
  34. <Fragment>
  35. <Header closeButton>
  36. <h4>{t('Overwrite Widget')}</h4>
  37. </Header>
  38. <Body>
  39. {MODAL_DESCRIPTION}
  40. <CardWrapper>
  41. <Card widget={widget} iconColor={iconColor} />
  42. </CardWrapper>
  43. </Body>
  44. <Footer>
  45. <ButtonBar gap={1.5}>
  46. <Button onClick={closeModal}>{t('Cancel')}</Button>
  47. <Button priority="primary" onClick={handleConfirm}>
  48. {t('Confirm')}
  49. </Button>
  50. </ButtonBar>
  51. </Footer>
  52. </Fragment>
  53. );
  54. }
  55. export default OverwriteWidgetModal;
  56. export const modalCss = css`
  57. width: 100%;
  58. max-width: 700px;
  59. margin: 70px auto;
  60. `;
  61. const CardWrapper = styled('div')`
  62. padding: ${space(3)} 0;
  63. `;