Skip to content

Commit

Permalink
show delete integration btn only if allow_delete is truthy (#3377)
Browse files Browse the repository at this point in the history
# What this PR does
Show delete integration btn only if `allow_delete` is `true` for it


## Which issue(s) this PR fixes
grafana/oncall-private#2302


## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
  • Loading branch information
brojd authored Nov 17, 2023
1 parent 8f13e31 commit 53ca533
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 208 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { FC, ReactNode } from 'react';

interface RenderConditionallyProps {
shouldRender?: boolean;
children: ReactNode;
}

const RenderConditionally: FC<RenderConditionallyProps> = ({ shouldRender, children }) =>
shouldRender ? <>{children}</> : null;

export default RenderConditionally;

This file was deleted.

This file was deleted.

65 changes: 33 additions & 32 deletions grafana-plugin/src/pages/integrations/Integrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
initErrorDataState,
} from 'components/PageErrorHandlingWrapper/PageErrorHandlingWrapper.helpers';
import PluginLink from 'components/PluginLink/PluginLink';
import RenderConditionally from 'components/RenderConditionally/RenderConditionally';
import Text from 'components/Text/Text';
import TextEllipsisTooltip from 'components/TextEllipsisTooltip/TextEllipsisTooltip';
import TooltipBadge from 'components/TooltipBadge/TooltipBadge';
Expand Down Expand Up @@ -540,39 +541,39 @@ class Integrations extends React.Component<IntegrationsProps, IntegrationsState>
</HorizontalGroup>
</div>
</CopyToClipboard>

<div className={cx('thin-line-break')} />

<WithPermissionControlTooltip key="delete" userAction={UserActions.IntegrationsWrite}>
<div className={cx('integrations-actionItem')}>
<div
onClick={() => {
this.setState({
confirmationModal: {
isOpen: true,
confirmText: 'Delete',
dismissText: 'Cancel',
onConfirm: () => this.handleDeleteAlertReceiveChannel(item.id),
title: 'Delete integration',
body: (
<Text type="primary">
Are you sure you want to delete <Emoji text={item.verbal_name} /> integration?
</Text>
),
},
});
}}
style={{ width: '100%' }}
>
<Text type="danger">
<HorizontalGroup spacing={'xs'}>
<Icon name="trash-alt" />
<span>Delete Integration</span>
</HorizontalGroup>
</Text>
<RenderConditionally shouldRender={item.allow_delete}>
<div className={cx('thin-line-break')} />
<WithPermissionControlTooltip key="delete" userAction={UserActions.IntegrationsWrite}>
<div className={cx('integrations-actionItem')}>
<div
onClick={() => {
this.setState({
confirmationModal: {
isOpen: true,
confirmText: 'Delete',
dismissText: 'Cancel',
onConfirm: () => this.handleDeleteAlertReceiveChannel(item.id),
title: 'Delete integration',
body: (
<Text type="primary">
Are you sure you want to delete <Emoji text={item.verbal_name} /> integration?
</Text>
),
},
});
}}
className="u-width-100"
>
<Text type="danger">
<HorizontalGroup spacing={'xs'}>
<Icon name="trash-alt" />
<span>Delete Integration</span>
</HorizontalGroup>
</Text>
</div>
</div>
</div>
</WithPermissionControlTooltip>
</WithPermissionControlTooltip>
</RenderConditionally>
</div>
)}
>
Expand Down

0 comments on commit 53ca533

Please sign in to comment.