From 6f918d1914c8dfc0783780b27a69a28b758eba2f Mon Sep 17 00:00:00 2001 From: Andrew Macri Date: Tue, 24 Dec 2024 08:15:36 -0500 Subject: [PATCH] - fixed a type error in `x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/index.tsx` In `main`, the `convertToBuildEsQuery` function called in the page above accepts a parameter named `dataViewSpec`, which is typed as: ```typescript dataViewSpec: DataViewSpec | undefined; ``` In `8.x`, the `convertToBuildEsQuery` function takes a different parameter named `indexPattern` instead of `dataViewSpec`, and it's typed differently: ```typescript indexPattern: DataViewBase | undefined; ``` The page was updated to call the `convertToBuildEsQuery` function using the `8.x` version of the parameter. - fixed a type error by updating `x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/settings_flyout/alert_selection/use_data_view/index.ts` In `8.x`, when the `AlertSelectionQuery` component in `x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/settings_flyout/alert_selection/alert_selection_query/index.tsx` obtains a `sourcererDataView` via `useSourcererDataView` in the following code: ```typescript const { sourcererDataView, loading: isLoadingIndexPattern } = useSourcererDataView( SourcererScopeName.detections ); ``` the `sourcererDataView` is typed as: ```typescript const sourcererDataView: DataViewSpec | undefined ``` The `dataViewSpec` parameter of the `useDataView` hook was updated (in this 8.x branch) to reflect the fact that `sourcererDataView` may be undefined: ```typescript dataViewSpec: DataViewSpec | undefined; ``` and an additional check for `undefined` was added in `useDataView`. --- .../public/attack_discovery/pages/index.tsx | 6 +++--- .../settings_flyout/alert_selection/use_data_view/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/index.tsx b/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/index.tsx index affb0d4588301..5ae253940568c 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/index.tsx +++ b/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/index.tsx @@ -184,18 +184,18 @@ const AttackDiscoveryPageComponent: React.FC = () => { const pageTitle = useMemo(() => , []); - const { sourcererDataView } = useSourcererDataView(); + const { indexPattern } = useSourcererDataView(); // filterQuery is the combined search bar query and filters in ES format: const [filterQuery, kqlError] = useMemo( () => convertToBuildEsQuery({ config: getEsQueryConfig(uiSettings), - dataViewSpec: sourcererDataView, + indexPattern, queries: [query ?? getDefaultQuery()], // <-- search bar query filters: filters ?? [], // <-- search bar filters }), - [filters, query, sourcererDataView, uiSettings] + [filters, indexPattern, query, uiSettings] ); // renders a toast if the filter query is invalid: diff --git a/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/settings_flyout/alert_selection/use_data_view/index.ts b/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/settings_flyout/alert_selection/use_data_view/index.ts index 829a685c7cc7a..e71fcf57a399d 100644 --- a/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/settings_flyout/alert_selection/use_data_view/index.ts +++ b/x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/settings_flyout/alert_selection/use_data_view/index.ts @@ -14,7 +14,7 @@ export const useDataView = ({ dataViewSpec, loading, }: { - dataViewSpec: DataViewSpec; + dataViewSpec: DataViewSpec | undefined; loading: boolean; }): DataView | undefined => { const { dataViews } = useKibana().services; @@ -25,7 +25,7 @@ export const useDataView = ({ let active = true; async function createDataView() { - if (!loading) { + if (dataViewSpec != null && !loading) { try { const dv = await dataViews.create(dataViewSpec);