1
- import { createStyles , makeStyles , Theme , Tooltip } from '@material-ui/core'
1
+ import { createStyles , IconButton , makeStyles , Theme , Tooltip } from '@material-ui/core'
2
2
import Button from '@material-ui/core/Button'
3
3
import Card from '@material-ui/core/Card'
4
4
import CardActions from '@material-ui/core/CardActions'
5
5
import CardContent from '@material-ui/core/CardContent'
6
6
import Typography from '@material-ui/core/Typography'
7
+ import DeleteIcon from '@material-ui/icons/Delete'
7
8
import { Settings } from '@sensenet/default-content-types'
8
9
import { useRepository } from '@sensenet/hooks-react'
9
10
import { clsx } from 'clsx'
@@ -12,6 +13,7 @@ import { Link, useHistory } from 'react-router-dom'
12
13
import { ResponsivePersonalSettings } from '../../context'
13
14
import { useLocalization } from '../../hooks'
14
15
import { getPrimaryActionUrl } from '../../services'
16
+ import { useDialog } from '../dialogs'
15
17
16
18
const useStyles = makeStyles ( ( theme : Theme ) => {
17
19
return createStyles ( {
@@ -42,21 +44,42 @@ const useStyles = makeStyles((theme: Theme) => {
42
44
} )
43
45
} )
44
46
45
- export const SETUP_DOCS_URL = 'https://docs.sensenet.com/concepts/basics/07- settings'
47
+ export const SETUP_DOCS_URL = 'https://docs.sensenet.com/guides/ settings/setup '
46
48
47
- export const createAnchorFromName = ( displayName : string ) => `#${ displayName . replace ( '.' , '-' ) . toLocaleLowerCase ( ) } `
49
+ export const createAnchorFromName = ( name : string ) => `#${ name . toLocaleLowerCase ( ) } `
48
50
49
51
type ContentCardProps = {
50
52
settings : Settings
51
53
onContextMenu : ( ev : React . MouseEvent ) => void
52
54
}
53
55
56
+ const hasDocumentation = [ 'Portal' , 'OAuth' , 'DocumentPreview' , 'OfficeOnline' , 'Indexing' , 'Sharing' ]
57
+ const isSystemSettings = [
58
+ 'DocumentPreview' ,
59
+ 'OAuth' ,
60
+ 'OfficeOnline' ,
61
+ 'Indexing' ,
62
+ 'Sharing' ,
63
+ 'Logging' ,
64
+ 'Portal' ,
65
+ 'Permission' ,
66
+ 'MailProcessor' ,
67
+ 'UserProfile' ,
68
+ 'ColumnSettings' ,
69
+ 'TaskManagement' ,
70
+ 'MultiFactorAuthentication' ,
71
+ ]
72
+
54
73
export const ContentCard = ( { settings, onContextMenu } : ContentCardProps ) => {
55
74
const localization = useLocalization ( ) . settings
56
75
const repository = useRepository ( )
57
76
const uiSettings = useContext ( ResponsivePersonalSettings )
58
77
const history = useHistory ( )
59
78
const classes = useStyles ( )
79
+ const { openDialog } = useDialog ( )
80
+ const settingsName = settings . DisplayName || settings . Name
81
+ const settingsTitle = settingsName . replace ( / \. s e t t i n g s / gi, '' )
82
+ const dataTestName = settingsTitle . replace ( / \s + / g, '-' ) . toLowerCase ( )
60
83
61
84
return (
62
85
< Card
@@ -65,11 +88,11 @@ export const ContentCard = ({ settings, onContextMenu }: ContentCardProps) => {
65
88
onContextMenu ( ev )
66
89
} }
67
90
className = { classes . card }
68
- data-test = { `content-card-${ settings . DisplayName ? .replace ( / \s + / g, '-' ) . toLowerCase ( ) } ` } >
91
+ data-test = { `content-card-${ settingsName . replace ( / \s + / g, '-' ) . toLowerCase ( ) } ` } >
69
92
< CardContent >
70
- < Tooltip placement = "top" title = { settings . DisplayName || settings . Name } >
93
+ < Tooltip placement = "top" title = { settingsName } >
71
94
< Typography variant = "h5" gutterBottom = { true } className = { classes . title } >
72
- { settings . DisplayName || settings . Name }
95
+ { settingsTitle }
73
96
</ Typography >
74
97
</ Tooltip >
75
98
< Typography
@@ -79,31 +102,46 @@ export const ContentCard = ({ settings, onContextMenu }: ContentCardProps) => {
79
102
/>
80
103
</ CardContent >
81
104
< CardActions style = { { justifyContent : 'flex-end' } } >
105
+ { ! isSystemSettings . includes ( settingsTitle ) && (
106
+ < IconButton
107
+ data-test = { `${ dataTestName } -delete-button` }
108
+ aria-label = "delete"
109
+ onClick = { ( ) => {
110
+ openDialog ( {
111
+ name : 'delete' ,
112
+ props : { content : [ settings ] } ,
113
+ dialogProps : { disableBackdropClick : true , disableEscapeKeyDown : true } ,
114
+ } )
115
+ } } >
116
+ < DeleteIcon />
117
+ </ IconButton >
118
+ ) }
82
119
< Link
83
120
to = { getPrimaryActionUrl ( { content : settings , repository, uiSettings, location : history . location } ) }
84
121
style = { { textDecoration : 'none' } } >
85
122
< Button
86
123
aria-label = { localization . edit }
87
124
size = "small"
88
125
className = { classes . button }
89
- style = { { marginRight : '35px' } }
90
- data-test = { `${ settings . Name . replace ( / \s + / g, '-' ) . toLowerCase ( ) } -edit-button` } >
126
+ data-test = { `${ dataTestName } -edit-button` } >
91
127
{ localization . edit }
92
128
</ Button >
93
129
</ Link >
94
- < a
95
- target = "_blank"
96
- rel = "noopener noreferrer"
97
- href = { `${ SETUP_DOCS_URL } ${ createAnchorFromName ( settings . DisplayName ? settings . DisplayName : '' ) } ` }
98
- style = { { textDecoration : 'none' } } >
99
- < Button
100
- aria-label = { localization . learnMore }
101
- size = "small"
102
- className = { classes . button }
103
- data-test = "content-card-learnmore-button" >
104
- { localization . learnMore }
105
- </ Button >
106
- </ a >
130
+ { hasDocumentation . includes ( settingsTitle ) && (
131
+ < a
132
+ target = "_blank"
133
+ rel = "noopener noreferrer"
134
+ href = { `${ SETUP_DOCS_URL } ${ createAnchorFromName ( settings . Name ) } ` }
135
+ style = { { textDecoration : 'none' } } >
136
+ < Button
137
+ aria-label = { localization . learnMore }
138
+ size = "small"
139
+ className = { classes . button }
140
+ data-test = { `${ dataTestName } -learnmore-button` } >
141
+ { localization . learnMore }
142
+ </ Button >
143
+ </ a >
144
+ ) }
107
145
</ CardActions >
108
146
</ Card >
109
147
)
0 commit comments