-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add url interception without listening #133
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attach some screenshots and add test cases.
app/__tests__/popup.test.jsx
Outdated
.find("button") | ||
.at(0) | ||
.hasClass("button-start-listening") | ||
).toEqual(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use toBeTruthy()
app/components/AddRuleModal.tsx
Outdated
type="text" | ||
name="modal-url" | ||
id="url-input-modal" | ||
onChange={e => props.updateModalUrl(e.target.value)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onChange={props.updateModalUrl}
.
updateModalUrl
will receive event
object as first argument and do the e.target.value
inside updateModalUrl
.
Advantage: avoiding function declaration on reach render.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had missed this point^^. Thanks for reminding. Better to use this pattern everytime we pass event/event properties
app/components/AddRuleModal.tsx
Outdated
export const AddRuleModal: React.SFC<{}> = props => { | ||
return ( | ||
<Modal show={props.showModal} handleClose={props.handleClose}> | ||
<label htmlFor="modal-url">URL</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for
should be associated with id
not name
app/components/AddRuleModal.tsx
Outdated
<input | ||
className="form-control" | ||
type="text" | ||
name="modal-url" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name like modal-url
can be better. no need to have modal in context for the name of this input.
better will be request_url
.
avoid -
(hypen) for names.
app/components/AddRuleModal.tsx
Outdated
id="url-input-modal" | ||
onChange={e => props.updateModalUrl(e.target.value)} | ||
/> | ||
<label htmlFor="modal-method">Method</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for
should be associated with id
not name
app/components/AddRuleModal.tsx
Outdated
defaultValue="GET" | ||
value={props.modalMethod} | ||
className="modal-method" | ||
onChange={e => props.updateModalMethod(e.target.value)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onChange={props.updateModalUrl}
. for the same reason above.
@@ -0,0 +1,14 @@ | |||
import * as React from "react"; | |||
export const Modal = ({ handleClose, show, children }) => { | |||
const showHideClassName = show ? "modal display-block" : "modal display-none"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to switch the css classes.
Instead either we render or no render the component.
app/containers/Popup.tsx
Outdated
@@ -28,6 +31,11 @@ const isChromeUrl = (url: string) => { | |||
return CHROME_URL_REGEX.test(url); | |||
}; | |||
export class Popup extends React.Component<POPUP_PROPS & DispatchProps, {}> { | |||
state = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to redux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since its a container
component and the state
defined here is used just to show/hide the modal
window(not much complication regarding state involved), should we move this to redux ?
…resence of className
…y function creation by passing event object instead of target.value
… property to show/hide modal window
…e - Stored modal window state across tabs for data persistence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need validation for the user input URL
.
app/__tests__/AddRuleModal.test.jsx
Outdated
expect(wrapper.find("Modal")).toHaveLength(1); | ||
}); | ||
test("Contains a input, select and a button element", () => { | ||
expect(wrapper.find("input")).toBeTruthy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, this won't work. wrapper.find("input")
always returns an object. so we have to check for the length to make sure the element exists
app/__tests__/AddRuleModal.test.jsx
Outdated
showModal: false, | ||
modalMethod: "GET", | ||
addRequest: jest.fn(), | ||
modalUrl: "www.codemancers.com", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't modal data based on UI. what if tomorrow we decided to not go with Modal
?
the name become meaningless and since data is used everywhere, renaming will impact a lot of places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. ^^ that makes sense. Will change names.
return { type: INITIALISE_DEFAULTS, payload: { currentTab, currentUrl, interceptStatus } }; | ||
return { | ||
type: INITIALISE_DEFAULTS, | ||
payload: { currentTab, currentUrl, interceptStatus } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we already have initialState
, why we need to send the payload?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although initialState
is defined in the reducer, we dont have any data about the currentTabId
, currentTabUrl
. Therefore, I dispatch this action as soon as the popup
is opened so that we can store information based on tabId
. Better to rename this as currentTabId
, currentTabUrl
.
I also dispatch interceptStatus
with empty string so that after each time the popup is opened, the Success
or Error
message gets erased.
@@ -0,0 +1,16 @@ | |||
import * as React from "react"; | |||
export const Modal = ({ handleClose, show, children }) => { | |||
if (!show) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition shouldn't be a part of this component.
{showModal && <Modal {...props} />}
…lements to assert their presence
…d for AddRuleModal component
…t method in Popup.tsx
…lid and inValid urls
…ate changes in reducer
…ercept url on onChange event.
@Amit-MB Also please put the error message of URL validaiton near the text box itself. Don't put those error message in global error. |
I have also added the ability to edit url's in this PR (see 4th screenshot in PR description). Let's for @girish and check if there are any better design approaches. @revathskumar , |
47e30fe
to
8a2d9a9
Compare
…specs accordingly
app/components/AddRuleModal.tsx
Outdated
updateAddRequestMethod: (value: string, tabId: number) => void; | ||
updateAddRequestUrl: (value: string, tabId: number) => void; | ||
} | ||
export const AddRuleModal: React.SFC<AddRuleModalProps> = props => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it extend from Component
.
As already discussed, if we need instance methods never use Function
component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using functions
(defined internally) and not methods
or lifecycle methods
as well. Do we really need a stateful
component here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functions defining in render method is not good, this is similar to it.
This will define all the methods again and again when each time it renders.
By using Component
doesn't mean stateful
. we are not using internal state.
app/components/AddRuleModal.tsx
Outdated
</button> | ||
<button | ||
className="btn btn-primary btn-add-rule" | ||
onClick={() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid inline method and move to instance method.
app/components/AddRuleModal.tsx
Outdated
|
||
const handleClose = () => { | ||
//erase the previously set error message on each re-render | ||
props.addRuleErrorNotify(``, props.tabId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why using backticks?
app/components/AddRuleModal.tsx
Outdated
props.addRuleErrorNotify(``, props.tabId); | ||
//reset the url to empty string and request method to "GET" | ||
props.updateAddRequestUrl(``, props.tabId); | ||
props.updateAddRequestMethod(`GET`, props.tabId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backticks
app/components/AddRuleModal.tsx
Outdated
//erase the previously set error message on each re-render | ||
props.addRuleErrorNotify(``, props.tabId); | ||
//reset the url to empty string and request method to "GET" | ||
props.updateAddRequestUrl(``, props.tabId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backticks
app/components/RequestList.tsx
Outdated
updateInterceptorStatus?: (tabId: number) => void; | ||
fetchResponse: React.MouseEvent<HTMLSpanElement>; | ||
handleSwitchToggle: any; | ||
handleChangeUrl: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate?
…alue instead of value to prevent cursor jump issue
This will fix the failing test
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Add URL Modal:
After the URL is added for interception: