Skip to content
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
5563f83
Initial typescript version
kertal Nov 22, 2019
e24bc6b
Use extracted functions
kertal Nov 25, 2019
d9c0d74
Fix types
kertal Nov 25, 2019
2e05092
Extract save & initialize functions
kertal Nov 25, 2019
dc47644
Add even more typescript
kertal Nov 25, 2019
e0cc901
Improve types
kertal Nov 26, 2019
01b5cb5
Improving types, extracting another function
kertal Nov 26, 2019
093bedc
fix merge conflicts
kertal Nov 27, 2019
8038c00
Code refactoring, deangularisation, migrate to Promise
kertal Nov 30, 2019
a31bd35
Merge upstream/master
kertal Dec 1, 2019
7a0dc19
Migrate Visualize AngularPromise to native promise
kertal Dec 2, 2019
ae0b043
Fix Discover Edit URL link
kertal Dec 2, 2019
2f7e6c1
Migrate to use of NP services (savedObjects + indexPatterns)
kertal Dec 2, 2019
cf2b1f8
Migrate confirmModalPromise to a NP backed version - add code :)
kertal Dec 2, 2019
174d784
cleanup confirmModalPromise, fix creation of visualize data table
kertal Dec 2, 2019
b7a7960
Fix JSON import test
kertal Dec 2, 2019
be2e79c
Remove init from types
kertal Dec 3, 2019
5c6f162
Split between createSavedObjectClass and SavedObjectProvider
kertal Dec 3, 2019
051a936
Adapt Discover to use deangularized SavedObject version
kertal Dec 3, 2019
334dd1f
Fix type errors
kertal Dec 3, 2019
d6f1a6b
Remove redundant file
kertal Dec 3, 2019
4b1e8b1
Fix functional test failure importing JSON
kertal Dec 3, 2019
b4d6363
Migrate chrome.untrackNavLinksForDeletedSavedObjects
kertal Dec 4, 2019
a4d19dd
Improve types
kertal Dec 4, 2019
54b8622
Code improvements
kertal Dec 4, 2019
10d6b45
Require NP chrome for SavedObjectLoader
kertal Dec 4, 2019
bb838c1
Fix type error
kertal Dec 4, 2019
c3e8e05
Merge remote-tracking branch 'upstream/master' into kertal-pr-2019-11…
kertal Dec 4, 2019
cdca97f
Fix IndexPatterns type error
kertal Dec 4, 2019
9a47751
Merge remote-tracking branch 'upstream/master' into kertal-pr-2019-11…
kertal Dec 5, 2019
47eb12c
maja review improvements
kertal Dec 5, 2019
c130333
Fix broken functional test
kertal Dec 6, 2019
7926552
Merge remote-tracking branch 'upstream/master' into kertal-pr-2019-11…
kertal Dec 9, 2019
de0ce4e
Add missing static properties of SavedSearch class
kertal Dec 9, 2019
be86b58
merge upstream
kertal Dec 10, 2019
114576a
Fix types
kertal Dec 10, 2019
01cf3f3
use encodeURIComponent in saved_visualizations.js, remove kbnUrl
kertal Dec 10, 2019
8774715
Remove unnecessary type cast
kertal Dec 10, 2019
30dcc2a
Further deangularize gis_map_saved_object_loader.js
kertal Dec 10, 2019
b38c89b
Remove npStart imports from helper functions
kertal Dec 10, 2019
3022a7d
Fix types
kertal Dec 10, 2019
3006561
merge upstream & fix conflicts
kertal Dec 10, 2019
6aa01c6
Review changes
kertal Dec 10, 2019
2ce5f34
Fix mocha tests that broke due to refactoring
kertal Dec 10, 2019
c441b88
merge upstream & fix conflicts
kertal Dec 11, 2019
b063f3d
Add missing savedObjects property in dashboard_app_controller.tsx
kertal Dec 11, 2019
87b0ba7
Address review comments
kertal Dec 12, 2019
163f53f
Merge remote-tracking branch 'upstream/master' into kertal-pr-2019-11…
kertal Dec 12, 2019
5b7b989
Restore statics values at SavedSearch
kertal Dec 12, 2019
d03416c
Revert "Address review comments"
kertal Dec 12, 2019
74a7488
Revert "Restore statics values at SavedSearch"
kertal Dec 12, 2019
eb72d95
Restore statics values at SavedSearch
kertal Dec 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export function getSavedDashboardMock(
getQuery: () => ({ query: '', language: 'kuery' }),
getFilters: () => [],
...config,
};
} as SavedObjectDashboard;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
State,
AppStateClass as TAppStateClass,
KbnUrl,
SaveOptions,
SavedObjectSaveOpts,
unhashUrl,
} from './legacy_imports';
import { FilterStateManager, IndexPattern } from '../../../data/public';
Expand Down Expand Up @@ -603,7 +603,7 @@ export class DashboardAppController {
* @return {Promise}
* @resolved {String} - The id of the doc
*/
function save(saveOptions: SaveOptions): Promise<SaveResult> {
function save(saveOptions: SavedObjectSaveOpts): Promise<SaveResult> {
return saveDashboard(angular.toJson, timefilter, dashboardStateManager, saveOptions)
.then(function(id) {
if (id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const legacyChrome = chrome;
export { State } from 'ui/state_management/state';
export { AppState } from 'ui/state_management/app_state';
export { AppStateClass } from 'ui/state_management/app_state';
export { SaveOptions } from 'ui/saved_objects/saved_object';
export { SavedObjectSaveOpts } from 'ui/saved_objects/types';
export { npSetup, npStart } from 'ui/new_platform';
export { SavedObjectRegistryProvider } from 'ui/saved_objects';
export { IPrivate } from 'ui/private';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { TimefilterContract } from 'src/plugins/data/public';
import { SaveOptions } from '../legacy_imports';
import { SavedObjectSaveOpts } from '../legacy_imports';
import { updateSavedDashboard } from './update_saved_dashboard';
import { DashboardStateManager } from '../dashboard_state_manager';

Expand All @@ -34,7 +34,7 @@ export function saveDashboard(
toJson: (obj: any) => string,
timeFilter: TimefilterContract,
dashboardStateManager: DashboardStateManager,
saveOptions: SaveOptions
saveOptions: SavedObjectSaveOpts
): Promise<string> {
dashboardStateManager.saveState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { SavedObject } from 'ui/saved_objects/saved_object';
import { SavedObject } from 'ui/saved_objects/types';
import { SearchSourceContract } from '../../../../../ui/public/courier';
import { esFilters, Query, RefreshInterval } from '../../../../../../plugins/data/public';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import './saved_dashboard';
import { uiModules } from 'ui/modules';
import { SavedObjectLoader, SavedObjectsClientProvider } from 'ui/saved_objects';
import { savedObjectManagementRegistry } from '../../management/saved_object_registry';
import { npStart } from '../../../../../ui/public/new_platform';

const module = uiModules.get('app/dashboard');

Expand All @@ -35,7 +36,7 @@ savedObjectManagementRegistry.register({
});

// This is the only thing that gets injected into controllers
module.service('savedDashboards', function (Private, SavedDashboard, kbnUrl, chrome) {
module.service('savedDashboards', function (Private, SavedDashboard) {
const savedObjectClient = Private(SavedObjectsClientProvider);
return new SavedObjectLoader(SavedDashboard, kbnUrl, chrome, savedObjectClient);
return new SavedObjectLoader(SavedDashboard, savedObjectClient, npStart.core.chrome);
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('discoverField', function () {
let $scope;
let indexPattern;
let $elem;
beforeEach(() => pluginInstance.initializeServices(true));
beforeEach(() => pluginInstance.initializeServices());
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(ngMock.module('app/discover'));
beforeEach(ngMock.inject(function (Private, $rootScope, $compile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('discover field chooser directives', function () {
on-remove-field="removeField"
></disc-field-chooser>
`);
beforeEach(() => pluginInstance.initializeServices(true));
beforeEach(() => pluginInstance.initializeServices());
beforeEach(() => pluginInstance.initializeInnerAngular());

beforeEach(ngMock.module('app/discover', ($provide) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { npStart } from 'ui/new_platform';

describe('context app', function () {
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(() => pluginInstance.initializeServices(true));
beforeEach(() => pluginInstance.initializeServices());
beforeEach(ngMock.module('app/discover'));
beforeEach(ngMock.module(function createServiceStubs($provide) {
$provide.value('indexPatterns', createIndexPatternsStub());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { getQueryParameterActions } from '../actions';

describe('context app', function () {
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(() => pluginInstance.initializeServices(true));
beforeEach(() => pluginInstance.initializeServices());
beforeEach(ngMock.module('app/discover'));

describe('action setPredecessorCount', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { getQueryParameterActions } from '../actions';

describe('context app', function () {
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(() => pluginInstance.initializeServices(true));
beforeEach(() => pluginInstance.initializeServices());
beforeEach(ngMock.module('app/discover'));

describe('action setQueryParameters', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { getQueryParameterActions } from '../actions';

describe('context app', function () {
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(() => pluginInstance.initializeServices(true));
beforeEach(() => pluginInstance.initializeServices());
beforeEach(ngMock.module('app/discover'));

describe('action setSuccessorCount', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Doc Table', function () {

let fakeRowVals;
let stubFieldFormatConverter;
beforeEach(() => pluginInstance.initializeServices(true));
beforeEach(() => pluginInstance.initializeServices());
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(ngMock.module('app/discover'));
beforeEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ import {
IUiSettingsClient,
} from 'kibana/public';
import * as docViewsRegistry from 'ui/registry/doc_views';
import chromeLegacy from 'ui/chrome';
import { IPrivate } from 'ui/private';
import { FilterManager, TimefilterContract, IndexPatternsContract } from 'src/plugins/data/public';
// @ts-ignore
import { createSavedSearchesService } from '../saved_searches/saved_searches';
// @ts-ignore
import { createSavedSearchFactory } from '../saved_searches/_saved_search';
import { DiscoverStartPlugins } from '../plugin';
import { DataStart } from '../../../../data/public';
import { EuiUtilsStart } from '../../../../../../plugins/eui_utils/public';
import { SavedSearch } from '../types';
import { SharePluginStart } from '../../../../../../plugins/share/public';
Expand All @@ -42,6 +40,7 @@ export interface DiscoverServices {
capabilities: Capabilities;
chrome: ChromeStart;
core: CoreStart;
data: DataStart;
docLinks: DocLinksStart;
docViewsRegistry: docViewsRegistry.DocViewsRegistry;
eui_utils: EuiUtilsStart;
Expand All @@ -52,35 +51,19 @@ export interface DiscoverServices {
share: SharePluginStart;
timefilter: TimefilterContract;
toastNotifications: ToastsStart;
// legacy
getSavedSearchById: (id: string) => Promise<SavedSearch>;
getSavedSearchUrlById: (id: string) => Promise<string>;
uiSettings: IUiSettingsClient;
}

export async function buildGlobalAngularServices() {
const injector = await chromeLegacy.dangerouslyGetActiveInjector();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

const Private = injector.get<IPrivate>('Private');
const kbnUrl = injector.get<IPrivate>('kbnUrl');
const SavedSearchFactory = createSavedSearchFactory(Private);
const service = createSavedSearchesService(Private, SavedSearchFactory, kbnUrl, chromeLegacy);
return {
getSavedSearchById: async (id: string) => service.get(id),
getSavedSearchUrlById: async (id: string) => service.urlFor(id),
export async function buildServices(core: CoreStart, plugins: DiscoverStartPlugins) {
const services = {
savedObjectsClient: core.savedObjects.client,
indexPatterns: plugins.data.indexPatterns,
chrome: core.chrome,
overlays: core.overlays,
};
}

export async function buildServices(core: CoreStart, plugins: DiscoverStartPlugins, test: false) {
const globalAngularServices = !test
? await buildGlobalAngularServices()
: {
getSavedSearchById: async (id: string) => void id,
getSavedSearchUrlById: async (id: string) => void id,
State: null,
};

const savedObjectService = createSavedSearchesService(services);
return {
...globalAngularServices,
addBasePath: core.http.basePath.prepend,
capabilities: core.application.capabilities,
chrome: core.chrome,
Expand All @@ -90,6 +73,8 @@ export async function buildServices(core: CoreStart, plugins: DiscoverStartPlugi
docViewsRegistry,
eui_utils: plugins.eui_utils,
filterManager: plugins.data.query.filterManager,
getSavedSearchById: async (id: string) => savedObjectService.get(id),
getSavedSearchUrlById: async (id: string) => savedObjectService.urlFor(id),
indexPatterns: plugins.data.indexPatterns,
inspector: plugins.inspector,
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/kibana/public/discover/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ export class DiscoverPlugin implements Plugin<DiscoverSetup, DiscoverStart> {
this.innerAngularInitialized = true;
};

this.initializeServices = async (test = false) => {
this.initializeServices = async () => {
if (this.servicesInitialized) {
return;
}
const services = await buildServices(core, plugins, test);
const services = await buildServices(core, plugins);
setServices(services);
this.servicesInitialized = true;
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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 { SavedObjectKibanaServices } from 'ui/saved_objects/types';
import { createSavedObjectClass } from 'ui/saved_objects/saved_object';

export function createSavedSearchClass(services: SavedObjectKibanaServices) {
const SavedObjectClass = createSavedObjectClass(services);

class SavedSearch extends SavedObjectClass {
public static type: string = 'search';
public static mapping = {
title: 'text',
description: 'text',
hits: 'integer',
columns: 'keyword',
sort: 'keyword',
version: 'integer',
};
// Order these fields to the top, the rest are alphabetical
public static fieldOrder = ['title', 'description'];
public static searchSource = true;

public id: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those can be removed now because they are already defined in the base type

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adapted this change, since it makes sense, but had to revert, because for some reason inheritance doesn't work in this case (Functional tests were failing). could be because we don't inherit directly but generate the Class to inherit from. A pattern we should and will change.

public showInRecentlyAccessed: boolean;

constructor(id: string) {
super({
id,
type: 'search',
mapping: {
title: 'text',
description: 'text',
hits: 'integer',
columns: 'keyword',
sort: 'keyword',
version: 'integer',
},
searchSource: true,
defaults: {
title: '',
description: '',
columns: [],
hits: 0,
sort: [],
version: 1,
},
});
this.showInRecentlyAccessed = true;
this.id = id;
this.getFullPath = () => `/app/kibana#/discover/${String(id)}`;
}
}

return SavedSearch;
}
Loading