index.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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({allowRPC: true});
  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. const allFields = [...groupBys];
  28. for (const visualize of visualizes) {
  29. for (const yAxis of visualize.yAxes) {
  30. if (allFields.includes(yAxis)) {
  31. continue;
  32. }
  33. allFields.push(yAxis);
  34. }
  35. }
  36. return allFields.filter(Boolean);
  37. }, [resultMode, sampleFields, groupBys, visualizes]);
  38. const [sorts, setSorts] = useSorts({fields});
  39. return (
  40. <div>
  41. {extras?.includes('dataset toggle') && (
  42. <ToolbarDataset dataset={dataset} setDataset={setDataset} />
  43. )}
  44. <ToolbarResults resultMode={resultMode} setResultMode={setResultMode} />
  45. <ToolbarVisualize />
  46. <ToolbarGroupBy disabled={resultMode !== 'aggregate'} />
  47. <ToolbarSortBy fields={fields} sorts={sorts} setSorts={setSorts} />
  48. </div>
  49. );
  50. }