-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-file-manager): add bulk actions (#3608)
- Loading branch information
Showing
19 changed files
with
380 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/app-file-manager/src/components/BulkActions/ActionDelete.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, { useMemo } from "react"; | ||
import { ReactComponent as DeleteIcon } from "@material-design-icons/svg/outlined/delete.svg"; | ||
import { observer } from "mobx-react-lite"; | ||
|
||
import { FileManagerViewConfig } from "~/modules/FileManagerRenderer/FileManagerView/FileManagerViewConfig"; | ||
import { useFileManagerApi } from "~/modules/FileManagerApiProvider/FileManagerApiContext"; | ||
import { useFileManagerView } from "~/modules/FileManagerRenderer/FileManagerViewProvider"; | ||
import { getFilesLabel } from "~/components/BulkActions/BulkActions"; | ||
|
||
export const ActionDelete = observer(() => { | ||
const { deleteFile } = useFileManagerView(); | ||
const { canDelete } = useFileManagerApi(); | ||
|
||
const { useWorker, useButtons, useDialog } = FileManagerViewConfig.Browser.BulkAction; | ||
const { IconButton } = useButtons(); | ||
const worker = useWorker(); | ||
const { showConfirmationDialog, showResultsDialog } = useDialog(); | ||
|
||
const filesLabel = useMemo(() => { | ||
return getFilesLabel(worker.items.length); | ||
}, [worker.items.length]); | ||
|
||
const canDeleteAll = useMemo(() => { | ||
return worker.items.every(item => canDelete(item)); | ||
}, [worker.items]); | ||
|
||
const openDeleteDialog = () => | ||
showConfirmationDialog({ | ||
title: "Delete files", | ||
message: `You are about to delete ${filesLabel}. Are you sure you want to continue?`, | ||
loadingLabel: `Processing ${filesLabel}`, | ||
execute: async () => { | ||
await worker.processInSeries(async ({ item, report }) => { | ||
try { | ||
await deleteFile(item.id); | ||
|
||
report.success({ | ||
title: `${item.name}`, | ||
message: "File successfully deleted." | ||
}); | ||
} catch (e) { | ||
report.error({ | ||
title: `${item.name}`, | ||
message: e.message | ||
}); | ||
} | ||
}); | ||
|
||
worker.resetItems(); | ||
|
||
showResultsDialog({ | ||
results: worker.results, | ||
title: "Delete files", | ||
message: "Finished deleting files! See full report below:" | ||
}); | ||
} | ||
}); | ||
|
||
if (!canDeleteAll) { | ||
console.log("You don't have permissions to delete files."); | ||
return null; | ||
} | ||
|
||
return ( | ||
<IconButton | ||
icon={<DeleteIcon />} | ||
onAction={openDeleteDialog} | ||
label={`Delete ${filesLabel}`} | ||
tooltipPlacement={"bottom"} | ||
/> | ||
); | ||
}); |
82 changes: 82 additions & 0 deletions
82
packages/app-file-manager/src/components/BulkActions/ActionMove.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { useCallback, useMemo } from "react"; | ||
import { ReactComponent as MoveIcon } from "@material-design-icons/svg/outlined/drive_file_move.svg"; | ||
import { observer } from "mobx-react-lite"; | ||
import { useMoveToFolderDialog, useNavigateFolder } from "@webiny/app-aco"; | ||
import { FolderItem } from "@webiny/app-aco/types"; | ||
|
||
import { useFileManagerView } from "~/modules/FileManagerRenderer/FileManagerViewProvider"; | ||
import { FileManagerViewConfig } from "~/modules/FileManagerRenderer/FileManagerView/FileManagerViewConfig"; | ||
import { getFilesLabel } from "~/components/BulkActions/BulkActions"; | ||
import { ROOT_FOLDER } from "~/constants"; | ||
|
||
export const ActionMove = observer(() => { | ||
const { moveFileToFolder } = useFileManagerView(); | ||
const { currentFolderId } = useNavigateFolder(); | ||
|
||
const { useWorker, useButtons, useDialog } = FileManagerViewConfig.Browser.BulkAction; | ||
const { IconButton } = useButtons(); | ||
const worker = useWorker(); | ||
const { showConfirmationDialog, showResultsDialog } = useDialog(); | ||
const { showDialog: showMoveDialog } = useMoveToFolderDialog(); | ||
|
||
const filesLabel = useMemo(() => { | ||
return getFilesLabel(worker.items.length); | ||
}, [worker.items.length]); | ||
|
||
const openWorkerDialog = useCallback( | ||
(folder: FolderItem) => { | ||
showConfirmationDialog({ | ||
title: "Move files", | ||
message: `You are about to move ${filesLabel} to ${folder.title}. Are you sure you want to continue?`, | ||
loadingLabel: `Processing ${filesLabel}`, | ||
execute: async () => { | ||
await worker.processInSeries(async ({ item, report }) => { | ||
try { | ||
await moveFileToFolder(item.id, folder.id); | ||
|
||
report.success({ | ||
title: `${item.name}`, | ||
message: "File successfully moved." | ||
}); | ||
} catch (e) { | ||
report.error({ | ||
title: `${item.name}`, | ||
message: e.message | ||
}); | ||
} | ||
}); | ||
|
||
worker.resetItems(); | ||
|
||
showResultsDialog({ | ||
results: worker.results, | ||
title: "Move files", | ||
message: "Finished moving files! See full report below:" | ||
}); | ||
} | ||
}); | ||
}, | ||
[filesLabel] | ||
); | ||
|
||
const openMoveDialog = () => | ||
showMoveDialog({ | ||
title: "Select folder", | ||
message: "Select a new location for selected files:", | ||
loadingLabel: `Processing ${filesLabel}`, | ||
acceptLabel: `Move`, | ||
focusedFolderId: currentFolderId || ROOT_FOLDER, | ||
async onAccept({ folder }) { | ||
openWorkerDialog(folder); | ||
} | ||
}); | ||
|
||
return ( | ||
<IconButton | ||
icon={<MoveIcon />} | ||
onAction={openMoveDialog} | ||
label={`Move ${filesLabel}`} | ||
tooltipPlacement={"bottom"} | ||
/> | ||
); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/app-file-manager/src/components/BulkActions/BulkActions.styled.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import styled from "@emotion/styled"; | ||
import { ButtonContainer } from "@webiny/app-admin"; | ||
|
||
export const BulkActionsContainer = styled.div` | ||
width: 100%; | ||
height: 64px; | ||
background-color: var(--mdc-theme-surface); | ||
border-bottom: 1px solid rgba(0, 0, 0, 0.12); | ||
`; | ||
|
||
export const BulkActionsInner = styled.div` | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 0 12px 0 16px; | ||
`; | ||
|
||
export const ButtonsContainer = styled.div` | ||
display: flex; | ||
align-items: center; | ||
${ButtonContainer} { | ||
margin: 0; | ||
} | ||
`; |
44 changes: 44 additions & 0 deletions
44
packages/app-file-manager/src/components/BulkActions/BulkActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { useMemo } from "react"; | ||
import { ReactComponent as Close } from "@material-design-icons/svg/outlined/close.svg"; | ||
import { i18n } from "@webiny/app/i18n"; | ||
import { Buttons } from "@webiny/app-admin"; | ||
import { IconButton } from "@webiny/ui/Button"; | ||
import { Typography } from "@webiny/ui/Typography"; | ||
|
||
import { useFileManagerViewConfig } from "~/modules/FileManagerRenderer/FileManagerView/FileManagerViewConfig"; | ||
import { useFileManagerView } from "~/modules/FileManagerRenderer/FileManagerViewProvider"; | ||
|
||
import { BulkActionsContainer, BulkActionsInner, ButtonsContainer } from "./BulkActions.styled"; | ||
|
||
const t = i18n.ns("app-file-manager/components/bulk-actions"); | ||
|
||
export const getFilesLabel = (count = 0): string => { | ||
return `${count} ${count === 1 ? "file" : "files"}`; | ||
}; | ||
|
||
export const BulkActions = () => { | ||
const { browser } = useFileManagerViewConfig(); | ||
const view = useFileManagerView(); | ||
|
||
const headline = useMemo((): string => { | ||
return t`{label} selected:`({ | ||
label: getFilesLabel(view.selected.length) | ||
}); | ||
}, [view.selected]); | ||
|
||
if (view.hasOnSelectCallback || !view.selected.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<BulkActionsContainer> | ||
<BulkActionsInner> | ||
<ButtonsContainer> | ||
<Typography use={"headline6"}>{headline}</Typography> | ||
<Buttons actions={browser.bulkActions} /> | ||
</ButtonsContainer> | ||
<IconButton icon={<Close />} onClick={() => view.setSelected([])} /> | ||
</BulkActionsInner> | ||
</BulkActionsContainer> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/app-file-manager/src/components/BulkActions/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { ActionDelete } from "./ActionDelete"; | ||
export { ActionMove } from "./ActionMove"; | ||
export * from "./BulkActions"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/app-file-manager/src/components/LayoutSwitch/LayoutSwitch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from "react"; | ||
|
||
import { ReactComponent as GridIcon } from "@material-design-icons/svg/outlined/view_module.svg"; | ||
import { ReactComponent as TableIcon } from "@material-design-icons/svg/outlined/view_list.svg"; | ||
import { i18n } from "@webiny/app/i18n"; | ||
import { IconButton } from "@webiny/ui/Button"; | ||
import { Tooltip } from "@webiny/ui/Tooltip"; | ||
|
||
import { useFileManagerView } from "~/modules/FileManagerRenderer/FileManagerViewProvider"; | ||
|
||
const t = i18n.ns("app-file-manager/components/layout-switch"); | ||
|
||
export const LayoutSwitch = () => { | ||
const view = useFileManagerView(); | ||
|
||
return ( | ||
<Tooltip | ||
content={t`{mode} layout`({ | ||
mode: view.listTable ? "Grid" : "Table" | ||
})} | ||
placement={"bottom"} | ||
> | ||
<IconButton | ||
icon={view.listTable ? <GridIcon /> : <TableIcon />} | ||
onClick={() => view.setListTable(!view.listTable)} | ||
> | ||
{t`Switch`} | ||
</IconButton> | ||
</Tooltip> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/app-file-manager/src/components/LayoutSwitch/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./LayoutSwitch"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.