-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Discover] Refactor discover.js controller topnav code #79062
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
Merged
kertal
merged 44 commits into
elastic:master
from
kertal:kertal-pr-2020-10-01-discover-refactor-topnav-code
Nov 25, 2020
Merged
Changes from 29 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
edfc3bc
Initial refactorings
kertal 430d646
Fix async - await issue
kertal 0db09ea
Refactor updateSearchSource to update_search_source.ts
kertal c075d5f
Fix types & jest tests
kertal b2803aa
Extract persistSavedSearch function
kertal b8119b8
Merge master / fix conflicts
kertal 42be32e
Merge remote-tracking branch 'upstream/master' into kertal-pr-2020-10…
kertal 34de861
Update types
kertal d4b246b
Refactor
kertal ca127f8
Improve code
kertal f4fbf2b
Remove console.log
kertal 17d51dd
Merge branch 'master' into kertal-pr-2020-10-01-discover-refactor-top…
kibanamachine 595e2ae
Merge branch 'kertal-pr-2020-10-01-discover-refactor-topnav-code' of …
kertal 764d632
Merge remote-tracking branch 'upstream/master' into kertal-pr-2020-10…
kertal 1496644
Improve index pattern loading code
kertal fe77851
Refactor index pattern code and add test
kertal 828db70
Fix type
kertal ce3ada9
Add another test
kertal 5ad8491
Merge and fix conflicts
kertal 886b7c9
Add tests
kertal 81fa22e
Update snapshot
kertal 3735b50
Undo fixed scroll changes
kertal a1b0c8a
Add more tests and refactor
kertal 3fb0982
Improve test code
kertal 8b335b2
Merge and fix conflicts
kertal deef3fd
Merge branch 'master' into kertal-pr-2020-10-01-discover-refactor-top…
kibanamachine d8902dd
Merge remote-tracking branch 'upstream/master' into kertal-pr-2020-10…
kertal 5a1f3ef
Merge branch 'kertal-pr-2020-10-01-discover-refactor-topnav-code' of …
kertal 3e83e59
Improve index pattern code
kertal 4e1f56b
Add removeField to SearchSource
kertal 2c362e9
Address review comments
kertal 9c87314
Address review comments
kertal 6c09281
Merge remote-tracking branch 'upstream/master' into kertal-pr-2020-10…
kertal 748bf48
Generate API
kertal 797063f
Generate API part 2
kertal 240d365
Merge remote-tracking branch 'upstream/master' into kertal-pr-2020-10…
kertal 4a5b11c
Seems I've broken sorting ... time to fix
kertal f659bb0
Merge branch 'master' into kertal-pr-2020-10-01-discover-refactor-top…
kibanamachine 1ef02fa
Merge branch 'master' into kertal-pr-2020-10-01-discover-refactor-top…
kibanamachine 2acc852
Add jest test to search_source.test.ts
kertal e74c39d
Merge branch 'kertal-pr-2020-10-01-discover-refactor-topnav-code' of …
kertal bddbb23
Merge branch 'master' into kertal-pr-2020-10-01-discover-refactor-top…
kibanamachine 910b5da
Improve SearchSource code
kertal be26672
Merge branch 'kertal-pr-2020-10-01-discover-refactor-topnav-code' of …
kertal 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
This file contains hidden or 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,30 @@ | ||
| /* | ||
| * 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 { IUiSettingsClient } from '../../../../core/public'; | ||
|
|
||
| export const configMock = ({ | ||
| get: (key: string) => { | ||
| if (key === 'defaultIndex') { | ||
| return 'the-index-pattern-id'; | ||
| } | ||
|
|
||
| return ''; | ||
| }, | ||
| } as unknown) as IUiSettingsClient; |
This file contains hidden or 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,74 @@ | ||
| /* | ||
| * 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 { IndexPattern, indexPatterns } from '../kibana_services'; | ||
| import { IIndexPatternFieldList } from '../../../data/common/index_patterns/fields'; | ||
|
|
||
| const fields = [ | ||
| { | ||
| name: '_index', | ||
| type: 'string', | ||
| scripted: false, | ||
| filterable: true, | ||
| }, | ||
| { | ||
| name: 'message', | ||
| type: 'string', | ||
| scripted: false, | ||
| filterable: false, | ||
| }, | ||
| { | ||
| name: 'extension', | ||
| type: 'string', | ||
| scripted: false, | ||
| filterable: true, | ||
| }, | ||
| { | ||
| name: 'bytes', | ||
| type: 'number', | ||
| scripted: false, | ||
| filterable: true, | ||
| }, | ||
| { | ||
| name: 'scripted', | ||
| type: 'number', | ||
| scripted: true, | ||
| filterable: false, | ||
| }, | ||
| ] as IIndexPatternFieldList; | ||
|
|
||
| fields.getByName = (name: string) => { | ||
| return fields.find((field) => field.name === name); | ||
| }; | ||
|
|
||
| const indexPattern = ({ | ||
| id: 'the-index-pattern-id', | ||
| title: 'the-index-pattern-title', | ||
| metaFields: ['_index', '_score'], | ||
| flattenHit: undefined, | ||
| formatHit: jest.fn((hit) => hit._source), | ||
| fields, | ||
| getComputedFields: () => ({}), | ||
| getSourceFiltering: () => ({}), | ||
| getFieldByName: () => ({}), | ||
| } as unknown) as IndexPattern; | ||
|
|
||
| indexPattern.flattenHit = indexPatterns.flattenHitWrapper(indexPattern, indexPattern.metaFields); | ||
|
|
||
| export const indexPatternMock = indexPattern; |
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * 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 { IndexPatternsService } from '../../../data/common'; | ||
| import { indexPatternMock } from './index_pattern'; | ||
|
|
||
| export const indexPatternsMock = ({ | ||
| getCache: () => { | ||
| return [indexPatternMock]; | ||
| }, | ||
| get: (id: string) => { | ||
| if (id === 'the-index-pattern-id') { | ||
| return indexPatternMock; | ||
| } | ||
| }, | ||
| } as unknown) as IndexPatternsService; | ||
This file contains hidden or 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,41 @@ | ||
| /* | ||
| * 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 { SavedSearch } from '../saved_searches'; | ||
|
|
||
| export const savedSearchMock = ({ | ||
| id: 'the-saved-search-id', | ||
| type: 'search', | ||
| attributes: { | ||
| title: 'the-saved-search-title', | ||
| kibanaSavedObjectMeta: { | ||
| searchSourceJSON: | ||
| '{"highlightAll":true,"version":true,"query":{"query":"foo : \\"bar\\" ","language":"kuery"},"filter":[],"indexRefName":"kibanaSavedObjectMeta.searchSourceJSON.index"}', | ||
| }, | ||
| }, | ||
| references: [ | ||
| { | ||
| name: 'kibanaSavedObjectMeta.searchSourceJSON.index', | ||
| type: 'index-pattern', | ||
| id: 'the-index-pattern-id', | ||
| }, | ||
| ], | ||
| migrationVersion: { search: '7.5.0' }, | ||
| error: undefined, | ||
| } as unknown) as SavedSearch; |
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.
Should we return an empty string here as well?
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.
for the case when the id is different? of course we can build up on this very basic mock, will be useful in other tests, however the original code here provides different error handling, so mocking this would work differently