Skip to content

Commit

Permalink
feat(explore): add tooltip to timepicker label (apache#12401)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie authored and amitmiran137 committed Jan 14, 2021
1 parent 2e2552d commit 64d37c1
Showing 1 changed file with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Popover from 'src/common/components/Popover';
import { Divider } from 'src/common/components';
import Icon from 'src/components/Icon';
import { Select } from 'src/components/Select';
import { Tooltip } from 'src/common/components/Tooltip';
import { SelectOptionType, FrameType } from './types';
import {
COMMON_RANGE_VALUES_SET,
Expand Down Expand Up @@ -181,27 +182,41 @@ export default function DateFilterControl(props: DateFilterLabelProps) {
const [timeRangeValue, setTimeRangeValue] = useState(value);
const [validTimeRange, setValidTimeRange] = useState<boolean>(false);
const [evalResponse, setEvalResponse] = useState<string>(value);
const [tooltipTitle, setTooltipTitle] = useState<string>(value);

useEffect(() => {
const valueToLower = value.toLowerCase();
if (
valueToLower.startsWith('last') ||
valueToLower.startsWith('next') ||
valueToLower.startsWith('previous')
) {
setActualTimeRange(value);
setValidTimeRange(true);
} else {
fetchTimeRange(value, endpoints).then(({ value, error }) => {
if (error) {
setEvalResponse(error || '');
setValidTimeRange(false);
fetchTimeRange(value, endpoints).then(({ value: actualRange, error }) => {
if (error) {
setEvalResponse(error || '');
setValidTimeRange(false);
setTooltipTitle(value || '');
} else {
/*
HRT == human readable text
ADR == actual datetime range
+--------------+------+----------+--------+----------+-----------+
| | Last | Previous | Custom | Advanced | No Filter |
+--------------+------+----------+--------+----------+-----------+
| control pill | HRT | HRT | ADR | ADR | ADR |
+--------------+------+----------+--------+----------+-----------+
| tooltip | ADR | ADR | HRT | HRT | HRT |
+--------------+------+----------+--------+----------+-----------+
*/
const valueToLower = value.toLowerCase();
if (
valueToLower.startsWith('last') ||
valueToLower.startsWith('next') ||
valueToLower.startsWith('previous')
) {
setActualTimeRange(value);
setTooltipTitle(actualRange || '');
} else {
setActualTimeRange(value || '');
setValidTimeRange(true);
setActualTimeRange(actualRange || '');
setTooltipTitle(value || '');
}
});
}
setValidTimeRange(true);
}
});
}, [value]);

useEffect(() => {
Expand Down Expand Up @@ -327,13 +342,15 @@ export default function DateFilterControl(props: DateFilterLabelProps) {
onVisibleChange={togglePopover}
overlayStyle={overlayStyle}
>
<Label
className="pointer"
data-test="time-range-trigger"
onClick={() => setShow(true)}
>
{actualTimeRange}
</Label>
<Tooltip placement="top" title={tooltipTitle}>
<Label
className="pointer"
data-test="time-range-trigger"
onClick={() => setShow(true)}
>
{actualTimeRange}
</Label>
</Tooltip>
</StyledPopover>
</>
);
Expand Down

0 comments on commit 64d37c1

Please sign in to comment.