Skip to content

Commit

Permalink
Merge branch 'develop' into feature/Shortcut-panel-in-reference-picker
Browse files Browse the repository at this point in the history
  • Loading branch information
hassanad94 authored Nov 20, 2023
2 parents 59e0252 + 14d7b49 commit 6aee70d
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 110 deletions.
24 changes: 24 additions & 0 deletions apps/sensenet/cypress/e2e/content-types/switcher.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { PATHS, resolvePathParams } from '../../../src/application-paths'
import { pathWithQueryParams } from '../../../src/services/query-string-builder'

const contextMenuItems = ['browse', 'copyto', 'edit', 'moveto', 'delete']
describe('Groups', () => {
before(() => {
cy.login()
cy.visit(
pathWithQueryParams({
path: resolvePathParams({ path: PATHS.contentTypes.appPath, params: { browseType: 'explorer' } }),
newParams: { repoUrl: Cypress.env('repoUrl') },
}),
)
//cy.get('[data-test="groups"]').click()
})
it('Switch should reveal hidden types', () => {
cy.get('[data-test="table-cell-application"]').should('not.exist')
cy.get('[data-test="hidden-type-switch"]')
.click()
.then(() => {
cy.get('[data-test="table-cell-application"]').should('exist')
})
})
})
48 changes: 48 additions & 0 deletions apps/sensenet/cypress/e2e/search/search.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,52 @@ describe('Search', () => {
.then((fullname) => expect(fullname).to.eq('Business Cat'))
})
})

