Skip to content

Commit

Permalink
Convert index patterns to namespaceType 'multiple-isolated'
Browse files Browse the repository at this point in the history
This will happen in the 8.0 release. It requires that index patterns are
retrieved with the `resolve` API, and that the various resolve outcomes
are handled appropriately on the client side using the appropriate
Spaces APIs.
  • Loading branch information
jportner committed Apr 26, 2021
1 parent 7d974af commit afc3490
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/plugins/data/server/saved_objects/index_patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { indexPatternSavedObjectTypeMigrations } from './index_pattern_migration
export const indexPatternSavedObjectType: SavedObjectsType = {
name: 'index-pattern',
hidden: false,
namespaceType: 'single',
namespaceType: 'multiple-isolated',
convertToMultiNamespaceTypeVersion: '8.0.0',
management: {
icon: 'indexPatternApp',
defaultSearchField: 'title',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/index_pattern_management/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["management", "data", "urlForwarding", "indexPatternFieldEditor"],
"requiredPlugins": ["management", "data", "urlForwarding", "indexPatternFieldEditor", "spacesOss"],
"requiredBundles": ["kibanaReact", "kibanaUtils"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { IndexPattern, IndexPatternField } from '../../../../../plugins/data/public';
import { ResolvedIndexPattern, IndexPatternField } from '../../../../../plugins/data/public';
import { useKibana } from '../../../../../plugins/kibana_react/public';
import { IPM_APP_ID } from '../../constants';
import { IndexPatternManagmentContext } from '../../types';
import { Tabs } from './tabs';
import { IndexHeader } from './index_header';

export interface EditIndexPatternProps extends RouteComponentProps {
indexPattern: IndexPattern;
resolvedIndexPattern: ResolvedIndexPattern;
}

const mappingAPILink = i18n.translate(
Expand All @@ -55,14 +56,18 @@ const confirmModalOptionsDelete = {
};

export const EditIndexPattern = withRouter(
({ indexPattern, history, location }: EditIndexPatternProps) => {
({ resolvedIndexPattern, history, location }: EditIndexPatternProps) => {
const { indexPattern } = resolvedIndexPattern;
const {
uiSettings,
indexPatternManagementStart,
overlays,
chrome,
http,
data,
spacesOss,
} = useKibana<IndexPatternManagmentContext>().services;
const { basePath } = http;
const [fields, setFields] = useState<IndexPatternField[]>(indexPattern.getNonScriptedFields());
const [conflictedFields, setConflictedFields] = useState<IndexPatternField[]>(
indexPattern.fields.getAll().filter((field) => field.type === 'conflict')
Expand Down Expand Up @@ -144,6 +149,46 @@ export const EditIndexPattern = withRouter(
const showTagsSection = Boolean(indexPattern.timeFieldName || (tags && tags.length > 0));
const kibana = useKibana();
const docsUrl = kibana.services.docLinks!.links.elasticsearch.mapping;

useEffect(() => {
if (resolvedIndexPattern.outcome === 'aliasMatch' && spacesOss.isSpacesAvailable) {
// This index pattern has been resolved from a legacy URL, we should redirect the user to the new URL and display a toast.
const path = basePath.prepend(
`kibana/${IPM_APP_ID}/patterns/${indexPattern.id}${window.location.hash}`
);
const objectNoun = 'index pattern'; // TODO: i18n
spacesOss.ui.redirectLegacyUrl(path, objectNoun);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const getLegacyUrlConflictCallout = () => {
if (
resolvedIndexPattern.outcome === 'conflict' &&
resolvedIndexPattern.aliasTargetId &&
spacesOss.isSpacesAvailable
) {
// We have resolved to one index pattern, but there is another one with a legacy URL associated with this page. We should display a
// callout with a warning for the user, and provide a way for them to navigate to the other index pattern.
const otherObjectId = resolvedIndexPattern.aliasTargetId;
const otherObjectPath = basePath.prepend(
`kibana/${IPM_APP_ID}/patterns/${otherObjectId}${window.location.hash}`
);
return (
<>
<EuiSpacer />
{spacesOss.ui.components.getLegacyUrlConflict({
objectNoun: 'index pattern', // TODO: i18n
currentObjectId: indexPattern.id!,
otherObjectId,
otherObjectPath,
})}
</>
);
}
return null;
};

return (
<EuiPanel paddingSize={'l'}>
<div data-test-subj="editIndexPattern" role="region" aria-label={headingAriaLabel}>
Expand Down Expand Up @@ -185,6 +230,7 @@ export const EditIndexPattern = withRouter(
/>{' '}
</p>
</EuiText>
{getLegacyUrlConflictCallout()}
{conflictedFields.length > 0 && (
<>
<EuiSpacer />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React, { useEffect, useState } from 'react';
import { withRouter, RouteComponentProps } from 'react-router-dom';
import { IndexPattern } from '../../../../../plugins/data/public';
import { ResolvedIndexPattern } from '../../../../../plugins/data/public';
import { useKibana } from '../../../../../plugins/kibana_react/public';
import { IndexPatternManagmentContext } from '../../types';
import { getEditBreadcrumbs } from '../breadcrumbs';
Expand All @@ -17,17 +17,17 @@ import { EditIndexPattern } from '../edit_index_pattern';

const EditIndexPatternCont: React.FC<RouteComponentProps<{ id: string }>> = ({ ...props }) => {
const { data, setBreadcrumbs } = useKibana<IndexPatternManagmentContext>().services;
const [indexPattern, setIndexPattern] = useState<IndexPattern>();
const [resolvedIndexPattern, setResolvedIndexPattern] = useState<ResolvedIndexPattern>();

useEffect(() => {
data.indexPatterns.get(props.match.params.id).then((ip: IndexPattern) => {
setIndexPattern(ip);
setBreadcrumbs(getEditBreadcrumbs(ip));
data.indexPatterns.resolve(props.match.params.id).then((ip: ResolvedIndexPattern) => {
setResolvedIndexPattern(ip);
setBreadcrumbs(getEditBreadcrumbs(ip.indexPattern));
});
}, [data.indexPatterns, props.match.params.id, setBreadcrumbs]);

if (indexPattern) {
return <EditIndexPattern indexPattern={indexPattern} />;
if (resolvedIndexPattern) {
return <EditIndexPattern resolvedIndexPattern={resolvedIndexPattern} />;
} else {
return <></>;
}
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/index_pattern_management/public/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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.
*/

export const IPM_APP_ID = 'indexPatterns';
export const newAppPath = `management/kibana/${IPM_APP_ID}`;
export const legacyPatternsPath = 'management/kibana/index_patterns';
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function mountManagementSection(
) {
const [
{ chrome, application, uiSettings, notifications, overlays, http, docLinks },
{ data, indexPatternFieldEditor },
{ data, indexPatternFieldEditor, spacesOss },
indexPatternManagementStart,
] = await getStartServices();
const canSave = Boolean(application.capabilities.indexPatterns.save);
Expand All @@ -61,6 +61,7 @@ export async function mountManagementSection(
docLinks,
data,
indexPatternFieldEditor,
spacesOss,
indexPatternManagementStart: indexPatternManagementStart as IndexPatternManagementStart,
setBreadcrumbs: params.setBreadcrumbs,
getMlCardState,
Expand Down
8 changes: 3 additions & 5 deletions src/plugins/index_pattern_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {

import { ManagementSetup } from '../../management/public';
import { IndexPatternFieldEditorStart } from '../../index_pattern_field_editor/public';
import type { SpacesOssPluginStart } from '../../spaces_oss/public';
import { IPM_APP_ID, legacyPatternsPath, newAppPath } from './constants';

export interface IndexPatternManagementSetupDependencies {
management: ManagementSetup;
Expand All @@ -27,6 +29,7 @@ export interface IndexPatternManagementSetupDependencies {
export interface IndexPatternManagementStartDependencies {
data: DataPublicPluginStart;
indexPatternFieldEditor: IndexPatternFieldEditorStart;
spacesOss: SpacesOssPluginStart;
}

export type IndexPatternManagementSetup = IndexPatternManagementServiceSetup;
Expand All @@ -37,8 +40,6 @@ const sectionsHeader = i18n.translate('indexPatternManagement.indexPattern.secti
defaultMessage: 'Index Patterns',
});

const IPM_APP_ID = 'indexPatterns';

export class IndexPatternManagementPlugin
implements
Plugin<
Expand All @@ -61,9 +62,6 @@ export class IndexPatternManagementPlugin
throw new Error('`kibana` management section not found.');
}

const newAppPath = `management/kibana/${IPM_APP_ID}`;
const legacyPatternsPath = 'management/kibana/index_patterns';

urlForwarding.forwardApp('management/kibana/index_pattern', newAppPath, (path) => '/create');
urlForwarding.forwardApp(legacyPatternsPath, newAppPath, (path) => {
const pathInApp = path.substr(legacyPatternsPath.length + 1);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/index_pattern_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ManagementAppMountParams } from '../../management/public';
import { IndexPatternManagementStart } from './index';
import { KibanaReactContextValue } from '../../kibana_react/public';
import { IndexPatternFieldEditorStart } from '../../index_pattern_field_editor/public';
import type { SpacesOssPluginStart } from '../../spaces_oss/public';

export interface IndexPatternManagmentContext {
chrome: ChromeStart;
Expand All @@ -31,6 +32,7 @@ export interface IndexPatternManagmentContext {
docLinks: DocLinksStart;
data: DataPublicPluginStart;
indexPatternFieldEditor: IndexPatternFieldEditorStart;
spacesOss: SpacesOssPluginStart;
indexPatternManagementStart: IndexPatternManagementStart;
setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs'];
getMlCardState: () => MlCardState;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/index_pattern_management/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
{ "path": "../kibana_utils/tsconfig.json" },
{ "path": "../es_ui_shared/tsconfig.json" },
{ "path": "../index_pattern_field_editor/tsconfig.json" },
{ "path": "../spaces_oss/tsconfig.json" },
]
}

0 comments on commit afc3490

Please sign in to comment.