Skip to content

Commit 0072e6a

Browse files
authored
add ShareMenuItem component (#23977)
1 parent 48a45c6 commit 0072e6a

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2020 Graylog, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*/
17+
import * as React from 'react';
18+
19+
import { MenuItem } from 'components/bootstrap';
20+
import SharingDisabledPopover from 'components/permissions/SharingDisabledPopover';
21+
import HasOwnership from 'components/common/HasOwnership';
22+
23+
type Props = {
24+
/**
25+
* When a custom description is provided
26+
* the button will be disabled
27+
*/
28+
disabledInfo?: string;
29+
entityId: string;
30+
entityType: string;
31+
onClick: () => void;
32+
title?: string;
33+
};
34+
35+
const ShareMenuItem = ({
36+
entityId,
37+
entityType,
38+
onClick,
39+
disabledInfo = undefined,
40+
title = undefined,
41+
}: Props) => (
42+
<HasOwnership id={entityId} type={entityType}>
43+
{({ disabled: hasMissingPermissions }) => (
44+
<MenuItem
45+
onSelect={onClick}
46+
disabled={!!disabledInfo || hasMissingPermissions}
47+
title="Share">
48+
{title ?? 'Share'}{' '}
49+
{(!!disabledInfo || hasMissingPermissions) && (
50+
<SharingDisabledPopover type={entityType} description={disabledInfo} />
51+
)}
52+
</MenuItem>
53+
)}
54+
</HasOwnership>
55+
);
56+
57+
export default ShareMenuItem;

graylog2-web-interface/src/components/common/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export { default as Select } from './Select';
113113
export { default as SelectPopover } from './SelectPopover';
114114
export { default as SelectableList } from './SelectableList';
115115
export { default as ShareButton } from './ShareButton';
116+
export { default as ShareMenuItem } from './ShareMenuItem';
116117
export { default as SortableList } from './SortableList';
117118
export { default as Spinner } from './Spinner';
118119
export { default as Spoiler } from './Spoiler';

0 commit comments

Comments
 (0)