Skip to content

Commit 033c592

Browse files
committed
copy move new picker
1 parent 5598913 commit 033c592

2 files changed

Lines changed: 58 additions & 50 deletions

File tree

apps/sensenet/src/components/dialogs/copy-move.tsx

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { LinearProgress } from '@material-ui/core'
2-
import DialogActions from '@material-ui/core/DialogActions'
3-
import DialogContent from '@material-ui/core/DialogContent'
41
import { PathHelper } from '@sensenet/client-utils'
52
import { GenericContent } from '@sensenet/default-content-types'
63
import { useLogger, useRepository } from '@sensenet/hooks-react'
7-
import { GenericContentWithIsParent, Picker, PickerModes } from '@sensenet/pickers-react'
4+
import { PickerAdvanced } from '@sensenet/pickers-react'
85
import React, { useEffect, useMemo, useState } from 'react'
96
import { useHistory } from 'react-router-dom'
107
import { useGlobalStyles } from '../../globalStyles'
@@ -35,26 +32,21 @@ export const CopyMoveDialog: React.FunctionComponent<CopyMoveDialogProps> = (pro
3532
const [isExecInProgress, setIsExecInProgress] = useState(false)
3633

3734
const selectionRoots = useMemo(() => [snRoute.path], [snRoute.path])
38-
const itemsODataOptions = useMemo(() => ({ filter: '' }), [])
39-
40-
const blackList =
41-
props.operation === 'copy'
42-
? [props.content[0].Path]
43-
: [props.content[0].Path, `/${PathHelper.getParentPath(props.content[0].Path)}`]
4435

4536
useEffect(() => {
4637
setLocalization(localizations[props.operation])
4738
}, [localizations, props.operation])
4839

49-
const [destination, setDestination] = useState(props.currentParent.DisplayName)
40+
const [destinationString, setDestinationString] = useState(props.currentParent.DisplayName)
41+
const [currentNode, setCurrentNode] = useState(props.currentParent)
5042

5143
if (!props.content.length) {
5244
return null
5345
}
5446

55-
const handleSubmit = async (selection: GenericContentWithIsParent[]) => {
47+
const handleSubmit = async () => {
5648
try {
57-
const target = selection[0]
49+
const target = currentNode
5850

5951
setIsExecInProgress(true)
6052

@@ -164,28 +156,25 @@ export const CopyMoveDialog: React.FunctionComponent<CopyMoveDialogProps> = (pro
164156
)
165157
})()}
166158
<span style={{ marginLeft: '0.25rem' }}>
167-
to <span style={{ color: 'yellow' }}>{destination}</span>
159+
to <span style={{ color: 'yellow' }}>{destinationString}</span>
168160
</span>
169161
</div>
170162
</DialogTitle>
171-
<Picker
163+
<PickerAdvanced
172164
repository={repo}
173-
currentPath={props.currentParent.Path}
174-
selectionRoots={selectionRoots}
175-
itemsODataOptions={itemsODataOptions}
165+
defaultValue={props.content}
166+
path={props.currentParent.Path}
176167
renderIcon={(item) => <Icon item={item} />}
177-
renderLoading={() => <LinearProgress />}
178-
pickerContainer={DialogContent}
179-
actionsContainer={DialogActions}
180-
handleCancel={closeLastDialog}
181-
handleSubmit={handleSubmit}
182-
selectionBlacklist={blackList}
183-
isExecInProgress={isExecInProgress}
184-
required={1}
185-
classes={{ cancelButton: globalClasses.cancelButton }}
186-
setDestination={setDestination}
187-
currentParent={props.currentParent}
188-
treePickerMode={PickerModes.COPY_MOVE_TREE}
168+
onCancel={closeLastDialog}
169+
onSubmit={() => {
170+
handleSubmit()
171+
}}
172+
selectionRoots={selectionRoots}
173+
showDialogTitle={false}
174+
canPick={false}
175+
showSearch={false}
176+
setDestinationString={setDestinationString}
177+
setCurrentNode={setCurrentNode}
189178
/>
190179
</>
191180
)

