Skip to content

Commit

Permalink
[8.x] Fix issue with short URL not working for dashboard (#197484) (#…
Browse files Browse the repository at this point in the history
…203738)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Fix issue with short URL not working for dashboard
(#197484)](#197484)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Eyo O.
Eyo","email":"7893459+eokoneyo@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-12-11T09:38:35Z","message":"Fix
issue with short URL not working for dashboard (#197484)\n\n##
Summary\r\n\r\n\r\nThis PR Resolves
https://github.com/elastic/kibana/issues/191090\r\n\r\nIn addition, it
adds implementation to allow consumers pass in their\r\ncallout message
of choice for handling the message displayed to users on\r\nattempting
to copy a url especially that when short urls are allowed, in\r\ndraft
mode the URL copied will not point to the same configuration once\r\nthe
change has been persisted.\r\n\r\nFor lens the message that was
displayed previously when presented with\r\nthe option to copy a link
remains the same, however for dashboard a new\r\nmessage is being added.
See screenshot below;\r\n\r\n\r\n<img width=\"540\" alt=\"Screenshot
2024-10-23 at 22 58
46\"\r\nsrc=\"https://github.com/user-attachments/assets/90d584b5-d48c-4521-b75c-2c7827ddf444\">\r\n\r\n\r\n###
Checklist\r\n<!-- \r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials -->\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n<!--\r\n- [ ]
[Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n-->","sha":"4511abe03e7d4dfbe539f8707f9a42410d600df1","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:SharedUX","ui-copy","backport:prev-major"],"title":"Fix
issue with short URL not working for
dashboard","number":197484,"url":"https://github.com/elastic/kibana/pull/197484","mergeCommit":{"message":"Fix
issue with short URL not working for dashboard (#197484)\n\n##
Summary\r\n\r\n\r\nThis PR Resolves
https://github.com/elastic/kibana/issues/191090\r\n\r\nIn addition, it
adds implementation to allow consumers pass in their\r\ncallout message
of choice for handling the message displayed to users on\r\nattempting
to copy a url especially that when short urls are allowed, in\r\ndraft
mode the URL copied will not point to the same configuration once\r\nthe
change has been persisted.\r\n\r\nFor lens the message that was
displayed previously when presented with\r\nthe option to copy a link
remains the same, however for dashboard a new\r\nmessage is being added.
See screenshot below;\r\n\r\n\r\n<img width=\"540\" alt=\"Screenshot
2024-10-23 at 22 58
46\"\r\nsrc=\"https://github.com/user-attachments/assets/90d584b5-d48c-4521-b75c-2c7827ddf444\">\r\n\r\n\r\n###
Checklist\r\n<!-- \r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials -->\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n<!--\r\n- [ ]
[Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n-->","sha":"4511abe03e7d4dfbe539f8707f9a42410d600df1"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197484","number":197484,"mergeCommit":{"message":"Fix
issue with short URL not working for dashboard (#197484)\n\n##
Summary\r\n\r\n\r\nThis PR Resolves
https://github.com/elastic/kibana/issues/191090\r\n\r\nIn addition, it
adds implementation to allow consumers pass in their\r\ncallout message
of choice for handling the message displayed to users on\r\nattempting
to copy a url especially that when short urls are allowed, in\r\ndraft
mode the URL copied will not point to the same configuration once\r\nthe
change has been persisted.\r\n\r\nFor lens the message that was
displayed previously when presented with\r\nthe option to copy a link
remains the same, however for dashboard a new\r\nmessage is being added.
See screenshot below;\r\n\r\n\r\n<img width=\"540\" alt=\"Screenshot
2024-10-23 at 22 58
46\"\r\nsrc=\"https://github.com/user-attachments/assets/90d584b5-d48c-4521-b75c-2c7827ddf444\">\r\n\r\n\r\n###
Checklist\r\n<!-- \r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials -->\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n<!--\r\n- [ ]
[Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n-->","sha":"4511abe03e7d4dfbe539f8707f9a42410d600df1"}}]}]
BACKPORT-->

Co-authored-by: Eyo O. Eyo <7893459+eokoneyo@users.noreply.github.com>
  • Loading branch information
kibanamachine and eokoneyo authored Dec 11, 2024
1 parent ff1cae3 commit 55ac8cf
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ export const shareModalStrings = {
defaultMessage:
'One or more panels on this dashboard have changed. Before you generate a snapshot, save the dashboard.',
}),
getDraftSharePanelChangesWarning: () =>
i18n.translate('dashboard.snapshotShare.panelChangesWarning', {
defaultMessage:
'You are about to share a dashboard with unsaved changes, and the link may not work properly. Save the dashboard first to create a permanent link.',
}),
getEmbedSharePanelChangesWarning: () =>
i18n.translate('dashboard.embedShare.draftWarning', {
defaultMessage:
'You are about to create an embedded dashboard with unsaved changes, and the embed code may not work properly. Save the dashboard first to create a permanent embedded dashboard.',
}),
getDraftShareWarning: (shareType: 'embed' | 'link') =>
i18n.translate('dashboard.snapshotShare.draftWarning', {
defaultMessage:
'This dashboard has unsaved changes. Consider saving your dashboard before generating the {shareType}.',
values: { shareType: shareType === 'embed' ? 'embed code' : 'link' },
}),
};

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { omit } from 'lodash';
import moment from 'moment';
import React, { ReactElement, useState } from 'react';

import { EuiCheckboxGroup } from '@elastic/eui';
import { EuiCallOut, EuiCheckboxGroup } from '@elastic/eui';
import type { Capabilities } from '@kbn/core/public';
import { QueryState } from '@kbn/data-plugin/common';
import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics';
import { ViewMode } from '@kbn/embeddable-plugin/public';
import { i18n } from '@kbn/i18n';
import { getStateFromKbnUrl, setStateToKbnUrl, unhashUrl } from '@kbn/kibana-utils-plugin/public';

import { FormattedMessage } from '@kbn/i18n-react';
import { convertPanelMapToPanelsArray, DashboardPanelMap } from '../../../../common';
import { DashboardLocatorParams } from '../../../dashboard_container';
import {
Expand Down Expand Up @@ -122,7 +123,7 @@ export function ShowShareModal({
const allUnsavedPanels = (() => {
if (
Object.keys(unsavedDashboardState?.panels ?? {}).length === 0 &&
Object.keys(panelModifications ?? {}).length === 0
Object.keys(omit(panelModifications ?? {}, PANELS_CONTROL_GROUP_KEY)).length === 0
) {
// if this dashboard has no modifications or unsaved panels return early. No overrides needed.
return;
Expand Down Expand Up @@ -195,18 +196,58 @@ export function ShowShareModal({
unhashUrl(baseUrl)
);

const allowShortUrl = getDashboardCapabilities().createShortUrl;

shareService.toggleShareContextMenu({
isDirty,
anchorElement,
allowEmbed: true,
allowShortUrl: getDashboardCapabilities().createShortUrl,
allowShortUrl,
shareableUrl,
objectId: savedObjectId,
objectType: 'dashboard',
objectTypeMeta: {
title: i18n.translate('dashboard.share.shareModal.title', {
defaultMessage: 'Share this dashboard',
}),
config: {
link: {
draftModeCallOut: (
<EuiCallOut
color="warning"
data-test-subj="DashboardDraftModeCopyLinkCallOut"
title={
<FormattedMessage
id="dashboard.share.shareModal.draftModeCallout.title"
defaultMessage="Unsaved changes"
/>
}
>
{Boolean(unsavedDashboardState?.panels)
? shareModalStrings.getDraftSharePanelChangesWarning()
: shareModalStrings.getDraftShareWarning('link')}
</EuiCallOut>
),
},
embed: {
draftModeCallOut: (
<EuiCallOut
color="warning"
data-test-subj="DashboardDraftModeEmbedCallOut"
title={
<FormattedMessage
id="dashboard.share.shareModal.draftModeCallout.title"
defaultMessage="Unsaved changes"
/>
}
>
{Boolean(unsavedDashboardState?.panels)
? shareModalStrings.getEmbedSharePanelChangesWarning()
: shareModalStrings.getDraftShareWarning('embed')}
</EuiCallOut>
),
},
},
},
sharingData: {
title:
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/share/public/components/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
ShareContext,
} from '../../types';

export type { ShareMenuItemV2 } from '../../types';
export type { ShareMenuItemV2, ShareContextObjectTypeConfig } from '../../types';

export interface IShareContext extends ShareContext {
allowEmbed: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Share modal embed content tab', () => {
beforeEach(() => {
component = mountWithIntl(
<EmbedContent
isDirty={false}
objectType="dashboard"
setIsNotSaved={() => jest.fn()}
shareableUrl="/home#/"
Expand Down
14 changes: 13 additions & 1 deletion src/plugins/share/public/components/tabs/embed/embed_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import useMountedState from 'react-use/lib/useMountedState';
import { format as formatUrl, parse as parseUrl } from 'url';
import { AnonymousAccessState } from '../../../../common';

import { type IShareContext } from '../../context';
import type { IShareContext, ShareContextObjectTypeConfig } from '../../context';

type EmbedProps = Pick<
IShareContext,
Expand All @@ -32,8 +32,10 @@ type EmbedProps = Pick<
| 'shareableUrl'
| 'embedUrlParamExtensions'
| 'objectType'
| 'isDirty'
> & {
setIsNotSaved: () => void;
objectConfig?: ShareContextObjectTypeConfig;
};

interface UrlParams {
Expand All @@ -52,7 +54,9 @@ export const EmbedContent = ({
shareableUrlForSavedObject,
shareableUrl,
objectType,
objectConfig = {},
setIsNotSaved,
isDirty,
}: EmbedProps) => {
const isMounted = useMountedState();
const [urlParams, setUrlParams] = useState<UrlParams | undefined>(undefined);
Expand Down Expand Up @@ -252,12 +256,20 @@ export const EmbedContent = ({
/>
);

const { draftModeCallOut: DraftModeCallout } = objectConfig;

return (
<>
<EuiForm>
<EuiText size="s">{helpText}</EuiText>
<EuiSpacer />
{renderUrlParamExtensions()}
{isDirty && DraftModeCallout && (
<>
<EuiSpacer size="m" />
{DraftModeCallout}
</>
)}
<EuiSpacer />
</EuiForm>
<EuiFlexGroup justifyContent="flexEnd" responsive={false}>
Expand Down
12 changes: 10 additions & 2 deletions src/plugins/share/public/components/tabs/embed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ const embedTabReducer: IEmbedTab['reducer'] = (state = { url: '', isNotSaved: fa
};

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

const setIsNotSaved = useCallback(() => {
dispatch({
Expand All @@ -55,8 +61,10 @@ const EmbedTabContent: NonNullable<IEmbedTab['content']> = ({ state, dispatch })
shareableUrlForSavedObject,
shareableUrl,
objectType,
objectConfig: objectTypeMeta?.config?.embed,
isNotSaved: state?.isNotSaved,
setIsNotSaved,
isDirty,
}}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/share/public/components/tabs/link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const linkTabReducer: ILinkTab['reducer'] = (
const LinkTabContent: ILinkTab['content'] = ({ state, dispatch }) => {
const {
objectType,
objectTypeMeta,
objectId,
isDirty,
shareableUrl,
Expand Down Expand Up @@ -86,6 +87,7 @@ const LinkTabContent: ILinkTab['content'] = ({ state, dispatch }) => {
<LinkContent
{...{
objectType,
objectConfig: objectTypeMeta?.config?.link,
objectId,
isDirty,
shareableUrl,
Expand Down
23 changes: 7 additions & 16 deletions src/plugins/share/public/components/tabs/link/link_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import {
copyToClipboard,
EuiButton,
EuiCallOut,
EuiFlexGroup,
EuiFlexItem,
EuiForm,
Expand All @@ -21,7 +20,7 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import React, { useCallback, useState, useRef, useEffect } from 'react';
import type { IShareContext } from '../../context';
import type { IShareContext, ShareContextObjectTypeConfig } from '../../context';

type LinkProps = Pick<
IShareContext,
Expand All @@ -33,7 +32,7 @@ type LinkProps = Pick<
| 'delegatedShareUrlHandler'
| 'shareableUrlLocatorParams'
| 'allowShortUrl'
>;
> & { objectConfig?: ShareContextObjectTypeConfig };

interface UrlParams {
[extensionName: string]: {
Expand All @@ -44,6 +43,7 @@ interface UrlParams {
export const LinkContent = ({
isDirty,
objectType,
objectConfig = {},
shareableUrl,
urlService,
shareableUrlLocatorParams,
Expand Down Expand Up @@ -116,6 +116,8 @@ export const LinkContent = ({
setIsLoading(false);
}, [snapshotUrl, delegatedShareUrlHandler, allowShortUrl, createShortUrl]);

const { draftModeCallOut: DraftModeCallout } = objectConfig;

return (
<>
<EuiForm>
Expand All @@ -126,21 +128,10 @@ export const LinkContent = ({
values={{ objectType }}
/>
</EuiText>
{isDirty && objectType === 'lens' && (
{isDirty && DraftModeCallout && (
<>
<EuiSpacer size="m" />
<EuiCallOut
color="warning"
iconType="warning"
title={
<FormattedMessage id="share.link.warning.title" defaultMessage="Unsaved changes" />
}
>
<FormattedMessage
id="share.link.warning.lens"
defaultMessage="Copy the link to get a temporary link. Save the lens visualization to create a permanent link."
/>
</EuiCallOut>
{DraftModeCallout}
</>
)}
<EuiSpacer size="l" />
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/share/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { ComponentType, ReactElement } from 'react';
import type { ComponentType, ReactElement, ReactNode } from 'react';
import type { InjectedIntl } from '@kbn/i18n-react';
import { EuiContextMenuPanelDescriptor } from '@elastic/eui';
import { EuiContextMenuPanelItemDescriptorEntry } from '@elastic/eui/src/components/context_menu/context_menu';
Expand All @@ -21,6 +21,10 @@ export type BrowserUrlService = UrlService<
BrowserShortUrlClient
>;

export interface ShareContextObjectTypeConfig {
draftModeCallOut?: ReactNode;
}

/**
* @public
* Properties of the current object to share. Registered share
Expand All @@ -37,6 +41,7 @@ export interface ShareContext {
*/
objectTypeMeta: {
title: string;
config?: Partial<Record<'link' | 'export' | 'embed', ShareContextObjectTypeConfig>>;
};
objectId?: string;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7679,8 +7679,6 @@
"share.link.copyEmbedCodeButton": "Copier le code intégré",
"share.link.copyLinkButton": "Copier le lien",
"share.link.helpText": "Partager un lien direct vers ce {objectType}.",
"share.link.warning.lens": "Copiez le lien afin d’obtenir un lien temporaire. Enregistrez la visualisation Lens pour créer un lien permanent.",
"share.link.warning.title": "Modifications non enregistrées",
"share.modalContent.copyUrlButtonLabel": "Copier l'URL Post",
"share.postURLWatcherMessage": "Copiez cette URL POST pour appeler la génération depuis l'extérieur de Kibana ou à partir de Watcher.",
"share.postURLWatcherMessage.unsavedChanges": "L'URL peut changer si vous mettez Kibana à niveau.",
Expand Down Expand Up @@ -26269,6 +26267,8 @@
"xpack.lens.app.share.defaultDashboardTitle": "Visualisation Lens [{date}]",
"xpack.lens.app.shareButtonDisabledWarning": "La visualisation ne comprend aucune donnée à partager.",
"xpack.lens.app.shareModal.title": "Partager cette visualisation Lens",
"xpack.lens.app.shareModal.draftModeCallout.link.warning": "Copiez le lien afin d’obtenir un lien temporaire. Enregistrez la visualisation Lens pour créer un lien permanent.",
"xpack.lens.app.shareModal.draftModeCallout.title": "Modifications non enregistrées",
"xpack.lens.app.shareTitle": "Partager",
"xpack.lens.app.shareTitleAria": "Partager la visualisation",
"xpack.lens.app.showUnderlyingDataMultipleLayers": "Impossible d’afficher les données sous-jacentes pour les visualisations avec plusieurs calques.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7555,8 +7555,6 @@
"share.link.copyEmbedCodeButton": "埋め込みコードをコピー",
"share.link.copyLinkButton": "リンクをコピー",
"share.link.helpText": "この{objectType}への直接リンクを共有します。",
"share.link.warning.lens": "リンクをコピーして、一時リンクを取得します。Lensビジュアライゼーションを保存して、永続リンクを作成します。",
"share.link.warning.title": "保存されていない変更",
"share.modalContent.copyUrlButtonLabel": "POST URLをコピー",
"share.postURLWatcherMessage": "POST URLをコピーしてKibana外または旧Watcherから生成を呼び出します。",
"share.postURLWatcherMessage.unsavedChanges": "Kibanaをアップグレードした場合、URLが変更されることがあります。",
Expand Down Expand Up @@ -26127,6 +26125,8 @@
"xpack.lens.app.share.defaultDashboardTitle": "Lensビジュアライゼーション[{date}]",
"xpack.lens.app.shareButtonDisabledWarning": "ビジュアライゼーションには共有するデータがありません。",
"xpack.lens.app.shareModal.title": "このLensビジュアライゼーションを共有",
"xpack.lens.app.shareModal.draftModeCallout.link.warning": "リンクをコピーして、一時リンクを取得します。Lensビジュアライゼーションを保存して、永続リンクを作成します。",
"xpack.lens.app.shareModal.draftModeCallout.title": "保存されていない変更",
"xpack.lens.app.shareTitle": "共有",
"xpack.lens.app.shareTitleAria": "ビジュアライゼーションを共有",
"xpack.lens.app.showUnderlyingDataMultipleLayers": "複数レイヤーのビジュアライゼーションでは、基本データを表示できません",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7598,8 +7598,6 @@
"share.link.copyEmbedCodeButton": "复制嵌入代码",
"share.link.copyLinkButton": "复制链接",
"share.link.helpText": "共享指向此 {objectType} 的直接链接。",
"share.link.warning.lens": "复制链接以获取临时链接。保存 Lens 可视化以创建永久链接。",
"share.link.warning.title": "未保存的更改",
"share.modalContent.copyUrlButtonLabel": "复制 Post URL",
"share.postURLWatcherMessage": "复制此 POST URL 以从 Kibana 外部或从 Watcher 调用生成。",
"share.postURLWatcherMessage.unsavedChanges": "如果升级 Kibana,URL 可能会发生更改。",
Expand Down Expand Up @@ -26211,6 +26209,8 @@
"xpack.lens.app.share.defaultDashboardTitle": "Lens 可视化 [{date}]",
"xpack.lens.app.shareButtonDisabledWarning": "此可视化没有可共享的数据。",
"xpack.lens.app.shareModal.title": "共享此 Lens 可视化",
"xpack.lens.app.shareModal.draftModeCallout.link.warning": "复制链接以获取临时链接。保存 Lens 可视化以创建永久链接。",
"xpack.lens.app.shareModal.draftModeCallout.title": "未保存的更改",
"xpack.lens.app.shareTitle": "共享",
"xpack.lens.app.shareTitleAria": "共享可视化",
"xpack.lens.app.showUnderlyingDataMultipleLayers": "无法显示具有多个图层的可视化的底层数据",
Expand Down
Loading

0 comments on commit 55ac8cf

Please sign in to comment.