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

Feature/tree actions #1575

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
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
71 changes: 71 additions & 0 deletions apps/sensenet/src/components/ContentBreadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ const useStyles = makeStyles((theme: Theme) => {
},
marginLeft: 'auto',
},
treeActionWrapper: {
marginRight: '7.5%',
' & .MuiIconButton-root': {
color: theme.palette.type === 'light' ? theme.palette.common.black : theme.palette.common.white,
},
// marginLeft: '10px',
borderLeft: theme.palette.type === 'light' ? '1px solid #DBDBDB' : '1px solid rgba(255, 255, 255, 0.11)',
},
})
})

type ContentBreadcrumbsProps<T extends GenericContent> = {
onItemClick?: (item: BreadcrumbItem<T>) => void
batchActions?: boolean
treeActions?: boolean
}

export const ContentBreadcrumbs = <T extends GenericContent = GenericContent>(props: ContentBreadcrumbsProps<T>) => {
Expand Down Expand Up @@ -78,6 +87,68 @@ export const ContentBreadcrumbs = <T extends GenericContent = GenericContent>(pr
: history.push(getPrimaryActionUrl({ content: item.content, repository, uiSettings, location }))
}}
/>
{props.treeActions && selected.length > 0 ? (
<div className={classes.treeActionWrapper} data-test="tree-actions">
<Tooltip title={localization.treeActions.delete} placement="bottom">
<IconButton
data-test="tree-delete"
aria-label="delete"
onClick={() => {
openDialog({
name: 'delete',
props: { content: selected },
dialogProps: { disableBackdropClick: true, disableEscapeKeyDown: true },
})
}}>
<DeleteIcon />
</IconButton>
</Tooltip>
<Tooltip title={localization.treeActions.move} placement="bottom">
<IconButton
data-test="tree-move"
aria-label="move"
onClick={() => {
openDialog({
name: 'copy-move',
props: {
content: selected,
currentParent: parent,
operation: 'move',
},
dialogProps: {
disableBackdropClick: true,
disableEscapeKeyDown: true,
classes: { paper: globalClasses.pickerDialog },
},
})
}}>
<FileCopyIcon />
</IconButton>
</Tooltip>
<Tooltip title={localization.treeActions.copy} placement="bottom">
<IconButton
data-test="tree-copy"
aria-label="copy"
onClick={() => {
openDialog({
name: 'copy-move',
props: {
content: selected,
currentParent: parent,
operation: 'copy',
},
dialogProps: {
disableBackdropClick: true,
disableEscapeKeyDown: true,
classes: { paper: globalClasses.pickerDialog },
},
})
}}>
<FileCopyOutlinedIcon />
</IconButton>
</Tooltip>
</div>
) : null}
{props.batchActions && selected.length > 0 ? (
<div className={classes.batchActionWrapper} data-test="batch-actions">
<Tooltip title={localization.batchActions.delete} placement="bottom">
Expand Down
9 changes: 8 additions & 1 deletion apps/sensenet/src/components/content/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@sensenet/hooks-react'
import { ColumnSetting } from '@sensenet/list-controls-react/src/ContentList/content-list-base-props'
import { clsx } from 'clsx'
import React, { useCallback, useContext, useState } from 'react'
import React, { useCallback, useContext, useEffect, useState } from 'react'
import { useHistory } from 'react-router'
import { ResponsivePersonalSettings } from '../../context'
import { globals, useGlobalStyles } from '../../globalStyles'
Expand Down Expand Up @@ -96,6 +96,7 @@ export function Explore({
const pathFromUrl = useQuery().get('path')
const snRoute = useSnRoute()
const activeAction = snRoute.match!.params.action
const [selected, setSelected] = useState<GenericContent[]>([])

const onActivateItemOverride = async (activeItem: GenericContent) => {
const expandedItem = await repository.load({
Expand Down Expand Up @@ -186,6 +187,10 @@ export function Explore({
)
}

useEffect(() => {
selectionService.selection.setValue(selected)
}, [selected, selectionService.selection])

return (
<LoadSettingsContextProvider>
<CurrentContentProvider idOrPath={currentPath}>
Expand All @@ -197,13 +202,15 @@ export function Explore({
onNavigate(i.content)
}}
batchActions={true}
treeActions={true}
/>
</div>
<div className={classes.treeAndDatagridWrapper}>
{hasTree && (
<TreeWithData
onItemClick={(item) => {
onNavigate(item)
setSelected([item])
}}
parentPath={PathHelper.isAncestorOf(rootPath, currentPath) ? rootPath : currentPath}
activeItemPath={currentPath}
Expand Down
5 changes: 4 additions & 1 deletion apps/sensenet/src/components/tree/tree-with-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ export default function TreeWithData(props: TreeWithDataProps) {
}),
]

return () => subscriptions.forEach((s) => s.dispose())
return () => {
console.log('unmounting')
subscriptions.forEach((s) => s.dispose())
}
}, [
treeData,
eventHub.onContentDeleted,
Expand Down
6 changes: 6 additions & 0 deletions apps/sensenet/src/localization/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,12 @@ const values = {
copy: 'Copy selected items',
copyPath: 'Copy path',
},
treeActions: {
delete: 'Delete selected items',
move: 'Move selected items',
copy: 'Copy selected items',
copyPath: 'Copy path',
},
referenceContentListDialog: {
errorAlreadyInList: 'The selected item is already in the list',
},
Expand Down
Loading