Skip to content
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

Spaces -> Client to NP #54298

Merged
merged 31 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d2883da
moves
legrego Jan 8, 2020
8c4516d
updates to support spaces client in NP
legrego Jan 8, 2020
cce8d1f
fixing MLs import
legrego Jan 8, 2020
890b685
update karma mock
legrego Jan 8, 2020
e0ac89c
Merge branch 'master' of github.com:elastic/kibana into spaces/np-client
legrego Jan 9, 2020
6c8c55d
remove unnecessary setup license
legrego Jan 10, 2020
33f04bd
Merge branch 'master' into spaces/np-client
elasticmachine Jan 10, 2020
f650303
Merge branch 'master' of github.com:elastic/kibana into spaces/np-client
legrego Jan 30, 2020
25fcc60
fix merge from master
legrego Jan 30, 2020
0a4198f
moving management app registration to NP
legrego Jan 30, 2020
295773c
move space selector app to NP
legrego Jan 30, 2020
1df82cf
Merge branch 'spaces/np-client' of github.com:legrego/kibana into spa…
legrego Jan 30, 2020
5bdf2b9
remove unused xpackMain legacy dependency
legrego Jan 30, 2020
925ceed
hide spaces management if not authorized
legrego Jan 30, 2020
602b11e
Merge branch 'master' of github.com:elastic/kibana into spaces/np-client
legrego Jan 31, 2020
03a122f
additional testing
legrego Jan 31, 2020
95d390e
additional cleanup
legrego Jan 31, 2020
73cc266
additional testing
legrego Feb 3, 2020
7350cfa
Merge branch 'master' of github.com:elastic/kibana into spaces/np-client
legrego Feb 4, 2020
dca42cc
use NP advancedSettings plugin
legrego Feb 4, 2020
35b81ea
Apply suggestions from code review
legrego Feb 5, 2020
e038ff1
Merge branch 'spaces/np-client' of github.com:legrego/kibana into spa…
legrego Feb 5, 2020
4399b59
start addressing PR feedback
legrego Feb 5, 2020
d6ffb18
Merge branch 'master' of github.com:elastic/kibana into spaces/np-client
legrego Feb 5, 2020
d45e63d
reverting logic to determine serverBasePath
legrego Feb 6, 2020
3f24902
removing spaces mock
legrego Feb 6, 2020
9ebe560
mantain BWC with old management links
legrego Feb 6, 2020
6fac7e4
Merge branch 'master' of github.com:elastic/kibana into spaces/np-client
legrego Feb 6, 2020
2a01095
add types to management mock
legrego Feb 6, 2020
25008da
address remaining PR feedback
legrego Feb 7, 2020
cdf2c10
Merge branch 'master' into spaces/np-client
elasticmachine Feb 10, 2020
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
@@ -0,0 +1,22 @@
/*
* 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.
*/

