.map(toggleDescendants(data.id))[0],
ON_SEARCH_CHANGE: (searchValue) => {
- // node.children = children.filter((id: string) => id.replace(parentId, '').toLowerCase().indexOf(searchValue.toLowerCase()) > -1);
- const ids: string[] = [];
+ const fileIds: string[] = [];
+ const directoryIds: string[] = [];
const filteredFiles = Object.keys(fetchedFiles)
.filter((key: string) => {
const node = fetchedFiles[key];
const { id, value: { type, name } } = node;
if (type === CollectionFileType.DIRECTORY) {
- ids.push(id);
+ directoryIds.push(id);
return true;
}
const includeFile = name.toLowerCase().indexOf(searchValue.toLowerCase()) > -1;
if (includeFile) {
- ids.push(id);
+ fileIds.push(id);
}
return includeFile;
})
.reduce((prev, next) => {
const node = JSON.parse(JSON.stringify(fetchedFiles[next]));
- node.children = node.children.filter((key: string) => ids.indexOf(key) > -1);
- prev[next] = node;
+ const { value: { type }, children } = node;
+
+ node.children = node.children.filter((key: string) => {
+ const isFile = directoryIds.indexOf(key) === -1;
+ return isFile ?
+ fileIds.indexOf(key) > -1 :
+ !!fileIds.find(id => id.indexOf(key) > -1);
+ });
+
+ if (type === CollectionFileType.FILE || children.length > 0) {
+ prev[next] = node;
+ }
+
return prev;
}, {});
export const filterCollectionFilesBySelection = (tree: CollectionPanelFilesState, selected: boolean) => {
const allFiles = getNodeDescendants('')(tree).map(node => node.value);
-
const selectedDirectories = allFiles.filter(file => file.selected === selected && file.type === CollectionFileType.DIRECTORY);
const selectedFiles = allFiles.filter(file => file.selected === selected && !selectedDirectories.some(dir => dir.id === file.path));
return [...selectedDirectories, ...selectedFiles];
manifestText: collection.manifestText,
};
const newCollection = await services.collectionService.create(collectionCopy);
- const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, false).map(file => file.id);
- await services.collectionService.deleteFiles(newCollection.uuid, paths);
+ const copiedFiles = await services.collectionService.files(newCollection.uuid);
+ const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, true).map(file => file.id);
+ const filesToDelete = copiedFiles.map(({ id }) => id).filter(file => {
+ return !paths.find(path => path.indexOf(file.replace(newCollection.uuid, '')) > -1);
+ });
+ // console.log(paths.length, filesToDelete.length, copiedFiles.length);
+ await services.collectionService.deleteFiles(
+ '',
+ filesToDelete
+ );
dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY_FORM_NAME }));
dispatch(snackbarActions.OPEN_SNACKBAR({
message: 'New collection created.',