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

Reset all filters button on Events page #435

Merged
merged 16 commits into from
Jun 16, 2018
Merged

Reset all filters button on Events page #435

merged 16 commits into from
Jun 16, 2018

Conversation

jonyardley
Copy link
Contributor

@jonyardley jonyardley commented Jun 13, 2018

This PR adds a Reset all filters button to the Events page.

The button should exhibit the following behaviours:

  • When no filters are selected it should not be visible
  • When one or more filters are selected it should be visible
  • When pressed it should reset all filters and fade out and up
  • When pressed it should also reset the Event List view position to the top

Test Plan

Following the steps outlined above should suffice.

Areas of risk

  • Events page
    • All Filters
    • Event List

Further Notes

We have agreed that the header should probably be hidden when scrolling however due to a funky jitterbug with the scrolling and the refresh component we have decided to pull this feature out into a new issue/PR so that it can be tackled separately in order to get this out sooner.

Fixes: #340

Pre-flight check-list

Before raising a pull request

  • Documentation
  • Unit tests

Pre-merge check-list

  • Link to Trello ticket/GitHub issue (If applicable)
  • Any risky areas identified
  • Test plan provided
  • Tester approved

Tester check-list

  • Tested on multiple devices / OS versions (Test on the physical device(s) you have access to, otherwise use BrowserStack):

    • Galaxy S8 (Android 7.0/8.0)
    • Galaxy S7 (Android 6.0)
    • iPhone X (iOS 11.x)
    • iPhone 8 (11.x)
    • iPhone 7 (iOS 10.x)

    Optional:

    • Google Pixel 2
    • Galaxy S8 Plus
    • Galaxy S7 Edge
    • Galaxy S6
    • iPhone 7+
    • iPhone 6

Accessibility Testing (If applicable)

  • Text-to-Voice (Android: Voice Assistant / iOS: Speak Selection)
  • Large Text (=<200%)
  • Landscape Screen orientation

Weak connection testing (If applicable)

  • Airplane mode
  • 2G/3G Network Settings

@jonyardley jonyardley added the wip label Jun 13, 2018
@@ -61,4 +61,4 @@ export const clearStagedEventFilters = () => (

export const clearEventFilters = () => (
dispatch: Dispatch<EventFiltersAction>
) => dispatch({ type: "CLEAR__EVENT_FILTERS" });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🎺

@jonyardley jonyardley changed the title WIP: Initial commit with working reset button WIP: Reset all button Jun 14, 2018
@jonyardley jonyardley changed the title WIP: Reset all button Reset all filters button on Events page Jun 15, 2018
};

animationFinished = (): void => {
this.setState({ isAnimating: false });
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be called when the button has already been unmounted, in which case setState will throw an exception.

Copy link
Contributor Author

@jonyardley jonyardley Jun 15, 2018

Choose a reason for hiding this comment

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

Ah yeah, good catch. I notice that isMounted() is now deprecated. Do you have a pattern in mind to catch this? Maybe a try catch (might be a bit crude).

Copy link
Contributor Author

@jonyardley jonyardley Jun 15, 2018

Choose a reason for hiding this comment

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

Looked into this a bit more and there is a post from Dan Abramov on this issue:

facebook/react#2787 (comment)

In any case, React doesn’t throw errors when this happens anymore. But we will intentionally keep the suboptimal case clunky so that the developers have incentives to implement the right solution (cancellation).

It is now only a warning and not an error so inclined to leave this as is due do it being a edgy edge case unless you think it will be a major issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, interesting. We tested this we @RGBboy for the heart animation. I'm pretty sure we could make this crash. 🤔

As far as I can see the recommendation is to set a field, which is basically what we ended up doing here:

componentWillUnmount() {
this.completeAnimation();
}

Maybe our crash was unrelated though and we can just leave this at it is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I created a unit test for unmount -> setState and it threw an exception. So I just added a quick fix for this, just to be on the safe side.

const DEFAULT_FADE_VALUE = 1;
const DEFAULT_TOP_OFFSET_VALUE = 0;

class ResetAllFiltersButton extends React.Component<Props, State> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to make this a PureComponent, so it doesn't rerender all the time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certainly!

<View>
<ResetAllFiltersButton
visible={anyAppliedFilters}
onPress={() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you make ResetAllFiltersButton a pure component, this shouldn't be an inline function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you elaborate a bit? Not sure I follow this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

As fas as I know, this will generate a new function every time in render, which means that inside ResetAllFiltersButton this check will always be false: props.onPress === nextProps.onPress. So it will render every time.

We could solve this by adding the function to the FilterHeader class:

resetAllFilters = () => {
  this.props.resetAllFiltersPress();
  this.props.scrollEventListToTop();
};

Then use onPress={this.resetAllFilters}. This will always pass in the same function.

@frigus02
Copy link
Contributor

The reset button has a weird touch area. It is mostly above the text. Do you think we are able to increase the touch area below the text?

The highlighted part in the screenshot is the touchable area:

image

@jonyardley
Copy link
Contributor Author

@frigus02 The padding this will be a bit tricky here. As we will need to animate the padding on the categories header too and would rather keep animation to a minimum.

@frigus02
Copy link
Contributor

Ah, right. Makese sense with the animation 👍

@frigus02 frigus02 merged commit 4d3027b into master Jun 16, 2018
@frigus02 frigus02 deleted the reset-all-filters branch June 16, 2018 11:08
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.

3 participants