-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Vega] Filter bar in Vega is not usable with non default index pattern. #84090
Merged
Merged
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a16fec4
[Vega] Filtering is not working
alexwizp 39dd4b7
Merge remote-tracking branch 'upstream/master' into 81738
alexwizp 9cf57e7
fix CI
alexwizp 6952981
some work
alexwizp 58a1d93
Merge remote-tracking branch 'upstream/master' into 81738
alexwizp d0c3f53
some work
alexwizp ef4e702
add tests for extract_index_pattern
alexwizp 410cc4c
Merge remote-tracking branch 'upstream/master' into 81738
alexwizp e66c610
simplify extract_index_pattern
alexwizp 7fd0ad2
Merge remote-tracking branch 'upstream/master' into 81738
alexwizp 0eb9680
fix type error
alexwizp e068c90
cleanup
alexwizp 6c846f0
Merge branch 'master' into 81738
kibanamachine 0010868
Update vega_base_view.js
alexwizp 629398d
Update extract_index_pattern.test.ts
alexwizp 1491d37
Merge branch 'master' into 81738
kibanamachine 606e67d
fix PR comments
alexwizp 7b25522
Merge branch 'master' into 81738
kibanamachine 37044aa
fix some comments
alexwizp 4cfe514
Merge branch 'master' into 81738
kibanamachine 90c87c0
Merge branch 'master' into 81738
kibanamachine 1548365
findByTitle -> getByTitle
alexwizp 5c9643a
Merge remote-tracking branch 'upstream/master' into 81738
alexwizp d8022ef
remove getByTitle
alexwizp cea9694
fix vega_base_view
alexwizp 7a0a9b7
fix jest
alexwizp b538cab
allow to set multiple indexes from top_nav
alexwizp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...ta/public/kibana-plugin-plugins-data-public.indexpatternsservice.findbytitle.md
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,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternsService](./kibana-plugin-plugins-data-public.indexpatternsservice.md) > [findByTitle](./kibana-plugin-plugins-data-public.indexpatternsservice.findbytitle.md) | ||
|
||
## IndexPatternsService.findByTitle property | ||
|
||
Returns an object matching a given title | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
findByTitle: (title: string, refresh?: boolean) => Promise<IndexPattern | undefined>; | ||
``` |
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
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", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
/* | ||
* 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 { 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 ( | ||
await Promise.all( | ||
data.reduce<Data[]>((accumulator, currentValue) => { | ||
if (currentValue.url?.index) { | ||
accumulator.push(indexPatterns.findByTitle(currentValue.url.index)); | ||
} | ||
|
||
return accumulator; | ||
}, []) | ||
) | ||
).filter((index) => Boolean(index)) as IndexPattern[]; | ||
}; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could rely on
getIdsWithTitle
, filter based on the result, and thenget
Lets call this
getByTitle