flamegraphPreferences.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. export type FlamegraphColorCodings = [
  2. 'by symbol name',
  3. 'by system / application',
  4. 'by library',
  5. 'by recursion'
  6. ];
  7. export type FlamegraphSorting = ['left heavy', 'call order'];
  8. export type FlamegraphViewOptions = ['top down', 'bottom up'];
  9. export type FlamegraphAxisOptions = ['standalone', 'transaction'];
  10. export interface FlamegraphPreferences {
  11. colorCoding: FlamegraphColorCodings[number];
  12. sorting: FlamegraphSorting[number];
  13. view: FlamegraphViewOptions[number];
  14. xAxis: FlamegraphAxisOptions[number];
  15. }
  16. type FlamegraphPreferencesAction =
  17. | {payload: FlamegraphPreferences['colorCoding']; type: 'set color coding'}
  18. | {payload: FlamegraphPreferences['sorting']; type: 'set sorting'}
  19. | {payload: FlamegraphPreferences['view']; type: 'set view'}
  20. | {
  21. payload: FlamegraphPreferences['xAxis'];
  22. type: 'set xAxis';
  23. };
  24. export function flamegraphPreferencesReducer(
  25. state: FlamegraphPreferences,
  26. action: FlamegraphPreferencesAction
  27. ): FlamegraphPreferences {
  28. switch (action.type) {
  29. case 'set color coding': {
  30. return {
  31. ...state,
  32. colorCoding: action.payload,
  33. };
  34. }
  35. case 'set sorting': {
  36. return {
  37. ...state,
  38. sorting: action.payload,
  39. };
  40. }
  41. case 'set view': {
  42. return {
  43. ...state,
  44. view: action.payload,
  45. };
  46. }
  47. case 'set xAxis': {
  48. return {...state, xAxis: action.payload};
  49. }
  50. default: {
  51. return state;
  52. }
  53. }
  54. }