-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
saved_workspace.ts
68 lines (64 loc) · 2.39 KB
/
saved_workspace.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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';
import { extractReferences, injectReferences } from './saved_workspace_references';
import {
SavedObject,
createSavedObjectClass,
SavedObjectKibanaServices,
} from '../../../../../../src/plugins/saved_objects/public';
export interface SavedWorkspace extends SavedObject {
wsState?: string;
}
export function createSavedWorkspaceClass(services: SavedObjectKibanaServices) {
// SavedWorkspace constructor. Usually you'd interact with an instance of this.
// ID is option, without it one will be generated on save.
const SavedObjectClass = createSavedObjectClass(services);
class SavedWorkspaceClass extends SavedObjectClass {
public static type: string = 'graph-workspace';
// if type:workspace has no mapping, we push this mapping into ES
public static mapping: Record<string, string> = {
title: 'text',
description: 'text',
numLinks: 'integer',
numVertices: 'integer',
version: 'integer',
wsState: 'json',
};
// Order these fields to the top, the rest are alphabetical
public static fieldOrder = ['title', 'description'];
public static searchSource = false;
public wsState?: string;
constructor(id: string) {
// Gives our SavedWorkspace the properties of a SavedObject
super({
type: SavedWorkspaceClass.type,
mapping: SavedWorkspaceClass.mapping,
searchSource: SavedWorkspaceClass.searchSource,
extractReferences,
injectReferences,
// if this is null/undefined then the SavedObject will be assigned the defaults
id,
// default values that will get assigned if the doc is new
defaults: {
title: i18n.translate('xpack.graph.savedWorkspace.workspaceNameTitle', {
defaultMessage: 'New Graph Workspace',
}),
numLinks: 0,
numVertices: 0,
wsState: '{}',
version: 1,
},
});
}
// Overwrite the default getDisplayName function which uses type and which is not very
// user friendly for this object.
getDisplayName = () => {
return 'graph workspace';
};
}
return SavedWorkspaceClass;
}