context('more contentTypes filter', () => {
const term = 'admin*'
before(() => {
cy.login()
cy.visit(pathWithQueryParams({ path: '/', newParams: { repoUrl: Cypress.env('repoUrl') } }))
})
beforeEach(() => {
cy.get('[data-test="sensenet-logo"]').click()
cy.get('[data-test="search-button"]')
.click()
.get('[data-test="command-box"] input')
.type(term, { delay: 250 })
.get('[data-test="search-suggestion-list"] ul')
.children()
.as('search')
.first()
.click()
.location()
.should((loc) => {
expect(loc.pathname).to.eq(PATHS.search.appPath)
expect(loc.search).to.eq(`?term=${term}`)
})
})

it('result contains users and groups', () => {
cy.get('[data-test="table-cell-admin"]').should('exist')
cy.get('[data-test="table-cell-administrators"]').should('exist')
cy.get('[data-test="table-cell-captain-picard"]').should('not.exist')
})

it('the "more" menu contains more than 20 items including "group" and "user"', () => {
cy.get('[data-test="more-type-filter-button"]').click()
cy.get('[id="more-type-filter"]').contains('li', 'User')
cy.get('[id="more-type-filter"]').contains('li', 'Group')
cy.get('[data-test="more-menu-item-user"]').parent().children().its('length').should('be.gt', 20)
// press <ESC> to hide the menu to unblock the UI
cy.get('body').trigger('keydown', { keyCode: 27 })
})

it('result contains one user after use the filter', () => {
cy.get('[data-test="more-type-filter-button"]').click().get('[data-test="more-menu-item-user"]').click()
// "MORE" changed to "USER"
cy.get('[data-test="more-type-filter-button"]').contains('User')
// "Administrators" disappeared
cy.get('[data-test="table-cell-administrators"]').should('not.exist')
})
})
})
23 changes: 20 additions & 3 deletions apps/sensenet/cypress/e2e/setup/setup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ describe('Setup', () => {
it('should open a binary editor with the content of the "settings item" if Edit button is clicked', () => {
cy.get('[data-test="content-card-documentpreview.settings"]')
.within(() => {
cy.get('[data-test="documentpreview.settings-edit-button"]').click()
cy.get('[data-test="documentpreview-edit-button"]').click()
})
.get('[data-test="editor-title"]')
.should('have.text', 'DocumentPreview.settings')
})

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

it('check white- and blacklisted buttons', () => {
// custom settings can be deleted and never hasn't documentation
cy.get(`[data-test="testsettings-delete-button"]`).should('exist')
cy.get(`[data-test="testsettings-edit-button"]`).should('exist')
cy.get(`[data-test="testsettings-learnmore-button"]`).should('not.exist')

// indexing is system and documented
cy.get(`[data-test="indexing-delete-button"]`).should('not.exist')
cy.get(`[data-test="indexing-edit-button"]`).should('exist')
cy.get(`[data-test="indexing-learnmore-button"]`).should('exist')

// logging is system and not documented
cy.get(`[data-test="logging-delete-button"]`).should('not.exist')
cy.get(`[data-test="logging-edit-button"]`).should('exist')
cy.get(`[data-test="logging-learnmore-button"]`).should('not.exist')
})

it('should delete a setup file', () => {
cy.get('[data-test="settings-container"]').then((grid) => {
cy.scrollToItem({
Expand Down
30 changes: 4 additions & 26 deletions apps/sensenet/src/components/MainRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const TrashComponent = lazy(() => import(/* webpackChunkName: "Trash" */ './tras
const EventListComponent = lazy(() => import(/* webpackChunkName: "EventList" */ './event-list/event-list'))
const CustomContent = lazy(() => import(/* webpackChunkName: "CustomContent" */ './content/CustomContent'))
const SettingsComponent = lazy(() => import(/* webpackChunkName: "setup" */ './settings'))
const ContentTypeListComponent = lazy(
() => import(/* webpackChunkName: "contenttypes" */ './content-list/contenttype-list'),
)

export const MainRouter = () => {
return (
Expand Down Expand Up @@ -63,32 +66,7 @@ export const MainRouter = () => {
</Route>

<Route path={PATHS.contentTypes.appPath}>
<ContentComponent
rootPath={PATHS.contentTypes.snPath}
fieldsToDisplay={[
{ field: 'DisplayName' },
{ field: 'Name' },
{ field: 'Description' },
{ field: 'ParentTypeName' as any },
{ field: 'ModificationDate' },
{ field: 'ModifiedBy' },
]}
loadChildrenSettings={{
select: [
'DisplayName',
'Name',
'Description',
'ParentTypeName' as any,
'ModificationDate',
'ModifiedBy',
],
query: "+TypeIs:'ContentType' .AUTOFILTERS:OFF",
inlinecount: 'allpages',
top: 1000,
}}
hasTree={false}
alwaysRefreshChildren={true}
/>
<ContentTypeListComponent />
</Route>

<Route path={PATHS.dashboard.appPath}>
Expand Down
15 changes: 15 additions & 0 deletions apps/sensenet/src/components/content-list/content-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,23 @@ export const ContentList = <T extends GenericContent = GenericContent>(props: Co
setActiveContent(rowMouseEventHandlerParams.rowData)
handleItemClick(rowMouseEventHandlerParams)
},
rowStyle: {
position: 'static',
top: 'auto',
height: 'auto',
overflow: 'initial',
padding: '5px 0px',
},
onRowDoubleClick: onItemDoubleClickFunc,
disableHeader: props.hideHeader,
containerStyle: {
height: '100%',
display: 'flex',
flexDirection: 'column',
overflowY: 'auto',
maxHeight: '100%',
paddingBottom: '15px',
},
}}
/>
{activeContent ? (
Expand Down
63 changes: 63 additions & 0 deletions apps/sensenet/src/components/content-list/contenttype-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { lazy, useState } from 'react'
import { PATHS } from '../../application-paths'
import { Switch } from '@sensenet/controls-react'
import { useRepository } from '@sensenet/hooks-react'

const ContentComponent = lazy(() => import(/* webpackChunkName: "content" */ '../content'))

const ContentTypeList: React.FC = () => {
const repository = useRepository()
const [showHiddenTypes, setShowHiddenTypes] = useState(false)
const categoryField = repository.schemas.getFieldTypeByName('Categories')
const isCategoryFieldAvailable = categoryField !== undefined

const renderBeforeGrid = () => {
if (!isCategoryFieldAvailable) {
return <></>
}

return (
<div style={{ marginTop: '20px', marginBottom: '20px' }}>
<label htmlFor="showHiddenTypes" style={{ marginRight: '10px' }}>
Show hidden types
</label>
<Switch
data-test="hidden-type-switch"
size="medium"
checked={showHiddenTypes}
onChange={() => setShowHiddenTypes(!showHiddenTypes)}
/>
</div>
)
}

const contentTypeQuery =
"+TypeIs:'ContentType'" +
(isCategoryFieldAvailable && !showHiddenTypes ? ' -Categories:*HideByDefault*' : '') +
' .AUTOFILTERS:OFF'

return (
<ContentComponent
renderBeforeGrid={renderBeforeGrid}
rootPath={PATHS.contentTypes.snPath}
fieldsToDisplay={[
{ field: 'DisplayName' },
{ field: 'Name' },
{ field: 'Description' },
{ field: 'ParentTypeName' as any },
{ field: 'ModificationDate' },
{ field: 'ModifiedBy' },
]}
loadChildrenSettings={{
select: ['DisplayName', 'Name', 'Description', 'ParentTypeName' as any, 'ModificationDate', 'ModifiedBy'],
query: contentTypeQuery,
inlinecount: 'allpages',
top: 1000,
}}
hasTree={false}
alwaysRefreshChildren={true}
/>
)
}

export default ContentTypeList
79 changes: 63 additions & 16 deletions apps/sensenet/src/components/search/filters/type-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import Image from '@material-ui/icons/Image'
import InsertDriveFile from '@material-ui/icons/InsertDriveFile'
import Person from '@material-ui/icons/Person'
import Search from '@material-ui/icons/Search'
import React, { useState } from 'react'
import { ConstantContent } from '@sensenet/client-core'
import { GenericContent } from '@sensenet/default-content-types'
import { useRepository } from '@sensenet/hooks-react'
import React, { useEffect, useState } from 'react'
import { useSearch } from '../../../context/search'
import { useLocalization } from '../../../hooks'

Expand Down Expand Up @@ -75,14 +78,54 @@ const useStyles = makeStyles(() => {
})
})

type moreOptionsItem = {
name: string
type: string
}

export const TypeFilter = () => {
const repo = useRepository()
const classes = useStyles()
const localization = useLocalization().search.filters.type
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null)

const searchState = useSearch()
const [otherContentTypes, setOtherContentTypes] = useState<moreOptionsItem[]>([])

useEffect(() => {
const ac = new AbortController()
const categoryField = repo.schemas.getFieldTypeByName('Categories')
const fetchData = async () => {
try {
if (categoryField) {
const response = await repo.loadCollection<GenericContent>({
path: ConstantContent.PORTAL_ROOT.Path,
oDataOptions: {
query: "-Categories:'*HideByDefault*' +TypeIs:'ContentType' .AUTOFILTERS:OFF",
select: ['Type', 'DisplayName'],
orderby: 'Name',
},
requestInit: { signal: ac.signal },
})
const items: moreOptionsItem[] = response.d.results.map((item) => ({
name: item.DisplayName ?? item.Name,
type: item.Name,
}))
setOtherContentTypes(items)
} else {
setOtherContentTypes(moreOptions)
}
} catch (error) {
console.error('Error fetching data:', error)
}
}
fetchData()

return () => {
ac.abort()
}
}, [repo])

const [[activeFromMore], othersFromMore] = moreOptions.reduce(
const [[activeFromMore], othersFromMore] = otherContentTypes.reduce(
([pass, fail], filter) => {
return filter.name === searchState.filters.type.name ? [[...pass, filter], fail] : [pass, [...fail, filter]]
},
Expand All @@ -108,6 +151,7 @@ export const TypeFilter = () => {
))}

<Button
data-test="more-type-filter-button"
aria-controls="more-type-filter"
aria-haspopup="true"
variant="outlined"
Expand All @@ -116,7 +160,7 @@ export const TypeFilter = () => {
onClick={(event) => {
setAnchorEl(event.currentTarget)
}}>
{activeFromMore ? localization[activeFromMore.name as keyof typeof localization] : localization.more}
{activeFromMore ? activeFromMore.name : localization.more}
</Button>
<Menu
id="more-type-filter"
Expand All @@ -133,18 +177,21 @@ export const TypeFilter = () => {
vertical: 'top',
horizontal: 'right',
}}>
{(othersFromMore as Filter[]).map((filter) => (
<MenuItem
key={filter.name}
onClick={() => {
setAnchorEl(null)
searchState.setFilters((filters) =>
filters.type.name === filter.name ? filters : { ...filters, type: filter },
)
}}>
{localization[filter.name as keyof typeof localization]}
</MenuItem>
))}
{(othersFromMore as Filter[])
.sort((a, b) => a.name.localeCompare(b.name))
.map((filter) => (
<MenuItem
key={filter.name}
data-test={`more-menu-item-${filter.name.toLowerCase()}`}
onClick={() => {
setAnchorEl(null)
searchState.setFilters((filters) =>
filters.type.name === filter.name ? filters : { ...filters, type: filter },
)
}}>
{filter.name}
</MenuItem>
))}
</Menu>
</div>
)
Expand Down
16 changes: 7 additions & 9 deletions apps/sensenet/src/components/search/search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ export const SearchBar = () => {
className={classes.inputButton}
aria-label={localization.clearTerm}
title={localization.clearTerm}
onClick={() => null}>
<Cancel
onClick={() => {
if (searchInputRef.current) {
searchInputRef.current.value = ''
}
searchState.setTerm('')
}}
/>
onClick={() => {
if (searchInputRef.current) {
searchInputRef.current.value = ''
}
searchState.setTerm('')
}}>
<Cancel />
</IconButton>
)}
<IconButton
Expand Down
Loading

0 comments on commit 6aee70d

Please sign in to comment.