Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dashboard PV278
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Polaško
Dashboard PV278
Commits
df17063e
There was an error fetching the commit references. Please try again later.
Commit
df17063e
authored
4 years ago
by
Martin Maroši
Browse files
Options
Downloads
Patches
Plain Diff
Add filter input.
parent
0d8dc555
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/views/HomePage.js
+22
-4
22 additions, 4 deletions
src/views/HomePage.js
with
22 additions
and
4 deletions
src/views/HomePage.js
+
22
−
4
View file @
df17063e
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
Api
from
"
../utils/api
"
;
import
debounce
from
"
lodash/debounce
"
;
import
{
makeStyles
}
from
"
@material-ui/core/styles
"
;
import
Table
from
"
@material-ui/core/Table
"
;
import
TableBody
from
"
@material-ui/core/TableBody
"
;
...
...
@@ -11,6 +12,7 @@ import TableRow from "@material-ui/core/TableRow";
import
Paper
from
"
@material-ui/core/Paper
"
;
import
Pagination
from
"
@material-ui/lab/Pagination
"
;
import
CircularProgress
from
"
@material-ui/core/CircularProgress
"
;
import
TextField
from
"
@material-ui/core/TextField
"
;
import
{
useHistory
}
from
"
react-router-dom
"
;
const
useStyles
=
makeStyles
((
theme
)
=>
({
...
...
@@ -77,21 +79,36 @@ const DataTable = ({ rows }) => {
);
};
const
queryBuilder
=
({
max
=
15
,
skip
=
0
,
filter
,
sortBy
})
=>
{
return
`max=
${
max
}
&skip=
${
skip
}
`
;
};
const
HomePage
=
()
=>
{
const
[
data
,
setData
]
=
useState
([]);
const
[{
max
,
skip
,
count
},
setPagination
]
=
useState
({
const
[{
max
,
skip
,
count
,
filterValue
},
setPagination
]
=
useState
({
max
:
15
,
skip
:
0
,
count
:
0
count
:
0
,
filterValue
:
""
});
const
[
initialized
,
setInitialized
]
=
useState
(
false
);
const
[
filter
,
setFilter
]
=
useState
(
""
);
const
handleFilter
=
({
target
:
{
value
}
})
=>
{
setFilter
(
value
);
};
const
onFilter
=
()
=>
setPagination
((
prevPagination
)
=>
({
...
prevPagination
,
filterValue
:
filter
}));
const
handlePagination
=
(
_event
,
page
)
=>
{
setPagination
((
prevPagination
)
=>
({
...
prevPagination
,
skip
:
(
page
-
1
)
*
prevPagination
.
max
}));
};
const
query
=
`max=
${
max
}
&
skip
=
${
skip
}
`
;
const
query
=
queryBuilder
({
max
,
skip
,
filterValue
})
;
useEffect
(()
=>
{
setInitialized
(
false
);
Promise
.
all
([
...
...
@@ -100,7 +117,7 @@ const HomePage = () => {
setPagination
((
prevPagination
)
=>
({
...
prevPagination
,
count
:
data
[
"
COUNT
"
]
}))
)
]).
then
(()
=>
setInitialized
(
true
));
},
[
skip
]);
},
[
skip
,
filterValue
]);
if
(
!
initialized
)
{
return
(
...
...
@@ -117,6 +134,7 @@ const HomePage = () => {
<
h1
>
Home
page
<
/h1
>
<
button
onClick
=
{
addMessage
}
>
Add
message
<
/button
>
<
button
onClick
=
{
replaceMessage
}
>
replace
message
<
/button
>
<
TextField
onBlur
=
{
onFilter
}
type
=
"
number
"
label
=
"
Filter by year
"
value
=
{
filter
}
onChange
=
{
handleFilter
}
/
>
<
Pagination
count
=
{
Math
.
ceil
(
count
/
max
)}
page
=
{
skip
/
max
+
1
}
onChange
=
{
handlePagination
}
/
>
<
DataTable
rows
=
{
data
}
/
>
<
/div
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment