-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(explore): time picker can not be switched between now and specific #12793
fix(explore): time picker can not be switched between now and specific #12793
Conversation
import { | ||
CustomRangeKey, | ||
SelectOptionType, | ||
FrameComponentProps, | ||
} from '../types'; | ||
|
||
const dttmToMoment = (dttm: string): Moment => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move these to utils.js
@@ -183,31 +197,27 @@ export const customTimeRangeEncode = (customRange: CustomRangeType): string => { | |||
} = { ...customRange }; | |||
// specific : specific | |||
if (SPECIFIC_MODE.includes(sinceMode) && SPECIFIC_MODE.includes(untilMode)) { | |||
const since = sinceMode === 'specific' ? sinceDatetime : sinceMode; | |||
const until = untilMode === 'specific' ? untilDatetime : untilMode; | |||
const since = sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode; // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from "now/midnight" switch to "specific", "since" requires materialization from "now" to "YYYY-mm-ddThh:mm:ss".
Tested manually works fine 🟢 |
Thanks for the quick testing
…On Wed, Jan 27, 2021 at 11:58 PM adam-stasiak-polidea < ***@***.***> wrote:
Tested manually works fine 🟢
Tested on chrome,safari,firefox - ok
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#12793 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPMKUTF2DIZNQNTVRU6KJTS4AZ2HANCNFSM4WVL4BOQ>
.
|
Codecov Report
@@ Coverage Diff @@
## master #12793 +/- ##
==========================================
+ Coverage 66.86% 67.00% +0.13%
==========================================
Files 1022 1021 -1
Lines 50107 50095 -12
Branches 5193 5190 -3
==========================================
+ Hits 33506 33568 +62
+ Misses 16470 16393 -77
- Partials 131 134 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -183,31 +197,27 @@ export const customTimeRangeEncode = (customRange: CustomRangeType): string => { | |||
} = { ...customRange }; | |||
// specific : specific | |||
if (SPECIFIC_MODE.includes(sinceMode) && SPECIFIC_MODE.includes(untilMode)) { | |||
const since = sinceMode === 'specific' ? sinceDatetime : sinceMode; | |||
const until = untilMode === 'specific' ? untilDatetime : untilMode; | |||
const since = sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode; // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do all of these lines have eslint-disable-line
on them? Can we either not introduce linting errors, or only disable the specific rule that's failing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this comes down to personal preference (these lines are easier to read as one-liners, but the linter wants to break them up). I've personally come to appreciate uniformity over legibility. I'd vote for removing the eslint-disable-line
s here and fixing the linting errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah, if it's only formatting, then 100% let's follow the linter. @zhaoyongjie mind updating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glad to follow to linting rules and make the change, however, I still believe breaking the lines is unnecessary. It makes it harder to read this code, especially in the case where we want to compare since and until side by side.
but I am still willing to follow everyone's conventions.
⇓ disable linting
...
// specific : specific
if (SPECIFIC_MODE.includes(sinceMode) && SPECIFIC_MODE.includes(untilMode)) {
const since = sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode; // eslint-disable-line
const until = untilMode === 'specific' ? dttmToString(untilDatetime) : untilMode; // eslint-disable-line
return `${since} : ${until}`;
}
// specific : relative
if (SPECIFIC_MODE.includes(sinceMode) && untilMode === 'relative') {
const since = sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode; // eslint-disable-line
const until = `DATEADD(DATETIME("${since}"), ${untilGrainValue}, ${untilGrain})`; // eslint-disable-line
return `${since} : ${until}`;
}
// relative : specific
if (sinceMode === 'relative' && SPECIFIC_MODE.includes(untilMode)) {
const until = untilMode === 'specific' ? dttmToString(untilDatetime) : untilMode; // eslint-disable-line
const since = `DATEADD(DATETIME("${until}"), ${-Math.abs(sinceGrainValue)}, ${sinceGrain})`; // eslint-disable-line
return `${since} : ${until}`;
}
// relative : relative
const since = `DATEADD(DATETIME("${anchorValue}"), ${-Math.abs(sinceGrainValue)}, ${sinceGrain})`; // eslint-disable-line
const until = `DATEADD(DATETIME("${anchorValue}"), ${untilGrainValue}, ${untilGrain})`;
return `${since} : ${until}`;
...
⇓ enable linting
...
// specific : specific
if (SPECIFIC_MODE.includes(sinceMode) && SPECIFIC_MODE.includes(untilMode)) {
const since =
sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode;
const until =
untilMode === 'specific' ? dttmToString(untilDatetime) : untilMode;
return `${since} : ${until}`;
}
// specific : relative
if (SPECIFIC_MODE.includes(sinceMode) && untilMode === 'relative') {
const since =
sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode;
const until = `DATEADD(DATETIME("${since}"), ${untilGrainValue}, ${untilGrain})`;
return `${since} : ${until}`;
}
// relative : specific
if (sinceMode === 'relative' && SPECIFIC_MODE.includes(untilMode)) {
const until =
untilMode === 'specific' ? dttmToString(untilDatetime) : untilMode;
const since = `DATEADD(DATETIME("${until}"), ${-Math.abs(
sinceGrainValue,
)}, ${sinceGrain})`;
return `${since} : ${until}`;
}
// relative : relative
const since = `DATEADD(DATETIME("${anchorValue}"), ${-Math.abs(
sinceGrainValue,
)}, ${sinceGrain})`;
const until = `DATEADD(DATETIME("${anchorValue}"), ${untilGrainValue}, ${untilGrain})`;
return `${since} : ${until}`;
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const customTimeRangeEncode = (customRange: CustomRangeType): string => {
const {
sinceDatetime,
sinceMode,
sinceGrain,
sinceGrainValue,
untilDatetime,
untilMode,
untilGrain,
untilGrainValue,
anchorValue,
} = { ...customRange };
let since: string = sinceMode;
let until: string = untilMode;
if (since === 'specific') {
since = dttmToString(sinceDatetime);
}
if (until === 'specific') {
until = dttmToString(untilDatetime);
}
if (since === 'relative' && until === 'relative') {
since = `DATEADD(DATETIME("${anchorValue}"), ${-Math.abs(
sinceGrainValue,
)}, ${sinceGrain})`;
until = `DATEADD(DATETIME("${anchorValue}"), ${untilGrainValue}, ${untilGrain})`;
}
if (since === 'relative') {
since = `DATEADD(DATETIME("${until}"), ${-Math.abs(
sinceGrainValue,
)}, ${sinceGrain})`;
}
if (until === 'relative') {
until = `DATEADD(DATETIME("${since}"), ${untilGrainValue}, ${untilGrain})`;
}
return `${since} : ${until}`;
};
@zhaoyongjie would this be cleaner? It passes all your test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'd prefer to reformat according to the linter's preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approve as product/design/QA sign off.
tried switching between all different settings ✅
apologize that we didn't catch it earlier ..
I removed |
|
||
export const dttmToString = (dttm: string): string => | ||
dttmToMoment(dttm).format(MOMENT_FORMAT); | ||
|
||
export const customTimeRangeDecode = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit: can we break utils.ts
into separate files under a utils
folder? These functions are complex enough to warrant a separate file.
@@ -183,31 +197,27 @@ export const customTimeRangeEncode = (customRange: CustomRangeType): string => { | |||
} = { ...customRange }; | |||
// specific : specific | |||
if (SPECIFIC_MODE.includes(sinceMode) && SPECIFIC_MODE.includes(untilMode)) { | |||
const since = sinceMode === 'specific' ? sinceDatetime : sinceMode; | |||
const until = untilMode === 'specific' ? untilDatetime : untilMode; | |||
const since = sinceMode === 'specific' ? dttmToString(sinceDatetime) : sinceMode; // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const customTimeRangeEncode = (customRange: CustomRangeType): string => {
const {
sinceDatetime,
sinceMode,
sinceGrain,
sinceGrainValue,
untilDatetime,
untilMode,
untilGrain,
untilGrainValue,
anchorValue,
} = { ...customRange };
let since: string = sinceMode;
let until: string = untilMode;
if (since === 'specific') {
since = dttmToString(sinceDatetime);
}
if (until === 'specific') {
until = dttmToString(untilDatetime);
}
if (since === 'relative' && until === 'relative') {
since = `DATEADD(DATETIME("${anchorValue}"), ${-Math.abs(
sinceGrainValue,
)}, ${sinceGrain})`;
until = `DATEADD(DATETIME("${anchorValue}"), ${untilGrainValue}, ${untilGrain})`;
}
if (since === 'relative') {
since = `DATEADD(DATETIME("${until}"), ${-Math.abs(
sinceGrainValue,
)}, ${sinceGrain})`;
}
if (until === 'relative') {
until = `DATEADD(DATETIME("${since}"), ${untilGrainValue}, ${untilGrain})`;
}
return `${since} : ${until}`;
};
@zhaoyongjie would this be cleaner? It passes all your test cases.
BTW, I found this line: superset/superset-frontend/src/explore/components/controls/DateFilterControl/types.ts Line 60 in 6731cd0
could probably be updated to
|
), | ||
).toEqual({ | ||
customRange: { | ||
sinceDatetime: '2021-01-20T00:00:00', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I fully understand the purpose of the customTimeRangeDecode
function. It is supposed to apply the dateadd
and datetime
functions? However, according to the code, this sinceDatetime
seems to always return 7_DAYS_AGO
when the input format is relative : specific
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then shouldn't sinceDatetime
be set to 2021-01-27T00:00:00
here, just to be more consistent with what is set in the input values?
Do you also do decode/encode when switching between non-advanced modes (i.e. modes that doesn't allow free text)? Not sure how feasible it is, but gut feeling tells me that it might be easier and cleaner to use he same config object internally for all frames and only do decode/encode when the time picker needs to communicate with the outside world.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
customTimeRangeEncode
is used only in the CustomFrame.customTimeRangeDecode
is used in 2 places: CustomFrame and guessFrame function in DateFilterControl.
customTimeRangeDecode can determine whether an expression can be used in CustomFrame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sinceDatetime
set to 2021-01-27T00:00:00
just to be more consistent in CustomFrame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation.
thanks for pointing this out. I will fix it. |
152f7c2
to
8142a86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the updates, lgtm!
#12793) * fix(explore): time picker can not be switched between now and specifc * fix linting * fix type * fix UT
apache#12793) * fix(explore): time picker can not be switched between now and specifc * fix linting * fix type * fix UT (cherry picked from commit 642a76f)
SUMMARY
fix time picker can not be switched between "now" and "specific".
closes: #12780
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
before
Screen.Recording.2021-01-26.at.2.07.48.PM.mov
fixed
Jan-27-2021.22-37-25.mp4
TEST PLAN
ADDITIONAL INFORMATION