Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nos Hs2023
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Språksamlingane
stadnamn
Nos Hs2023
Commits
bae65c7f
Commit
bae65c7f
authored
2 years ago
by
esikkala
Browse files
Options
Downloads
Patches
Plain Diff
Date facet: add apply button
parent
83d6f869
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/client/components/facet_bar/DateFacet.js
+78
-65
78 additions, 65 deletions
src/client/components/facet_bar/DateFacet.js
with
78 additions
and
65 deletions
src/client/components/facet_bar/DateFacet.js
+
78
−
65
View file @
bae65c7f
...
...
@@ -3,11 +3,12 @@ import PropTypes from 'prop-types'
import
{
TextField
}
from
'
@mui/material
'
import
DatePicker
from
'
@mui/lab/DatePicker
'
import
Box
from
'
@mui/material/Box
'
import
Button
from
'
@mui/material/Button
'
import
moment
from
'
moment
'
import
intl
from
'
react-intl-universal
'
/**
* A
component for a date facet with pickers using @material-ui/p
icker
s
and Moment.js.
* A
date facet component built on @mui/lab/DateP
icker and Moment.js.
*/
class
DateFacet
extends
React
.
Component
{
constructor
(
props
)
{
...
...
@@ -15,7 +16,8 @@ class DateFacet extends React.Component {
this
.
state
=
{
from
:
moment
(
this
.
props
.
facet
.
min
),
to
:
moment
(
this
.
props
.
facet
.
max
),
error
:
false
fromError
:
false
,
toError
:
false
}
}
...
...
@@ -25,14 +27,9 @@ class DateFacet extends React.Component {
if
(
this
.
isValidDate
(
from
)
&&
this
.
isValidDate
(
to
)
&&
from
.
isSameOrBefore
(
to
))
{
const
values
=
[
from
.
format
(
'
YYYY-MM-DD
'
),
to
.
format
(
'
YYYY-MM-DD
'
)
]
this
.
updateFacet
(
values
)
this
.
setState
({
error
:
false
})
this
.
setState
({
fromError
:
false
})
}
else
{
this
.
setState
({
e
rror
:
true
})
this
.
setState
({
fromE
rror
:
true
})
}
}
...
...
@@ -42,24 +39,30 @@ class DateFacet extends React.Component {
if
(
this
.
isValidDate
(
from
)
&&
this
.
isValidDate
(
to
)
&&
from
.
isSameOrBefore
(
to
))
{
const
values
=
[
this
.
state
.
from
.
format
(
'
YYYY-MM-DD
'
),
to
.
format
(
'
YYYY-MM-DD
'
)
]
this
.
updateFacet
(
values
)
this
.
setState
({
error
:
false
})
this
.
setState
({
toError
:
false
})
}
else
{
this
.
setState
({
e
rror
:
true
})
this
.
setState
({
toE
rror
:
true
})
}
}
updateFacet
=
values
=>
{
this
.
props
.
updateFacetOption
({
facetClass
:
this
.
props
.
facetClass
,
facetID
:
this
.
props
.
facetID
,
option
:
this
.
props
.
facet
.
filterType
,
value
:
values
})
handleApplyOnClick
=
()
=>
this
.
updateFacet
()
updateFacet
=
()
=>
{
const
{
from
,
to
}
=
this
.
state
if
(
this
.
isValidDate
(
from
)
&&
this
.
isValidDate
(
to
)
&&
from
.
isSameOrBefore
(
to
))
{
const
values
=
[
from
.
format
(
'
YYYY-MM-DD
'
),
to
.
format
(
'
YYYY-MM-DD
'
)
]
this
.
props
.
updateFacetOption
({
facetClass
:
this
.
props
.
facetClass
,
facetID
:
this
.
props
.
facetID
,
option
:
this
.
props
.
facet
.
filterType
,
value
:
values
})
}
}
isValidDate
=
date
=>
{
...
...
@@ -72,63 +75,73 @@ class DateFacet extends React.Component {
}
render
()
{
const
{
from
,
to
,
e
rror
}
=
this
.
state
const
{
from
,
to
,
fromError
,
toE
rror
}
=
this
.
state
const
{
min
,
max
}
=
this
.
props
.
facet
const
{
someFacetIsFetching
}
=
this
.
props
return
(
<
div
>
<
DatePicker
label
=
{
intl
.
get
(
'
facets.dateFacet.fromLabel
'
)}
renderInput
=
{
params
=>
<
TextField
error
=
{
error
}
helperText
=
{
error
?
intl
.
get
(
'
facets.dateFacet.toBeforeFrom
'
)
:
'
'
}
{...
params
}
/>
}
placeholder
=
{
moment
(
min
).
format
(
'
DD.MM.YYYY
'
)}
mask
=
'
__.__.____
'
value
=
{
from
}
onChange
=
{
date
=>
this
.
handleFromChange
(
date
)}
inputFormat
=
'
DD.MM.YYYY
'
minDate
=
{
moment
(
min
)}
maxDate
=
{
moment
(
max
)}
invalidDateMessage
=
{
intl
.
get
(
'
facets.dateFacet.invalidDate
'
)}
// minDateMessage={intl.get('facets.dateFacet.minDate', { minDate: moment(min).format('DD.MM.YYYY') })}
// maxDateMessage={intl.get('facets.dateFacet.maxDate', { maxDate: moment(max).format('DD.MM.YYYY') })}
cancelText
=
{
intl
.
get
(
'
facets.dateFacet.cancel
'
)}
shouldDisableDate
=
{
date
=>
date
.
isAfter
(
to
)}
disabled
=
{
someFacetIsFetching
}
/
>
<
Box
sx
=
{
theme
=>
({
marginTop
:
theme
.
spacing
(
2.5
)
})}
>
<
Box
sx
=
{{
height
:
'
100%
'
,
display
:
'
flex
'
}}
>
<
Box
sx
=
{{
width
:
'
160px
'
}}
>
<
DatePicker
label
=
{
intl
.
get
(
'
facets.dateFacet.
to
Label
'
)}
label
=
{
intl
.
get
(
'
facets.dateFacet.
from
Label
'
)}
renderInput
=
{
params
=>
<
TextField
error
=
{
e
rror
}
helperText
=
{
e
rror
?
intl
.
get
(
'
facets.dateFacet.
toBeforeFrom
'
)
:
'
'
}
error
=
{
fromE
rror
}
helperText
=
{
fromE
rror
?
intl
.
get
(
'
facets.dateFacet.
invalidDate
'
)
:
'
'
}
{...
params
}
/>
}
placeholder
=
{
moment
(
m
ax
).
format
(
'
DD.MM.YYYY
'
)}
placeholder
=
{
moment
(
m
in
).
format
(
'
DD.MM.YYYY
'
)}
mask
=
'
__.__.____
'
value
=
{
to
}
onChange
=
{
date
=>
this
.
handle
To
Change
(
date
)}
value
=
{
from
}
onChange
=
{
date
=>
this
.
handle
From
Change
(
date
)}
inputFormat
=
'
DD.MM.YYYY
'
minDate
=
{
moment
(
min
)}
maxDate
=
{
moment
(
max
)}
invalidDateMessage
=
{
intl
.
get
(
'
facets.dateFacet.invalidDate
'
)}
// minDateMessage={intl.get('facets.dateFacet.minDate', { minDate: moment(min).format('DD.MM.YYYY') })}
// maxDateMessage={intl.get('facets.dateFacet.maxDate', { maxDate: moment(max).format('DD.MM.YYYY') })}
cancelText
=
{
intl
.
get
(
'
facets.dateFacet.cancel
'
)}
shouldDisableDate
=
{
date
=>
date
.
isBefore
(
from
)}
disabled
=
{
someFacetIsFetching
}
/
>
<
Box
sx
=
{
theme
=>
({
marginTop
:
theme
.
spacing
(
1.5
)
})}
>
<
DatePicker
label
=
{
intl
.
get
(
'
facets.dateFacet.toLabel
'
)}
renderInput
=
{
params
=>
<
TextField
error
=
{
toError
}
helperText
=
{
toError
?
intl
.
get
(
'
facets.dateFacet.invalidDate
'
)
:
'
'
}
{...
params
}
/>
}
placeholder
=
{
moment
(
max
).
format
(
'
DD.MM.YYYY
'
)}
mask
=
'
__.__.____
'
value
=
{
to
}
onChange
=
{
date
=>
this
.
handleToChange
(
date
)}
inputFormat
=
'
DD.MM.YYYY
'
minDate
=
{
moment
(
min
)}
maxDate
=
{
moment
(
max
)}
disabled
=
{
someFacetIsFetching
}
/
>
<
/Box
>
<
/Box
>
<
Box
sx
=
{
theme
=>
({
marginLeft
:
theme
.
spacing
(
1.5
),
paddingTop
:
'
55px
'
})}
>
<
Button
variant
=
'
contained
'
color
=
'
primary
'
onClick
=
{
this
.
handleApplyOnClick
}
disabled
=
{
someFacetIsFetching
||
fromError
||
toError
}
>
{
intl
.
get
(
'
facetBar.applyFacetSelection
'
)}
<
/Button
>
<
/Box
>
<
/
div
>
<
/
Box
>
)
}
}
...
...
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