PlaylistNewPage.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React, { FC } from 'react';
  2. import { connect, MapStateToProps } from 'react-redux';
  3. import { NavModel } from '@grafana/data';
  4. import { locationService } from '@grafana/runtime';
  5. import { useStyles2 } from '@grafana/ui';
  6. import Page from 'app/core/components/Page/Page';
  7. import { getNavModel } from 'app/core/selectors/navModel';
  8. import { StoreState } from 'app/types';
  9. import { GrafanaRouteComponentProps } from '../../core/navigation/types';
  10. import { PlaylistForm } from './PlaylistForm';
  11. import { createPlaylist } from './api';
  12. import { getPlaylistStyles } from './styles';
  13. import { Playlist } from './types';
  14. import { usePlaylist } from './usePlaylist';
  15. interface ConnectedProps {
  16. navModel: NavModel;
  17. }
  18. interface Props extends ConnectedProps, GrafanaRouteComponentProps {}
  19. export const PlaylistNewPage: FC<Props> = ({ navModel }) => {
  20. const styles = useStyles2(getPlaylistStyles);
  21. const { playlist, loading } = usePlaylist();
  22. const onSubmit = async (playlist: Playlist) => {
  23. await createPlaylist(playlist);
  24. locationService.push('/playlists');
  25. };
  26. return (
  27. <Page navModel={navModel}>
  28. <Page.Contents isLoading={loading}>
  29. <h3 className={styles.subHeading}>New Playlist</h3>
  30. <p className={styles.description}>
  31. A playlist rotates through a pre-selected list of dashboards. A playlist can be a great way to build
  32. situational awareness, or just show off your metrics to your team or visitors.
  33. </p>
  34. <PlaylistForm onSubmit={onSubmit} playlist={playlist} />
  35. </Page.Contents>
  36. </Page>
  37. );
  38. };
  39. const mapStateToProps: MapStateToProps<ConnectedProps, {}, StoreState> = (state: StoreState) => ({
  40. navModel: getNavModel(state.navIndex, 'playlists'),
  41. });
  42. export default connect(mapStateToProps)(PlaylistNewPage);