-
Notifications
You must be signed in to change notification settings - Fork 8k
/
spaces_list.tsx
73 lines (64 loc) · 2.03 KB
/
spaces_list.tsx
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
/*
* 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 React, { FC, useState } from 'react';
import { i18n } from '@kbn/i18n';
import type { Capabilities } from '@kbn/core/public';
import type { SpacesPluginStart, ShareToSpaceFlyoutProps } from '@kbn/spaces-plugin/public';
import { DATA_VIEW_SAVED_OBJECT_TYPE } from '@kbn/data-views-plugin/public';
interface Props {
spacesApi: SpacesPluginStart;
capabilities: Capabilities | undefined;
spaceIds: string[];
id: string;
title: string;
refresh(): void;
}
const noun = i18n.translate('indexPatternManagement.indexPatternTable.savedObjectName', {
defaultMessage: 'data view',
});
export const SpacesList: FC<Props> = ({
spacesApi,
capabilities,
spaceIds,
id,
title,
refresh,
}) => {
const [showFlyout, setShowFlyout] = useState(false);
function onClose() {
setShowFlyout(false);
}
const LazySpaceList = spacesApi.ui.components.getSpaceList;
const LazyShareToSpaceFlyout = spacesApi.ui.components.getShareToSpaceFlyout;
const shareToSpaceFlyoutProps: ShareToSpaceFlyoutProps = {
savedObjectTarget: {
type: DATA_VIEW_SAVED_OBJECT_TYPE,
namespaces: spaceIds,
id,
title,
noun,
},
onUpdate: refresh,
onClose,
};
const canAssignSpaces = !capabilities || !!capabilities.savedObjectsManagement.shareIntoSpace;
const clickProperties = canAssignSpaces
? { cursorStyle: 'pointer', listOnClick: () => setShowFlyout(true) }
: { cursorStyle: 'not-allowed' };
return (
<>
<LazySpaceList
namespaces={spaceIds}
displayLimit={8}
behaviorContext="outside-space"
{...clickProperties}
/>
{showFlyout && <LazyShareToSpaceFlyout {...shareToSpaceFlyoutProps} />}
</>
);
};