libraryTab.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import * as React from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'app/components/alert';
  4. import {t} from 'app/locale';
  5. import space from 'app/styles/space';
  6. import {DEFAULT_WIDGETS, WidgetTemplate} from 'app/views/dashboardsV2/widgetLibrary/data';
  7. import WidgetLibraryCard from 'app/views/dashboardsV2/widgetLibrary/widgetCard';
  8. type Props = {
  9. selectedWidgets: WidgetTemplate[];
  10. errored: boolean;
  11. setSelectedWidgets: (widgets: WidgetTemplate[]) => void;
  12. setErrored: (errored: boolean) => void;
  13. };
  14. function DashboardWidgetLibraryTab({
  15. selectedWidgets,
  16. errored,
  17. setSelectedWidgets,
  18. setErrored,
  19. }: Props) {
  20. return (
  21. <React.Fragment>
  22. {errored && !!!selectedWidgets.length ? (
  23. <Alert type="error">
  24. {t(
  25. 'Please select at least one Widget from our Library. Alternatively, you can build a custom widget from scratch.'
  26. )}
  27. </Alert>
  28. ) : null}
  29. <Title>{t('%s WIDGETS', DEFAULT_WIDGETS.length)}</Title>
  30. <ScrollGrid>
  31. <WidgetLibraryGrid>
  32. {DEFAULT_WIDGETS.map(widgetCard => {
  33. return (
  34. <WidgetLibraryCard
  35. key={widgetCard.title}
  36. widget={widgetCard}
  37. selectedWidgets={selectedWidgets}
  38. setSelectedWidgets={setSelectedWidgets}
  39. setErrored={setErrored}
  40. />
  41. );
  42. })}
  43. </WidgetLibraryGrid>
  44. </ScrollGrid>
  45. </React.Fragment>
  46. );
  47. }
  48. const WidgetLibraryGrid = styled('div')`
  49. display: grid;
  50. grid-template-columns: repeat(2, minmax(100px, 1fr));
  51. grid-template-rows: repeat(2, max-content);
  52. grid-gap: ${space(1)};
  53. `;
  54. const ScrollGrid = styled('div')`
  55. max-height: 550px;
  56. overflow: scroll;
  57. -ms-overflow-style: none;
  58. scrollbar-width: none;
  59. &::-webkit-scrollbar {
  60. display: none;
  61. }
  62. `;
  63. const Title = styled('h3')`
  64. margin-bottom: ${space(1)};
  65. padding: 0 !important;
  66. font-size: ${p => p.theme.fontSizeSmall};
  67. text-transform: uppercase;
  68. color: ${p => p.theme.gray300};
  69. `;
  70. export default DashboardWidgetLibraryTab;