Skip to content

Commit c9f5440

Browse files
committed
Conditional "Delete" iconbutton.
1 parent 7e660ff commit c9f5440

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

apps/sensenet/src/components/settings/content-card.tsx

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { createStyles, makeStyles, Theme, Tooltip } from '@material-ui/core'
1+
import { createStyles, IconButton, makeStyles, Theme, Tooltip } from '@material-ui/core'
22
import Button from '@material-ui/core/Button'
33
import Card from '@material-ui/core/Card'
44
import CardActions from '@material-ui/core/CardActions'
55
import CardContent from '@material-ui/core/CardContent'
66
import Typography from '@material-ui/core/Typography'
7+
import DeleteIcon from '@material-ui/icons/Delete'
78
import { Settings } from '@sensenet/default-content-types'
89
import { useRepository } from '@sensenet/hooks-react'
910
import { clsx } from 'clsx'
@@ -12,6 +13,7 @@ import { Link, useHistory } from 'react-router-dom'
1213
import { ResponsivePersonalSettings } from '../../context'
1314
import { useLocalization } from '../../hooks'
1415
import { getPrimaryActionUrl } from '../../services'
16+
import { useDialog } from '../dialogs'
1517

1618
const useStyles = makeStyles((theme: Theme) => {
1719
return createStyles({
@@ -52,6 +54,20 @@ type ContentCardProps = {
5254
}
5355

5456
const hasDocumentation = ['Portal', 'OAuth', 'DocumentPreview', 'OfficeOnline', 'Indexing', 'Sharing']
57+
const isSystemSettings = [
58+
'OAuth',
59+
'OfficeOnline',
60+
'Indexing',
61+
'Sharing',
62+
'Logging',
63+
'Portal',
64+
'Permission',
65+
'MailProcessor',
66+
'UserProfile',
67+
'ColumnSettings',
68+
'TaskManagement',
69+
'MultiFactorAuthentication',
70+
]
5571

5672
export const ContentCard = ({ settings, onContextMenu }: ContentCardProps) => {
5773
const localization = useLocalization().settings
@@ -60,7 +76,8 @@ export const ContentCard = ({ settings, onContextMenu }: ContentCardProps) => {
6076
const history = useHistory()
6177
const classes = useStyles()
6278
const settingsName = settings.DisplayName || settings.Name
63-
const settingsTitle = settingsName.replace(/.settings/gi, '')
79+
const settingsTitle = settingsName.replace(/\.settings/gi, '')
80+
const { openDialog } = useDialog()
6481

6582
return (
6683
<Card
@@ -83,33 +100,47 @@ export const ContentCard = ({ settings, onContextMenu }: ContentCardProps) => {
83100
/>
84101
</CardContent>
85102
<CardActions style={{ justifyContent: 'flex-end' }}>
103+
{!isSystemSettings.includes(settingsTitle) && (
104+
<IconButton
105+
data-test="batch-delete"
106+
aria-label="delete"
107+
onClick={() => {
108+
openDialog({
109+
name: 'delete',
110+
props: { content: [settings] },
111+
dialogProps: { disableBackdropClick: true, disableEscapeKeyDown: true },
112+
})
113+
}}>
114+
<DeleteIcon />
115+
</IconButton>
116+
)}
86117
<Link
87118
to={getPrimaryActionUrl({ content: settings, repository, uiSettings, location: history.location })}
88119
style={{ textDecoration: 'none' }}>
89120
<Button
90121
aria-label={localization.edit}
91122
size="small"
92123
className={classes.button}
93-
style={{ marginRight: '35px' }}
124+
//style={{ marginRight: '35px' }}
94125
data-test={`${settings.Name.replace(/\s+/g, '-').toLowerCase()}-edit-button`}>
95126
{localization.edit}
96127
</Button>
97128
</Link>
98-
<a
99-
target="_blank"
100-
rel="noopener noreferrer"
101-
href={`${SETUP_DOCS_URL}${createAnchorFromName(settings.Name)}`}
102-
style={{ textDecoration: 'none' }}>
103-
{hasDocumentation.includes(settingsTitle) && (
129+
{hasDocumentation.includes(settingsTitle) && (
130+
<a
131+
target="_blank"
132+
rel="noopener noreferrer"
133+
href={`${SETUP_DOCS_URL}${createAnchorFromName(settings.Name)}`}
134+
style={{ textDecoration: 'none' }}>
104135
<Button
105136
aria-label={localization.learnMore}
106137
size="small"
107138
className={classes.button}
108139
data-test="content-card-learnmore-button">
109140
{localization.learnMore}
110141
</Button>
111-
)}
112-
</a>
142+
</a>
143+
)}
113144
</CardActions>
114145
</Card>
115146
)

0 commit comments

Comments
 (0)