Commit e54f4ec3 authored by Claudia's avatar Claudia
Browse files

Bug 1744786 - [devtools] Default select the new request that was sent by edit...

Bug 1744786 - [devtools] Default select the new request that was sent by edit and resend panel r=bomsy

Differential Revision: https://phabricator.services.mozilla.com/D135729
parent ebdd8a29
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -8,10 +8,21 @@ const {
  OPEN_ACTION_BAR,
  SELECT_ACTION_BAR_TAB,
  PANELS,
  SEND_CUSTOM_REQUEST,
  RIGHT_CLICK_REQUEST,
  PRESELECT_REQUEST,
} = require("devtools/client/netmonitor/src/constants");

const {
  selectRequest,
} = require("devtools/client/netmonitor/src/actions/selection");

const {
  openNetworkDetails,
} = require("devtools/client/netmonitor/src/actions/ui");

const {
  getRequestByChannelId,
} = require("devtools/client/netmonitor/src/selectors/index");
/**
 * Open the entire HTTP Custom Request panel
 * @returns {Function}
@@ -71,15 +82,23 @@ function sendHTTPCustomRequest(connector, request) {
    }

    if (request.requestPostData) {
      data.body = request.requestPostData.postData.text;
      data.body = request.requestPostData.postData?.text;
    }

    const { channelId } = await connector.sendHTTPRequest(data);

    dispatch({
      type: SEND_CUSTOM_REQUEST,
    const newRequest = getRequestByChannelId(getState(), channelId);
    // If the new custom request is available already select the request, else
    // preselect the request.
    if (newRequest) {
      await dispatch(selectRequest(newRequest.id));
    } else {
      await dispatch({
        type: PRESELECT_REQUEST,
        id: channelId,
      });
    }
    dispatch(openNetworkDetails(true));
  };
}

+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ const actionTypes = {
  DISABLE_BROWSER_CACHE: "DISABLE_BROWSER_CACHE",
  OPEN_STATISTICS: "OPEN_STATISTICS",
  PERSIST_CHANGED: "PERSIST_CHANGED",
  PRESELECT_REQUEST: "PRESELECT_REQUEST",
  REMOVE_SELECTED_CUSTOM_REQUEST: "REMOVE_SELECTED_CUSTOM_REQUEST",
  RESET_COLUMNS: "RESET_COLUMNS",
  SELECT_REQUEST: "SELECT_REQUEST",
+8 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ const {
  REMOVE_SELECTED_CUSTOM_REQUEST,
  RIGHT_CLICK_REQUEST,
  SELECT_REQUEST,
  PRESELECT_REQUEST,
  SEND_CUSTOM_REQUEST,
  TOGGLE_RECORDING,
  UPDATE_REQUEST,
@@ -101,6 +102,13 @@ function requestsReducer(state = Requests(), action) {
      };
    }

    case PRESELECT_REQUEST: {
      return {
        ...state,
        preselectedId: action.id,
      };
    }

    // Removing temporary cloned request (created for re-send, but canceled).
    case REMOVE_SELECTED_CUSTOM_REQUEST: {
      return closeCustomRequest(state);
+46 −46
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ const NetworkContentActor = ActorClassWithSpec(networkContentSpec, {
   *        The channel id for the request
   */
  async sendHTTPRequest(request) {
    return new Promise(resolve => {
      const { url, method, headers, body, cause } = request;
      // Set the loadingNode and loadGroup to the target document - otherwise the
      // request won't show up in the opened netmonitor.
@@ -72,14 +73,14 @@ const NetworkContentActor = ActorClassWithSpec(networkContentSpec, {
      const channel = NetUtil.newChannel({
        uri: NetUtil.newURI(url),
        loadingNode: doc,
      securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
        securityFlags:
          Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
        contentPolicyType:
          NetworkUtils.stringToCauseType(cause.type) ||
          Ci.nsIContentPolicy.TYPE_OTHER,
      });

      channel.QueryInterface(Ci.nsIHttpChannel);

      channel.loadGroup = doc.documentLoadGroup;
      channel.loadFlags |=
        Ci.nsIRequest.LOAD_BYPASS_CACHE |
@@ -113,7 +114,6 @@ const NetworkContentActor = ActorClassWithSpec(networkContentSpec, {
        channel.explicitSetUploadStream(bodyStream, null, -1, method, false);
      }

    return new Promise(resolve => {
      // Make sure the fetch has completed before sending the channel id,
      // so that there is a higher possibilty that the request get into the
      // redux store beforehand (but this does not gurantee that).