Skip to content

Commit

Permalink
Legacy url conflict UI improvements (#114172) (#114382)
Browse files Browse the repository at this point in the history
# Conflicts:
#	docs/development/core/public/kibana-plugin-core-public.doclinksstart.md

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
jportner and kibanamachine authored Oct 9, 2021
1 parent 7f70d40 commit 7053f5b
Show file tree
Hide file tree
Showing 42 changed files with 364 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ readonly links: {
mappingRolesFieldRules: string;
runAsPrivilege: string;
}>;
readonly spaces: Readonly<{
kibanaLegacyUrlAliases: string;
kibanaDisableLegacyUrlAliasesApi: string;
}>;
readonly watcher: Record<string, string>;
readonly ccs: Record<string, string>;
readonly plugins: Record<string, string>;
Expand Down

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ export class DocLinksService {
mappingRolesFieldRules: `${ELASTICSEARCH_DOCS}role-mapping-resources.html#mapping-roles-rule-field`,
runAsPrivilege: `${ELASTICSEARCH_DOCS}security-privileges.html#_run_as_privilege`,
},
spaces: {
kibanaLegacyUrlAliases: `${KIBANA_DOCS}legacy-url-aliases.html`,
kibanaDisableLegacyUrlAliasesApi: `${KIBANA_DOCS}spaces-api-disable-legacy-url-aliases.html`,
},
watcher: {
jiraAction: `${ELASTICSEARCH_DOCS}actions-jira.html`,
pagerDutyAction: `${ELASTICSEARCH_DOCS}actions-pagerduty.html`,
Expand Down Expand Up @@ -712,6 +716,10 @@ export interface DocLinksStart {
mappingRolesFieldRules: string;
runAsPrivilege: string;
}>;
readonly spaces: Readonly<{
kibanaLegacyUrlAliases: string;
kibanaDisableLegacyUrlAliasesApi: string;
}>;
readonly watcher: Record<string, string>;
readonly ccs: Record<string, string>;
readonly plugins: Record<string, string>;
Expand Down
4 changes: 4 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ export interface DocLinksStart {
mappingRolesFieldRules: string;
runAsPrivilege: string;
}>;
readonly spaces: Readonly<{
kibanaLegacyUrlAliases: string;
kibanaDisableLegacyUrlAliasesApi: string;
}>;
readonly watcher: Record<string, string>;
readonly ccs: Record<string, string>;
readonly plugins: Record<string, string>;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/embeddable/embeddable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe('embeddable', () => {
...savedVis,
sharingSavedObjectProps: {
outcome: 'conflict',
errorJSON: '{targetType: "lens", sourceId: "1", targetSpace: "space"}',
sourceId: '1',
aliasTargetId: '2',
},
} as ResolvedLensSavedObjectAttributes);
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ export class Embeddable
defaultMessage: `You've encountered a URL conflict`,
}),
longMessage: (
<this.deps.spaces.ui.components.getSavedObjectConflictMessage
json={sharingSavedObjectProps.errorJSON!}
<this.deps.spaces.ui.components.getEmbeddableLegacyUrlConflict
targetType={DOC_TYPE}
sourceId={sharingSavedObjectProps.sourceId!}
/>
),
};
Expand Down
11 changes: 2 additions & 9 deletions x-pack/plugins/lens/public/lens_attribute_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function getLensAttributeService(
outcome,
alias_target_id: aliasTargetId,
} = await savedObjectStore.load(savedObjectId);
const { attributes, references, type, id } = savedObject;
const { attributes, references, id } = savedObject;
const document = {
...attributes,
references,
Expand All @@ -57,14 +57,7 @@ export function getLensAttributeService(
const sharingSavedObjectProps = {
aliasTargetId,
outcome,
errorJSON:
outcome === 'conflict'
? JSON.stringify({
targetType: type,
sourceId: id,
targetSpace: (await startDependencies.spaces.getActiveSpace()).id,
})
: undefined,
sourceId: id,
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getPersisted = async ({
lensServices: LensAppServices;
history?: History<unknown>;
}): Promise<
{ doc: Document; sharingSavedObjectProps: Omit<SharingSavedObjectProps, 'errorJSON'> } | undefined
{ doc: Document; sharingSavedObjectProps: Omit<SharingSavedObjectProps, 'sourceId'> } | undefined
> => {
const { notifications, spaces, attributeService } = lensServices;
let doc: Document;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/state_management/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface LensAppState extends EditorFrameState {
savedQuery?: SavedQuery;
searchSessionId: string;
resolvedDateRange: DateRange;
sharingSavedObjectProps?: Omit<SharingSavedObjectProps, 'errorJSON'>;
sharingSavedObjectProps?: Omit<SharingSavedObjectProps, 'sourceId'>;
}

export type DispatchSetState = (state: Partial<LensAppState>) => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,5 +834,5 @@ export interface ILensInterpreterRenderHandlers extends IInterpreterRenderHandle
export interface SharingSavedObjectProps {
outcome?: 'aliasMatch' | 'exactMatch' | 'conflict';
aliasTargetId?: string;
errorJSON?: string;
sourceId?: string;
}
5 changes: 3 additions & 2 deletions x-pack/plugins/maps/public/embeddable/map_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,9 @@ export class MapEmbeddable
iconType="alert"
iconColor="danger"
data-test-subj="embeddable-maps-failure"
body={spaces.ui.components.getSavedObjectConflictMessage({
json: sharingSavedObjectProps.errorJSON!,
body={spaces.ui.components.getEmbeddableLegacyUrlConflict({
targetType: MAP_SAVED_OBJECT_TYPE,
sourceId: sharingSavedObjectProps.sourceId!,
})}
/>
</div>
Expand Down
12 changes: 2 additions & 10 deletions x-pack/plugins/maps/public/map_attribute_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import { checkForDuplicateTitle, OnSaveProps } from '../../../../src/plugins/sav
import { getCoreOverlays, getEmbeddableService, getSavedObjectsClient } from './kibana_services';
import { extractReferences, injectReferences } from '../common/migrations/references';
import { MapByValueInput, MapByReferenceInput } from './embeddable/types';
import { getSpacesApi } from './kibana_services';

export interface SharingSavedObjectProps {
outcome?: 'aliasMatch' | 'exactMatch' | 'conflict';
aliasTargetId?: string;
errorJSON?: string;
sourceId?: string;
}

type MapDoc = MapSavedObjectAttributes & {
Expand Down Expand Up @@ -88,14 +87,7 @@ export function getMapAttributeService(): MapAttributeService {
sharingSavedObjectProps: {
aliasTargetId,
outcome,
errorJSON:
outcome === 'conflict' && getSpacesApi()
? JSON.stringify({
targetType: MAP_SAVED_OBJECT_TYPE,
sourceId: savedObjectId,
targetSpace: (await getSpacesApi()!.getActiveSpace()).id,
})
: undefined,
sourceId: savedObjectId,
},
};
},
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/spaces/public/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ export const getSpacesFeatureDescription = () => {

return spacesFeatureDescription;
};

export const DEFAULT_OBJECT_NOUN = i18n.translate('xpack.spaces.shareToSpace.objectNoun', {
defaultMessage: 'object',
});
3 changes: 2 additions & 1 deletion x-pack/plugins/spaces/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export type {
CopyToSpaceSavedObjectTarget,
} from './copy_saved_objects_to_space';

export type { LegacyUrlConflictProps, EmbeddableLegacyUrlConflictProps } from './legacy_urls';

export type {
LegacyUrlConflictProps,
ShareToSpaceFlyoutProps,
ShareToSpaceSavedObjectTarget,
} from './share_saved_objects_to_space';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

import type { EmbeddableLegacyUrlConflictProps } from '../types';
import type { InternalProps } from './embeddable_legacy_url_conflict_internal';

export const getEmbeddableLegacyUrlConflict = async (
internalProps: InternalProps
): Promise<React.FC<EmbeddableLegacyUrlConflictProps>> => {
const { EmbeddableLegacyUrlConflictInternal } = await import(
'./embeddable_legacy_url_conflict_internal'
);
return (props: EmbeddableLegacyUrlConflictProps) => {
return <EmbeddableLegacyUrlConflictInternal {...{ ...internalProps, ...props }} />;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import {
EuiButtonEmpty,
EuiCallOut,
EuiCodeBlock,
EuiLink,
EuiSpacer,
EuiTextAlign,
} from '@elastic/eui';
import React, { useState } from 'react';
import useAsync from 'react-use/lib/useAsync';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import type { StartServicesAccessor } from 'src/core/public';

import type { PluginsStart } from '../../plugin';
import type { SpacesManager } from '../../spaces_manager';
import type { EmbeddableLegacyUrlConflictProps } from '../types';

export interface InternalProps {
spacesManager: SpacesManager;
getStartServices: StartServicesAccessor<PluginsStart>;
}

export const EmbeddableLegacyUrlConflictInternal = (
props: InternalProps & EmbeddableLegacyUrlConflictProps
) => {
const { spacesManager, getStartServices, targetType, sourceId } = props;

const [expandError, setExpandError] = useState(false);

const { value: asyncParams } = useAsync(async () => {
const [{ docLinks }] = await getStartServices();
const { id: targetSpace } = await spacesManager.getActiveSpace();
const docLink = docLinks.links.spaces.kibanaDisableLegacyUrlAliasesApi;
const aliasJsonString = JSON.stringify({ targetSpace, targetType, sourceId }, null, 2);
return { docLink, aliasJsonString };
}, [getStartServices, spacesManager]);
const { docLink, aliasJsonString } = asyncParams ?? {};

if (!aliasJsonString || !docLink) {
return null;
}

return (
<>
<FormattedMessage
id="xpack.spaces.embeddableLegacyUrlConflict.messageText"
defaultMessage="We found 2 saved objects for this panel. Disable the legacy URL alias to fix this error."
/>
<EuiSpacer />
{expandError ? (
<EuiTextAlign textAlign="left">
<EuiCallOut
title={
<FormattedMessage
id="xpack.spaces.embeddableLegacyUrlConflict.calloutTitle"
defaultMessage="Copy this JSON and use it with the {documentationLink}"
values={{
documentationLink: (
<EuiLink external href={docLink} target="_blank">
{'_disable_legacy_url_aliases API'}
</EuiLink>
),
}}
/>
}
color="danger"
iconType="alert"
>
<EuiCodeBlock fontSize="s" language="json" isCopyable={true} paddingSize="none">
{aliasJsonString}
</EuiCodeBlock>
</EuiCallOut>
</EuiTextAlign>
) : (
<EuiButtonEmpty onClick={() => setExpandError(true)}>
{i18n.translate('xpack.spaces.embeddableLegacyUrlConflict.detailsButton', {
defaultMessage: `View details`,
})}
</EuiButtonEmpty>
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
* 2.0.
*/

export { DocumentationLinksService } from './documentation_links';
export { getEmbeddableLegacyUrlConflict } from './embeddable_legacy_url_conflict';
export { getLegacyUrlConflict } from './legacy_url_conflict';
Loading

0 comments on commit 7053f5b

Please sign in to comment.