Skip to content
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

feat(explore): add tooltip to timepicker label #12401

Merged
merged 2 commits into from
Jan 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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