flamegraphPreferences.tsx 1.7 KB

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