Skip to content

Commit

Permalink
- fixed a type error in `x-pack/solutions/security/plugins/security_s…
Browse files Browse the repository at this point in the history
…olution/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`.
  • Loading branch information
andrew-goldstein committed Dec 24, 2024
1 parent b3a6708 commit 6f918d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,18 @@ const AttackDiscoveryPageComponent: React.FC = () => {

const pageTitle = useMemo(() => <PageTitle />, []);

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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useDataView = ({
dataViewSpec,
loading,
}: {
dataViewSpec: DataViewSpec;
dataViewSpec: DataViewSpec | undefined;
loading: boolean;
}): DataView | undefined => {
const { dataViews } = useKibana().services;
Expand All @@ -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);

Expand Down

0 comments on commit 6f918d1

Please sign in to comment.