Files
2024-02-15 17:01:50 +00:00

41 lines
940 B
TypeScript

import type {FlamegraphFrame} from 'sentry/utils/profiling/flamegraphFrame';
type SetProfilesThreadId = {
payload: number;
type: 'set thread id';
};
type SetRootNode = {
payload: FlamegraphFrame | null;
type: 'set selected root';
};
type FlamegraphProfilesAction = SetProfilesThreadId | SetRootNode;
export type FlamegraphProfiles = {
selectedRoot: FlamegraphFrame | null;
threadId: number | null;
};
export function flamegraphProfilesReducer(
state: FlamegraphProfiles,
action: FlamegraphProfilesAction
): FlamegraphProfiles {
switch (action.type) {
case 'set selected root': {
return {...state, selectedRoot: action.payload};
}
case 'set thread id': {
// When the profile index changes, we want to drop the selected and hovered nodes
return {
...state,
selectedRoot: null,
threadId: action.payload,
};
}
default: {
return state;
}
}
}