packages/sn-pickers-react/src/components/picker-advanced.tsx

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ type TreeNodeProps = {
177177
path: string
178178
expanded: string[]
179179
setExpanded: React.Dispatch<React.SetStateAction<string[]>>
180-
onSetCurrentPath: (path: string) => void
180+
onSetCurrentNode: (content: GenericContent) => void
181181
}
182-
const TreeNode = ({ node, repository, renderIcon, path, expanded, setExpanded, onSetCurrentPath }: TreeNodeProps) => {
182+
const TreeNode = ({ node, repository, renderIcon, path, expanded, setExpanded, onSetCurrentNode }: TreeNodeProps) => {
183183
const classes = useStyles()
184184
const [childNodes, setChildNodes] = useState<GenericContent[]>([])
185185

@@ -189,11 +189,9 @@ const TreeNode = ({ node, repository, renderIcon, path, expanded, setExpanded, o
189189
path: node.Path,
190190
requestInit: { signal: abortController.signal },
191191
})
192-
const children = sortResults(childrenResult.d.results)
193-
if (!children || children.length === 0) return
194192

195-
onSetCurrentPath(node.Path)
196-
setChildNodes(childrenResult.d.results)
193+
onSetCurrentNode(node)
194+
setChildNodes(sortResults(childrenResult.d.results))
197195

198196
setExpanded((prevExpanded) =>
199197
prevExpanded.includes(node.Id.toString()) ? prevExpanded : [...prevExpanded, node.Id.toString()],
@@ -215,7 +213,7 @@ const TreeNode = ({ node, repository, renderIcon, path, expanded, setExpanded, o
215213
label={
216214
<div style={{ display: 'flex', alignItems: 'center', gap: 6, cursor: 'pointer' }} onClick={handleNodeClick}>
217215
<div className={classes.treeIcon}>{renderIcon(node)}</div>
218-
<div className={classes.treeLabel}>{node.DisplayName}</div>
216+
<div className={classes.treeLabel}>{node.Name}</div>
219217
</div>
220218
}
221219
collapseIcon={<MinusSquare />}
@@ -230,7 +228,7 @@ const TreeNode = ({ node, repository, renderIcon, path, expanded, setExpanded, o
230228
path={path}
231229
expanded={expanded}
232230
setExpanded={setExpanded}
233-
onSetCurrentPath={onSetCurrentPath}
231+
onSetCurrentNode={onSetCurrentNode}
234232
/>
235233
))}
236234
</TreeItem>
@@ -258,6 +256,11 @@ interface PickerAdvancedProps {
258256
onSubmit?: (selectedItems: GenericContent[]) => void | undefined
259257
allowMultiple?: boolean
260258
selectionRoots?: string[]
259+
showDialogTitle?: boolean
260+
canPick?: boolean
261+
showSearch?: boolean
262+
setDestinationString?: React.Dispatch<React.SetStateAction<string | undefined>>
263+
setCurrentNode?: React.Dispatch<React.SetStateAction<GenericContent>>
261264
}
262265
export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
263266
defaultValue,
@@ -268,6 +271,11 @@ export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
268271
onSubmit,
269272
allowMultiple = true,
270273
selectionRoots,
274+
showDialogTitle = true,
275+
canPick = true,
276+
showSearch = true,
277+
setDestinationString,
278+
setCurrentNode,
271279
}) => {
272280
const classes = useStyles()
273281
const theme = useTheme()
@@ -318,8 +326,8 @@ export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
318326
cellRenderer: (props: { data: GenericContent }) => renderIcon(props.data),
319327
cellStyle: { padding: 0 },
320328
}
321-
const availableCols = [iconCol, ...baseColumns, addCol]
322-
const selectedCols = [iconCol, ...baseColumns, removeCol]
329+
const availableCols = [iconCol, ...baseColumns, ...(canPick ? [addCol] : [])]
330+
const selectedCols = [iconCol, ...baseColumns, ...(canPick ? [removeCol] : [])]
323331

324332
//Button Actions
325333
const handleAdd = (item: GenericContent) => {
@@ -366,8 +374,17 @@ export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
366374
}, 250),
367375
[],
368376
)
377+
const onSetCurrentNode = (currNode: GenericContent) => {
378+
if (setCurrentNode) {
379+
setCurrentNode(currNode)
380+
}
381+
onSetCurrentPath(currNode.Path)
382+
}
369383
const onSetCurrentPath = (currPath: string) => {
370384
setCurrentPath(currPath)
385+
if (setDestinationString) {
386+
setDestinationString(currPath)
387+
}
371388
if (currPath === path) {
372389
setIsInitPath(true)
373390
}
@@ -446,18 +463,20 @@ export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
446463

447464
return (
448465
<div className={classes.mainCont}>
449-
<DialogTitle className={classes.dialogTitle}>Picker</DialogTitle>
466+
{showDialogTitle && <DialogTitle className={classes.dialogTitle}>Picker</DialogTitle>}
450467
<div className={classes.header}>
451468
<div className={classes.path}>{currentPath}</div>
452469
<div className={classes.search}>
453-
<TextField
454-
ref={searchFieldRef}
455-
fullWidth={true}
456-
placeholder={'Search'}
457-
onChange={(ev) => {
458-
onSearchFieldChange(ev.target.value)
459-
}}
460-
/>
470+
{showSearch && (
471+
<TextField
472+
ref={searchFieldRef}
473+
fullWidth={true}
474+
placeholder={'Search'}
475+
onChange={(ev) => {
476+
onSearchFieldChange(ev.target.value)
477+
}}
478+
/>
479+
)}
461480
</div>
462481
</div>
463482
<div className={classes.pickingCont}>
@@ -476,7 +495,7 @@ export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
476495
path={path}
477496
expanded={expanded}
478497
setExpanded={setExpanded}
479-
onSetCurrentPath={onSetCurrentPath}
498+
onSetCurrentNode={onSetCurrentNode}
480499
/>
481500
)}
482501
</TreeView>

0 commit comments

Comments
 (0)