Skip to content

Commit

Permalink
Show metadata only when info and timestamp are available
Browse files Browse the repository at this point in the history
  • Loading branch information
jennypavlova committed Aug 30, 2023
1 parent 34f7b96 commit 9e50cc2
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React from 'react';
import { EuiText, EuiLink } from '@elastic/eui';
import { FormattedDate, FormattedMessage, FormattedTime } from '@kbn/i18n-react';
import { EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner } from '@elastic/eui';
import { useDateRangeProviderContext } from '../hooks/use_date_range';
import { Popover } from '../tabs/common/popover';
import { useMetadataStateProviderContext } from '../hooks/use_metadata_state';

Expand Down Expand Up @@ -54,14 +53,11 @@ const MetadataExplanationTooltipContent = React.memo(() => {
});

export const MetadataExplanationMessage = () => {
const { getDateRangeInTimestamp } = useDateRangeProviderContext();
const { metadata, loading } = useMetadataStateProviderContext();

const dateFromRange = new Date(metadata?.info?.timestamp ?? getDateRangeInTimestamp().to);

return loading ? (
<EuiLoadingSpinner />
) : (
) : metadata?.info?.timestamp ? (
<EuiFlexGroup gutterSize="xs" alignItems="baseline">
<EuiFlexItem grow={false}>
<EuiText size="xs" color="subdued">
Expand All @@ -70,11 +66,16 @@ export const MetadataExplanationMessage = () => {
defaultMessage="Showing metadata collected on {date} @ {time}"
values={{
date: (
<FormattedDate value={dateFromRange} month="short" day="numeric" year="numeric" />
<FormattedDate
value={new Date(metadata?.info?.timestamp)}
month="short"
day="numeric"
year="numeric"
/>
),
time: (
<FormattedTime
value={dateFromRange}
value={new Date(metadata?.info?.timestamp)}
hour12={false}
hour="2-digit"
minute="2-digit"
Expand All @@ -97,5 +98,5 @@ export const MetadataExplanationMessage = () => {
</Popover>
</EuiFlexItem>
</EuiFlexGroup>
);
) : null;
};

0 comments on commit 9e50cc2

Please sign in to comment.