Skip to content

Commit

Permalink
Revert "Adds cloud links to user popover (#66825)" (#82802)
Browse files Browse the repository at this point in the history
This reverts commit 8cdf566.
  • Loading branch information
cqliu1 authored Nov 6, 2020
1 parent d620046 commit e378555
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 292 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/cloud/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "8.0.0",
"kibanaVersion": "kibana",
"configPath": ["xpack", "cloud"],
"optionalPlugins": ["usageCollection", "home", "security"],
"optionalPlugins": ["usageCollection", "home"],
"server": true,
"ui": true
}
2 changes: 1 addition & 1 deletion x-pack/plugins/cloud/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { PluginInitializerContext } from '../../../../src/core/public';
import { CloudPlugin } from './plugin';

export { CloudSetup, CloudConfigType } from './plugin';
export { CloudSetup } from './plugin';
export function plugin(initializerContext: PluginInitializerContext) {
return new CloudPlugin(initializerContext);
}
18 changes: 0 additions & 18 deletions x-pack/plugins/cloud/public/mocks.ts

This file was deleted.

28 changes: 6 additions & 22 deletions x-pack/plugins/cloud/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,52 @@

import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'src/core/public';
import { i18n } from '@kbn/i18n';
import { SecurityPluginStart } from '../../security/public';
import { getIsCloudEnabled } from '../common/is_cloud_enabled';
import { ELASTIC_SUPPORT_LINK } from '../common/constants';
import { HomePublicPluginSetup } from '../../../../src/plugins/home/public';
import { createUserMenuLinks } from './user_menu_links';

