Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
inventory-promotion-react
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ascend
inventory-promotion-react
Commits
c2c68656
Commit
c2c68656
authored
May 12, 2021
by
Ben Anderson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create select field to filter products
parent
7d32de39
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
15 deletions
+54
-15
ProductForm.jsx
src/component/ProductForm.jsx
+0
-1
ProductIndex.jsx
src/component/ProductIndex.jsx
+45
-5
ProductTable.jsx
src/component/ProductTable.jsx
+9
-9
No files found.
src/component/ProductForm.jsx
View file @
c2c68656
...
...
@@ -128,7 +128,6 @@ export default function ProductForm(props) {
type=
"text"
className=
"form-control"
id=
"productSku"
disabled=
{
method
===
"PUT"
?
true
:
false
}
value=
{
form
.
sku
}
onChange=
{
(
e
)
=>
setForm
({
...
form
,
sku
:
e
.
target
.
value
})
}
/>
...
...
src/component/ProductIndex.jsx
View file @
c2c68656
import
React
,
{
useEffect
,
useState
}
from
"react"
;
import
ProductTable
from
"./ProductTable.jsx"
import
ProductTable
from
"./ProductTable.jsx"
;
import
Config
from
"../config.js"
;
import
{
Link
}
from
"react-router-dom"
;
export
default
function
ProductIndex
()
{
const
[
products
,
setProducts
]
=
useState
([]);
const
[
displayProducts
,
setDisplayProducts
]
=
useState
([]);
const
[
categories
,
setCategories
]
=
useState
([]);
const
[
activeCategory
,
setActiveCategory
]
=
useState
(
""
);
console
.
log
(
displayProducts
);
const
fetchProducts
=
async
()
=>
{
const
res
=
await
fetch
(
`
${
Config
.
inventoryUrl
}
`
);
if
(
res
.
ok
)
{
const
data
=
await
res
.
json
();
setProducts
([...
data
]);
setDisplayProducts
([...
data
]);
setCategories
([
...
data
.
reduce
((
acc
,
prod
)
=>
{
if
(
!
acc
.
includes
(
prod
.
category
))
{
acc
.
push
(
prod
.
category
);
}
return
acc
;
},
[]),
]);
}
};
...
...
@@ -26,10 +39,37 @@ export default function ProductIndex() {
+ New Product
</
Link
>
</
div
>
{
products
.
length
>
0
?
<
ProductTable
productData=
{
products
}
/>
:
<
p
>
No products found.
</
p
>
}
{
products
.
length
>
0
?
(
<>
<
label
htmlFor=
"category-select"
className=
"form-label"
>
Category
</
label
>
<
select
className=
"form-select w-25 mt-1"
id=
"category-select"
onChange=
{
(
e
)
=>
{
if
(
e
.
target
.
value
===
""
)
{
setDisplayProducts
([...
products
]);
return
;
}
const
filtered
=
products
.
filter
(
(
prod
)
=>
prod
.
category
===
e
.
target
.
value
);
setDisplayProducts
([...
filtered
]);
}
}
>
<
option
></
option
>
{
categories
.
map
((
category
,
i
)
=>
(
<
option
key=
{
i
+
679
}
>
{
category
}
</
option
>
))
}
</
select
>
<
ProductTable
productData=
{
displayProducts
}
fetchProducts=
{
fetchProducts
}
products=
{
displayProducts
}
/>
</>
)
:
(
<
p
>
No products found.
</
p
>
)
}
</
div
>
);
}
src/component/ProductTable.jsx
View file @
c2c68656
...
...
@@ -4,16 +4,16 @@ import { Container, Table } from "react-bootstrap";
import
Config
from
"../config.js"
;
import
{
deleteProduct
}
from
"../actions/apiRequests"
;
export
default
function
ProductTable
({
productData
})
{
const
[
products
,
setProducts
]
=
useState
([
productData
]);
export
default
function
ProductTable
({
fetchProducts
,
products
})
{
// const [products, setProducts] = useState([...
productData]);
const
fetchProducts
=
async
()
=>
{
const
res
=
await
fetch
(
`
${
Config
.
inventoryUrl
}
`
);
if
(
res
.
ok
)
{
const
data
=
await
res
.
json
();
setProducts
([...
data
]);
}
};
//
const fetchProducts = async () => {
//
const res = await fetch(`${Config.inventoryUrl}`);
//
if (res.ok) {
//
const data = await res.json();
//
setProducts([...data]);
//
}
//
};
const
handleDelete
=
(
sku
)
=>
{
deleteProduct
(
sku
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment