|
| 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; |
0 commit comments