Bug 1575231 - The Search worker should provide target panel. r=Honza
authorlloan <lloanalas@outlook.com>
Wed, 21 Aug 2019 09:58:44 +0000
changeset 489159 c34ef6625ca789761d667572fc347039bdb8c08c
parent 489158 a531fd366fdf53689298c575d229505a2ae9005d
child 489160 d7d41033f5615723ac638929850221c1d683d34c
push id36465
push userdvarga@mozilla.com
push dateWed, 21 Aug 2019 16:47:43 +0000
treeherdermozilla-central@4ab60925635c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1575231
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1575231 - The Search worker should provide target panel. r=Honza Differential Revision: https://phabricator.services.mozilla.com/D42803
devtools/client/netmonitor/src/workers/search/search.js
--- a/devtools/client/netmonitor/src/workers/search/search.js
+++ b/devtools/client/netmonitor/src/workers/search/search.js
@@ -13,98 +13,106 @@ function searchInResource(resource, quer
   const results = [];
 
   if (resource.url) {
     results.push(
       findMatches(resource, query, {
         key: "url",
         label: "Url",
         type: "url",
+        panel: "headers",
       })
     );
   }
 
   if (resource.responseHeaders) {
     results.push(
       findMatches(resource, query, {
         key: "responseHeaders.headers",
         label: "Response Headers",
         type: "responseHeaders",
+        panel: "headers",
       })
     );
   }
 
   if (resource.requestHeaders) {
     results.push(
       findMatches(resource, query, {
         key: "requestHeaders.headers",
         label: "Request Headers",
         type: "requestHeaders",
+        panel: "headers",
       })
     );
   }
 
   if (resource.responseCookies) {
     let key = "responseCookies";
 
     if (resource.responseCookies.cookies) {
       key = "responseCookies.cookies";
     }
 
     results.push(
       findMatches(resource, query, {
         key,
         label: "Response Cookies",
         type: "responseCookies",
+        panel: "cookies",
       })
     );
   }
 
   if (resource.requestCookies) {
     let key = "requestCookies";
 
     if (resource.requestCookies.cookies) {
       key = "requestCookies.cookies";
     }
 
     results.push(
       findMatches(resource, query, {
         key,
         label: "Request Cookies",
         type: "requestCookies",
+        panel: "cookies",
       })
     );
   }
 
   if (resource.securityInfo) {
     results.push(
       findMatches(resource, query, {
         key: "securityInfo",
         label: "Security Information",
         type: "securityInfo",
+        panel: "security",
       })
     );
   }
 
   if (resource.responseContent) {
     results.push(
       findMatches(resource, query, {
         key: "responseContent.content.text",
         label: "Response Content",
         type: "responseContent",
+        panel: "response",
       })
     );
   }
 
   if (resource.requestPostData) {
     results.push(
       findMatches(resource, query, {
         key: "requestPostData.postData.text",
         label: "Request Post Data",
         type: "requestPostData",
+        panel: "headers",
       })
     );
   }
 
   return getResults(results);
 }
 
 /**
@@ -241,24 +249,24 @@ function searchInText(query, text, data)
  * Search for query in array.
  * Iterates through each array item and handles item based on type.
  * @param query
  * @param arr
  * @param data
  * @returns {*}
  */
 function searchInArray(query, arr, data) {
-  const { type, key, label } = data;
+  const { key, label } = data;
   const matches = arr
     .filter(match => JSON.stringify(match).includes(query))
     .map((match, i) =>
       findMatches(match, query, {
+        ...data,
         label: match.hasOwnProperty("name") ? match.name : label,
         key: key + ".[" + i + "]",
-        type,
       })
     );
 
   return getResults(matches);
 }
 
 /**
  * Return query match and up to 50 characters on left and right.
@@ -286,17 +294,16 @@ function getTruncatedValue(value, query,
  * Iterates through object, including nested objects, returns all
  * found matches.
  * @param query
  * @param obj
  * @param data
  * @returns {*}
  */
 function searchInObject(query, obj, data) {
-  const { type } = data;
   const matches = data.hasOwnProperty("collector") ? data.collector : [];
 
   for (const objectKey in obj) {
     const objectKeyType = getType(obj[objectKey]);
 
     // if the value is an object, send to search in object
     if (objectKeyType === "object" && Object.keys(obj[objectKey].length > 1)) {
       searchInObject(query, obj[objectKey], {
@@ -304,17 +311,16 @@ function searchInObject(query, obj, data
         collector: matches,
       });
     } else if (
       (objectKeyType === "string" && obj[objectKey].includes(query)) ||
       objectKey.includes(query)
     ) {
       const match = {
         ...data,
-        type,
       };
 
       const value = obj[objectKey];
       const startIndex = value.indexOf(query);
 
       match.label = objectKey;
       match.startIndex = startIndex;
       match.value = getTruncatedValue(value, query, startIndex);