StartModal.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, { FC, useState } from 'react';
  2. import { SelectableValue, urlUtil } from '@grafana/data';
  3. import { locationService } from '@grafana/runtime';
  4. import { Button, Checkbox, Field, FieldSet, Modal, RadioButtonGroup } from '@grafana/ui';
  5. import { PlaylistDTO, PlaylistMode } from './types';
  6. export interface StartModalProps {
  7. playlist: PlaylistDTO;
  8. onDismiss: () => void;
  9. }
  10. export const StartModal: FC<StartModalProps> = ({ playlist, onDismiss }) => {
  11. const [mode, setMode] = useState<PlaylistMode>(false);
  12. const [autoFit, setAutofit] = useState(false);
  13. const modes: Array<SelectableValue<PlaylistMode>> = [
  14. { label: 'Normal', value: false },
  15. { label: 'TV', value: 'tv' },
  16. { label: 'Kiosk', value: true },
  17. ];
  18. const onStart = () => {
  19. const params: any = {};
  20. if (mode) {
  21. params.kiosk = mode;
  22. }
  23. if (autoFit) {
  24. params.autofitpanels = true;
  25. }
  26. locationService.push(urlUtil.renderUrl(`/playlists/play/${playlist.uid}`, params));
  27. };
  28. return (
  29. <Modal isOpen={true} icon="play" title="Start playlist" onDismiss={onDismiss}>
  30. <FieldSet>
  31. <Field label="Mode">
  32. <RadioButtonGroup value={mode} options={modes} onChange={setMode} />
  33. </Field>
  34. <Checkbox
  35. label="Autofit"
  36. description="Panel heights will be adjusted to fit screen size"
  37. name="autofix"
  38. value={autoFit}
  39. onChange={(e) => setAutofit(e.currentTarget.checked)}
  40. />
  41. </FieldSet>
  42. <Modal.ButtonRow>
  43. <Button variant="primary" onClick={onStart}>
  44. Start {playlist.name}
  45. </Button>
  46. </Modal.ButtonRow>
  47. </Modal>
  48. );
  49. };