Skip to content

Commit 9d9acc6

Browse files
authored
Cleanup and improve configuration page (#1584)
* Remove ".settings" from content-card's title. * Render "learn more" conditionally. * Conditional "Delete" iconbutton. * Add an e2e test conditional buttons. * fix anchor
1 parent 8d97b92 commit 9d9acc6

File tree

2 files changed

+79
-24
lines changed

2 files changed

+79
-24
lines changed

apps/sensenet/cypress/e2e/setup/setup.cy.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ describe('Setup', () => {
4242
it('should open a binary editor with the content of the "settings item" if Edit button is clicked', () => {
4343
cy.get('[data-test="content-card-documentpreview.settings"]')
4444
.within(() => {
45-
cy.get('[data-test="documentpreview.settings-edit-button"]').click()
45+
cy.get('[data-test="documentpreview-edit-button"]').click()
4646
})
4747
.get('[data-test="editor-title"]')
4848
.should('have.text', 'DocumentPreview.settings')
4949
})
5050

5151
it('should open the document of the selected "settings item" if "Learn more" button is clicked', () => {
5252
cy.get('[data-test="content-card-documentpreview.settings"]').within(() => {
53-
cy.get('[data-test="content-card-learnmore-button"]')
54-
.get('a[href="https://docs.sensenet.com/concepts/basics/07-settings#documentpreview-settings"]')
53+
cy.get('[data-test="documentpreview-learnmore-button"]')
54+
.get('a[href="https://docs.sensenet.com/guides/settings/setup#documentpreview-settings"]')
5555
.should('have.attr', 'target', '_blank')
5656
})
5757
})
@@ -86,6 +86,23 @@ describe('Setup', () => {
8686
})
8787
})
8888

89+
it('check white- and blacklisted buttons', () => {
90+
// custom settings can be deleted and never hasn't documentation
91+
cy.get(`[data-test="testsettings-delete-button"]`).should('exist')
92+
cy.get(`[data-test="testsettings-edit-button"]`).should('exist')
93+
cy.get(`[data-test="testsettings-learnmore-button"]`).should('not.exist')
94+
95+
// indexing is system and documented
96+
cy.get(`[data-test="indexing-delete-button"]`).should('not.exist')
97+
cy.get(`[data-test="indexing-edit-button"]`).should('exist')
98+
cy.get(`[data-test="indexing-learnmore-button"]`).should('exist')
99+
100+
// logging is system and not documented
101+
cy.get(`[data-test="logging-delete-button"]`).should('not.exist')
102+
cy.get(`[data-test="logging-edit-button"]`).should('exist')
103+
cy.get(`[data-test="logging-learnmore-button"]`).should('not.exist')
104+
})
105+
89106
it('should delete a setup file', () => {
90107
cy.get('[data-test="settings-container"]').then((grid) => {
91108
cy.scrollToItem({

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

Lines changed: 59 additions & 21 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({
@@ -42,21 +44,42 @@ const useStyles = makeStyles((theme: Theme) => {
4244
})
4345
})
4446

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'
4648

47-
export const createAnchorFromName = (displayName: string) => `#${displayName.replace('.', '-').toLocaleLowerCase()}`
49+
export const createAnchorFromName = (name: string) => `#${name.toLocaleLowerCase()}`
4850

4951
type ContentCardProps = {
5052
settings: Settings
5153
onContextMenu: (ev: React.MouseEvent) => void
5254
}
5355

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+
5473
export const ContentCard = ({ settings, onContextMenu }: ContentCardProps) => {
5574
const localization = useLocalization().settings
5675
const repository = useRepository()
5776
const uiSettings = useContext(ResponsivePersonalSettings)
5877
const history = useHistory()
5978
const classes = useStyles()
79+
const { openDialog } = useDialog()
80+
const settingsName = settings.DisplayName || settings.Name
81+
const settingsTitle = settingsName.replace(/\.settings/gi, '')
82+
const dataTestName = settingsTitle.replace(/\s+/g, '-').toLowerCase()
6083

6184
return (
6285
<Card
@@ -65,11 +88,11 @@ export const ContentCard = ({ settings, onContextMenu }: ContentCardProps) => {
6588
onContextMenu(ev)
6689
}}
6790
className={classes.card}
68-
data-test={`content-card-${settings.DisplayName?.replace(/\s+/g, '-').toLowerCase()}`}>
91+
data-test={`content-card-${settingsName.replace(/\s+/g, '-').toLowerCase()}`}>
6992
<CardContent>
70-
<Tooltip placement="top" title={settings.DisplayName || settings.Name}>
93+
<Tooltip placement="top" title={settingsName}>
7194
<Typography variant="h5" gutterBottom={true} className={classes.title}>
72-
{settings.DisplayName || settings.Name}
95+
{settingsTitle}
7396
</Typography>
7497
</Tooltip>
7598
<Typography
@@ -79,31 +102,46 @@ export const ContentCard = ({ settings, onContextMenu }: ContentCardProps) => {
79102
/>
80103
</CardContent>
81104
<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+
)}
82119
<Link
83120
to={getPrimaryActionUrl({ content: settings, repository, uiSettings, location: history.location })}
84121
style={{ textDecoration: 'none' }}>
85122
<Button
86123
aria-label={localization.edit}
87124
size="small"
88125
className={classes.button}
89-
style={{ marginRight: '35px' }}
90-
data-test={`${settings.Name.replace(/\s+/g, '-').toLowerCase()}-edit-button`}>
126+
data-test={`${dataTestName}-edit-button`}>
91127
{localization.edit}
92128
</Button>
93129
</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+
)}
107145
</CardActions>
108146
</Card>
109147
)

0 commit comments

Comments
 (0)