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

add SavedObjectType.management.displayName #113091

Merged
merged 7 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsTypeManagementDefinition](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.md) &gt; [displayName](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.displayname.md)

## SavedObjectsTypeManagementDefinition.displayName property

When specified, will be used instead of the type's name in SO management section's labels.

<b>Signature:</b>

```typescript
displayName?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface SavedObjectsTypeManagementDefinition<Attributes = any>
| Property | Type | Description |
| --- | --- | --- |
| [defaultSearchField](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.defaultsearchfield.md) | <code>string</code> | The default search field to use for this type. Defaults to <code>id</code>. |
| [displayName](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.displayname.md) | <code>string</code> | When specified, will be used instead of the type's name in SO management section's labels. |
| [getEditUrl](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.getediturl.md) | <code>(savedObject: SavedObject&lt;Attributes&gt;) =&gt; string</code> | Function returning the url to use to redirect to the editing page of this object. If not defined, editing will not be allowed. |
| [getInAppUrl](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.getinappurl.md) | <code>(savedObject: SavedObject&lt;Attributes&gt;) =&gt; {</code><br/><code> path: string;</code><br/><code> uiCapabilitiesPath: string;</code><br/><code> }</code> | Function returning the url to use to redirect to this object from the management section. If not defined, redirecting to the object will not be allowed. |
| [getTitle](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.gettitle.md) | <code>(savedObject: SavedObject&lt;Attributes&gt;) =&gt; string</code> | Function returning the title to display in the management table. If not defined, will use the object's type and id to generate a label. |
Expand Down
4 changes: 4 additions & 0 deletions src/core/server/saved_objects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ export interface SavedObjectsTypeManagementDefinition<Attributes = any> {
* Is the type importable or exportable. Defaults to `false`.
*/
importableAndExportable?: boolean;
/**
* When specified, will be used instead of the type's name in SO management section's labels.
*/
displayName?: string;
/**
* When set to false, the type will not be listed or searchable in the SO management section.
* Main usage of setting this property to false for a type is when objects from the type should
Expand Down
1 change: 1 addition & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2739,6 +2739,7 @@ export interface SavedObjectsType<Attributes = any> {
// @public
export interface SavedObjectsTypeManagementDefinition<Attributes = any> {
defaultSearchField?: string;
displayName?: string;
getEditUrl?: (savedObject: SavedObject<Attributes>) => string;
getInAppUrl?: (savedObject: SavedObject<Attributes>) => {
path: string;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/saved_objects_management/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export type {
SavedObjectRelationKind,
SavedObjectInvalidRelation,
SavedObjectGetRelationshipsResponse,
SavedObjectManagementTypeInfo,
} from './types';
11 changes: 9 additions & 2 deletions src/plugins/saved_objects_management/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Side Public License, v 1.
*/

import { SavedObject } from 'src/core/types';
import { SavedObjectsNamespaceType } from 'src/core/public';
import type { SavedObject } from 'src/core/types';
import type { SavedObjectsNamespaceType } from 'src/core/public';

/**
* The metadata injected into a {@link SavedObject | saved object} when returning
Expand Down Expand Up @@ -52,3 +52,10 @@ export interface SavedObjectGetRelationshipsResponse {
relations: SavedObjectRelation[];
invalidRelations: SavedObjectInvalidRelation[];
}

export interface SavedObjectManagementTypeInfo {
name: string;
namespaceType: SavedObjectsNamespaceType;
hidden: boolean;
displayName: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
* Side Public License, v 1.
*/

import { HttpStart } from 'src/core/public';
import type { HttpStart } from 'src/core/public';
import type { SavedObjectManagementTypeInfo } from '../../common/types';

interface GetAllowedTypesResponse {
types: string[];
types: SavedObjectManagementTypeInfo[];
}

export async function getAllowedTypes(http: HttpStart) {
export async function getAllowedTypes(http: HttpStart): Promise<SavedObjectManagementTypeInfo[]> {
const response = await http.get<GetAllowedTypesResponse>(
'/api/kibana/management/saved_objects/_allowed_types'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

import type { SavedObjectManagementTypeInfo } from '../../common/types';
import { getSavedObjectLabel } from './get_saved_object_label';

const toTypeInfo = (name: string, displayName?: string): SavedObjectManagementTypeInfo => ({
name,
displayName: displayName ?? name,
hidden: false,
namespaceType: 'single',
});

describe('getSavedObjectLabel', () => {
it('returns the type name if no types are provided', () => {
expect(getSavedObjectLabel('foo', [])).toEqual('foo');
});

it('returns the type name if type does not specify a display name', () => {
expect(getSavedObjectLabel('foo', [toTypeInfo('foo')])).toEqual('foo');
});

it('returns the type display name if type does specify a display name', () => {
expect(getSavedObjectLabel('foo', [toTypeInfo('foo', 'fooDisplay')])).toEqual('fooDisplay');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
* Side Public License, v 1.
*/

export function getSavedObjectLabel(type: string) {
switch (type) {
case 'index-pattern':
case 'index-patterns':
case 'indexPatterns':
return 'index patterns';
default:
return type;
}
import type { SavedObjectManagementTypeInfo } from '../../common/types';

/**
* Returns the label to be used for given saved object type.
*/
export function getSavedObjectLabel(type: string, types: SavedObjectManagementTypeInfo[]) {
const typeInfo = types.find((t) => t.name === type);
return typeInfo?.displayName ?? type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { i18n } from '@kbn/i18n';
import { EuiLoadingSpinner } from '@elastic/eui';
import { CoreSetup } from 'src/core/public';
import { ManagementAppMountParams } from '../../../management/public';
import type { SavedObjectManagementTypeInfo } from '../../common/types';
import { StartDependencies, SavedObjectsManagementPluginStart } from '../plugin';
import { getAllowedTypes } from './../lib';

Expand All @@ -22,7 +23,7 @@ interface MountParams {
mountParams: ManagementAppMountParams;
}

let allowedObjectTypes: string[] | undefined;
let allowedObjectTypes: SavedObjectManagementTypeInfo[] | undefined;

const title = i18n.translate('savedObjectsManagement.objects.savedObjectsTitle', {
defaultMessage: 'Saved Objects',
Expand All @@ -33,15 +34,15 @@ const SavedObjectsTablePage = lazy(() => import('./saved_objects_table_page'));
export const mountManagementSection = async ({ core, mountParams }: MountParams) => {
const [coreStart, { data, savedObjectsTaggingOss, spaces: spacesApi }, pluginStart] =
await core.getStartServices();
const { capabilities } = coreStart.application;
const { element, history, setBreadcrumbs } = mountParams;
if (allowedObjectTypes === undefined) {

if (!allowedObjectTypes) {
allowedObjectTypes = await getAllowedTypes(coreStart.http);
}

coreStart.chrome.docTitle.change(title);

const capabilities = coreStart.application.capabilities;

const RedirectToHomeIfUnauthorized: React.FunctionComponent = ({ children }) => {
const allowed = capabilities?.management?.kibana?.objects ?? false;

Expand Down

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

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import React from 'react';
import { findTestSubject } from '@elastic/eui/lib/test';
import { mountWithIntl } from '@kbn/test/jest';
import { SavedObjectWithMetadata } from '../../../../common';
import type { SavedObjectWithMetadata, SavedObjectManagementTypeInfo } from '../../../../common';
import { DeleteConfirmModal } from './delete_confirm_modal';

interface CreateObjectOptions {
Expand All @@ -32,6 +32,7 @@ const createObject = ({
});

describe('DeleteConfirmModal', () => {
const allowedTypes: SavedObjectManagementTypeInfo[] = [];
let onConfirm: jest.Mock;
let onCancel: jest.Mock;

Expand All @@ -47,6 +48,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={[]}
allowedTypes={allowedTypes}
/>
);
expect(wrapper.find('EuiLoadingElastic')).toHaveLength(1);
Expand All @@ -61,6 +63,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={objs}
allowedTypes={allowedTypes}
/>
);
expect(wrapper.find('.euiTableRow')).toHaveLength(3);
Expand All @@ -73,6 +76,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={[]}
allowedTypes={allowedTypes}
/>
);
wrapper.find('EuiButtonEmpty').simulate('click');
Expand All @@ -88,6 +92,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={[createObject()]}
allowedTypes={allowedTypes}
/>
);
wrapper.find('EuiButton').simulate('click');
Expand All @@ -109,6 +114,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={objs}
allowedTypes={allowedTypes}
/>
);
expect(wrapper.find('.euiTableRow')).toHaveLength(1);
Expand All @@ -126,6 +132,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={objs}
allowedTypes={allowedTypes}
/>
);

Expand All @@ -145,6 +152,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={objs}
allowedTypes={allowedTypes}
/>
);

Expand All @@ -164,6 +172,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={objs}
allowedTypes={allowedTypes}
/>
);

Expand All @@ -184,6 +193,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={objs}
allowedTypes={allowedTypes}
/>
);
const callout = findTestSubject(wrapper, 'sharedObjectsWarning');
Expand All @@ -202,6 +212,7 @@ describe('DeleteConfirmModal', () => {
onConfirm={onConfirm}
onCancel={onCancel}
selectedObjects={objs}
allowedTypes={allowedTypes}
/>
);
const callout = findTestSubject(wrapper, 'sharedObjectsWarning');
Expand Down
Loading