Skip to content

Commit

Permalink
Pass uiSettings to all data plugin services (elastic#42159)
Browse files Browse the repository at this point in the history
* kbn top nav in discover

* New top nav in dashboard and vis editor

* change kbn top nav directive

* Stop using template feature of kbn top nav

* Combined css

* console top nav

* Removed unnecessary use of kbn-top-nav in dev tools app (wrapping tabs)

* Changed console menu to new directive

* CSS adjustments + functional implementation of top nav menu item

* Fixed DevTools top nav toggle

* Optional show-border

* timelion menu works

* Improve filter sorting logic to be more stable

* Support showing filter bar as part of top nav

* Use search bar in top nav in discover and maps
Support search bar with no filter bar (TS)

* tmp revert

* Align search bar settings accross apps

* Reverted change in ML, removed unused css

* Added data test subj to top nav menu items

* Watch config by value

* Some directive magic to make sure that disabledButtons functions are watched correctly.

* Fix missing controls from new top nav in some visualizations

* showAutoRefreshOnly in input controls visualization

* Fixed inspector disabled test

* Fix dashboard action links
rewrite top nav menu item to functional style

* snapshots

* Fixed maps filter bar

* Remvoed comment

* Update Query Bar defaults

* Top nav menu item tests

* Moved storage instantiation to angular directive

* SearchBar jest tests

* Query bar additional tests

* Top nav menu tests

* Pass store into top nav menu correctly

* watch store by reference

* Added not null assertion

* Make index patterns optional (for timepicker only setup)

* QueryBar tests again

* Search bar tests

* Top nav tests

* Top nav menu tests

* removed unnecessary ui/new_platform mock

* Moved discover result count away from top nav

* Moved and improved top nav menu css

* remove unused translations

* Move timepicker (to be deprecated) into old kbn_top_nav

* Deleted search-bar and query-bar directives!

* moved search bar to kibana_react (it's a generic react component, not a service)

* translations

* Moved superDatePicker directive to kbn_top_nav (to be deprecated)
Deleted unused react_component directives call-out and tool-bar-search-box

* Use index patterns from data plugin itself instead of importing from ui/public

* Pass uiSettings from top level of data plugin

* Pass saved objects client from top level

* query bar input to rely on provided localStorage (?)

* import QueryBarInput correctly from vis ediror

* Query bar input tests - uiSettings

* Query bar - uiSettings tests

* import QueryBar from data plugin correctly

* Use provider to pass config to TSVB query bar inputs

* Add query bar input parms to agg types

* Standardize shape data plugin and use it to pass uiSettings in.

* Removed unnecessary mocks

* Fixed test typo

* Code review part 1

* Code review part 2 - clean up top nav menu item run interface

* Give top nav items better keys

* Simplified top nav construction logic in editor

* Fixed mock of search bar in top nav test

* Moved filter trigger button rendering to helper function

* Remove responsiveness from top nav items

* vertical align for cases where showSearchBarInline is true
(i.e. only menu and time picker in the same row)

* Export TopNavMenuData type

* Removed unused name attribute in top nav. Use app-name instead.

* Minor merge fixes

* Update data plugin shape

* type fixes

* fix core start import

* Fixed tests

* fix another test mock

* Brought back setup.ts for backward compatibility.
Chnaged to relative imports

* bad import from data plugin

* Yet another import :-(

* Code revire #1 @lukeelmers

* create wrapper for QueryBarInput

* use IndexPatterns type

* import order

* Code review fixes

* inject uiSettings into filter-bar directive

* Fix some type errors

* Fixes

* Filter bar context

* ts CoreSetupContextProvider

* Moved coreCOntext to vis_editor constructor

* Reverted filter bar context

* Removed editor html ng-show

* use saved objects contract + check uiSettings
  • Loading branch information
Liza Katz committed Aug 11, 2019
1 parent fe3422c commit 060d998
Show file tree
Hide file tree
Showing 47 changed files with 445 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@ import {
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import classNames from 'classnames';
import React, { Component } from 'react';
import chrome from 'ui/chrome';
import { UiSettingsClientContract } from 'src/core/public';
import { IndexPattern } from '../../index_patterns';
import { FilterEditor } from './filter_editor';
import { FilterItem } from './filter_item';
import { FilterOptions } from './filter_options';

const config = chrome.getUiSettingsClient();

interface Props {
filters: Filter[];
onFiltersUpdated: (filters: Filter[]) => void;
className: string;
indexPatterns: IndexPattern[];
intl: InjectedIntl;
uiSettings: UiSettingsClientContract;
}

interface State {
Expand Down Expand Up @@ -103,13 +102,14 @@ class FilterBarUI extends Component<Props, State> {
onUpdate={newFilter => this.onUpdate(i, newFilter)}
onRemove={() => this.onRemove(i)}
indexPatterns={this.props.indexPatterns}
uiSettings={this.props.uiSettings}
/>
</EuiFlexItem>
));
}

private renderAddFilter() {
const isPinned = config.get('filters:pinnedByDefault');
const isPinned = this.props.uiSettings.get('filters:pinnedByDefault');
const [indexPattern] = this.props.indexPatterns;
const index = indexPattern && indexPattern.id;
const newFilter = buildEmptyFilter(isPinned, index);
Expand Down Expand Up @@ -144,6 +144,7 @@ class FilterBarUI extends Component<Props, State> {
onSubmit={this.onAdd}
onCancel={this.onCloseAddFilterPopover}
key={JSON.stringify(newFilter)}
uiSettings={this.props.uiSettings}
/>
</div>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { get } from 'lodash';
import React, { Component } from 'react';
import { UiSettingsClientContract } from 'src/core/public';
import { Field, IndexPattern } from '../../../index_patterns';
import { GenericComboBox, GenericComboBoxProps } from './generic_combo_box';
import {
Expand All @@ -61,6 +62,7 @@ interface Props {
onSubmit: (filter: Filter) => void;
onCancel: () => void;
intl: InjectedIntl;
uiSettings: UiSettingsClientContract;
}

interface State {
Expand Down Expand Up @@ -327,6 +329,7 @@ class FilterEditorUI extends Component<Props, State> {
value={this.state.params}
onChange={this.onParamsChange}
data-test-subj="phraseValueInput"
uiSettings={this.props.uiSettings}
/>
);
case 'phrases':
Expand All @@ -336,6 +339,7 @@ class FilterEditorUI extends Component<Props, State> {
field={this.state.selectedField}
values={this.state.params}
onChange={this.onParamsChange}
uiSettings={this.props.uiSettings}
/>
);
case 'range':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/

import { Component } from 'react';
import chrome from 'ui/chrome';
import { getSuggestions } from 'ui/value_suggestions';
import { UiSettingsClientContract } from 'src/core/public';
import { Field, IndexPattern } from '../../../index_patterns';
const config = chrome.getUiSettingsClient();

export interface PhraseSuggestorProps {
indexPattern: IndexPattern;
field?: Field;
uiSettings: UiSettingsClientContract;
}

export interface PhraseSuggestorState {
Expand All @@ -52,7 +52,7 @@ export class PhraseSuggestor<T extends PhraseSuggestorProps> extends Component<
}

protected isSuggestingValues() {
const shouldSuggestValues = config.get('filterEditor:suggestValues');
const shouldSuggestValues = this.props.uiSettings.get('filterEditor:suggestValues');
const { field } = this.props;
return shouldSuggestValues && field && field.aggregatable && field.type === 'string';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import classNames from 'classnames';
import React, { Component } from 'react';
import { UiSettingsClientContract } from 'src/core/public';
import { IndexPattern } from '../../index_patterns';
import { FilterEditor } from './filter_editor';
import { FilterView } from './filter_view';
Expand All @@ -40,6 +41,7 @@ interface Props {
onUpdate: (filter: Filter) => void;
onRemove: () => void;
intl: InjectedIntl;
uiSettings: UiSettingsClientContract;
}

interface State {
Expand Down Expand Up @@ -169,6 +171,7 @@ class FilterItemUI extends Component<Props, State> {
indexPatterns={this.props.indexPatterns}
onSubmit={this.onSubmit}
onCancel={this.closePopover}
uiSettings={this.props.uiSettings}
/>
</div>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,20 @@ import { StubIndexPatterns } from './test_helpers/stub_index_pattern';
import { StubState } from './test_helpers/stub_state';
import { getFiltersArray } from './test_helpers/get_filters_array';

jest.mock(
'ui/chrome',
() => ({
getBasePath: jest.fn(() => 'path'),
getUiSettingsClient: jest.fn(() => {
return {
get: () => true,
};
}),
}),
{ virtual: true }
);

jest.mock('ui/new_platform', () => ({
npStart: {
core: {
chrome: {
recentlyAccessed: false,
},
},
},
npSetup: {
core: {
uiSettings: {
get: () => true,
},
import { coreMock } from '../../../../../../core/public/mocks';
const setupMock = coreMock.createSetup();

setupMock.uiSettings.get.mockImplementation((key: string) => {
return true;
});

jest.mock('ui/timefilter', () => {
return {
timefilter: {
setTime: jest.fn(),
},
},
}));
};
});

describe('filter_manager', () => {
let appStateStub: StubState;
Expand All @@ -79,7 +64,7 @@ describe('filter_manager', () => {
appStateStub = new StubState();
globalStateStub = new StubState();
indexPatterns = new StubIndexPatterns();
filterManager = new FilterManager(indexPatterns as IndexPatterns);
filterManager = new FilterManager(indexPatterns as IndexPatterns, setupMock.uiSettings);
readyFilters = getFiltersArray();

// FilterStateManager is tested indirectly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { Filter, isFilterPinned, FilterStateStore } from '@kbn/es-query';
import _ from 'lodash';
import { Subject } from 'rxjs';

import { npSetup } from 'ui/new_platform';

import { UiSettingsClientContract } from 'src/core/public';
// @ts-ignore
import { compareFilters } from './lib/compare_filters';
// @ts-ignore
Expand All @@ -46,9 +45,11 @@ export class FilterManager {
private filters: Filter[] = [];
private updated$: Subject<void> = new Subject();
private fetch$: Subject<void> = new Subject();
private uiSettings: UiSettingsClientContract;

constructor(indexPatterns: IndexPatterns) {
constructor(indexPatterns: IndexPatterns, uiSettings: UiSettingsClientContract) {
this.indexPatterns = indexPatterns;
this.uiSettings = uiSettings;
}

private mergeIncomingFilters(partitionedFilters: PartitionedFilters): Filter[] {
Expand Down Expand Up @@ -144,9 +145,8 @@ export class FilterManager {
return;
}

const { uiSettings } = npSetup.core;
if (pinFilterStatus === undefined) {
pinFilterStatus = uiSettings.get('filters:pinnedByDefault');
pinFilterStatus = this.uiSettings.get('filters:pinnedByDefault');
}

// Set the store of all filters. For now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,20 @@ import { getFilter } from './test_helpers/get_stub_filter';
import { FilterManager } from './filter_manager';
import { StubIndexPatterns } from './test_helpers/stub_index_pattern';

jest.mock('ui/new_platform', () => ({
npStart: {
core: {
chrome: {
recentlyAccessed: false,
},
},
},
npSetup: {
core: {
uiSettings: {
get: () => true,
},
import { coreMock } from '../../../../../../core/public/mocks';
const setupMock = coreMock.createSetup();

setupMock.uiSettings.get.mockImplementation((key: string) => {
return true;
});

jest.mock('ui/timefilter', () => {
return {
timefilter: {
setTime: jest.fn(),
},
},
}));
};
});

describe('filter_state_manager', () => {
let appStateStub: StubState;
Expand All @@ -55,7 +53,7 @@ describe('filter_state_manager', () => {
appStateStub = new StubState();
globalStateStub = new StubState();
const indexPatterns = new StubIndexPatterns();
filterManager = new FilterManager(indexPatterns as IndexPatterns);
filterManager = new FilterManager(indexPatterns as IndexPatterns, setupMock.uiSettings);
});

describe('app_state_undefined', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/legacy/core_plugins/data/public/filter/filter_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { UiSettingsClientContract } from 'src/core/public';
import { IndexPatterns } from '../index_patterns';
import { FilterManager } from './filter_manager';
/**
Expand All @@ -26,14 +27,13 @@ import { FilterManager } from './filter_manager';

export interface FilterServiceDependencies {
indexPatterns: IndexPatterns;
uiSettings: UiSettingsClientContract;
}

export class FilterService {
public setup({ indexPatterns }: FilterServiceDependencies) {
const filterManager = new FilterManager(indexPatterns);

public setup({ indexPatterns, uiSettings }: FilterServiceDependencies) {
return {
filterManager,
filterManager: new FilterManager(indexPatterns, uiSettings),
};
}

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

import chrome from 'ui/chrome';
// @ts-ignore
import { mockFields, mockIndexPattern } from 'ui/index_patterns/fixtures';
// @ts-ignore
Expand All @@ -36,8 +34,13 @@ import { isFilterable, getFromSavedObject } from 'ui/index_patterns/static_utils
// IndexPattern, StaticIndexPattern, Field
import * as types from 'ui/index_patterns';

const config = chrome.getUiSettingsClient();
const savedObjectsClient = chrome.getSavedObjectsClient();
import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public';

export interface IndexPatternDependencies {
uiSettings: UiSettingsClientContract;
savedObjectsClient: SavedObjectsClientContract;
}

/**
* Index Patterns Service
*
Expand All @@ -50,9 +53,9 @@ const savedObjectsClient = chrome.getSavedObjectsClient();
* @internal
*/
export class IndexPatternsService {
public setup() {
public setup({ uiSettings, savedObjectsClient }: IndexPatternDependencies) {
return {
indexPatterns: new IndexPatterns(config, savedObjectsClient),
indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient),
};
}

Expand Down
9 changes: 8 additions & 1 deletion src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,20 @@ export class DataPlugin implements Plugin<DataSetup, void, DataPluginSetupDepend
private readonly search: SearchService = new SearchService();

public setup(core: CoreSetup, { __LEGACY, interpreter }: DataPluginSetupDependencies): DataSetup {
const indexPatternsService = this.indexPatterns.setup();
const { uiSettings } = core;
const savedObjectsClient = __LEGACY.savedObjectsClient;

const indexPatternsService = this.indexPatterns.setup({
uiSettings,
savedObjectsClient,
});
return {
expressions: this.expressions.setup({
interpreter,
}),
indexPatterns: indexPatternsService,
filter: this.filter.setup({
uiSettings,
indexPatterns: indexPatternsService.indexPatterns,
}),
query: this.query.setup(),
Expand Down
Loading

0 comments on commit 060d998

Please sign in to comment.