Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into kbn-add-start-ser…
Browse files Browse the repository at this point in the history
…vice-accessor-type
  • Loading branch information
pgayvallet committed Mar 20, 2020
2 parents 682574e + 854f242 commit 76f5a85
Show file tree
Hide file tree
Showing 270 changed files with 3,454 additions and 1,445 deletions.
1 change: 1 addition & 0 deletions .sass-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ files:
- 'x-pack/legacy/plugins/rollup/**/*.s+(a|c)ss'
- 'x-pack/legacy/plugins/security/**/*.s+(a|c)ss'
- 'x-pack/legacy/plugins/canvas/**/*.s+(a|c)ss'
- 'x-pack/plugins/triggers_actions_ui/**/*.s+(a|c)ss'
ignore:
- 'x-pack/legacy/plugins/canvas/shareable_runtime/**/*.s+(a|c)ss'
- 'x-pack/legacy/plugins/lens/**/*.s+(a|c)ss'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
QueryStringInput: React.FC<Pick<Props, "query" | "placeholder" | "onChange" | "onSubmit" | "prepend" | "indexPatterns" | "screenTitle" | "dataTestSubj" | "disableAutoFocus" | "persistedLog" | "bubbleSubmitEvent" | "languageSwitcherPopoverAnchorPosition">>
QueryStringInput: React.FC<Pick<Props, "query" | "placeholder" | "onChange" | "onSubmit" | "prepend" | "indexPatterns" | "disableAutoFocus" | "screenTitle" | "persistedLog" | "bubbleSubmitEvent" | "languageSwitcherPopoverAnchorPosition" | "dataTestSubj">>
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "isLoading" | "intl" | "indexPatterns" | "filters" | "onQueryChange" | "customSubmitButton" | "screenTitle" | "dataTestSubj" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "refreshInterval" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "onRefresh" | "timeHistory" | "onFiltersUpdated" | "onRefreshChange">, "query" | "isLoading" | "indexPatterns" | "filters" | "onQueryChange" | "customSubmitButton" | "screenTitle" | "dataTestSubj" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "refreshInterval" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "onRefresh" | "timeHistory" | "onFiltersUpdated" | "onRefreshChange">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "isLoading" | "intl" | "indexPatterns" | "filters" | "onQueryChange" | "customSubmitButton" | "screenTitle" | "dataTestSubj" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "refreshInterval" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "onRefresh" | "timeHistory" | "onFiltersUpdated" | "onRefreshChange"> & ReactIntl.InjectedIntlProps>;
SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "isLoading" | "intl" | "indexPatterns" | "filters" | "refreshInterval" | "screenTitle" | "dataTestSubj" | "customSubmitButton" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "onRefresh" | "timeHistory" | "onFiltersUpdated" | "onRefreshChange">, "query" | "isLoading" | "indexPatterns" | "filters" | "refreshInterval" | "screenTitle" | "dataTestSubj" | "customSubmitButton" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "onRefresh" | "timeHistory" | "onFiltersUpdated" | "onRefreshChange">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "isLoading" | "intl" | "indexPatterns" | "filters" | "refreshInterval" | "screenTitle" | "dataTestSubj" | "customSubmitButton" | "showQueryBar" | "showQueryInput" | "showFilterBar" | "showDatePicker" | "showAutoRefreshOnly" | "isRefreshPaused" | "dateRangeFrom" | "dateRangeTo" | "showSaveQuery" | "savedQuery" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated" | "onClearSavedQuery" | "onRefresh" | "timeHistory" | "onFiltersUpdated" | "onRefreshChange"> & ReactIntl.InjectedIntlProps>;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export const momentMock = {
locale: jest.fn(() => 'default-locale'),
tz: {
setDefault: jest.fn(),
zone: jest.fn(
z => [{ name: 'tz1' }, { name: 'tz2' }, { name: 'tz3' }].find(f => z === f.name) || null
),
},
weekdays: jest.fn(() => ['dow1', 'dow2', 'dow3']),
updateLocale: jest.fn(),
Expand Down
20 changes: 20 additions & 0 deletions src/core/public/integrations/moment/moment_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ describe('MomentService', () => {
expect(momentMock.updateLocale).toHaveBeenCalledWith('default-locale', { week: { dow: 0 } });
});

