index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {useMemo} from 'react';
  2. import {useDataset} from 'sentry/views/explore/hooks/useDataset';
  3. import {useGroupBys} from 'sentry/views/explore/hooks/useGroupBys';
  4. import {useResultMode} from 'sentry/views/explore/hooks/useResultsMode';
  5. import {useSampleFields} from 'sentry/views/explore/hooks/useSampleFields';
  6. import {useSorts} from 'sentry/views/explore/hooks/useSorts';
  7. import {useVisualizes} from 'sentry/views/explore/hooks/useVisualizes';
  8. import {ToolbarDataset} from 'sentry/views/explore/toolbar/toolbarDataset';
  9. import {ToolbarGroupBy} from 'sentry/views/explore/toolbar/toolbarGroupBy';
  10. import {ToolbarResults} from 'sentry/views/explore/toolbar/toolbarResults';
  11. import {ToolbarSortBy} from 'sentry/views/explore/toolbar/toolbarSortBy';
  12. import {ToolbarVisualize} from 'sentry/views/explore/toolbar/toolbarVisualize';
  13. type Extras = 'dataset toggle';
  14. interface ExploreToolbarProps {
  15. extras?: Extras[];
  16. }
  17. export function ExploreToolbar({extras}: ExploreToolbarProps) {
  18. const [dataset, setDataset] = useDataset();
  19. const [resultMode, setResultMode] = useResultMode();
  20. const [sampleFields] = useSampleFields();
  21. const {groupBys} = useGroupBys();
  22. const [visualizes] = useVisualizes();
  23. const fields = useMemo(() => {
  24. if (resultMode === 'samples') {
  25. return sampleFields;
  26. }
  27. return [...groupBys, ...visualizes.flatMap(visualize => visualize.yAxes)].filter(
  28. Boolean
  29. );
  30. }, [resultMode, sampleFields, groupBys, visualizes]);
  31. const [sorts, setSorts] = useSorts({fields});
  32. return (
  33. <div>
  34. {extras?.includes('dataset toggle') && (
  35. <ToolbarDataset dataset={dataset} setDataset={setDataset} />
  36. )}
  37. <ToolbarResults resultMode={resultMode} setResultMode={setResultMode} />
  38. <ToolbarVisualize />
  39. <ToolbarGroupBy disabled={resultMode !== 'aggregate'} />
  40. <ToolbarSortBy fields={fields} sorts={sorts} setSorts={setSorts} />
  41. </div>
  42. );
  43. }