|
@@ -66,12 +66,25 @@ export function decodeFlamegraphStateFromQueryParams(
|
|
|
): DeepPartial<FlamegraphState> {
|
|
|
const decoded: DeepPartial<FlamegraphState> = {};
|
|
|
|
|
|
- if (typeof query.frameName === 'string' && typeof query.framePackage === 'string') {
|
|
|
+ // Similarly to how we encode frame name and values, we want to
|
|
|
+ // omit the field entirely if it is not present in the query string or
|
|
|
+ // if it is an empty string.
|
|
|
+ if (typeof query.frameName === 'string') {
|
|
|
decoded.profiles = {
|
|
|
...(decoded.profiles ?? {}),
|
|
|
highlightFrames: {
|
|
|
- name: query.frameName,
|
|
|
- package: query.framePackage,
|
|
|
+ ...(decoded.profiles?.highlightFrames ?? {}),
|
|
|
+ name: query.frameName ? query.frameName : undefined,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (typeof query.framePackage === 'string') {
|
|
|
+ decoded.profiles = {
|
|
|
+ ...(decoded.profiles ?? {}),
|
|
|
+ highlightFrames: {
|
|
|
+ ...(decoded.profiles?.highlightFrames ?? {}),
|
|
|
+ package: query.framePackage ? query.framePackage : undefined,
|
|
|
},
|
|
|
};
|
|
|
}
|
|
@@ -112,6 +125,19 @@ export function decodeFlamegraphStateFromQueryParams(
|
|
|
}
|
|
|
|
|
|
export function encodeFlamegraphStateToQueryParams(state: FlamegraphState) {
|
|
|
+ const highlightFrameToEncode: Record<string, string> = {};
|
|
|
+
|
|
|
+ // For some frames we do not have a package (or name) if that happens we want to omit
|
|
|
+ // the field entirely from the query string. This is to avoid default values being used
|
|
|
+ // as qs.parse will initialize empty values to "" which can differ from the respective
|
|
|
+ // frame values which are undefined.
|
|
|
+ if (state.profiles.highlightFrames?.name) {
|
|
|
+ highlightFrameToEncode.frameName = state.profiles.highlightFrames.name;
|
|
|
+ }
|
|
|
+ if (state.profiles.highlightFrames?.package) {
|
|
|
+ highlightFrameToEncode.framePackage = state.profiles.highlightFrames.package;
|
|
|
+ }
|
|
|
+
|
|
|
const highlightFrame = state.profiles.highlightFrames
|
|
|
? {
|
|
|
frameName: state.profiles.highlightFrames?.name,
|