/
saved_objects_management.ts
175 lines (171 loc) · 6.4 KB
/
saved_objects_management.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* 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 { SavedObject } from '..';
import type { SavedObjectsExportTransform } from './export';
import type { SavedObjectsImportHook } from './import';
/**
* Configuration options for the {@link SavedObjectsType | type}'s management section.
*
* @public
*/
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
* be included in the export via references or export hooks, but should not directly appear in the SOM.
* Defaults to `true`.
*
* @remarks `importableAndExportable` must be `true` to specify this property.
*/
visibleInManagement?: boolean;
/**
* The default search field to use for this type. Defaults to `id`.
*/
defaultSearchField?: string;
/**
* The eui icon name to display in the management table.
* If not defined, the default icon will be used.
*/
icon?: string;
/**
* 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.
*/
getTitle?: (savedObject: SavedObject<Attributes>) => string;
/**
* Function returning the url to use to redirect to the editing page of this object.
* If not defined, editing will not be allowed.
*/
getEditUrl?: (savedObject: SavedObject<Attributes>) => string;
/**
* 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.
*
* @returns undefined or an object containing a `path` and `uiCapabilitiesPath` properties. the `path` is the path to
* the object page, relative to the base path. `uiCapabilitiesPath` is the path to check in the
* {@link Capabilities | uiCapabilities} to check if the user has permission to access the object.
*/
getInAppUrl?: (savedObject: SavedObject<Attributes>) =>
| {
path: string;
uiCapabilitiesPath: string;
}
| undefined;
/**
* An optional export transform function that can be used transform the objects of the registered type during
* the export process.
*
* It can be used to either mutate the exported objects, or add additional objects (of any type) to the export list.
*
* See {@link SavedObjectsExportTransform | the transform type documentation} for more info and examples.
*
* When implementing both `isExportable` and `onExport`, it is mandatory that
* `isExportable` returns the same value for an object before and after going
* though the export transform.
* E.g `isExportable(objectBeforeTransform) === isExportable(objectAfterTransform)`
*
* @remarks `importableAndExportable` must be `true` to specify this property.
*/
onExport?: SavedObjectsExportTransform<Attributes>;
/**
* An optional {@link SavedObjectsImportHook | import hook} to use when importing given type.
*
* Import hooks are executed during the savedObjects import process and allow to interact
* with the imported objects. See the {@link SavedObjectsImportHook | hook documentation}
* for more info.
*
* @example
* Registering a hook displaying a warning about a specific type of object
* ```ts
* // src/plugins/my_plugin/server/plugin.ts
* import { myType } from './saved_objects';
*
* export class Plugin() {
* setup: (core: CoreSetup) => {
* core.savedObjects.registerType({
* ...myType,
* management: {
* ...myType.management,
* onImport: (objects) => {
* if(someActionIsNeeded(objects)) {
* return {
* warnings: [
* {
* type: 'action_required',
* message: 'Objects need to be manually enabled after import',
* actionPath: '/app/my-app/require-activation',
* },
* ]
* }
* }
* return {};
* }
* },
* });
* }
* }
* ```
*
* @remarks messages returned in the warnings are user facing and must be translated.
* @remarks `importableAndExportable` must be `true` to specify this property.
*/
onImport?: SavedObjectsImportHook<Attributes>;
/**
* Optional hook to specify whether an object should be exportable.
*
* If specified, `isExportable` will be called during export for each
* of this type's objects in the export, and the ones not matching the
* predicate will be excluded from the export.
*
* When implementing both `isExportable` and `onExport`, it is mandatory that
* `isExportable` returns the same value for an object before and after going
* though the export transform.
* E.g `isExportable(objectBeforeTransform) === isExportable(objectAfterTransform)`
*
* @example
* Registering a type with a per-object exportability predicate
* ```ts
* // src/plugins/my_plugin/server/plugin.ts
* import { myType } from './saved_objects';
*
* export class Plugin() {
* setup: (core: CoreSetup) => {
* core.savedObjects.registerType({
* ...myType,
* management: {
* ...myType.management,
* isExportable: (object) => {
* if (object.attributes.myCustomAttr === 'foo') {
* return false;
* }
* return true;
* }
* },
* });
* }
* }
* ```
*
* @remarks `importableAndExportable` must be `true` to specify this property.
*/
isExportable?: SavedObjectsExportablePredicate<Attributes>;
}
/**
* @public
*/
export type SavedObjectsExportablePredicate<Attributes = unknown> = (
obj: SavedObject<Attributes>
) => boolean;