Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide settings folder option #1616

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 60 additions & 4 deletions apps/sensenet/src/components/appbar/desktop-nav-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Grid, IconButton, ListItemIcon, ListItemText, MenuItem, MenuList, Paper, Typography } from '@material-ui/core'
import ClickAwayListener from '@material-ui/core/ClickAwayListener'
import { createStyles, makeStyles, Theme, useTheme } from '@material-ui/core/styles'
import { TuneOutlined } from '@material-ui/icons'
import KeyboardArrowDown from '@material-ui/icons/KeyboardArrowDown'
import { Switch } from '@sensenet/controls-react'
import { useInjector, useRepository } from '@sensenet/hooks-react'
Expand All @@ -17,6 +18,10 @@ import { UserAvatar } from '../UserAvatar'

const useStyles = makeStyles((theme: Theme) =>
createStyles({
viewOptions: {
cursor: 'pointer',
marginRight: '16px',
},
navMenu: {
height: '100%',
width: '140px',
Expand All @@ -38,6 +43,13 @@ const useStyles = makeStyles((theme: Theme) =>
height: 'fit-content',
width: '216px',
},
popperViewWrapper: {
position: 'absolute',
top: globals.common.headerHeight,
right: '1px',
height: 'fit-content',
width: '256px',
},
popper: {
backgroundColor: theme.palette.type === 'light' ? globals.light.navMenuColor : globals.dark.navMenuColor,
border: theme.palette.type === 'light' ? clsx(globals.light.borderColor, '1px') : 'none',
Expand All @@ -52,7 +64,7 @@ const useStyles = makeStyles((theme: Theme) =>
color: theme.palette.primary.main,
fontSize: '14px',
},
themeSwitcher: {
checkboxMenuItem: {
color: theme.palette.primary.main,
fontSize: '14px',
'& .MuiButtonBase-root': {
Expand All @@ -75,6 +87,7 @@ export const DesktopNavMenu: FunctionComponent = () => {
const localization = useLocalization()
const { openDialog } = useDialog()
const [openUserMenu, setOpenUserMenu] = useState(false)
const [openViewOptions, setOpenViewOptions] = useState(false)

const handleToggle = (setter: Dispatch<SetStateAction<boolean>>) => {
setter((prevState) => !prevState)
Expand All @@ -99,9 +112,21 @@ export const DesktopNavMenu: FunctionComponent = () => {
service.setPersonalSettingsValue({ ...settings, theme: event.target.checked ? 'dark' : 'light' })
}

const toggleHideSettingsFolder = () => (event: ChangeEvent<HTMLInputElement>) => {
const settings = service.userValue.getValue()
service.setPersonalSettingsValue({ ...settings, showHiddenItems: event.target.checked })
}

return (
<div className={clsx(globalClasses.centered, classes.navMenu)}>
<>
<IconButton
aria-label={localization.topMenu.openViewOptions}
aria-controls={openViewOptions ? 'menu-list-grow' : undefined}
className={classes.viewOptions}
onClick={() => handleToggle(setOpenViewOptions)}>
<TuneOutlined />
</IconButton>
<UserAvatar
user={currentUser}
repositoryUrl={repo.configuration.repositoryUrl}
Expand Down Expand Up @@ -185,10 +210,25 @@ export const DesktopNavMenu: FunctionComponent = () => {
<MenuItem onClick={logout} className={classes.userMenuItem}>
{localization.topMenu.logout}
</MenuItem>
</MenuList>
</ClickAwayListener>
</div>
</Paper>
) : null}
{openViewOptions ? (
<Paper className={classes.popperViewWrapper}>
<div className={classes.popper}>
<ClickAwayListener onClickAway={() => handleClose(setOpenViewOptions)}>
<MenuList autoFocusItem={openViewOptions} id="menu-list-grow">
<MenuItem onClick={() => handleClose(setOpenViewOptions)}>
<Typography component="div" style={{ margin: '0 auto' }}>
{localization.topMenu.viewOptions}
</Typography>
</MenuItem>
<MenuItem>
<Typography component="div" className={classes.themeSwitcher}>
<Grid component="label" container alignItems="center" spacing={1}>
<Grid item style={{ paddingRight: '32px' }} data-test="theme-status">
<Typography component="div" className={classes.checkboxMenuItem} style={{ width: '100%' }}>
<Grid component="label" container alignItems="center" justify="space-between">
<Grid item style={{ paddingRight: '16px' }} data-test="theme-status">
{personalSettings.theme === 'dark' ? 'Light theme' : 'Dark theme'}
</Grid>
<Grid item>
Expand All @@ -201,6 +241,22 @@ export const DesktopNavMenu: FunctionComponent = () => {
</Grid>
</Typography>
</MenuItem>
<MenuItem>
<Typography component="div" className={classes.checkboxMenuItem} style={{ width: '100%' }}>
<Grid component="label" container alignItems="center" justify="space-between">
<Grid item style={{ paddingRight: '16px' }}>
{localization.topMenu.showHiddenItems}
</Grid>
<Grid item>
<Switch
data-test="hide-settings-folder-checkbox"
checked={personalSettings.showHiddenItems}
onChange={toggleHideSettingsFolder()}
/>
</Grid>
</Grid>
</Typography>
</MenuItem>
</MenuList>
</ClickAwayListener>
</div>
Expand Down
15 changes: 13 additions & 2 deletions apps/sensenet/src/components/content-list/content-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import React, {
import { TableCellProps } from 'react-virtualized'
import { ResponsiveContext, ResponsivePersonalSettings } from '../../context'
import { globals, useGlobalStyles } from '../../globalStyles'
import { useLocalization, useSelectionService } from '../../hooks'
import { useLocalization, usePersonalSettings, useSelectionService } from '../../hooks'
import { ContentBreadcrumbs } from '../ContentBreadcrumbs'
import { ContentContextMenu } from '../context-menu/content-context-menu'
import { useDialog } from '../dialogs'
import { DropFileArea } from '../DropFileArea'
import { SelectionControl } from '../SelectionControl'
import { SETTINGS_FOLDER_FILTER } from '../tree/tree-with-data'
import { ContextMenuWrapper } from './context-menu-wrapper'
import {
ActionsField,
Expand Down Expand Up @@ -124,6 +125,7 @@ export const ContentList = <T extends GenericContent = GenericContent>(props: Co
const ancestors = useContext(CurrentAncestorsContext) as T[]
const device = useContext(ResponsiveContext)
const personalSettings = useContext(ResponsivePersonalSettings)
const userPersonalSettings = usePersonalSettings()
const loadSettings = useContext(LoadSettingsContext)
const repo = useRepository()
const classes = useStyles()
Expand Down Expand Up @@ -266,9 +268,18 @@ export const ContentList = <T extends GenericContent = GenericContent>(props: Co
}, []),
],
orderby: [[currentOrder as any, currentDirection as any]],
filter: !userPersonalSettings.showHiddenItems ? `(${SETTINGS_FOLDER_FILTER})` : '',
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentDirection, currentOrder, personalSettings.content.fields, props.fieldsToDisplay, repo, columnSettings])
}, [
currentDirection,
currentOrder,
personalSettings.content.fields,
userPersonalSettings.showHiddenItems,
props.fieldsToDisplay,
repo,
columnSettings,
])

useEffect(() => {
setSelected([])
Expand Down
21 changes: 13 additions & 8 deletions apps/sensenet/src/components/tree/tree-with-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GenericContent } from '@sensenet/default-content-types'
import { useLogger, useRepository, useRepositoryEvents } from '@sensenet/hooks-react'
import React, { useCallback, useEffect, useState } from 'react'
import Semaphore from 'semaphore-async-await'
import { usePreviousValue, useSelectionService } from '../../hooks'
import { usePersonalSettings, usePreviousValue, useSelectionService } from '../../hooks'
import { ItemType, Tree } from './tree'

type TreeWithDataProps = {
Expand All @@ -18,6 +18,7 @@ type TreeWithDataProps = {
let lastRequest: { path: string; lastIndex: number } | undefined

const ITEM_THRESHOLD = 50
export const SETTINGS_FOLDER_FILTER = `not ((Name eq 'Settings') and (isOf('SystemFolder')))`

const walkTree = (node: ItemType, callBack: (node: ItemType) => void) => {
if (node?.children?.length) {
Expand All @@ -31,6 +32,7 @@ const lock = new Semaphore(1)

export default function TreeWithData(props: TreeWithDataProps) {
const repo = useRepository()
const personalSettings = usePersonalSettings()
const [itemCount, setItemCount] = useState(0)
const [treeData, setTreeData] = useState<ItemType>()
const [isLoading, setIsLoading] = useState(false)
Expand All @@ -39,6 +41,7 @@ export default function TreeWithData(props: TreeWithDataProps) {
const logger = useLogger('tree-with-data')

const prevActiveItemPath = usePreviousValue(props.activeItemPath)
const prevShowHiddenItems = usePreviousValue(personalSettings.showHiddenItems)
const { onTreeLoadingChange } = props

const loadCollection = useCallback(
Expand All @@ -55,7 +58,7 @@ export default function TreeWithData(props: TreeWithDataProps) {
oDataOptions: {
top,
skip,
filter: 'IsFolder eq true',
filter: `IsFolder eq true ${!personalSettings.showHiddenItems ? `and (${SETTINGS_FOLDER_FILTER})` : ''}`,
orderby: [
['DisplayName', 'asc'],
['Name', 'asc'],
Expand All @@ -72,7 +75,7 @@ export default function TreeWithData(props: TreeWithDataProps) {
setIsLoading(false)
}
},
[logger, repo, onTreeLoadingChange],
[onTreeLoadingChange, repo, personalSettings.showHiddenItems, logger],
)

useEffect(() => {
Expand All @@ -97,7 +100,6 @@ export default function TreeWithData(props: TreeWithDataProps) {
const openTree = useCallback(
async (forced = false) => {
if (!forced && treeData && treeData.Path === props.parentPath) return

const buildTree = (items: GenericContent[], id?: number): any => {
if (!id) {
return { ...items[0], children: buildTree(items, items[0].Id), hasNextPage: false, expanded: true }
Expand All @@ -118,7 +120,10 @@ export default function TreeWithData(props: TreeWithDataProps) {
idOrPath: props.activeItemPath,
name: 'OpenTree',
method: 'GET',
oDataOptions: props.loadSettings,
oDataOptions: {
...props.loadSettings,
filter: !personalSettings.showHiddenItems ? SETTINGS_FOLDER_FILTER : '',
},
body: {
rootPath: props.parentPath,
withSystem: true,
Expand All @@ -132,7 +137,7 @@ export default function TreeWithData(props: TreeWithDataProps) {
setTreeData(undefined)
}
},
[props.activeItemPath, props.parentPath, repo, treeData, props.loadSettings],
[treeData, props.parentPath, props.activeItemPath, props.loadSettings, repo, personalSettings.showHiddenItems],
)

const loadMoreItems = useCallback(
Expand Down Expand Up @@ -279,8 +284,8 @@ export default function TreeWithData(props: TreeWithDataProps) {
])

useEffect(() => {
openTree()
}, [openTree])
openTree(personalSettings.showHiddenItems !== prevShowHiddenItems)
}, [openTree, personalSettings.showHiddenItems, prevShowHiddenItems])

const onItemClick = async (item: ItemType) => {
if (!treeData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const useStyles = makeStyles(() => {
color: 'grey',
marginLeft: '5px',
},

actionText: {
marginRight: '5px',
},
viewTitle: {
'& span': {
display: 'inline-block',
Expand Down Expand Up @@ -76,7 +78,8 @@ export const ViewTitle: React.FunctionComponent<ViewTitleProps> = (props) => {
return (
<div className={clsx(classes.title, globalClasses.centered)}>
<div data-test="viewtitle" className={classes.viewTitle}>
{props.title} <span className={classes.textBolder}>{props.titleBold}</span>
<span className={classes.actionText}>{props.title}</span>
<span className={classes.textBolder}>{props.titleBold}</span>
<span className={classes.typeinfo}>({props.content!.Type})</span>
</div>
<div className={classes.actionBar}>
Expand Down
3 changes: 3 additions & 0 deletions apps/sensenet/src/localization/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ const values = {
openUserMenu: 'Open user menu',
openNewMenu: `What's new`,
accountSettings: 'Account settings',
openViewOptions: 'Open view options',
showHiddenItems: 'Show hidden items',
viewOptions: 'View options',
},
navigationCommandProvider: {
personalSettingsPrimary: 'Personal Settings',
Expand Down
3 changes: 3 additions & 0 deletions apps/sensenet/src/localization/hungarian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ const values: Localization = {
openUserMenu: 'Felhasználói menü kinyitása',
openNewMenu: 'Újdonságok',
accountSettings: 'Felhasználói beállítások',
openViewOptions: 'Felületi beállítások kinyitása',
showHiddenItems: 'Rejtett elemek megj.',
viewOptions: 'Felület beállítások',
},
settings: {
edit: 'Módosítás',
Expand Down
2 changes: 2 additions & 0 deletions apps/sensenet/src/services/PersonalSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface CustomContentDrawerItem
export type PersonalSettingsType = PlatformDependent<UiSettings> & {
eventLogSize: number
sendLogWithCrashReports: boolean
showHiddenItems: boolean
logLevel: Array<keyof typeof LogLevel>
language: 'default' | 'hungarian'
theme: 'light' | 'dark'
Expand Down Expand Up @@ -138,6 +139,7 @@ export const defaultSettings: PersonalSettingsType = {
sendLogWithCrashReports: true,
logLevel: ['Information', 'Warning', 'Error', 'Fatal'],
theme: prefersDark ? 'dark' : 'light',
showHiddenItems: true,
uploadHandlers: [
'SenseNet.ContentRepository.File',
'SenseNet.ContentRepository.Image',
Expand Down
Loading