forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vega] Filter bar in Vega is not usable with non default index patter…
…n. (elastic#84090) * [Vega] Filtering is not working Closes: elastic#81738 * fix CI * some work * some work * add tests for extract_index_pattern * simplify extract_index_pattern * fix type error * cleanup * Update vega_base_view.js * Update extract_index_pattern.test.ts * fix PR comments * fix some comments * findByTitle -> getByTitle * remove getByTitle * fix vega_base_view * fix jest * allow to set multiple indexes from top_nav Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> # Conflicts: # src/plugins/vis_type_vega/public/vega_type.ts # src/plugins/vis_type_vega/public/vega_visualization.test.js # src/plugins/vis_type_vega/public/vega_visualization.ts
- Loading branch information
Showing
16 changed files
with
285 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/plugins/vis_type_vega/public/lib/extract_index_pattern.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { dataPluginMock } from '../../../data/public/mocks'; | ||
import { extractIndexPatternsFromSpec } from './extract_index_pattern'; | ||
import { setData } from '../services'; | ||
|
||
import type { VegaSpec } from '../data_model/types'; | ||
|
||
const getMockedSpec = (mockedObj: any) => (mockedObj as unknown) as VegaSpec; | ||
|
||
describe('extractIndexPatternsFromSpec', () => { | ||
const dataStart = dataPluginMock.createStartContract(); | ||
|
||
beforeAll(() => { | ||
setData(dataStart); | ||
}); | ||
|
||
test('should not throw errors if no index is specified', async () => { | ||
const spec = getMockedSpec({ | ||
data: {}, | ||
}); | ||
|
||
const indexes = await extractIndexPatternsFromSpec(spec); | ||
|
||
expect(indexes).toMatchInlineSnapshot(`Array []`); | ||
}); | ||
|
||
test('should extract single index pattern', async () => { | ||
const spec = getMockedSpec({ | ||
data: { | ||
url: { | ||
index: 'test', | ||
}, | ||
}, | ||
}); | ||
|
||
const indexes = await extractIndexPatternsFromSpec(spec); | ||
|
||
expect(indexes).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"id": "test", | ||
"title": "test", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
test('should extract multiple index patterns', async () => { | ||
const spec = getMockedSpec({ | ||
data: [ | ||
{ | ||
url: { | ||
index: 'test1', | ||
}, | ||
}, | ||
{ | ||
url: { | ||
index: 'test2', | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
const indexes = await extractIndexPatternsFromSpec(spec); | ||
|
||
expect(indexes).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"id": "test1", | ||
"title": "test1", | ||
}, | ||
Object { | ||
"id": "test2", | ||
"title": "test2", | ||
}, | ||
] | ||
`); | ||
}); | ||
|
||
test('should filter empty values', async () => { | ||
const spec = getMockedSpec({ | ||
data: [ | ||
{ | ||
url: { | ||
wrong: 'wrong', | ||
}, | ||
}, | ||
{ | ||
url: { | ||
index: 'ok', | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
const indexes = await extractIndexPatternsFromSpec(spec); | ||
|
||
expect(indexes).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"id": "ok", | ||
"title": "ok", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
src/plugins/vis_type_vega/public/lib/extract_index_pattern.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { flatten } from 'lodash'; | ||
import { getData } from '../services'; | ||
|
||
import type { Data, VegaSpec } from '../data_model/types'; | ||
import type { IndexPattern } from '../../../data/public'; | ||
|
||
export const extractIndexPatternsFromSpec = async (spec: VegaSpec) => { | ||
const { indexPatterns } = getData(); | ||
let data: Data[] = []; | ||
|
||
if (Array.isArray(spec.data)) { | ||
data = spec.data; | ||
} else if (spec.data) { | ||
data = [spec.data]; | ||
} | ||
|
||
return flatten<IndexPattern>( | ||
await Promise.all( | ||
data.reduce<Array<Promise<IndexPattern[]>>>((accumulator, currentValue) => { | ||
if (currentValue.url?.index) { | ||
accumulator.push(indexPatterns.find(currentValue.url.index)); | ||
} | ||
|
||
return accumulator; | ||
}, []) | ||
) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.