Skip to content

Commit

Permalink
[EDR Workflows][Osquery] Fix last results pack value (#192678)
Browse files Browse the repository at this point in the history
The “Last Results” tab in the active pack details is displaying
incorrect date-time values. This is due to a mismatch in data format.
The component responsible for formatting the date-time values expects a
string, but it is currently receiving an array with a single string
inside.

Before:

![Screenshot 2024-09-12 at 10 33
39](https://github.com/user-attachments/assets/844fd699-a086-44d8-aa0b-a06e65e5aa60)

After: 

![Screenshot 2024-09-12 at 12 40
04](https://github.com/user-attachments/assets/bcce9b69-58b8-438d-89e8-c78a3922845c)
  • Loading branch information
szwarckonrad authored Sep 17, 2024
1 parent 1ae7548 commit cfcb6e8
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions x-pack/plugins/osquery/public/packs/pack_queries_status_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const ViewResultsInLensActionComponent: React.FC<ViewResultsInDiscoverActionProp
const { data: logsDataView } = useLogsDataView({ skip: !actionId, checkOnly: true });

const handleClick = useCallback(
(event: any) => {
(event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();

if (logsDataView?.id) {
Expand Down Expand Up @@ -372,33 +372,31 @@ const ScheduledQueryLastResults: React.FC<ScheduledQueryLastResultsProps> = ({
interval,
});

const timestamp = useMemo(() => {
const dateTime = lastResultsData?.['@timestamp'];
if (!dateTime) return undefined;

return Array.isArray(dateTime) ? dateTime[0] : dateTime;
}, [lastResultsData]);

if (isLoading) {
return <EuiLoadingSpinner />;
}

if (!lastResultsData) {
return <>{'-'}</>;
}

return (
<EuiFlexGroup gutterSize="s" alignItems="center">
<EuiFlexItem grow={4}>
{lastResultsData?.['@timestamp'] ? (
{timestamp ? (
<EuiToolTip
content={
<>
<FormattedDate
value={lastResultsData['@timestamp']}
year="numeric"
month="short"
day="2-digit"
/>{' '}
<FormattedTime value={lastResultsData['@timestamp']} timeZoneName="short" />
<FormattedDate value={timestamp} year="numeric" month="short" day="2-digit" />{' '}
<FormattedTime value={timestamp} timeZoneName="short" />
</>
}
>
<div data-test-subj="last-results-date">
<FormattedRelative value={lastResultsData['@timestamp']} />
<FormattedRelative value={timestamp} />
</div>
</EuiToolTip>
) : (
Expand Down Expand Up @@ -584,7 +582,7 @@ const PackQueriesStatusTableComponent: React.FC<PackQueriesStatusTableProps> = (
Record<string, ReturnType<typeof ScheduledQueryExpandedContent>>
>({});

const renderQueryColumn = useCallback((query: string, item: any) => {
const renderQueryColumn = useCallback((query: string, item: PackQueryFormData) => {
const singleLine = removeMultilines(query);
const content = singleLine.length > 55 ? `${singleLine.substring(0, 55)}...` : singleLine;

Expand Down Expand Up @@ -618,7 +616,7 @@ const PackQueriesStatusTableComponent: React.FC<PackQueriesStatusTableProps> = (
);

const renderLastResultsColumn = useCallback(
(item: any) => (
(item: PackQueryFormData) => (
<ScheduledQueryLastResults
actionId={getPackActionId(item.id, packName)}
interval={item.interval}
Expand All @@ -627,19 +625,19 @@ const PackQueriesStatusTableComponent: React.FC<PackQueriesStatusTableProps> = (
[packName]
);
const renderDocsColumn = useCallback(
(item: any) => (
(item: PackQueryFormData) => (
<DocsColumnResults actionId={getPackActionId(item.id, packName)} interval={item.interval} />
),
[packName]
);
const renderAgentsColumn = useCallback(
(item: any) => (
(item: PackQueryFormData) => (
<AgentsColumnResults actionId={getPackActionId(item.id, packName)} interval={item.interval} />
),
[packName]
);
const renderErrorsColumn = useCallback(
(item: any) => (
(item: PackQueryFormData) => (
<ErrorsColumnResults
queryId={item.id}
interval={item.interval}
Expand All @@ -652,12 +650,12 @@ const PackQueriesStatusTableComponent: React.FC<PackQueriesStatusTableProps> = (
);

const renderDiscoverResultsAction = useCallback(
(item: any) => <PackViewInDiscoverAction item={item} packName={packName} />,
(item: PackQueryFormData) => <PackViewInDiscoverAction item={item} packName={packName} />,
[packName]
);

const renderLensResultsAction = useCallback(
(item: any) => <PackViewInLensAction item={item} packName={packName} />,
(item: PackQueryFormData) => <PackViewInLensAction item={item} packName={packName} />,
[packName]
);

Expand Down

0 comments on commit cfcb6e8

Please sign in to comment.