export interface CloudConfigType {
interface CloudConfigType {
id?: string;
resetPasswordUrl?: string;
deploymentUrl?: string;
accountUrl?: string;
}

interface CloudSetupDependencies {
home?: HomePublicPluginSetup;
}

interface CloudStartDependencies {
security?: SecurityPluginStart;
}

export interface CloudSetup {
cloudId?: string;
cloudDeploymentUrl?: string;
isCloudEnabled: boolean;
resetPasswordUrl?: string;
accountUrl?: string;
}

export class CloudPlugin implements Plugin<CloudSetup> {
private config!: CloudConfigType;
private isCloudEnabled: boolean;

constructor(private readonly initializerContext: PluginInitializerContext) {
this.config = this.initializerContext.config.get<CloudConfigType>();
this.isCloudEnabled = false;
}

public async setup(core: CoreSetup, { home }: CloudSetupDependencies) {
const { id, resetPasswordUrl, deploymentUrl } = this.config;
this.isCloudEnabled = getIsCloudEnabled(id);
const isCloudEnabled = getIsCloudEnabled(id);

if (home) {
home.environment.update({ cloud: this.isCloudEnabled });
if (this.isCloudEnabled) {
home.environment.update({ cloud: isCloudEnabled });
if (isCloudEnabled) {
home.tutorials.setVariable('cloud', { id, resetPasswordUrl });
}
}

return {
cloudId: id,
cloudDeploymentUrl: deploymentUrl,
isCloudEnabled: this.isCloudEnabled,
isCloudEnabled,
};
}

public start(coreStart: CoreStart, { security }: CloudStartDependencies) {
public start(coreStart: CoreStart) {
const { deploymentUrl } = this.config;
coreStart.chrome.setHelpSupportUrl(ELASTIC_SUPPORT_LINK);
if (deploymentUrl) {
Expand All @@ -74,10 +63,5 @@ export class CloudPlugin implements Plugin<CloudSetup> {
href: deploymentUrl,
});
}

if (security && this.isCloudEnabled) {
const userMenuLinks = createUserMenuLinks(this.config);
security.navControlService.addUserMenuLinks(userMenuLinks);
}
}
}
38 changes: 0 additions & 38 deletions x-pack/plugins/cloud/public/user_menu_links.ts

This file was deleted.

2 changes: 0 additions & 2 deletions x-pack/plugins/cloud/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const configSchema = schema.object({
apm: schema.maybe(apmConfigSchema),
resetPasswordUrl: schema.maybe(schema.string()),
deploymentUrl: schema.maybe(schema.string()),
accountUrl: schema.maybe(schema.string()),
});

export type CloudConfigType = TypeOf<typeof configSchema>;
Expand All @@ -33,7 +32,6 @@ export const config: PluginConfigDescriptor<CloudConfigType> = {
id: true,
resetPasswordUrl: true,
deploymentUrl: true,
accountUrl: true,
},
schema: configSchema,
};
1 change: 0 additions & 1 deletion x-pack/plugins/security/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
export { SecurityPluginSetup, SecurityPluginStart };
export { AuthenticatedUser } from '../common/model';
export { SecurityLicense, SecurityLicenseFeatures } from '../common/licensing';
export { UserMenuLink } from '../public/nav_control';

export const plugin: PluginInitializer<
SecurityPluginSetup,
Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/security/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { authenticationMock } from './authentication/index.mock';
import { createSessionTimeoutMock } from './session/session_timeout.mock';
import { licenseMock } from '../common/licensing/index.mock';
import { navControlServiceMock } from './nav_control/index.mock';

function createSetupMock() {
return {
Expand All @@ -16,13 +15,7 @@ function createSetupMock() {
license: licenseMock.create(),
};
}
function createStartMock() {
return {
navControlService: navControlServiceMock.createStart(),
};
}

export const securityMock = {
createSetup: createSetupMock,
createStart: createStartMock,
};
14 changes: 0 additions & 14 deletions x-pack/plugins/security/public/nav_control/index.mock.ts

This file was deleted.

3 changes: 1 addition & 2 deletions x-pack/plugins/security/public/nav_control/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { SecurityNavControlService, SecurityNavControlServiceStart } from './nav_control_service';
export { UserMenuLink } from './nav_control_component';
export { SecurityNavControlService } from './nav_control_service';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import React from 'react';
import { BehaviorSubject } from 'rxjs';
import { shallowWithIntl, nextTick, mountWithIntl } from 'test_utils/enzyme_helpers';
import { SecurityNavControl } from './nav_control_component';
import { AuthenticatedUser } from '../../common/model';
Expand All @@ -18,7 +17,6 @@ describe('SecurityNavControl', () => {
user: new Promise(() => {}) as Promise<AuthenticatedUser>,
editProfileUrl: '',
logoutUrl: '',
userMenuLinks$: new BehaviorSubject([]),
};

const wrapper = shallowWithIntl(<SecurityNavControl {...props} />);
Expand All @@ -44,7 +42,6 @@ describe('SecurityNavControl', () => {
user: Promise.resolve({ full_name: 'foo' }) as Promise<AuthenticatedUser>,
editProfileUrl: '',
logoutUrl: '',
userMenuLinks$: new BehaviorSubject([]),
};

const wrapper = shallowWithIntl(<SecurityNavControl {...props} />);
Expand Down Expand Up @@ -73,7 +70,6 @@ describe('SecurityNavControl', () => {
user: Promise.resolve({ full_name: 'foo' }) as Promise<AuthenticatedUser>,
editProfileUrl: '',
logoutUrl: '',
userMenuLinks$: new BehaviorSubject([]),
};

const wrapper = mountWithIntl(<SecurityNavControl {...props} />);
Expand All @@ -95,7 +91,6 @@ describe('SecurityNavControl', () => {
user: Promise.resolve({ full_name: 'foo' }) as Promise<AuthenticatedUser>,
editProfileUrl: '',
logoutUrl: '',
userMenuLinks$: new BehaviorSubject([]),
};

const wrapper = mountWithIntl(<SecurityNavControl {...props} />);
Expand All @@ -112,37 +107,4 @@ describe('SecurityNavControl', () => {
expect(findTestSubject(wrapper, 'profileLink')).toHaveLength(1);
expect(findTestSubject(wrapper, 'logoutLink')).toHaveLength(1);
});

it('renders a popover with additional user menu links registered by other plugins', async () => {
const props = {
user: Promise.resolve({ full_name: 'foo' }) as Promise<AuthenticatedUser>,
editProfileUrl: '',
logoutUrl: '',
userMenuLinks$: new BehaviorSubject([
{ label: 'link1', href: 'path-to-link-1', iconType: 'empty', order: 1 },
{ label: 'link2', href: 'path-to-link-2', iconType: 'empty', order: 2 },
{ label: 'link3', href: 'path-to-link-3', iconType: 'empty', order: 3 },
]),
};

const wrapper = mountWithIntl(<SecurityNavControl {...props} />);
await nextTick();
wrapper.update();

expect(findTestSubject(wrapper, 'userMenu')).toHaveLength(0);
expect(findTestSubject(wrapper, 'profileLink')).toHaveLength(0);
expect(findTestSubject(wrapper, 'userMenuLink__link1')).toHaveLength(0);
expect(findTestSubject(wrapper, 'userMenuLink__link2')).toHaveLength(0);
expect(findTestSubject(wrapper, 'userMenuLink__link3')).toHaveLength(0);
expect(findTestSubject(wrapper, 'logoutLink')).toHaveLength(0);

wrapper.find(EuiHeaderSectionItemButton).simulate('click');

expect(findTestSubject(wrapper, 'userMenu')).toHaveLength(1);
expect(findTestSubject(wrapper, 'profileLink')).toHaveLength(1);
expect(findTestSubject(wrapper, 'userMenuLink__link1')).toHaveLength(1);
expect(findTestSubject(wrapper, 'userMenuLink__link2')).toHaveLength(1);
expect(findTestSubject(wrapper, 'userMenuLink__link3')).toHaveLength(1);
expect(findTestSubject(wrapper, 'logoutLink')).toHaveLength(1);
});
});
Loading

0 comments on commit e378555

Please sign in to comment.