flamegraphProfiles.tsx 957 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {FlamegraphFrame} from 'sentry/utils/profiling/flamegraphFrame';
  2. type SetProfilesActiveIndex = {
  3. payload: number;
  4. type: 'set thread id';
  5. };
  6. type SetSelectedNode = {
  7. payload: FlamegraphFrame | null;
  8. type: 'set selected node';
  9. };
  10. type FlamegraphProfilesAction = SetProfilesActiveIndex | SetSelectedNode;
  11. type FlamegraphProfilesState = {
  12. selectedNode: FlamegraphFrame | null;
  13. threadId: number | null;
  14. };
  15. export function flamegraphProfilesReducer(
  16. state: FlamegraphProfilesState,
  17. action: FlamegraphProfilesAction
  18. ): FlamegraphProfilesState {
  19. switch (action.type) {
  20. case 'set selected node': {
  21. return {...state, selectedNode: action.payload};
  22. }
  23. case 'set thread id': {
  24. // When the profile index changes, we want to drop the selected and hovered nodes
  25. return {
  26. ...state,
  27. selectedNode: null,
  28. threadId: action.payload,
  29. };
  30. }
  31. default: {
  32. return state;
  33. }
  34. }
  35. }