Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
353b3822
Unverified
Commit
353b3822
authored
Aug 04, 2020
by
Hugo Häggmark
Committed by
GitHub
Aug 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TimePicker: Fixes app crash when changing custom range to nothing (#26775)
parent
4e2ab785
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
7 deletions
+62
-7
packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerCalendar.test.tsx
+53
-0
packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerCalendar.tsx
+9
-7
No files found.
packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerCalendar.test.tsx
0 → 100644
View file @
353b3822
import
{
dateTime
}
from
'@grafana/data'
;
import
{
inputToValue
}
from
'./TimePickerCalendar'
;
describe
(
'inputToValue'
,
()
=>
{
describe
(
'when called with valid dates'
,
()
=>
{
describe
(
'and from is after to'
,
()
=>
{
it
(
'then to should be first in the result'
,
()
=>
{
const
from
=
dateTime
(
'2020-04-16T11:00:00.000Z'
);
const
to
=
dateTime
(
'2020-04-16T10:00:00.000Z'
);
const
result
=
inputToValue
(
from
,
to
);
expect
(
result
).
toEqual
([
new
Date
(
'2020-04-16T10:00:00.000Z'
),
new
Date
(
'2020-04-16T11:00:00.000Z'
)]);
});
});
describe
(
'and from is before to'
,
()
=>
{
it
(
'then to should be second in the result'
,
()
=>
{
const
from
=
dateTime
(
'2020-04-16T10:00:00.000Z'
);
const
to
=
dateTime
(
'2020-04-16T11:00:00.000Z'
);
const
result
=
inputToValue
(
from
,
to
);
expect
(
result
).
toEqual
([
new
Date
(
'2020-04-16T10:00:00.000Z'
),
new
Date
(
'2020-04-16T11:00:00.000Z'
)]);
});
});
});
describe
(
'when called with an invalid from datetime'
,
()
=>
{
it
(
'then from should replaced with specified default'
,
()
=>
{
const
from
=
dateTime
(
'2020-04-32T10:00:00.000Z'
);
// invalid date
const
to
=
dateTime
(
'2020-04-16T10:00:00.000Z'
);
const
invalidDateDefault
=
new
Date
(
'2020-04-16T11:00:00.000Z'
);
const
result
=
inputToValue
(
from
,
to
,
invalidDateDefault
);
expect
(
result
).
toEqual
([
new
Date
(
'2020-04-16T10:00:00.000Z'
),
new
Date
(
'2020-04-16T11:00:00.000Z'
)]);
});
});
describe
(
'when called with an invalid to datetime'
,
()
=>
{
it
(
'then to should replaced with specified default'
,
()
=>
{
const
from
=
dateTime
(
'2020-04-16T10:00:00.000Z'
);
const
to
=
dateTime
(
'2020-04-32T10:00:00.000Z'
);
// invalid date
const
invalidDateDefault
=
new
Date
(
'2020-04-16T11:00:00.000Z'
);
const
result
=
inputToValue
(
from
,
to
,
invalidDateDefault
);
expect
(
result
).
toEqual
([
new
Date
(
'2020-04-16T10:00:00.000Z'
),
new
Date
(
'2020-04-16T11:00:00.000Z'
)]);
});
});
});
packages/grafana-ui/src/components/TimePicker/TimeRangePicker/TimePickerCalendar.tsx
View file @
353b3822
import
React
,
{
memo
,
useState
,
useEffect
,
useCallback
,
FormEvent
}
from
'react'
;
import
React
,
{
FormEvent
,
memo
,
useCallback
,
useEffect
,
useState
}
from
'react'
;
import
{
css
}
from
'emotion'
;
import
Calendar
from
'react-calendar/dist/entry.nostyle'
;
import
{
GrafanaTheme
,
DateTime
,
TimeZone
,
dateTimePars
e
}
from
'@grafana/data'
;
import
{
useTheme
,
stylesFactory
}
from
'../../../themes'
;
import
{
dateTime
,
DateTime
,
dateTimeParse
,
GrafanaTheme
,
TimeZon
e
}
from
'@grafana/data'
;
import
{
stylesFactory
,
useTheme
}
from
'../../../themes'
;
import
{
TimePickerTitle
}
from
'./TimePickerTitle'
;
import
{
Button
}
from
'../../Button'
;
import
{
Icon
}
from
'../../Icon/Icon'
;
...
...
@@ -285,14 +285,16 @@ const Footer = memo<Props>(({ onClose, onApply }) => {
);
});
function
inputToValue
(
from
:
DateTime
,
to
:
DateTime
):
Date
[]
{
export
function
inputToValue
(
from
:
DateTime
,
to
:
DateTime
,
invalidDateDefault
:
Date
=
new
Date
()
):
Date
[]
{
const
fromAsDate
=
from
.
toDate
();
const
toAsDate
=
to
.
toDate
();
const
fromAsValidDate
=
dateTime
(
fromAsDate
).
isValid
()
?
fromAsDate
:
invalidDateDefault
;
const
toAsValidDate
=
dateTime
(
toAsDate
).
isValid
()
?
toAsDate
:
invalidDateDefault
;
if
(
fromAs
Date
>
toAs
Date
)
{
return
[
toAs
Date
,
fromAs
Date
];
if
(
fromAs
ValidDate
>
toAsValid
Date
)
{
return
[
toAs
ValidDate
,
fromAsValid
Date
];
}
return
[
fromAs
Date
,
toAs
Date
];
return
[
fromAs
ValidDate
,
toAsValid
Date
];
}
function
useOnCalendarChange
(
onChange
:
(
from
:
DateTime
,
to
:
DateTime
)
=>
void
,
timeZone
?:
TimeZone
)
{
...
...
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