-
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
Changes from 42 commits
edfc3bc
430d646
0db09ea
c075d5f
b2803aa
b8119b8
42be32e
34de861
d4b246b
ca127f8
f4fbf2b
17d51dd
595e2ae
764d632
1496644
fe77851
828db70
ce3ada9
5ad8491
886b7c9
81fa22e
3735b50
a1b0c8a
3fb0982
8b335b2
deef3fd
d8902dd
5a1f3ef
3e83e59
4e1f56b
2c362e9
9c87314
6c09281
748bf48
797063f
240d365
4a5b11c
f659bb0
1ef02fa
2acc852
e74c39d
bddbb23
910b5da
be26672
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <!-- 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) > [SearchSource](./kibana-plugin-plugins-data-public.searchsource.md) > [removeField](./kibana-plugin-plugins-data-public.searchsource.removefield.md) | ||
|
|
||
| ## SearchSource.removeField() method | ||
|
|
||
| remove field | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| removeField<K extends keyof SearchSourceFields>(field: K): this; | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Type | Description | | ||
| | --- | --- | --- | | ||
| | field | <code>K</code> | | | ||
|
|
||
| <b>Returns:</b> | ||
|
|
||
| `this` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,13 +142,22 @@ export class SearchSource { | |
| */ | ||
| setField<K extends keyof SearchSourceFields>(field: K, value: SearchSourceFields[K]) { | ||
| if (value == null) { | ||
| delete this.fields[field]; | ||
| return this.removeField(field); | ||
| } else { | ||
| this.fields[field] = value; | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * remove field | ||
| * @param field: field name | ||
| */ | ||
| removeField<K extends keyof SearchSourceFields>(field: K) { | ||
| delete this.fields[field]; | ||
| return this; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did I add this? To prevent TypeScript confusion, because when I used 'setFields(key, null)' to remove it, I got depending what I was trying to remove TypeScript errors
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if we could add a quick unit test for the new method
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely! I've added a jest test. |
||
|
|
||
| /** | ||
| * Internal, do not use. Overrides all search source fields with the new field array. | ||
| * | ||
|
|
||
| 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; |
| 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; |
| 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; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we return an empty string here as well?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| }, | ||
| } as unknown) as IndexPatternsService; | ||
| 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; |
Uh oh!
There was an error while loading. Please reload this page.