OptionsPane.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { useSelector } from 'react-redux';
  4. import { GrafanaTheme } from '@grafana/data';
  5. import { selectors } from '@grafana/e2e-selectors';
  6. import { useStyles } from '@grafana/ui';
  7. import { StoreState } from 'app/types';
  8. import { OptionsPaneOptions } from './OptionsPaneOptions';
  9. import { VisualizationButton } from './VisualizationButton';
  10. import { VisualizationSelectPane } from './VisualizationSelectPane';
  11. import { OptionPaneRenderProps } from './types';
  12. import { usePanelLatestData } from './usePanelLatestData';
  13. export const OptionsPane: React.FC<OptionPaneRenderProps> = ({
  14. plugin,
  15. panel,
  16. onFieldConfigsChange,
  17. onPanelOptionsChanged,
  18. onPanelConfigChange,
  19. dashboard,
  20. instanceState,
  21. }) => {
  22. const styles = useStyles(getStyles);
  23. const isVizPickerOpen = useSelector((state: StoreState) => state.panelEditor.isVizPickerOpen);
  24. const { data } = usePanelLatestData(panel, { withTransforms: true, withFieldConfig: false }, true);
  25. return (
  26. <div className={styles.wrapper} aria-label={selectors.components.PanelEditor.OptionsPane.content}>
  27. {!isVizPickerOpen && (
  28. <>
  29. <div className={styles.vizButtonWrapper}>
  30. <VisualizationButton panel={panel} />
  31. </div>
  32. <div className={styles.optionsWrapper}>
  33. <OptionsPaneOptions
  34. panel={panel}
  35. dashboard={dashboard}
  36. plugin={plugin}
  37. instanceState={instanceState}
  38. data={data}
  39. onFieldConfigsChange={onFieldConfigsChange}
  40. onPanelOptionsChanged={onPanelOptionsChanged}
  41. onPanelConfigChange={onPanelConfigChange}
  42. />
  43. </div>
  44. </>
  45. )}
  46. {isVizPickerOpen && <VisualizationSelectPane panel={panel} data={data} />}
  47. </div>
  48. );
  49. };
  50. const getStyles = (theme: GrafanaTheme) => {
  51. return {
  52. wrapper: css`
  53. height: 100%;
  54. width: 100%;
  55. display: flex;
  56. flex: 1 1 0;
  57. flex-direction: column;
  58. padding: 0;
  59. `,
  60. optionsWrapper: css`
  61. flex-grow: 1;
  62. min-height: 0;
  63. `,
  64. vizButtonWrapper: css`
  65. padding: 0 ${theme.spacing.md} ${theme.spacing.md} 0;
  66. `,
  67. legacyOptions: css`
  68. label: legacy-options;
  69. .panel-options-grid {
  70. display: flex;
  71. flex-direction: column;
  72. }
  73. .panel-options-group {
  74. margin-bottom: 0;
  75. }
  76. .panel-options-group__body {
  77. padding: ${theme.spacing.md} 0;
  78. }
  79. .section {
  80. display: block;
  81. margin: ${theme.spacing.md} 0;
  82. &:first-child {
  83. margin-top: 0;
  84. }
  85. }
  86. `,
  87. };
  88. };