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

refactor(frontend): Define reusable components for search filters, tweak appearance #344

Merged
merged 5 commits into from
Dec 7, 2021

Conversation

amatissart
Copy link
Member

@amatissart amatissart commented Dec 6, 2021

Description

This is a prerequisite to implement the new page "My rated videos", that will also include similar filters (on public/private ratings, etc.)

2 new components:

  • FilterSection: a generic filter section with an underlined title
  • ChoicesFilterSection: a filter column, with multiple checkboxes defined by a list of choices.
    Used by LanguageFilter and DateFilter.

Screenshots

Before After
image image
image image

@amatissart amatissart changed the title refactor(frontend): Define reusable components for search filters, tweak apparence refactor(frontend): Define reusable components for search filters, tweak appearance Dec 6, 2021
Copy link
Collaborator

@GresilleSiffle GresilleSiffle left a comment

Choose a reason for hiding this comment

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

The new design is great!

I found one issue related to the security, and one error in the browser console. Can you confirm if you have the same error?

I didn't take the time to spot where the error was triggered, but in the console, moving a slider display this message:

Material-UI: A component is changing the default value state of an uncontrolled Slider after being initialized. To suppress this warning opt to use a controlled Slider.

I confirm that, even if the message considers itself as a warning, it appears as an error.

capture

edit: we saw with @amatissart that the error is also present in main, thus not introduced by this PR, and could be fixed by using the prop value instead of defaultValue in the component src/features/recommendation/CriteriaFilter.tsx

See: https://v4.mui.com/api/slider/#props

<>
<Typography
variant="h6"
style={{ borderBottom: '1px solid #E7E5DB', marginBottom: '0.3em' }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not recommend using inline style in our components.

The day we will add a Content Security Policy in the front end, inline style will be blocked if not explicity authorized. And authorizing inline style would be a security flaw.

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src#unsafe_inline_styles

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the PR to use className instead of inline style.

Although your point about Content-Security-Policy is valid, enforcing such a policy everywhere would probably be constraining. Usage of inline styles is quite deeply baked into Material UI: see mui/material-ui#19938

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're right.

I'm curious about how many mui components use inline style.

<DateFilter setFilter={setFilter} />
<LanguageFilter setFilter={setFilter} />
<Collapse in={expanded} timeout="auto" unmountOnExit>
<Grid container spacing={4} style={{ marginBottom: '8px' }}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoidable inline style.

startIcon={!expanded ? <ExpandMore /> : <ExpandLess />}
aria-expanded={expanded}
aria-label="show more"
onClick={handleExpandClick}
style={{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoidable inline style.

startIcon={!expanded ? <ExpandMore /> : <ExpandLess />}
aria-expanded={expanded}
aria-label="show more"
onClick={handleExpandClick}
style={{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoidable inline style.

<DateFilter setFilter={setFilter} />
<LanguageFilter setFilter={setFilter} />
<Collapse in={expanded} timeout="auto" unmountOnExit>
<Grid container spacing={4} style={{ marginBottom: '8px' }}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoidable inline style.

@amatissart
Copy link
Member Author

capture

edit: we saw with @amatissart that the error is also present in main, thus not introduced by this PR, and could be fixed by using the prop value instead of defaultValue in the component src/features/recommendation/CriteriaFilter.tsx

See: https://v4.mui.com/api/slider/#props

As discussed on Discord, updating the CustomSlider to behave as a controlled input require additional changes. As it's not related to this PR and the current uncontrolled sliders seem to work as expected despite the warning in development mode, I would suggest to address this issue separately.

@amatissart amatissart merged commit f81af80 into main Dec 7, 2021
@GresilleSiffle GresilleSiffle deleted the filters-ui-components branch December 7, 2021 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants