[Security Solution][Detection Engine] fixes warning toasts on exception flyout (#180800)

## Summary

 - addresses https://github.com/elastic/kibana/issues/160851

warning was displaying because of error

```JSON
{
  "name": "TypeError",
  "message": "indexPattern.getAllowHidden is not a function",
  "stack": "TypeError: indexPattern.getAllowHidden is not a function\n    at DataViewsServicePublic.getFieldsForIndexPattern (http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/plugin/dataViews/1.0.0/dataViews.plugin.js:2519:131)\n    at http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/plugin/securitySolution/1.0.0/securitySolution.chunk.63.js:200144:45\n    at fetchExtendedField (http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/plugin/lists/1.0.0/lists.chunk.0.js:19767:38)\n    at BuilderEntryItem._entry$field3 (http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/plugin/lists/1.0.0/lists.chunk.0.js:19772:5)\n    at invokePassiveEffectCreate (http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:375924:20)\n    at HTMLUnknownElement.callCallback (http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:356387:14)\n    at Object.invokeGuardedCallbackDev (http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:356436:16)\n    at invokeGuardedCallback (http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:356498:31)\n    at flushPassiveEffectsImpl (http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:376011:9)\n    at unstable_runWithPriority (http://localhost:5601/kbn/XXXXXXXXXXXX/bundles/kbn-ui-shared-deps-npm/kbn-ui-shared-deps-npm.dll.js:437229:12)"
}
```

which originated in
https://github.com/elastic/kibana/blob/8.13/src/plugins/data_views/common/data_views/data_views.ts#L539

```ts

      allowHidden:
        (indexPattern as DataViewSpec).allowHidden || (indexPattern as DataView)?.getAllowHidden(),

```

In this case index.allowHidden is `false`, so `getAllowHidden()` is
called. Because `getAllowHidden` is undefined, it causes error above.

In my fix, I check if `allowHidden` is set and if not, only after this
`getAllowHidden()` is getting called
This commit is contained in:
Vitalii Dmyterko 2024-04-16 11:18:51 +01:00 committed by GitHub
parent 747b2ad747
commit cefdb33a67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 80 additions and 2 deletions

View file

@ -201,7 +201,7 @@ describe('IndexPatterns', () => {
expect(apiClient.getFieldsForWildcard).toBeCalledWith(args);
});
test('getFieldsForWildcard called with allowNoIndex set to true as default ', async () => {
test('getFieldsForWildcard called with allowNoIndex set to true as default', async () => {
const id = '1';
await indexPatterns.get(id);
expect(apiClient.getFieldsForWildcard).toBeCalledWith({
@ -214,6 +214,82 @@ describe('IndexPatterns', () => {
});
});
test('getFieldsForIndexPattern called with allowHidden set to undefined as default', async () => {
await indexPatterns.getFieldsForIndexPattern({ id: '1' } as DataViewSpec, {
pattern: 'something',
});
expect(apiClient.getFieldsForWildcard).toBeCalledWith({
allowHidden: undefined,
allowNoIndex: true,
metaFields: false,
pattern: undefined,
rollupIndex: undefined,
type: undefined,
});
});
test('getFieldsForIndexPattern called with allowHidden set to true', async () => {
await indexPatterns.getFieldsForIndexPattern({ id: '1', allowHidden: true } as DataViewSpec, {
pattern: 'something',
});
expect(apiClient.getFieldsForWildcard).toBeCalledWith({
allowHidden: true,
allowNoIndex: true,
metaFields: false,
pattern: undefined,
rollupIndex: undefined,
type: undefined,
});
});
test('getFieldsForIndexPattern called with allowHidden set to false', async () => {
await indexPatterns.getFieldsForIndexPattern({ id: '1', allowHidden: false } as DataViewSpec, {
pattern: 'something',
});
expect(apiClient.getFieldsForWildcard).toBeCalledWith({
allowHidden: false,
allowNoIndex: true,
metaFields: false,
pattern: undefined,
rollupIndex: undefined,
type: undefined,
});
});
test('getFieldsForIndexPattern called with getAllowHidden returning true', async () => {
await indexPatterns.getFieldsForIndexPattern(
{ id: '1', getAllowHidden: () => true } as DataView,
{
pattern: 'something',
}
);
expect(apiClient.getFieldsForWildcard).toBeCalledWith({
allowHidden: true,
allowNoIndex: true,
metaFields: false,
pattern: undefined,
rollupIndex: undefined,
type: undefined,
});
});
test('getFieldsForIndexPattern called with getAllowHidden returning false', async () => {
await indexPatterns.getFieldsForIndexPattern(
{ id: '1', getAllowHidden: () => false } as DataView,
{
pattern: 'something',
}
);
expect(apiClient.getFieldsForWildcard).toBeCalledWith({
allowHidden: false,
allowNoIndex: true,
metaFields: false,
pattern: undefined,
rollupIndex: undefined,
type: undefined,
});
});
test('does cache ad-hoc data views', async () => {
const id = '1';

View file

@ -572,7 +572,9 @@ export class DataViewsService {
...options,
pattern: indexPattern.title as string,
allowHidden:
(indexPattern as DataViewSpec).allowHidden || (indexPattern as DataView)?.getAllowHidden(),
(indexPattern as DataViewSpec).allowHidden == null
? (indexPattern as DataView)?.getAllowHidden?.()
: (indexPattern as DataViewSpec).allowHidden,
});
private getFieldsAndIndicesForDataView = async (