export const PAGE_TITLE_COMPONENT: string;
legrego marked this conversation as resolved.
Show resolved Hide resolved
export const PAGE_SUBTITLE_COMPONENT: string;
export const PAGE_FOOTER_COMPONENT: string;
3 changes: 3 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ export const npSetup = {
}),
},
},
spaces: {
Copy link
Member

Choose a reason for hiding this comment

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

note: can you please explain why we need this? I seems spaces is the only x-pack plugin mentioned here and I'm wondering if we should have something similar in x-pack.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was a while ago..I had Karma test failures, so I followed the instructions in the migration guide to "fix" it. I have a lot less in the LP plugin now though, so maybe I'm already past the issue. I'll remove and see what happens. If it fails, I should be able to introduce a mock within the spaces plugin itself.

kibana/src/core/MIGRATION.md

Lines 1564 to 1570 in 5d6dbf0

#### What about karma tests?
While our plan is to only provide first-class mocks for Jest tests, there are many legacy karma tests that cannot be quickly or easily converted to Jest -- particularly those which are still relying on mocking Angular services via `ngMock`.
For these tests, we are maintaining a separate set of mocks. Files with a `.karma_mock.{js|ts|tsx}` extension will be loaded _globally_ before karma tests are run.
It is important to note that this behavior is different from `jest.mock('ui/new_platform')`, which only mocks tests on an individual basis. If you encounter any failures in karma tests as a result of new platform migration efforts, you may need to add a `.karma_mock.js` file for the affected services, or add to the existing karma mock we are maintaining in `ui/new_platform`.

Copy link
Member Author

@legrego legrego Feb 6, 2020

Choose a reason for hiding this comment

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

Update: the LP spaces plugin runs its legacy.ts as part of a hack, so that it runs for all LP plugins. The goal of legacy.ts is to call the NP registerLegacyAPI, so that the plugin can finish its initialization. In the case of these Karma tests, we need the npSetup static import provided by new_platform.karma.mock to have the spaces plugin registered, so that legacy.ts can call registerLegacyAPI.

So an alternative to placing this here, is to place a guard within legacy.ts, to only call registerLegacyAPI if the spaces plugin is actually defined. What do you think about that approach?

Copy link
Member

Choose a reason for hiding this comment

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

So an alternative to placing this here, is to place a guard within legacy.ts, to only call registerLegacyAPI if the spaces plugin is actually defined. What do you think about that approach?

On the surface it sounds like a better workaround to me, do you have any concerns regarding it?

Copy link
Member

Choose a reason for hiding this comment

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

And thanks for the explanation!

Copy link
Member Author

Choose a reason for hiding this comment

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

On the surface it sounds like a better workaround to me, do you have any concerns regarding it?

None at all! Resolved in 3f24902

registerLegacyAPI: sinon.fake(),
},
},
};

Expand Down
36 changes: 36 additions & 0 deletions src/plugins/home/public/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { featureCatalogueRegistryMock } from '../services/feature_catalogue/feature_catalogue_registry.mock';
import { environmentServiceMock } from '../services/environment/environment.mock';

const createSetupContract = () => ({
featureCatalogue: featureCatalogueRegistryMock.createSetup(),
environment: environmentServiceMock.createSetup(),
});

const createStartContract = () => ({
featureCatalogue: featureCatalogueRegistryMock.createStart(),
environment: environmentServiceMock.createStart(),
});

export const homePluginMock = {
createSetupContract,
createStartContract,
};
10 changes: 10 additions & 0 deletions src/plugins/management/public/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@
* under the License.
*/

