Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(export): add select all in export modal (#1192)
- Loading branch information
Showing
9 changed files
with
150 additions
and
30 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { FC } from "react"; | ||
import Box from "@material-ui/core/Box"; | ||
import { Button } from "@material-ui/core"; | ||
import { FaFolderOpen } from "react-icons/fa"; | ||
import { ExportType } from "./export-config"; | ||
import { useTranslation } from "react-i18next"; | ||
import { ExportTypesMap } from "./export-options"; | ||
import { remote } from "electron"; | ||
import path from "path"; | ||
import Checkbox from "@material-ui/core/Checkbox"; | ||
import FormControlLabel from "@material-ui/core/FormControlLabel"; | ||
|
||
type ExportControlsProps = { | ||
setActiveExportValue: (exportType: ExportType, value: boolean) => void; | ||
setExportsPathsValue: (exportType: ExportType, value: string) => void; | ||
activeExports: ExportTypesMap<boolean>; | ||
exportPaths: ExportTypesMap<string>; | ||
enabledExports: ExportTypesMap<boolean>; | ||
}; | ||
|
||
const ExportControls: FC<ExportControlsProps> = ({ | ||
setActiveExportValue, | ||
setExportsPathsValue, | ||
activeExports, | ||
exportPaths, | ||
enabledExports, | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
const areAllBoxesChecked = Object.values(ExportType).every( | ||
(exportType) => activeExports[exportType] | ||
); | ||
|
||
const setAllBoxes = (checked: boolean) => { | ||
Object.values(ExportType) | ||
.filter((exportType) => enabledExports[exportType]) | ||
.forEach((exportType) => { | ||
setActiveExportValue(exportType, checked); | ||
}); | ||
}; | ||
|
||
const toggleAllBoxes = () => { | ||
setAllBoxes(!areAllBoxesChecked); | ||
}; | ||
|
||
const browseForAll = async () => { | ||
const filePath = await remote.dialog.showOpenDialog({ | ||
properties: ["openDirectory"], | ||
}); | ||
|
||
Object.values(ExportType).forEach((exportType) => { | ||
if (filePath.filePaths.length > 0) { | ||
const folderPath = filePath.filePaths[0]; | ||
const filename = path.basename(exportPaths[exportType]); | ||
setExportsPathsValue(exportType, `${folderPath}/${filename}`); | ||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<Box paddingBottom={1} display="flex" justifyContent="space-between"> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox checked={areAllBoxesChecked} onChange={toggleAllBoxes} /> | ||
} | ||
label={ | ||
areAllBoxesChecked | ||
? t("exportModal.unselectAll") | ||
: t("exportModal.selectAll") | ||
} | ||
/> | ||
<Button size="small" onClick={browseForAll} endIcon={<FaFolderOpen />}> | ||
{t("exportModal.browseAll")} | ||
</Button> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ExportControls; |
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
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
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