it('does not set unknkown zone', async () => {
const tz$ = new BehaviorSubject('timezone/undefined');
const uiSettings = uiSettingsServiceMock.createSetupContract();
uiSettings.get$.mockReturnValueOnce(tz$);

service.start({ uiSettings });
await flushPromises();
expect(momentMock.tz.setDefault).not.toHaveBeenCalled();
});

it('sets timezone when a zone is defined', async () => {
const tz$ = new BehaviorSubject('tz3');
const uiSettings = uiSettingsServiceMock.createSetupContract();
uiSettings.get$.mockReturnValueOnce(tz$);

service.start({ uiSettings });
await flushPromises();
expect(momentMock.tz.setDefault).toHaveBeenCalledWith('tz3');
});

test('updates moment config', async () => {
const tz$ = new BehaviorSubject('tz1');
const dow$ = new BehaviorSubject('dow1');
Expand Down
5 changes: 4 additions & 1 deletion src/core/public/integrations/moment/moment_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export class MomentService implements CoreService {
public async setup() {}

public async start({ uiSettings }: StartDeps) {
const setDefaultTimezone = (tz: string) => moment.tz.setDefault(tz);
const setDefaultTimezone = (tz: string) => {
const zone = moment.tz.zone(tz);
if (zone) moment.tz.setDefault(zone.name);
};
const setStartDayOfWeek = (day: string) => {
const dow = moment.weekdays().indexOf(day);
moment.updateLocale(moment.locale(), { week: { dow } } as any);
Expand Down
2 changes: 0 additions & 2 deletions src/dev/jest/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export default {
'!packages/kbn-ui-framework/src/services/**/*/index.js',
'src/legacy/core_plugins/**/*.{js,jsx,ts,tsx}',
'!src/legacy/core_plugins/**/{__test__,__snapshots__}/**/*',
'src/legacy/ui/public/{agg_types,vis}/**/*.{ts,tsx}',
'!src/legacy/ui/public/{agg_types,vis}/**/*.d.ts',
],
moduleNameMapper: {
'@elastic/eui$': '<rootDir>/node_modules/@elastic/eui/test-env',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ import { InputTimeRange, TimefilterContract, TimeRange } from 'src/plugins/data/
import { ViewMode } from 'src/plugins/embeddable/public';
import { createKbnUrlStateStorage } from 'src/plugins/kibana_utils/public';

jest.mock('ui/agg_types', () => ({
aggTypes: {
metrics: [],
buckets: [],
},
}));

describe('DashboardState', function() {
let dashboardState: DashboardStateManager;
const savedDashboard = getSavedDashboardMock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,7 @@ describe('discover field chooser directives', function() {
beforeEach(() => pluginInstance.initializeServices());
beforeEach(() => pluginInstance.initializeInnerAngular());

beforeEach(
ngMock.module('app/discover', $provide => {
$provide.decorator('config', $delegate => {
// disable shortDots for these tests
$delegate.get = _.wrap($delegate.get, function(origGet, name) {
if (name === 'shortDots:enable') {
return false;
} else {
return origGet.call(this, name);
}
});

return $delegate;
});
})
);
beforeEach(ngMock.module('app/discover'));

beforeEach(
ngMock.inject(function(Private) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logsta
describe('Doc Table', function() {
let $parentScope;
let $scope;
let config;

// Stub out a minimal mapping of 4 fields
let mapping;
Expand All @@ -41,8 +40,7 @@ describe('Doc Table', function() {
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(ngMock.module('app/discover'));
beforeEach(
ngMock.inject(function(_config_, $rootScope, Private) {
config = _config_;
ngMock.inject(function($rootScope, Private) {
$parentScope = $rootScope;
$parentScope.indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
mapping = $parentScope.indexPattern.fields;
Expand Down Expand Up @@ -144,12 +142,6 @@ describe('Doc Table', function() {
filter: sinon.spy(),
maxLength: 50,
});

// Ignore the metaFields (_id, _type, etc) since we don't have a mapping for them
sinon
.stub(config, 'get')
.withArgs('metaFields')
.returns([]);
});
afterEach(function() {
destroy();
Expand Down Expand Up @@ -215,11 +207,6 @@ describe('Doc Table', function() {
maxLength: 50,
});

sinon
.stub(config, 'get')
.withArgs('metaFields')
.returns(['_id']);

// Open the row
$scope.toggleRow();
$scope.$digest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import angular from 'angular';
import { EuiIcon } from '@elastic/eui';
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
import { CoreStart, LegacyCoreStart, IUiSettingsClient } from 'kibana/public';
// @ts-ignore
import { StateManagementConfigProvider } from 'ui/state_management/config_provider';
import { CoreStart, LegacyCoreStart } from 'kibana/public';
// @ts-ignore
import { KbnUrlProvider } from 'ui/url';
import { DataPublicPluginStart } from '../../../../../plugins/data/public';
Expand Down Expand Up @@ -108,7 +106,6 @@ export function initializeInnerAngularModule(
createLocalI18nModule();
createLocalPrivateModule();
createLocalPromiseModule();
createLocalConfigModule(core.uiSettings);
createLocalKbnUrlModule();
createLocalTopNavModule(navigation);
createLocalStorageModule();
Expand Down Expand Up @@ -143,7 +140,6 @@ export function initializeInnerAngularModule(
'ngRoute',
'react',
'ui.bootstrap',
'discoverConfig',
'discoverI18n',
'discoverPrivate',
'discoverPromise',
Expand Down Expand Up @@ -176,21 +172,6 @@ function createLocalKbnUrlModule() {
.service('kbnUrl', (Private: IPrivate) => Private(KbnUrlProvider));
}

function createLocalConfigModule(uiSettings: IUiSettingsClient) {
angular
.module('discoverConfig', ['discoverPrivate'])
.provider('stateManagementConfig', StateManagementConfigProvider)
.provider('config', () => {
return {
$get: () => ({
get: (value: string) => {
return uiSettings ? uiSettings.get(value) : undefined;
},
}),
};
});
}

function createLocalPromiseModule() {
angular.module('discoverPromise', []).service('Promise', PromiseServiceCreator);
}
Expand Down Expand Up @@ -229,7 +210,7 @@ const createLocalStorageService = function(type: string) {

function createElasticSearchModule(data: DataPublicPluginStart) {
angular
.module('discoverEs', ['discoverConfig'])
.module('discoverEs', [])
// Elasticsearch client used for requesting data. Connects to the /elasticsearch proxy
.service('es', () => {
return data.search.__LEGACY.esClient;
Expand All @@ -242,12 +223,7 @@ function createPagerFactoryModule() {

function createDocTableModule() {
angular
.module('discoverDocTable', [
'discoverKbnUrl',
'discoverConfig',
'discoverPagerFactory',
'react',
])
.module('discoverDocTable', ['discoverKbnUrl', 'discoverPagerFactory', 'react'])
.directive('docTable', createDocTableDirective)
.directive('kbnTableHeader', createTableHeaderDirective)
.directive('toolBarPagerText', createToolBarPagerTextDirective)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export { wrapInI18nContext } from 'ui/i18n';
import { search } from '../../../../../plugins/data/public';
export const { getRequestInspectorStats, getResponseInspectorStats, tabifyAggResponse } = search;
// @ts-ignore
export { intervalOptions } from 'ui/agg_types';
// @ts-ignore
export { timezoneProvider } from 'ui/vis/lib/timezone';
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ getAngularModule().config($routeProvider => {
});
});

function ContextAppRouteController($routeParams, $scope, config, $route) {
function ContextAppRouteController($routeParams, $scope, $route) {
const filterManager = getServices().filterManager;
const indexPattern = $route.current.locals.indexPattern.ip;
const {
Expand All @@ -77,9 +77,9 @@ function ContextAppRouteController($routeParams, $scope, config, $route) {
setFilters,
setAppState,
} = getState({
defaultStepSize: config.get('context:defaultSize'),
defaultStepSize: getServices().uiSettings.get('context:defaultSize'),
timeFieldName: indexPattern.timeFieldName,
storeInSessionStorage: config.get('state:storeInSessionStorage'),
storeInSessionStorage: getServices().uiSettings.get('state:storeInSessionStorage'),
});
this.state = { ...appState.getState() };
this.anchorId = $routeParams.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ module.directive('contextApp', function ContextApp() {
};
});

function ContextAppController($scope, config, Private) {
const { filterManager, indexpatterns } = getServices();
function ContextAppController($scope, Private) {
const { filterManager, indexpatterns, uiSettings } = getServices();
const queryParameterActions = getQueryParameterActions(filterManager, indexpatterns);
const queryActions = Private(QueryActionsProvider);
this.state = createInitialState(
parseInt(config.get('context:step'), 10),
getFirstSortableField(this.indexPattern, config.get('context:tieBreakerFields')),
parseInt(uiSettings.get('context:step'), 10),
getFirstSortableField(this.indexPattern, uiSettings.get('context:tieBreakerFields')),
this.discoverUrl
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/
import { FieldName } from './field_name/field_name';
import { wrapInI18nContext } from '../../../kibana_services';
import { getServices, wrapInI18nContext } from '../../../kibana_services';

export function FieldNameDirectiveProvider(config, reactDirective) {
export function FieldNameDirectiveProvider(reactDirective) {
return reactDirective(
wrapInI18nContext(FieldName),
[
Expand All @@ -29,7 +29,7 @@ export function FieldNameDirectiveProvider(config, reactDirective) {
],
{ restrict: 'AE' },
{
useShortDots: config.get('shortDots:enable'),
useShortDots: getServices().uiSettings.get('shortDots:enable'),
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
getRequestInspectorStats,
getResponseInspectorStats,
getServices,
intervalOptions,
unhashUrl,
subscribeWithScope,
tabifyAggResponse,
Expand All @@ -64,7 +63,7 @@ const {
share,
timefilter,
toastNotifications,
uiSettings,
uiSettings: config,
visualizations,
} = getServices();

Expand All @@ -76,6 +75,7 @@ import {
connectToQueryState,
syncQueryStateWithUrl,
getDefaultQuery,
search,
} from '../../../../../../../plugins/data/public';
import { getIndexPatternId } from '../helpers/get_index_pattern_id';
import { addFatalError } from '../../../../../../../plugins/kibana_legacy/public';
Expand Down Expand Up @@ -131,7 +131,7 @@ app.config($routeProvider => {
*
* @type {State}
*/
const id = getIndexPatternId(index, indexPatternList, uiSettings.get('defaultIndex'));
const id = getIndexPatternId(index, indexPatternList, config.get('defaultIndex'));
return Promise.props({
list: indexPatternList,
loaded: indexPatterns.get(id),
Expand Down Expand Up @@ -184,7 +184,6 @@ function discoverController(
$timeout,
$window,
Promise,
config,
kbnUrl,
localStorage,
uiCapabilities
Expand Down Expand Up @@ -286,7 +285,7 @@ function discoverController(
mode: 'absolute',
});
};
$scope.intervalOptions = intervalOptions;
$scope.intervalOptions = search.aggs.intervalOptions;
$scope.minimumVisibleRows = 50;
$scope.fetchStatus = fetchStatuses.UNINITIALIZED;
$scope.showSaveQuery = uiCapabilities.discover.saveQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
import { IUiSettingsClient } from 'kibana/public';
import { TableHeader } from './table_header/table_header';
import { wrapInI18nContext } from '../../../../kibana_services';
import { wrapInI18nContext, getServices } from '../../../../kibana_services';

export function createTableHeaderDirective(reactDirective: any) {
const { uiSettings: config } = getServices();

export function createTableHeaderDirective(reactDirective: any, config: IUiSettingsClient) {
return reactDirective(
wrapInI18nContext(TableHeader),
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import _ from 'lodash';
import $ from 'jquery';
import { IUiSettingsClient } from 'kibana/public';
// @ts-ignore
import rison from 'rison-node';
import '../../doc_viewer';
Expand All @@ -45,8 +44,7 @@ interface LazyScope extends ng.IScope {
export function createTableRowDirective(
$compile: ng.ICompileService,
$httpParamSerializer: any,
kbnUrl: any,
config: IUiSettingsClient
kbnUrl: any
) {
const cellTemplate = _.template(noWhiteSpace(cellTemplateHtml));
const truncateByHeightTemplate = _.template(noWhiteSpace(truncateByHeightTemplateHtml));
Expand Down Expand Up @@ -140,7 +138,7 @@ export function createTableRowDirective(
const newHtmls = [openRowHtml];

const mapping = indexPattern.fields.getByName;
const hideTimeColumn = config.get('doc_table:hideTimeColumn');
const hideTimeColumn = getServices().uiSettings.get('doc_table:hideTimeColumn');
if (indexPattern.timeFieldName && !hideTimeColumn) {
newHtmls.push(
cellTemplate({
Expand Down
Loading

0 comments on commit 76f5a85

Please sign in to comment.