flamegraphSearch.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import type Fuse from 'fuse.js';
  2. import {FlamegraphFrame} from 'sentry/utils/profiling/flamegraphFrame';
  3. export type FlamegraphSearchResult = {
  4. frame: FlamegraphFrame;
  5. match: Fuse.RangeTuple;
  6. };
  7. export type FlamegraphSearch = {
  8. index: number | null;
  9. query: string;
  10. results: Map<string, FlamegraphSearchResult>;
  11. };
  12. type ClearFlamegraphSearchAction = {
  13. type: 'clear search';
  14. };
  15. type SetFlamegraphResultsAction = {
  16. payload: {
  17. query: string;
  18. results: FlamegraphSearch['results'];
  19. };
  20. type: 'set results';
  21. };
  22. type FlamegraphSearchArrowNavigationAction = {
  23. payload: number;
  24. type: 'set search index position';
  25. };
  26. type FlamegraphSearchAction =
  27. | ClearFlamegraphSearchAction
  28. | FlamegraphSearchArrowNavigationAction
  29. | SetFlamegraphResultsAction;
  30. export function flamegraphSearchReducer(
  31. state: FlamegraphSearch,
  32. action: FlamegraphSearchAction
  33. ): FlamegraphSearch {
  34. switch (action.type) {
  35. case 'clear search': {
  36. return {
  37. ...state,
  38. query: '',
  39. index: null,
  40. results: new Map(),
  41. };
  42. }
  43. case 'set results': {
  44. return {...state, ...action.payload};
  45. }
  46. case 'set search index position': {
  47. return {...state, index: action.payload};
  48. }
  49. default: {
  50. return state;
  51. }
  52. }
  53. }