Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
order-management-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
order-management-react
Commits
9c983fe0
Commit
9c983fe0
authored
May 07, 2021
by
Kevin Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-104]
✨
Search now filters orders list based on search input. [
@kkaminski
]
parent
48543cf6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
31 deletions
+28
-31
OrderIndexPage.tsx
src/pages/OrderIndexPage.tsx
+28
-31
No files found.
src/pages/OrderIndexPage.tsx
View file @
9c983fe0
import
React
,
{
useState
,
useEffect
}
from
'react'
import
React
,
{
useState
,
useEffect
}
from
'react'
import
{
OrderDetails
}
from
'components'
import
{
OrderDetails
}
from
'components'
import
{
OrderService
}
from
'services'
;
import
{
Order
}
from
'Order'
;
import
{
Order
}
from
'Order'
;
import
{
useAllOrders
}
from
'hooks'
import
{
useAllOrders
}
from
'hooks'
import
{
import
{
...
@@ -15,47 +14,46 @@ import {
...
@@ -15,47 +14,46 @@ import {
const
OrderIndexPage
=
()
=>
{
const
OrderIndexPage
=
()
=>
{
const
{
orders
}
=
useAllOrders
();
const
{
orders
}
=
useAllOrders
();
const
[
searchInput
,
setSearchInput
]
=
useState
(
""
)
const
[
searchInput
,
setSearchInput
]
=
useState
(
""
)
const
[
allOrders
,
setAllOrders
]
=
useState
<
any
>
([])
const
[
allOrders
,
setAllOrders
]
=
useState
<
Order
[]
>
([])
const
[
filteredOrders
,
setFilteredOrders
]
=
useState
<
Order
[]
>
([])
const
[
orderDetailsArr
,
setOrderDetailsArr
]
=
useState
<
any
>
([])
const
orderDetailsArrCreator
=
(
orders
:
Order
[])
=>
{
return
orders
.
map
((
order
:
Order
,
idx
:
any
)
=>
{
return
<
Tr
key=
{
idx
}
><
OrderDetails
date=
{
order
.
orderCreatedAt
}
orderNumber=
{
order
.
id
}
status=
{
order
.
orderStatus
}
/></
Tr
>
})
}
useEffect
(()
=>
{
useEffect
(()
=>
{
setAllOrders
(
orders
)
setAllOrders
(
orders
)
},
[
orders
])
},
[
orders
])
const
handleChange
=
(
e
:
any
)
=>
{
useEffect
(()
=>
{
console
.
log
(
"e.key"
,
e
.
key
)
if
(
searchInput
.
length
!==
0
)
{
if
(
e
.
key
===
"Enter"
)
{
setOrderDetailsArr
(
orderDetailsArrCreator
(
filteredOrders
))
handleClick
()
}
else
{
setOrderDetailsArr
(
orderDetailsArrCreator
(
allOrders
))
}
}
const
value
=
e
.
target
.
value
},
[
searchInput
,
allOrders
,
filteredOrders
])
setSearchInput
(
value
)
}
useEffect
(()
=>
{
const
newArray
:
Order
[]
=
[]
const
handleClick
=
()
=>
{
console
.
log
(
searchInput
)
console
.
log
(
allOrders
)
const
searchLength
=
searchInput
.
length
const
newArray
=
[]
for
(
const
ele
of
allOrders
)
{
for
(
const
ele
of
allOrders
)
{
// const snippet = ele.id.slice(0, searchLength).toString()
if
(
ele
.
id
.
includes
(
searchInput
))
{
if
(
ele
.
id
.
includes
(
searchInput
))
{
newArray
.
push
(
ele
)
newArray
.
push
(
ele
)
}
}
}
}
console
.
log
(
"newarray"
,
newArray
)
setFilteredOrders
(
newArray
)
if
(
searchLength
!==
0
)
{
},
[
searchInput
,
allOrders
])
setAllOrders
(
newArray
)
}
else
{
setAllOrders
(
orders
)
}
}
const
orderDetailsArr
=
allOrders
.
map
((
order
:
Order
,
idx
:
any
)
=>
{
const
handleChange
=
(
e
:
any
)
=>
{
return
<
Tr
key=
{
idx
}
><
OrderDetails
console
.
log
(
e
.
target
.
value
)
date=
{
order
.
orderCreatedAt
}
setSearchInput
(
e
.
target
.
value
)
orderNumber=
{
order
.
id
}
}
status=
{
order
.
orderStatus
}
/></
Tr
>
})
return
(
return
(
<
div
className=
"table-div"
>
<
div
className=
"table-div"
>
...
@@ -68,7 +66,6 @@ const OrderIndexPage = () => {
...
@@ -68,7 +66,6 @@ const OrderIndexPage = () => {
onKeyDown=
{
handleChange
}
onKeyDown=
{
handleChange
}
>
>
</
Input
>
</
Input
>
{
/* <button onClick={handleClick}>Submit</button> */
}
<
br
/>
<
br
/>
<
div
className=
"index-table"
>
<
div
className=
"index-table"
>
<
Table
variant=
"striped"
colorScheme=
"messenger"
size=
"md"
>
<
Table
variant=
"striped"
colorScheme=
"messenger"
size=
"md"
>
...
...
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