From ba6f91ec79b82d3bab9ab7294f4360b93db70bb5 Mon Sep 17 00:00:00 2001 From: Amit Bhavikatti Date: Wed, 16 May 2018 12:05:04 +0530 Subject: [PATCH 1/3] Add title attribute to all buttons --- app/components/InterceptAllButton.tsx | 17 +-- .../Intercept_Components/InterceptTextBox.tsx | 7 +- app/components/request_list.tsx | 135 ++++++++++-------- app/containers/popup.tsx | 78 +++++----- 4 files changed, 125 insertions(+), 112 deletions(-) diff --git a/app/components/InterceptAllButton.tsx b/app/components/InterceptAllButton.tsx index 0347146..8c79e05 100644 --- a/app/components/InterceptAllButton.tsx +++ b/app/components/InterceptAllButton.tsx @@ -3,13 +3,14 @@ import * as React from "react"; export const InterceptAllButton = props => { return ( + id="intercept-all-btn" + title="Intercept Selected Requests" + className="btn btn-sm btn-primary btn-clear" + disabled={props.disabled} + onClick={props.handleCheckedRequests} + > + Intercept + ); }; @@ -17,4 +18,4 @@ InterceptAllButton.displayName = "InterceptAllButton"; InterceptAllButton.defaultProps = { disabled: false -}; \ No newline at end of file +}; diff --git a/app/components/Intercept_Components/InterceptTextBox.tsx b/app/components/Intercept_Components/InterceptTextBox.tsx index 3503e77..50abb2c 100644 --- a/app/components/Intercept_Components/InterceptTextBox.tsx +++ b/app/components/Intercept_Components/InterceptTextBox.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import {RequestHeaderList} from "./RequestHeaderList"; +import { RequestHeaderList } from "./RequestHeaderList"; export const InterceptTextBox = props => { const requestId = props.rowProps.checkbox.requestId; @@ -25,9 +25,9 @@ export const InterceptTextBox = props => {
- + +
+ +
+ { + return props.handleCheckedRequests(enabledRequests); + }} + /> + +
-
- props.handlePaginationChange(changedPageNo, props.tabId, "currentPageNumber")} - onPageSizeChange={changedRowSize => props.handlePaginationChange(changedRowSize, props.tabId, "currentRowSize")} - collapseOnDataChange={false} - SubComponent={row => ( - - )} - /> + + props.handlePaginationChange(changedPageNo, props.tabId, "currentPageNumber") + } + onPageSizeChange={changedRowSize => + props.handlePaginationChange(changedRowSize, props.tabId, "currentRowSize") + } + collapseOnDataChange={false} + SubComponent={row => ( + + )} + /> ); }; diff --git a/app/containers/popup.tsx b/app/containers/popup.tsx index 17e30f4..8e59fd5 100644 --- a/app/containers/popup.tsx +++ b/app/containers/popup.tsx @@ -1,11 +1,10 @@ import * as React from "react"; import * as cx from "classnames"; -import {connect} from "react-redux"; -import {Store} from "react-chrome-redux"; +import { connect } from "react-redux"; import * as MessageService from "./../message_service"; import RequestList from "./../components/request_list"; -import {POPUP_PROPS} from "./../types"; +import { POPUP_PROPS } from "./../types"; import * as actionTypes from "./../actions"; interface DispatchProps { @@ -22,7 +21,7 @@ interface DispatchProps { handleContentTypeChange: typeof actionTypes.handleContentTypeChange; handlePaginationChange: typeof actionTypes.handlePaginationChange; updateInterceptorStatus: typeof actionTypes.updateInterceptorStatus; - fetchResponse:typeof actionTypes.fetchResponse; + fetchResponse: typeof actionTypes.fetchResponse; } const CHROME_URL_REGEX = /^chrome:\/\/.+$/; @@ -50,9 +49,9 @@ export class Popup extends React.Component { this.props.updateField("enabled", enabledStatus); }); this.props.updateField("errorMessage", ""); - if(this.props.isInterceptorOn[this.props.tabId] === undefined ){ - this.props.updateInterceptorStatus(this.props.tabId, true) - } + if (this.props.isInterceptorOn[this.props.tabId] === undefined) { + this.props.updateInterceptorStatus(this.props.tabId, true); + } } isUrlInValid = (tabUrl: string) => { @@ -70,7 +69,7 @@ export class Popup extends React.Component { } else { MessageService.getRequests(this.props.tabId, requests => { MessageService.enableLogging(this.props.tabUrl, this.props.tabId); - this.props.updateFields({enabled: true, requests}); + this.props.updateFields({ enabled: true, requests }); }); } }; @@ -104,33 +103,34 @@ export class Popup extends React.Component { this.props.handlePaginationChange(newPageNo_rowSize, tabId, field); }; - disableInterceptor =(tabId:number) => { - MessageService.disableInterceptor(tabId) - } + disableInterceptor = (tabId: number) => { + MessageService.disableInterceptor(tabId); + }; - updateInterceptorStatus = (tabId:number, interceptMode:boolean) => { - this.props.updateInterceptorStatus(tabId, interceptMode) - } - updateBadgeIcon = (tabId:number,disabledStatus:boolean) => { - MessageService.updateBadgeIcon(tabId,disabledStatus) - } + updateInterceptorStatus = (tabId: number, interceptMode: boolean) => { + this.props.updateInterceptorStatus(tabId, interceptMode); + }; + updateBadgeIcon = (tabId: number, disabledStatus: boolean) => { + MessageService.updateBadgeIcon(tabId, disabledStatus); + }; handleSwitch = () => { - if(this.props.isInterceptorOn[this.props.tabId]){ - this.props.updateInterceptorStatus(this.props.tabId, false) - .then(() => { - this.disableInterceptor(this.props.tabId) - this.updateBadgeIcon(this.props.tabId, true) - }) - .catch((err) => { - // something broke in the background store - console.log(err) - }); - }else{ - this.props.updateInterceptorStatus(this.props.tabId, true) - this.updateBadgeIcon(this.props.tabId, false) + if (this.props.isInterceptorOn[this.props.tabId]) { + this.props + .updateInterceptorStatus(this.props.tabId, false) + .then(() => { + this.disableInterceptor(this.props.tabId); + this.updateBadgeIcon(this.props.tabId, true); + }) + .catch(err => { + // something broke in the background store + console.log(err); + }); + } else { + this.props.updateInterceptorStatus(this.props.tabId, true); + this.updateBadgeIcon(this.props.tabId, false); } - } + }; render() { const buttonClass = cx("btn btn-block", { @@ -164,7 +164,12 @@ export class Popup extends React.Component { INTERCEPTOR - @@ -174,12 +179,7 @@ export class Popup extends React.Component { {this.props.errorMessage ? (

{this.props.errorMessage}

) : null} - { - this.props.interceptStatus && -
- {this.props.interceptStatus} -
- } + {this.props.interceptStatus &&
{this.props.interceptStatus}
} Date: Wed, 16 May 2018 12:24:17 +0530 Subject: [PATCH 2/3] Set Start/Stop button title attr conditionally --- app/containers/popup.tsx | 42 ++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/app/containers/popup.tsx b/app/containers/popup.tsx index 8e59fd5..b94952e 100644 --- a/app/containers/popup.tsx +++ b/app/containers/popup.tsx @@ -30,12 +30,6 @@ const isChromeUrl = (url: string) => { return CHROME_URL_REGEX.test(url); }; -interface BgStore { - ready(): Promise; - getState(): any; - dispatch: any; -} - export class Popup extends React.Component { componentWillMount() { this.props.updateField("interceptStatus", ""); @@ -137,6 +131,8 @@ export class Popup extends React.Component { "button-start-listening btn-secondary": !this.props.enabled, "button-stop-listening btn-danger": this.props.enabled }); + const props = this.props; + const enabled = this.props.enabled; return (
@@ -165,44 +161,44 @@ export class Popup extends React.Component { INTERCEPTOR
- {this.props.errorMessage ? ( + {props.errorMessage ? (

{this.props.errorMessage}

) : null} - {this.props.interceptStatus &&
{this.props.interceptStatus}
} + {props.interceptStatus &&
{this.props.interceptStatus}
}
From cfa59175e4b8e203bf046644fb199bcea387a66e Mon Sep 17 00:00:00 2001 From: Amit Bhavikatti Date: Wed, 16 May 2018 12:31:15 +0530 Subject: [PATCH 3/3] Use props to check for enabled state instead of declaring its own variable --- app/containers/popup.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/containers/popup.tsx b/app/containers/popup.tsx index b94952e..de5d86a 100644 --- a/app/containers/popup.tsx +++ b/app/containers/popup.tsx @@ -132,7 +132,6 @@ export class Popup extends React.Component { "button-stop-listening btn-danger": this.props.enabled }); const props = this.props; - const enabled = this.props.enabled; return (
@@ -161,21 +160,21 @@ export class Popup extends React.Component { INTERCEPTOR
{props.errorMessage ? ( -

{this.props.errorMessage}

+

{props.errorMessage}

) : null} - {props.interceptStatus &&
{this.props.interceptStatus}
} + {props.interceptStatus &&
{props.interceptStatus}
}