ShareModal.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React, { useState } from 'react';
  2. import { AppEvents, SelectableValue, UrlQueryMap, urlUtil } from '@grafana/data';
  3. import { Checkbox, ClipboardButton, Field, FieldSet, Icon, Input, Modal, RadioButtonGroup } from '@grafana/ui';
  4. import appEvents from 'app/core/app_events';
  5. import { buildBaseUrl } from '../dashboard/components/ShareModal/utils';
  6. import { PlaylistMode } from './types';
  7. interface ShareModalProps {
  8. playlistUid: string;
  9. onDismiss: () => void;
  10. }
  11. export const ShareModal = ({ playlistUid, onDismiss }: ShareModalProps) => {
  12. const [mode, setMode] = useState<PlaylistMode>(false);
  13. const [autoFit, setAutofit] = useState(false);
  14. const modes: Array<SelectableValue<PlaylistMode>> = [
  15. { label: 'Normal', value: false },
  16. { label: 'TV', value: 'tv' },
  17. { label: 'Kiosk', value: true },
  18. ];
  19. const onShareUrlCopy = () => {
  20. appEvents.emit(AppEvents.alertSuccess, ['Content copied to clipboard']);
  21. };
  22. const params: UrlQueryMap = {};
  23. if (mode) {
  24. params.kiosk = mode;
  25. }
  26. if (autoFit) {
  27. params.autofitpanels = true;
  28. }
  29. const shareUrl = urlUtil.renderUrl(`${buildBaseUrl()}/play/${playlistUid}`, params);
  30. return (
  31. <Modal isOpen={true} title="Share playlist" onDismiss={onDismiss}>
  32. <FieldSet>
  33. <Field label="Mode">
  34. <RadioButtonGroup value={mode} options={modes} onChange={setMode} />
  35. </Field>
  36. <Field>
  37. <Checkbox
  38. label="Autofit"
  39. description="Panel heights will be adjusted to fit screen size"
  40. name="autofix"
  41. value={autoFit}
  42. onChange={(e) => setAutofit(e.currentTarget.checked)}
  43. />
  44. </Field>
  45. <Field label="Link URL">
  46. <Input
  47. id="link-url-input"
  48. value={shareUrl}
  49. readOnly
  50. addonAfter={
  51. <ClipboardButton variant="primary" getText={() => shareUrl} onClipboardCopy={onShareUrlCopy}>
  52. <Icon name="copy" /> Copy
  53. </ClipboardButton>
  54. }
  55. />
  56. </Field>
  57. </FieldSet>
  58. </Modal>
  59. );
  60. };