-
Notifications
You must be signed in to change notification settings - Fork 38
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
Practice solution #14
Open
o-drozzdyk
wants to merge
1
commit into
alexandra-protyanova:main
Choose a base branch
from
o-drozzdyk:develop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,248 +1,111 @@ | ||
/* eslint-disable jsx-a11y/accessible-emoji */ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import './App.scss'; | ||
|
||
// import usersFromServer from './api/users'; | ||
// import categoriesFromServer from './api/categories'; | ||
// import productsFromServer from './api/products'; | ||
|
||
// const products = productsFromServer.map((product) => { | ||
// const category = null; // find by product.categoryId | ||
// const user = null; // find by category.ownerId | ||
|
||
// return null; | ||
// }); | ||
|
||
export const App = () => ( | ||
<div className="section"> | ||
<div className="container"> | ||
<h1 className="title">Product Categories</h1> | ||
|
||
<div className="block"> | ||
<nav className="panel"> | ||
<p className="panel-heading">Filters</p> | ||
|
||
<p className="panel-tabs has-text-weight-bold"> | ||
<a | ||
data-cy="FilterAllUsers" | ||
href="#/" | ||
> | ||
All | ||
</a> | ||
|
||
<a | ||
data-cy="FilterUser" | ||
href="#/" | ||
> | ||
User 1 | ||
</a> | ||
|
||
<a | ||
data-cy="FilterUser" | ||
href="#/" | ||
className="is-active" | ||
> | ||
User 2 | ||
</a> | ||
|
||
<a | ||
data-cy="FilterUser" | ||
href="#/" | ||
> | ||
User 3 | ||
</a> | ||
</p> | ||
|
||
<div className="panel-block"> | ||
<p className="control has-icons-left has-icons-right"> | ||
<input | ||
data-cy="SearchField" | ||
type="text" | ||
className="input" | ||
placeholder="Search" | ||
value="qwe" | ||
import { products, findOwners, filterByOwner, filterByName } from './utils'; | ||
import { Table } from './components/Table/Table'; | ||
import { FilterUserList } from './components/FilterUserList/FilterUserList'; | ||
import { FilterByInput } from './components/FilterByInput/FilterByInput'; | ||
|
||
export const App = () => { | ||
const [selectedUser, setSelectedUser] = useState('All'); | ||
const [query, setQuery] = useState(''); | ||
const owners = findOwners(products); | ||
const ownersList = ['All', ...owners, 'John']; | ||
const filteredByUser = filterByOwner(products, selectedUser); | ||
const filteredProducts = filterByName(filteredByUser, query); | ||
|
||
return ( | ||
<div className="section"> | ||
<div className="container"> | ||
<h1 className="title">Product Categories</h1> | ||
|
||
<div className="block"> | ||
<nav className="panel"> | ||
<p className="panel-heading">Filters</p> | ||
|
||
<p className="panel-tabs has-text-weight-bold"> | ||
<FilterUserList | ||
owners={ownersList} | ||
selectedUser={selectedUser} | ||
onSelectedUser={user => setSelectedUser(user)} | ||
/> | ||
|
||
<span className="icon is-left"> | ||
<i className="fas fa-search" aria-hidden="true" /> | ||
</span> | ||
|
||
<span className="icon is-right"> | ||
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
<button | ||
data-cy="ClearButton" | ||
type="button" | ||
className="delete" | ||
/> | ||
</span> | ||
</p> | ||
</div> | ||
|
||
<div className="panel-block is-flex-wrap-wrap"> | ||
<a | ||
href="#/" | ||
data-cy="AllCategories" | ||
className="button is-success mr-6 is-outlined" | ||
> | ||
All | ||
</a> | ||
|
||
<a | ||
data-cy="Category" | ||
className="button mr-2 my-1 is-info" | ||
href="#/" | ||
> | ||
Category 1 | ||
</a> | ||
|
||
<a | ||
data-cy="Category" | ||
className="button mr-2 my-1" | ||
href="#/" | ||
> | ||
Category 2 | ||
</a> | ||
|
||
<a | ||
data-cy="Category" | ||
className="button mr-2 my-1 is-info" | ||
href="#/" | ||
> | ||
Category 3 | ||
</a> | ||
<a | ||
data-cy="Category" | ||
className="button mr-2 my-1" | ||
href="#/" | ||
> | ||
Category 4 | ||
</a> | ||
</div> | ||
|
||
<div className="panel-block"> | ||
<a | ||
data-cy="ResetAllButton" | ||
href="#/" | ||
className="button is-link is-outlined is-fullwidth" | ||
> | ||
Reset all filters | ||
</a> | ||
</div> | ||
</nav> | ||
</div> | ||
|
||
<div className="box table-container"> | ||
<p data-cy="NoMatchingMessage"> | ||
No products matching selected criteria | ||
</p> | ||
|
||
<table | ||
data-cy="ProductTable" | ||
className="table is-striped is-narrow is-fullwidth" | ||
> | ||
<thead> | ||
<tr> | ||
<th> | ||
<span className="is-flex is-flex-wrap-nowrap"> | ||
ID | ||
|
||
<a href="#/"> | ||
<span className="icon"> | ||
<i data-cy="SortIcon" className="fas fa-sort" /> | ||
</span> | ||
</a> | ||
</span> | ||
</th> | ||
|
||
<th> | ||
<span className="is-flex is-flex-wrap-nowrap"> | ||
Product | ||
|
||
<a href="#/"> | ||
<span className="icon"> | ||
<i data-cy="SortIcon" className="fas fa-sort-down" /> | ||
</span> | ||
</a> | ||
</span> | ||
</th> | ||
|
||
<th> | ||
<span className="is-flex is-flex-wrap-nowrap"> | ||
Category | ||
|
||
<a href="#/"> | ||
<span className="icon"> | ||
<i data-cy="SortIcon" className="fas fa-sort-up" /> | ||
</span> | ||
</a> | ||
</span> | ||
</th> | ||
|
||
<th> | ||
<span className="is-flex is-flex-wrap-nowrap"> | ||
User | ||
|
||
<a href="#/"> | ||
<span className="icon"> | ||
<i data-cy="SortIcon" className="fas fa-sort" /> | ||
</span> | ||
</a> | ||
</span> | ||
</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<tr data-cy="Product"> | ||
<td className="has-text-weight-bold" data-cy="ProductId"> | ||
1 | ||
</td> | ||
|
||
<td data-cy="ProductName">Milk</td> | ||
<td data-cy="ProductCategory">🍺 - Drinks</td> | ||
|
||
<td | ||
data-cy="ProductUser" | ||
className="has-text-link" | ||
<FilterByInput | ||
filterBy={newQuery => setQuery(newQuery)} | ||
query={query} | ||
onClearButton={() => setQuery('')} | ||
/> | ||
|
||
<div className="panel-block is-flex-wrap-wrap"> | ||
<a | ||
href="#/" | ||
data-cy="AllCategories" | ||
className="button is-success mr-6 is-outlined" | ||
> | ||
Max | ||
</td> | ||
</tr> | ||
|
||
<tr data-cy="Product"> | ||
<td className="has-text-weight-bold" data-cy="ProductId"> | ||
2 | ||
</td> | ||
|
||
<td data-cy="ProductName">Bread</td> | ||
<td data-cy="ProductCategory">🍞 - Grocery</td> | ||
All | ||
</a> | ||
|
||
<td | ||
data-cy="ProductUser" | ||
className="has-text-danger" | ||
<a | ||
data-cy="Category" | ||
className="button mr-2 my-1 is-info" | ||
href="#/" | ||
> | ||
Anna | ||
</td> | ||
</tr> | ||
Category 1 | ||
</a> | ||
|
||
<tr data-cy="Product"> | ||
<td className="has-text-weight-bold" data-cy="ProductId"> | ||
3 | ||
</td> | ||
|
||
<td data-cy="ProductName">iPhone</td> | ||
<td data-cy="ProductCategory">💻 - Electronics</td> | ||
<a | ||
data-cy="Category" | ||
className="button mr-2 my-1" | ||
href="#/" | ||
> | ||
Category 2 | ||
</a> | ||
|
||
<td | ||
data-cy="ProductUser" | ||
className="has-text-link" | ||
<a | ||
data-cy="Category" | ||
className="button mr-2 my-1 is-info" | ||
href="#/" | ||
> | ||
Category 3 | ||
</a> | ||
<a | ||
data-cy="Category" | ||
className="button mr-2 my-1" | ||
href="#/" | ||
> | ||
Category 4 | ||
</a> | ||
</div> | ||
|
||
<div className="panel-block"> | ||
<a | ||
data-cy="ResetAllButton" | ||
href="#/" | ||
className="button is-link is-outlined is-fullwidth" | ||
onClick={() => { | ||
setSelectedUser('All'); | ||
setQuery(''); | ||
}} | ||
> | ||
Roma | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
Reset all filters | ||
</a> | ||
</div> | ||
</nav> | ||
</div> | ||
|
||
<div className="box table-container"> | ||
{!filteredProducts.length | ||
? ( | ||
<p data-cy="NoMatchingMessage"> | ||
No products matching selected criteria | ||
</p> | ||
) | ||
: <Table products={filteredProducts} /> | ||
} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export const FilterByInput = ({ filterBy, query, onClearButton }) => ( | ||
<div className="panel-block"> | ||
<p className="control has-icons-left has-icons-right"> | ||
<input | ||
data-cy="SearchField" | ||
type="text" | ||
className="input" | ||
placeholder="Search" | ||
value={query} | ||
onChange={(event) => { | ||
filterBy(event.target.value); | ||
}} | ||
/> | ||
|
||
<span className="icon is-left"> | ||
<i className="fas fa-search" aria-hidden="true" /> | ||
</span> | ||
|
||
{query | ||
&& ( | ||
<span className="icon is-right"> | ||
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
<button | ||
data-cy="ClearButton" | ||
type="button" | ||
className="delete" | ||
onClick={onClearButton} | ||
/> | ||
</span> | ||
)} | ||
</p> | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import cn from 'classnames'; | ||
|
||
export const FilterUserList = ({ owners, selectedUser, onSelectedUser }) => ( | ||
owners.map(user => ( | ||
<a | ||
data-cy={user === 'All' ? 'FilterAllUsers' : 'FilterUser'} | ||
href="#/" | ||
className={cn({ | ||
'is-active': selectedUser === user, | ||
})} | ||
onClick={() => onSelectedUser(user)} | ||
> | ||
{user} | ||
</a> | ||
)) | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When function takes more than 1 line, make a separate function and pass it here