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

[Lens] Share link feature #148829

Merged
merged 17 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/plugins/share/public/components/share_context_menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ test('should only render permalink panel when there are no other panels', () =>
expect(component).toMatchSnapshot();
});

test('should disable the share URL when set', () => {
const component = shallow(<ShareContextMenu {...defaultProps} disabledShareUrl />);
expect(component).toMatchSnapshot();
});

describe('shareContextMenuExtensions', () => {
const shareContextMenuItems: ShareMenuItem[] = [
{
Expand Down Expand Up @@ -69,4 +74,15 @@ describe('shareContextMenuExtensions', () => {
);
expect(component).toMatchSnapshot();
});

test('should render a custom panel title when provided', () => {
const component = shallow(
<ShareContextMenu
{...defaultProps}
objectTypeTitle="Custom object"
shareMenuItems={shareContextMenuItems}
/>
);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ShareContextMenuProps {
objectId?: string;
objectType: string;
shareableUrl?: string;
shareableUrlForSavedObject?: string;
shareMenuItems: ShareMenuItem[];
sharingData: any;
onClose: () => void;
Expand All @@ -33,6 +34,8 @@ export interface ShareContextMenuProps {
showPublicUrlSwitch?: (anonymousUserCapabilities: Capabilities) => boolean;
urlService: BrowserUrlService;
snapshotShareWarning?: string;
objectTypeTitle?: string;
disabledShareUrl?: boolean;
}

export class ShareContextMenu extends Component<ShareContextMenuProps> {
Expand Down Expand Up @@ -64,6 +67,7 @@ export class ShareContextMenu extends Component<ShareContextMenuProps> {
objectId={this.props.objectId}
objectType={this.props.objectType}
shareableUrl={this.props.shareableUrl}
shareableUrlForSavedObject={this.props.shareableUrlForSavedObject}
anonymousAccess={this.props.anonymousAccess}
showPublicUrlSwitch={this.props.showPublicUrlSwitch}
urlService={this.props.urlService}
Expand All @@ -78,6 +82,7 @@ export class ShareContextMenu extends Component<ShareContextMenuProps> {
icon: 'link',
panel: permalinkPanel.id,
sortOrder: 0,
disabled: Boolean(this.props.disabledShareUrl),
});
panels.push(permalinkPanel);

Expand All @@ -94,6 +99,7 @@ export class ShareContextMenu extends Component<ShareContextMenuProps> {
objectId={this.props.objectId}
objectType={this.props.objectType}
shareableUrl={this.props.shareableUrl}
shareableUrlForSavedObject={this.props.shareableUrlForSavedObject}
urlParamExtensions={this.props.embedUrlParamExtensions}
anonymousAccess={this.props.anonymousAccess}
showPublicUrlSwitch={this.props.showPublicUrlSwitch}
Expand Down Expand Up @@ -131,7 +137,7 @@ export class ShareContextMenu extends Component<ShareContextMenuProps> {
title: i18n.translate('share.contextMenuTitle', {
defaultMessage: 'Share this {objectType}',
values: {
objectType: this.props.objectType,
objectType: this.props.objectTypeTitle || this.props.objectType,
},
}),
items: menuItems
Expand Down
16 changes: 16 additions & 0 deletions src/plugins/share/public/components/url_panel_content.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ describe('share url panel content', () => {
expect(component).toMatchSnapshot();
});

test('should use custom savedObjectUrl if provided for saved object export', () => {
const component = shallow(
<UrlPanelContent
{...defaultProps}
objectId="id1"
allowShortUrl={false}
shareableUrlForSavedObject="socustomurl:id1#"
/>
);

act(() => {
component.find(EuiRadioGroup).prop('onChange')!(ExportUrlAsType.EXPORT_URL_AS_SAVED_OBJECT);
});
expect(component.find(EuiCopy).prop('textToCopy')).toEqual('socustomurl:id1#?_g=');
});

test('should hide short url section when allowShortUrl is false', () => {
const component = shallow(
<UrlPanelContent {...defaultProps} allowShortUrl={false} objectId="id1" />
Expand Down
13 changes: 10 additions & 3 deletions src/plugins/share/public/components/url_panel_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface UrlPanelContentProps {
objectId?: string;
objectType: string;
shareableUrl?: string;
shareableUrlForSavedObject?: string;
urlParamExtensions?: UrlParamExtension[];
anonymousAccess?: AnonymousAccessServiceContract;
showPublicUrlSwitch?: (anonymousUserCapabilities: Capabilities) => boolean;
Expand Down Expand Up @@ -242,7 +243,7 @@ export class UrlPanelContent extends Component<UrlPanelContentProps, State> {
return;
}

const url = this.getSnapshotUrl();
const url = this.getSnapshotUrl(true);

const parsedUrl = parseUrl(url);
if (!parsedUrl || !parsedUrl.hash) {
Expand All @@ -269,8 +270,14 @@ export class UrlPanelContent extends Component<UrlPanelContentProps, State> {
return this.updateUrlParams(formattedUrl);
};

private getSnapshotUrl = () => {
const url = this.props.shareableUrl || window.location.href;
private getSnapshotUrl = (forSavedObject?: boolean) => {
let url = '';
if (forSavedObject && this.props.shareableUrlForSavedObject) {
url = this.props.shareableUrlForSavedObject;
Copy link
Contributor

@majagrubic majagrubic Jan 16, 2023

Choose a reason for hiding this comment

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

nit: how about setting shareableUrlForSavedObject to default value of '', and then this whole line can be simplified to: url = this.props.shareableUrlForSavedObject? Or even better:
const url = this.props.shareableUrlForSavedObject ?? (this.props.shareableUrl) || window.location.href)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand exactly what you propose.
Given a default value of '' for shareableUrlForSavedObject, and this line changing to:

const url = this.props.shareableUrlForSavedObject ?? (this.props.shareableUrl) || window.location.href)

Then any snapshot url would depend on shareableUrlForSavedObject, which is not what I need. The shareableUrlForSavedObject should be used only when the forSavedObject flag is on, not every time a snapshot URL is asked.

Copy link
Contributor

@majagrubic majagrubic Jan 18, 2023

Choose a reason for hiding this comment

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

Ah fair, I thought forSavedObject was always set to true, because other lines were collapsed 😬

}
if (!url) {
url = this.props.shareableUrl || window.location.href;
}
return this.updateUrlParams(url);
};

Expand Down
6 changes: 6 additions & 0 deletions src/plugins/share/public/services/share_menu_manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ export class ShareMenuManager {
sharingData,
menuItems,
shareableUrl,
shareableUrlForSavedObject,
embedUrlParamExtensions,
theme,
showPublicUrlSwitch,
urlService,
anonymousAccess,
snapshotShareWarning,
onClose,
objectTypeTitle,
disabledShareUrl,
}: ShowShareMenuOptions & {
menuItems: ShareMenuItem[];
urlService: BrowserUrlService;
Expand Down Expand Up @@ -107,15 +110,18 @@ export class ShareMenuManager {
allowShortUrl={allowShortUrl}
objectId={objectId}
objectType={objectType}
objectTypeTitle={objectTypeTitle}
shareMenuItems={menuItems}
sharingData={sharingData}
shareableUrl={shareableUrl}
shareableUrlForSavedObject={shareableUrlForSavedObject}
onClose={onClose}
embedUrlParamExtensions={embedUrlParamExtensions}
anonymousAccess={anonymousAccess}
showPublicUrlSwitch={showPublicUrlSwitch}
urlService={urlService}
snapshotShareWarning={snapshotShareWarning}
disabledShareUrl={disabledShareUrl}
/>
</EuiWrappingPopover>
</KibanaThemeProvider>
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/share/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ export interface ShareContext {
* If not set it will default to `window.location.href`
*/
shareableUrl: string;
shareableUrlForSavedObject?: string;
sharingData: { [key: string]: unknown };
isDirty: boolean;
onClose: () => void;
showPublicUrlSwitch?: (anonymousUserCapabilities: Capabilities) => boolean;
disabledShareUrl?: boolean;
}

/**
Expand Down Expand Up @@ -99,4 +101,5 @@ export interface ShowShareMenuOptions extends Omit<ShareContext, 'onClose'> {
embedUrlParamExtensions?: UrlParamExtension[];
snapshotShareWarning?: string;
onClose?: () => void;
objectTypeTitle?: string;
}
8 changes: 8 additions & 0 deletions test/functional/services/common/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,14 @@ class BrowserService extends FtrService {
await this.driver.switchTo().window(tabs[tabIndex]);
}

/**
* Opens a blank new tab.
* @return {Promise<string>}
*/
public async openNewTab() {
await this.driver.switchTo().newWindow('tab');
}

/**
* Sets a value in local storage for the focused window/frame.
*
Expand Down
Loading