Skip to content

Commit

Permalink
Replaced last import of chrome with core dep (#44007) (#44237)
Browse files Browse the repository at this point in the history
* Replaced last import of chrome with core dep

* pass saved objects client to FilterRow

* update tests

* fix warning

* updated snapshot
  • Loading branch information
Liza Katz authored Aug 28, 2019
1 parent 48aac69 commit 8025ea0
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 76 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import { QueryBar } from './query_bar';
import { IndexPattern } from '../../../index';

import { coreMock } from '../../../../../../../core/public/mocks';
const setupMock = coreMock.createSetup();
const startMock = coreMock.createStart();

setupMock.uiSettings.get.mockImplementation((key: string) => {
startMock.uiSettings.get.mockImplementation((key: string) => {
switch (key) {
case 'timepicker:quickRanges':
return [
Expand Down Expand Up @@ -98,7 +98,8 @@ describe('QueryBar', () => {
it('Should render the given query', () => {
const component = shallowWithIntl(
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
query={kqlQuery}
onSubmit={noop}
appName={'discover'}
Expand All @@ -118,7 +119,8 @@ describe('QueryBar', () => {
it('Should create a unique PersistedLog based on the appName and query language', () => {
shallowWithIntl(
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
query={kqlQuery}
onSubmit={noop}
appName={'discover'}
Expand All @@ -138,7 +140,8 @@ describe('QueryBar', () => {
it('Should render only timepicker when no options provided', () => {
const component = shallowWithIntl(
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
onSubmit={noop}
onChange={noop}
isDirty={false}
Expand All @@ -155,7 +158,8 @@ describe('QueryBar', () => {
it('Should not show timepicker when asked', () => {
const component = shallowWithIntl(
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
onSubmit={noop}
onChange={noop}
isDirty={false}
Expand All @@ -173,7 +177,8 @@ describe('QueryBar', () => {
it('Should render timepicker with options', () => {
const component = shallowWithIntl(
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
onSubmit={noop}
onChange={noop}
isDirty={false}
Expand All @@ -194,7 +199,8 @@ describe('QueryBar', () => {
it('Should render only query input bar', () => {
const component = shallowWithIntl(
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
query={kqlQuery}
onSubmit={noop}
onChange={noop}
Expand All @@ -215,7 +221,8 @@ describe('QueryBar', () => {
it('Should NOT render query input bar if disabled', () => {
const component = shallowWithIntl(
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
query={kqlQuery}
onSubmit={noop}
onChange={noop}
Expand All @@ -237,7 +244,8 @@ describe('QueryBar', () => {
it('Should NOT render query input bar if missing options', () => {
const component = shallowWithIntl(
<QueryBar.WrappedComponent
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
onSubmit={noop}
onChange={noop}
isDirty={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { documentationLinks } from 'ui/documentation_links';
import { Toast, toastNotifications } from 'ui/notify';
import { PersistedLog } from 'ui/persisted_log';
import { UiSettingsClientContract } from 'src/core/public';
import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public';
import { IndexPattern } from '../../../index_patterns';
import { QueryBarInput } from './query_bar_input';

Expand Down Expand Up @@ -67,6 +67,7 @@ interface Props {
customSubmitButton?: any;
isDirty: boolean;
uiSettings: UiSettingsClientContract;
savedObjectsClient: SavedObjectsClientContract;
}

interface State {
Expand Down Expand Up @@ -212,6 +213,7 @@ export class QueryBarUI extends Component<Props, State> {
onSubmit={this.onInputSubmit}
persistedLog={this.persistedLog}
uiSettings={this.props.uiSettings}
savedObjectsClient={this.props.savedObjectsClient}
/>
</EuiFlexItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { QueryLanguageSwitcher } from './language_switcher';
import { QueryBarInput, QueryBarInputUI } from './query_bar_input';
import { coreMock } from '../../../../../../../core/public/mocks';
const setupMock = coreMock.createSetup();
const startMock = coreMock.createStart();
import { IndexPattern } from '../../../index';

const noop = () => {
Expand Down Expand Up @@ -93,7 +93,8 @@ describe('QueryBarInput', () => {
indexPatterns={[mockIndexPattern]}
store={createMockStorage()}
intl={null as any}
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
/>
);

Expand All @@ -110,7 +111,8 @@ describe('QueryBarInput', () => {
indexPatterns={[mockIndexPattern]}
store={createMockStorage()}
intl={null as any}
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
/>
);

Expand All @@ -128,7 +130,8 @@ describe('QueryBarInput', () => {
store={createMockStorage()}
disableAutoFocus={true}
intl={null as any}
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
/>
);

Expand All @@ -148,7 +151,8 @@ describe('QueryBarInput', () => {
store={createMockStorage()}
disableAutoFocus={true}
intl={null as any}
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
/>
);

Expand All @@ -169,7 +173,8 @@ describe('QueryBarInput', () => {
store={mockStorage}
disableAutoFocus={true}
intl={null as any}
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
/>
);

Expand All @@ -194,7 +199,8 @@ describe('QueryBarInput', () => {
store={createMockStorage()}
disableAutoFocus={true}
intl={null as any}
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
/>
);

Expand All @@ -218,7 +224,8 @@ describe('QueryBarInput', () => {
store={createMockStorage()}
disableAutoFocus={true}
intl={null as any}
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
/>
);

Expand Down Expand Up @@ -247,9 +254,14 @@ describe('QueryBarInput', () => {
store={createMockStorage()}
disableAutoFocus={true}
intl={null as any}
uiSettings={setupMock.uiSettings}
uiSettings={startMock.uiSettings}
savedObjectsClient={startMock.savedObjects.client}
/>
);
expect(mockFetchIndexPatterns).toHaveBeenCalledWith(['logstash-*'], setupMock.uiSettings);
expect(mockFetchIndexPatterns).toHaveBeenCalledWith(
startMock.savedObjects.client,
['logstash-*'],
startMock.uiSettings
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { debounce, compact, isEqual, omit } from 'lodash';
import { PersistedLog } from 'ui/persisted_log';
import { kfetch } from 'ui/kfetch';
import { Storage } from 'ui/storage';
import { UiSettingsClientContract } from 'src/core/public';
import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public';
import { IndexPattern, StaticIndexPattern } from '../../../index_patterns';
import { Query } from '../index';
import { fromUser, matchPairs, toUser } from '../lib';
Expand All @@ -44,6 +44,7 @@ import { fetchIndexPatterns } from '../lib/fetch_index_patterns';
interface Props {
uiSettings: UiSettingsClientContract;
indexPatterns: Array<IndexPattern | string>;
savedObjectsClient: SavedObjectsClientContract;
store: Storage;
intl: InjectedIntl;
query: Query;
Expand Down Expand Up @@ -111,6 +112,7 @@ export class QueryBarInputUI extends Component<Props, State> {
) as IndexPattern[];

const objectPatternsFromStrings = (await fetchIndexPatterns(
this.props.savedObjectsClient,
stringPatterns,
this.props.uiSettings
)) as IndexPattern[];
Expand Down Expand Up @@ -451,6 +453,7 @@ export class QueryBarInputUI extends Component<Props, State> {
'onChange',
'onSubmit',
'uiSettings',
'savedObjectsClient',
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/

import chrome from 'ui/chrome';
import { isEmpty } from 'lodash';

import { UiSettingsClientContract } from 'src/core/public';
import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public';
import { getFromSavedObject } from '../../../index_patterns';

export async function fetchIndexPatterns(
savedObjectsClient: SavedObjectsClientContract,
indexPatternStrings: string[],
uiSettings: UiSettingsClientContract
) {
Expand All @@ -32,7 +30,7 @@ export async function fetchIndexPatterns(
}

const searchString = indexPatternStrings.map(string => `"${string}"`).join(' | ');
const indexPatternsFromSavedObjects = await chrome.getSavedObjectsClient().find({
const indexPatternsFromSavedObjects = await savedObjectsClient.find({
type: 'index-pattern',
fields: ['title', 'fields'],
search: searchString,
Expand All @@ -48,12 +46,7 @@ export async function fetchIndexPatterns(
const allMatches =
exactMatches.length === indexPatternStrings.length
? exactMatches
: [...exactMatches, await fetchDefaultIndexPattern(defaultIndex)];
: [...exactMatches, await savedObjectsClient.get('index-pattern', defaultIndex)];

return allMatches.map(getFromSavedObject);
}

const fetchDefaultIndexPattern = async (defaultIndex: string) => {
const savedObjectsClient = chrome.getSavedObjectsClient();
return await savedObjectsClient.get('index-pattern', defaultIndex);
};
Loading

0 comments on commit 8025ea0

Please sign in to comment.