Skip to content
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

localstorage for alert #11

Merged
merged 10 commits into from
Jun 1, 2017
Merged

localstorage for alert #11

merged 10 commits into from
Jun 1, 2017

Conversation

Dildaarkhan
Copy link
Contributor

Create a local storage for "Merchant Warning Alert for Revenue" after 5 attempts it will be disappear.

@Dildaarkhan Dildaarkhan requested a review from thibautRe May 26, 2017 08:45
Copy link
Contributor

@thibautRe thibautRe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, good job, it seem to work fine.

Just one other thing to think about, that localstorage behavior should be a opt-in behavior. So one thing you could do is have a prop for the component, like stopShowingWhenClosed, and the value of the prop could be the number of time you want the alert to be closed (in that case the hardcoded 5 you used). If that prop is not set (undefined) then the behavior shouldn't be used and the alert should always be shown no matter what.

@@ -57,34 +60,39 @@ export default class Alert extends React.Component {
}

render() {
const { children, type, unclosable } = this.props
if (this.state.count < 5) {
console.log(this.state.count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug log : can be removed

@@ -1,6 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import styles from '../styles.less'
import { loadstate, saveState } from './localStorage'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for the sake of having the same naming convention, you could rename loadstate to loadState (capital S)

const { children, type, unclosable } = this.props
if (this.state.count < 5) {
console.log(this.state.count)
saveState(this.state.count + 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think the behavior should rather be "if the user closes the popup 5 times we should stop showing it" rather than having the render function incrementing the number. To do so, you can use the close() method.

@@ -0,0 +1,20 @@
export const loadstate = () => {
try {
const serializedState = localStorage.getItem('count')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One problem I see with that implementation is that if you have several alert components, they will all share the same localStorage variable count, and will interfere with each other. To fix that, the localstorage key name should maybe be passed as a prop to the Alert component.

Copy link
Contributor

@thibautRe thibautRe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

You can also have a look into adding some documentation in the component's README file to document your changes and your new props. Additionnaly, you can add a Storybook story for that component with the new props that you added.

Also, you can add some tests for this behavior


if (this.state.count < this.props.stopShowingWhenClosed || this.props.stopShowingWhenClosed === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can unwrap stopShowingWhenClosed info in the const {...} = this.props line above

onClose: PropTypes.func,
}

static defaultProps = {
children: '',
type: 'info',
unclosable: false,
stopShowingWhenClosed: undefined,
componentKey: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this prop is really tied with stopShowingWhenClosed, maybe you should name it accordingly (for instance stopShowingWhenClosedKey (which is super long, I agree, but maybe it's better to understand what it really means)

@Dildaarkhan Dildaarkhan merged commit 6968dab into master Jun 1, 2017
@Dildaarkhan Dildaarkhan deleted the fyndiq-ui-new-alert branch June 1, 2017 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants