Skip to content

Commit 640f9c6

Browse files
authored
feat: add new time range component for the UI for the new data explorer (#5817)
* wip * feat: added validation, need to clean up design when they are ready and clean up the component logic * feat: connect all the things
1 parent f7bda80 commit 640f9c6

File tree

9 files changed

+733
-252
lines changed

9 files changed

+733
-252
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"@types/node": "^12.6.8",
100100
"@types/papaparse": "^4.5.9",
101101
"@types/react": "^17.0.35",
102-
"@types/react-datepicker": "^2.8.1",
102+
"@types/react-datepicker": "^4.4.2",
103103
"@types/react-dom": "^17.0.11",
104104
"@types/react-grid-layout": "^0.16.5",
105105
"@types/react-redux": "^7.1.9",
@@ -202,7 +202,7 @@
202202
"qrcode.react": "^3.1.0",
203203
"react": "^17.0.2",
204204
"react-beautiful-dnd": "^13.0.0",
205-
"react-datepicker": "^2.1.0",
205+
"react-datepicker": "^4.8.0",
206206
"react-dnd": "^9.3.2",
207207
"react-dnd-html5-backend": "^9.3.2",
208208
"react-dom": "^17.0.2",

src/dataExplorer/components/Results.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import {FluxResult} from 'src/types/flows'
2525

2626
import './Results.scss'
27+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
2728

2829
// simplified version migrated from src/flows/pipes/Table/view.tsx
2930
const QueryStat: FC = () => {
@@ -249,7 +250,9 @@ const Results: FC = () => {
249250
{tableHeader}
250251
{vizHeader}
251252
<div className="data-explorer-results--timezone">
252-
<TimeZoneDropdown />
253+
{isFlagEnabled('newTimeRangeComponent') ? null : (
254+
<TimeZoneDropdown />
255+
)}
253256
<SelectGroup style={{marginRight: 12}}>
254257
<SelectGroup.Option
255258
id="table"

src/dataExplorer/components/ResultsPane.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import TimeRangeDropdown from 'src/shared/components/TimeRangeDropdown'
2727
import Results from 'src/dataExplorer/components/Results'
2828
import {SubmitQueryButton} from 'src/timeMachine/components/SubmitQueryButton'
2929
import QueryTime from 'src/dataExplorer/components/QueryTime'
30+
import NewDatePicker from 'src/shared/components/dateRangePicker/NewDatePicker'
3031

3132
// Types
3233
import {TimeRange} from 'src/types'
@@ -40,6 +41,7 @@ import {getWindowPeriodVariableFromVariables} from 'src/variables/utils/getWindo
4041

4142
// Constants
4243
import {TIME_RANGE_START, TIME_RANGE_STOP} from 'src/variables/constants'
44+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
4345

4446
const FluxMonacoEditor = lazy(
4547
() => import('src/shared/components/FluxMonacoEditor')
@@ -49,6 +51,7 @@ const fakeNotify = notify
4951

5052
const rangeToParam = (timeRange: TimeRange) => {
5153
let timeRangeStart: string, timeRangeStop: string
54+
const durationRegExp = /([0-9]+)(y|mo|w|d|h|ms|s|m|us|µs|ns)$/g
5255

5356
if (!timeRange) {
5457
timeRangeStart = timeRangeStop = null
@@ -57,6 +60,10 @@ const rangeToParam = (timeRange: TimeRange) => {
5760
timeRangeStart = '-' + timeRange.duration
5861
} else if (timeRange.type === 'duration') {
5962
timeRangeStart = '-' + timeRange.lower
63+
} else if (!isNaN(Number(timeRange.lower)) || timeRange.lower === 'now()') {
64+
timeRangeStart = timeRange.lower
65+
} else if (!!timeRange?.lower?.match(durationRegExp)) {
66+
timeRangeStart = timeRange.lower
6067
} else if (isNaN(Date.parse(timeRange.lower))) {
6168
timeRangeStart = null
6269
} else {
@@ -65,6 +72,10 @@ const rangeToParam = (timeRange: TimeRange) => {
6572

6673
if (!timeRange.upper) {
6774
timeRangeStop = 'now()'
75+
} else if (!isNaN(Number(timeRange.upper)) || timeRange.upper === 'now()') {
76+
timeRangeStop = timeRange.upper
77+
} else if (!!timeRange?.upper?.match(durationRegExp)) {
78+
timeRangeStop = timeRange.upper
6879
} else if (isNaN(Date.parse(timeRange.upper))) {
6980
timeRangeStop = null
7081
} else {
@@ -197,10 +208,14 @@ const ResultsPane: FC = () => {
197208
text ? ComponentStatus.Default : ComponentStatus.Disabled
198209
}
199210
/>
200-
<TimeRangeDropdown
201-
timeRange={range}
202-
onSetTimeRange={(range: TimeRange) => setRange(range)}
203-
/>
211+
{isFlagEnabled('newTimeRangeComponent') ? (
212+
<NewDatePicker />
213+
) : (
214+
<TimeRangeDropdown
215+
timeRange={range}
216+
onSetTimeRange={(range: TimeRange) => setRange(range)}
217+
/>
218+
)}
204219
<SubmitQueryButton
205220
className="submit-btn"
206221
text="Run"

src/shared/components/dateRangePicker/DatePicker.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
isValidStrictly,
2929
} from 'src/utils/datetime/validator'
3030
import {isISODate} from 'src/shared/utils/dateTimeUtils'
31+
import {isValidDatepickerFormat} from 'src/shared/components/dateRangePicker/utils'
3132

3233
interface Props {
3334
label: string
@@ -44,16 +45,6 @@ interface State {
4445
inputFormat: string
4546
}
4647

47-
const isValidDatepickerFormat = (d: string): boolean => {
48-
return (
49-
isValidStrictly(d, 'YYYY-MM-DD HH:mm') ||
50-
isValidStrictly(d, 'YYYY-MM-DD HH:mm:ss') ||
51-
isValidStrictly(d, 'YYYY-MM-DD HH:mm:ss.sss') ||
52-
isValidStrictly(d, 'YYYY-MM-DD') ||
53-
isISODate(d)
54-
)
55-
}
56-
5748
const getFormat = (d: string): string => {
5849
if (isValidStrictly(d, 'YYYY-MM-DD')) {
5950
return 'YYYY-MM-DD'

0 commit comments

Comments
 (0)