Skip to content

Commit

Permalink
slight adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
eokoneyo committed Feb 18, 2025
1 parent c6a9183 commit d4162c9
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export const getShareAppMenuItem = ({
title: i18n.translate('discover.share.shareModal.title', {
defaultMessage: 'Share this Discover session',
}),
config: {
embed: {
showPublicUrlSwitch,
},
},
},
sharingData: {
isTextBased: isEsqlMode,
Expand All @@ -123,7 +128,6 @@ export const getShareAppMenuItem = ({
}),
},
isDirty: !savedSearch.id || stateContainer.appState.hasChanged(),
showPublicUrlSwitch,
onClose: () => {
anchorElement?.focus();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ import { ThemeServiceSetup } from '@kbn/core-theme-browser';
import { I18nStart } from '@kbn/core/public';
import React, { type PropsWithChildren, createContext, useContext } from 'react';

import { AnonymousAccessServiceContract } from '../../../common';
import type { ShareConfigs, BrowserUrlService, ShareContext, ShareTypes } from '../../types';

export type { ShareMenuItemV2 } from '../../types';
import type { ShareConfigs, ShareContext, ShareTypes } from '../../types';

export interface IShareContext extends ShareContext {
allowEmbed: boolean;
allowShortUrl: boolean;
shareMenuItems: ShareConfigs[];
anonymousAccess?: AnonymousAccessServiceContract;
urlService: BrowserUrlService;
theme: ThemeServiceSetup;
i18n: I18nStart;
publicAPIEnabled?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type EmbedProps = Pick<
| 'shareableUrlLocatorParams'
| 'shareableUrlForSavedObject'
| 'shareableUrl'
| 'embedUrlParamExtensions'
| 'objectType'
| 'isDirty'
| 'allowShortUrl'
Expand All @@ -52,7 +51,6 @@ interface UrlParams {
}

export const EmbedContent = ({
embedUrlParamExtensions: urlParamExtensions,
shareableUrlForSavedObject,
shareableUrl,
shareableUrlLocatorParams,
Expand All @@ -74,7 +72,11 @@ export const EmbedContent = ({
const [showPublicUrlSwitch, setShowPublicUrlSwitch] = useState(false);
const copiedTextToolTipCleanupIdRef = useRef<ReturnType<typeof setTimeout>>();

const { draftModeCallOut: DraftModeCallout, computeAnonymousCapabilities } = objectConfig;
const {
draftModeCallOut: DraftModeCallout,
computeAnonymousCapabilities,
embedUrlParamExtensions: urlParamExtensions,
} = objectConfig;

useEffect(() => {
if (computeAnonymousCapabilities && anonymousAccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,25 @@ type IEmbedTab = IModalTabDeclaration<{ url: string; isNotSaved: boolean }>;

const EmbedTabContent: NonNullable<IEmbedTab['content']> = ({ state, dispatch }) => {
const {
embedUrlParamExtensions,
shareableUrlForSavedObject,
shareableUrl,
objectType,
objectTypeMeta,
isDirty,
allowShortUrl,
anonymousAccess,
shareableUrlLocatorParams,
shareMenuItems,
} = useShareTabsContext('embed');

return (
<EmbedContent
{...{
embedUrlParamExtensions,
shareableUrlForSavedObject,
shareableUrl,
objectType,
objectConfig: objectTypeMeta?.config?.embed,
isDirty,
anonymousAccess,
anonymousAccess: shareMenuItems.config.anonymousAccess,
allowShortUrl,
shortUrlService: shareMenuItems.config.shortUrlService,
shareableUrlLocatorParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export class ShareMenuManager {
this.shareRegistry = shareRegistry;

return {
showShareDialog: this.showShareDialog.bind(this),

/**
* Collects share menu items from registered providers and mounts the share context menu under
* the given `anchorElement`. If the context menu is already opened, a call to this method closes it.
Expand All @@ -51,7 +49,7 @@ export class ShareMenuManager {

this.toggleShareContextMenu({
...options,
allowEmbed: false, // disableEmbed ? false : options.allowEmbed,
allowEmbed: disableEmbed ? false : options.allowEmbed,
onClose,
menuItems,
publicAPIEnabled: !disableEmbed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ export class ShareRegistry implements ShareRegistryApi {
private registerEmbedShareAction(): void {
this.registerShareIntentAction(this.globalMarker, {
shareType: 'embed',
config: ({ urlService }) => ({
shortUrlService: urlService?.shortUrls.get(null)!,
config: ({ urlService, anonymousAccessServiceProvider }) => ({
anonymousAccess: anonymousAccessServiceProvider!(),
shortUrlService: urlService.shortUrls.get(null),
}),
});
}
Expand All @@ -86,6 +87,10 @@ export class ShareRegistry implements ShareRegistryApi {
*/
register(value: ShareMenuProviderLegacy) {
// implement backwards compatibility for the share plugin
this.registerShareIntentAction(this.globalMarker, {
shareType: 'integration',
config: value.getShareMenuItemsLegacy,
});
}

registerShareIntegration<I extends ShareIntegration>(
Expand Down
39 changes: 0 additions & 39 deletions src/platform/plugins/shared/share/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ type LinkShareUIConfig = ShareActionUserInputBase<{
}>;

type EmbedShareUIConfig = ShareActionUserInputBase<{
allowEmbed: boolean;
embedUrlParamExtensions?: UrlParamExtension[];
computeAnonymousCapabilities?: (anonymousUserCapabilities: Capabilities) => boolean;
/**
Expand Down Expand Up @@ -249,14 +248,6 @@ export interface ShareContextMenuPanelItem
sortOrder?: number;
}

// we don't need this
// export type SupportedExportTypes =
// | 'pngV2'
// | 'printablePdfV2'
// | 'csv_v2'
// | 'csv_searchsource'
// | 'lens_csv';

/**
* @public
* Definition of a menu item rendered in the share menu. In the redesign, the
Expand All @@ -277,36 +268,6 @@ export interface ScreenshotExportOpts {
intl: InjectedIntl;
}

// export interface ShareMenuItemV2 extends ShareMenuItemBase {
// // extended props to support share modal
// label: 'PDF' | 'CSV' | 'PNG';
// // reportType?: SupportedExportTypes;
// requiresSavedState?: boolean;
// helpText?: ReactElement;
// copyURLButton?: { id: string; dataTestSubj: string; label: string };
// generateExportButton?: ReactElement;
// /**
// * Function to trigger an export
// */
// generateExport: (args: ScreenshotExportOpts) => Promise<unknown>;
// /**
// * Function to generate a URL to be used for automating export
// * Not applicable for exports that do not call a remote API (i.e Lens CSV export)
// */
// generateExportUrl?: (args: ScreenshotExportOpts) => string | undefined;
// theme?: ThemeServiceSetup;
// renderLayoutOptionSwitch?: boolean;
// layoutOption?: 'print';
// generateCopyUrl?: URL;
// renderCopyURLButton?: boolean;
// warnings?: Array<{ title: string; message: string }>;
// }

// export interface ShareMenuProviderV2 {
// readonly id: string;
// getShareMenuItems: (context: ShareContext) => ShareMenuItemV2[];
// }

export interface ShareMenuProviderLegacy {
readonly id: string;
getShareMenuItemsLegacy: (context: ShareContext) => ShareMenuItemLegacy[];
Expand Down
32 changes: 6 additions & 26 deletions src/plugins/share/public/services/share_menu_manager.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
Expand All @@ -16,21 +17,13 @@ import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { ShareContextMenu } from '../components/share_context_menu';
import { ShareMenuItem, ShowShareMenuOptions } from '../types';
import { ShareMenuRegistryStart } from './share_menu_registry';
import { AnonymousAccessServiceContract } from '../../common/anonymous_access';
import type { BrowserUrlService } from '../types';

export class ShareMenuManager {
private isOpen = false;

private container = document.createElement('div');

start(
core: CoreStart,
urlService: BrowserUrlService,
shareRegistry: ShareMenuRegistryStart,
disableEmbed: boolean,
anonymousAccessServiceProvider?: () => AnonymousAccessServiceContract
) {
start(core: CoreStart, shareRegistry: ShareMenuRegistryStart, disableEmbed: boolean) {
return {
/**
* Collects share menu items from registered providers and mounts the share context menu under
Expand All @@ -46,14 +39,11 @@ export class ShareMenuManager {

console.log('menu items:: %o \n', menuItems);

const anonymousAccess = anonymousAccessServiceProvider?.();
this.toggleShareContextMenu({
...options,
allowEmbed: disableEmbed ? false : options.allowEmbed,
onClose,
menuItems,
urlService,
anonymousAccess,
theme: core.theme,
});
},
Expand All @@ -76,19 +66,13 @@ export class ShareMenuManager {
shareableUrl,
shareableUrlForSavedObject,
shareableUrlLocatorParams,
embedUrlParamExtensions,
theme,
showPublicUrlSwitch,
urlService,
anonymousAccess,
snapshotShareWarning,
onClose,
objectTypeTitle,
disabledShareUrl,
}: ShowShareMenuOptions & {
menuItems: ShareMenuItem[];
urlService: BrowserUrlService;
anonymousAccess: AnonymousAccessServiceContract | undefined;
theme: ThemeServiceStart;
onClose: () => void;
}) {
Expand Down Expand Up @@ -125,10 +109,6 @@ export class ShareMenuManager {
shareableUrlForSavedObject={shareableUrlForSavedObject}
shareableUrlLocatorParams={shareableUrlLocatorParams}
onClose={onClose}
embedUrlParamExtensions={embedUrlParamExtensions}
anonymousAccess={anonymousAccess}
showPublicUrlSwitch={showPublicUrlSwitch}
urlService={urlService}
snapshotShareWarning={snapshotShareWarning}
disabledShareUrl={disabledShareUrl}
/>
Expand Down

0 comments on commit d4162c9

Please sign in to comment.