Skip to content

Commit

Permalink
[7.x] [Metrics UI] Minor fixes to inventory timeline (#78226) (#78339)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary authored Sep 23, 2020
1 parent db0dc62 commit 3b75b1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const IntervalLabel = ({ intervalAsString }: Props) => {
<p>
<FormattedMessage
id="xpack.infra.homePage.toolbar.showingLastOneMinuteDataText"
defaultMessage="Last {duration} of data"
defaultMessage="Last {duration} of data for the selected time"
values={{ duration: intervalAsString }}
/>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,28 @@ const ONE_MINUTE = 60;
const ONE_HOUR = ONE_MINUTE * 60;
const ONE_DAY = ONE_HOUR * 24;
const ONE_WEEK = ONE_DAY * 7;
const ONE_MONTH = ONE_DAY * 30;

const getDisplayInterval = (interval: string | undefined) => {
if (interval) {
const intervalInSeconds = getIntervalInSeconds(interval);
if (intervalInSeconds < 300) return '5m';
}
return interval;
};

const getTimeLengthFromInterval = (interval: string | undefined) => {
if (interval) {
const intervalInSeconds = getIntervalInSeconds(interval);
const multiplier =
intervalInSeconds < ONE_MINUTE
? ONE_HOUR / intervalInSeconds
: intervalInSeconds < ONE_HOUR
? 60
: intervalInSeconds < ONE_DAY
? 7
: intervalInSeconds < ONE_WEEK
? 30
: 1;
const timeLength = intervalInSeconds * multiplier;
// Get up to 288 datapoints based on interval
const timeLength =
intervalInSeconds <= ONE_MINUTE * 15
? ONE_DAY
: intervalInSeconds <= ONE_MINUTE * 35
? ONE_DAY * 3
: intervalInSeconds <= ONE_HOUR * 2.5
? ONE_WEEK
: ONE_MONTH;
return { timeLength, intervalInSeconds };
} else {
return { timeLength: 0, intervalInSeconds: 0 };
Expand All @@ -67,15 +74,19 @@ export function useTimeline(
);
};

const timeLengthResult = useMemo(() => getTimeLengthFromInterval(interval), [interval]);
const displayInterval = useMemo(() => getDisplayInterval(interval), [interval]);

const timeLengthResult = useMemo(() => getTimeLengthFromInterval(displayInterval), [
displayInterval,
]);
const { timeLength, intervalInSeconds } = timeLengthResult;

const timerange: InfraTimerangeInput = {
interval: interval ?? '',
interval: displayInterval ?? '',
to: currentTime + intervalInSeconds * 1000,
from: currentTime - timeLength * 1000,
lookbackSize: 0,
ignoreLookback: true,
forceInterval: true,
};

const { error, loading, response, makeRequest } = useHTTPRequest<SnapshotNodeResponse>(
Expand Down

0 comments on commit 3b75b1b

Please sign in to comment.