Skip to content

Commit 618ba53

Browse files
committed
add function to resolve type
1 parent 7f68b1a commit 618ba53

File tree

2 files changed

+20
-2
lines changed
  • x-pack/plugins/security_solution/public
    • common/components/formatted_date
    • management/pages/endpoint_hosts/view/details

2 files changed

+20
-2
lines changed

x-pack/plugins/security_solution/public/common/components/formatted_date/index.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ export const PreferenceFormattedDate = React.memo<{ dateFormat?: string; value:
2222

2323
PreferenceFormattedDate.displayName = 'PreferenceFormattedDate';
2424

25+
export const PreferenceFormattedDateFromPrimitive = ({
26+
value,
27+
}: {
28+
value?: string | number | null;
29+
}) => {
30+
if (value == null) {
31+
return getOrEmptyTagFromValue(value);
32+
}
33+
const maybeDate = getMaybeDate(value);
34+
if (!maybeDate.isValid()) {
35+
return getOrEmptyTagFromValue(value);
36+
}
37+
const date = maybeDate.toDate();
38+
return <PreferenceFormattedDate value={date} />;
39+
};
40+
41+
PreferenceFormattedDateFromPrimitive.displayName = 'PreferenceFormattedDateFromPrimitive';
42+
2543
/**
2644
* This function may be passed to `Array.find()` to locate the `P1DT`
2745
* configuration (sub) setting, a string array that contains two entries

x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/details/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { useNavigateByRouterEventHandler } from '../../../../../common/hooks/end
4242
import { getEndpointListPath } from '../../../../common/routing';
4343
import { SecurityPageName } from '../../../../../app/types';
4444
import { useFormatUrl } from '../../../../../common/components/link_to';
45-
import { PreferenceFormattedDate } from '../../../../../common/components/formatted_date';
45+
import { PreferenceFormattedDateFromPrimitive } from '../../../../../common/components/formatted_date';
4646

4747
export const EndpointDetailsFlyout = memo(() => {
4848
const history = useHistory();
@@ -170,7 +170,7 @@ const PolicyResponseFlyoutPanel = memo<{
170170
</EuiText>
171171
<EuiSpacer size="s" />
172172
<EuiText size="xs" color="subdued" data-test-subj="endpointDetailsPolicyResponseTimestamp">
173-
<PreferenceFormattedDate value={responseTimestamp} />
173+
<PreferenceFormattedDateFromPrimitive value={responseTimestamp} />
174174
</EuiText>
175175
<EuiSpacer size="s" />
176176
{error && (

0 commit comments

Comments
 (0)