const createSetupContract = () => ({
Copy link
Member

Choose a reason for hiding this comment

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

optional nit: can we use (): jest.Mocked<ManagementSetup> => ({ to make sure these are up to date when interface changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

This causes the following to fail:

const managementSetup = managementSetupMock.createSetupContract();
managementSetup.sections.getSection.mockReturnValue(foo);

Because managementSetup.sections is of type SectionsServiceSetup, rather than jest.Mocked<SectionsServiceSetup>.

Do you know of a way to tell TS what we really want to do here? I couldn't get it to work, but didn't spend more than 15 minutes on it.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I see. IIRC Platform team used something like DeeplyMockedKeys instead of jest.Mocked for cases like this, maybe that would work for us too... But feel free to ignore if it takes too much time to fix Management's mocks and types.

Copy link
Member Author

Choose a reason for hiding this comment

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

That worked perfectly, thanks for the tip!

sections: {
register: jest.fn(),
getSection: jest.fn(),
getSectionsEnabled: jest.fn(),
getAllSections: jest.fn(),
},
});

const createStartContract = () => ({
legacy: {},
});

export const managementPluginMock = {
createSetupContract,
createStartContract,
};
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/server/lib/spaces_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import { Request } from 'hapi';
import { Space } from '../../../../../plugins/spaces/server';
import { LegacySpacesPlugin } from '../../../spaces';
import { Space } from '../../../spaces/common/model/space';

interface GetActiveSpaceResponse {
valid: boolean;
Expand Down
28 changes: 0 additions & 28 deletions x-pack/legacy/plugins/spaces/common/constants.ts

This file was deleted.

34 changes: 0 additions & 34 deletions x-pack/legacy/plugins/spaces/common/is_reserved_space.test.ts

This file was deleted.

18 changes: 0 additions & 18 deletions x-pack/legacy/plugins/spaces/common/is_reserved_space.ts

This file was deleted.

16 changes: 0 additions & 16 deletions x-pack/legacy/plugins/spaces/common/model/space.ts

This file was deleted.

7 changes: 0 additions & 7 deletions x-pack/legacy/plugins/spaces/common/model/types.ts

This file was deleted.

14 changes: 2 additions & 12 deletions x-pack/legacy/plugins/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { wrapError } from './server/lib/errors';
import { migrateToKibana660 } from './server/lib/migrations';
// @ts-ignore
import { watchStatusAndLicenseToInitialize } from '../../server/lib/watch_status_and_license_to_initialize';
import { initSpaceSelectorView, initEnterSpaceView } from './server/routes/views';
import { initEnterSpaceView } from './server/routes/views';

export interface LegacySpacesPlugin {
getSpaceId: (request: Legacy.Request) => ReturnType<SpacesServiceSetup['getSpaceId']>;
Expand Down Expand Up @@ -50,15 +50,7 @@ export const spaces = (kibana: Record<string, any>) =>
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
managementSections: [],
apps: [
{
id: 'space_selector',
title: 'Spaces',
main: 'plugins/spaces/space_selector',
url: 'space_selector',
hidden: true,
},
],
apps: [],
hacks: ['plugins/spaces/legacy'],
mappings,
migrations: {
Expand Down Expand Up @@ -131,11 +123,9 @@ export const spaces = (kibana: Record<string, any>) =>
create: (pluginId: string) =>
new AuditLogger(server, pluginId, server.config(), server.plugins.xpack_main.info),
},
xpackMain: server.plugins.xpack_main,
});

initEnterSpaceView(server);
initSpaceSelectorView(server);

watchStatusAndLicenseToInitialize(server.plugins.xpack_main, this, async () => {
await createDefaultSpace();
Expand Down
18 changes: 0 additions & 18 deletions x-pack/legacy/plugins/spaces/public/__mocks__/xpack_info.ts

This file was deleted.

14 changes: 1 addition & 13 deletions x-pack/legacy/plugins/spaces/public/index.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Import the EUI global scope so we can use EUI constants
@import 'src/legacy/ui/public/styles/_styling_constants';

/* Spaces plugin styles */

// Prefix all styles with "spc" to avoid conflicts.
// Examples
// spcChart
// spcChart__legend
// spcChart__legend--small
// spcChart__legend-isLoading

@import './management/index';
@import './nav_control/index';
@import './space_selector/index';
@import './copy_saved_objects_to_space/index';
@import '../../../../plugins/spaces/public/index';
25 changes: 8 additions & 17 deletions x-pack/legacy/plugins/spaces/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SavedObjectsManagementAction } from 'src/legacy/core_plugins/management/public';
import { registerSettingsComponent } from 'ui/management';
import { npSetup, npStart } from 'ui/new_platform';
import { npSetup } from 'ui/new_platform';
import { SpacesPluginSetup } from '../../../../plugins/spaces/public';
import { setup as managementSetup } from '../../../../../src/legacy/core_plugins/management/public/legacy';
import { plugin } from '.';
import { SpacesPlugin, PluginsSetup, PluginsStart } from './plugin';
import './management/legacy_page_routes';

const spacesPlugin: SpacesPlugin = plugin();

const pluginsSetup: PluginsSetup = {
home: npSetup.plugins.home,
management: managementSetup,
__managementLegacyCompat: {
registerSettingsComponent,
const legacyAPI = {
registerSavedObjectsManagementAction: (action: SavedObjectsManagementAction) => {
managementSetup.savedObjects.registry.register(action);
},
registerSettingsComponent,
};

const pluginsStart: PluginsStart = {
management: npStart.plugins.management,
};

export const setup = spacesPlugin.setup(npSetup.core, pluginsSetup);
export const start = spacesPlugin.start(npStart.core, pluginsStart);
((npSetup.plugins as any).spaces as SpacesPluginSetup).registerLegacyAPI(legacyAPI);

This file was deleted.

This file was deleted.

Loading