-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from bcgov/DAP-978-add-folder-button
Dap-978 Add Folder Button to Create File List Page
- Loading branch information
Showing
12 changed files
with
180 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./copyFolderAndMetadata"; | ||
export * from "./getFolderMetadata"; | ||
export * from "./selectDirectory"; |
23 changes: 23 additions & 0 deletions
23
desktop/src/main/fileProcessing/actions/selectDirectory.ts
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,23 @@ | ||
import { dialog, type BrowserWindow } from "electron"; | ||
|
||
let selectedDir: string[] | undefined; | ||
let dirPathArray: string[]; | ||
|
||
/** | ||
* Opens a (modal) dialog window off the main window for a user to select a directory. | ||
* | ||
* @param win - the main process window. | ||
* @returns A string[] if a directory is selected or undefined if the dialog is closed with no selection. | ||
*/ | ||
export const selectDirectory = (win: BrowserWindow): string[] => { | ||
// open a dialog and allow a user to select multiple folders | ||
selectedDir = dialog.showOpenDialogSync(win, { | ||
properties: ["openDirectory", "multiSelections"], | ||
}); | ||
|
||
// if selectedDir is undefined we have no selected path so return an empty array | ||
// otherwise return the array of selected paths | ||
dirPathArray = selectedDir ?? [""]; | ||
|
||
return dirPathArray; | ||
}; |
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
17 changes: 17 additions & 0 deletions
17
desktop/src/renderer/src/components/file-list/ContinueButton.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,17 @@ | ||
import { Button } from "@bcgov/design-system-react-components"; | ||
|
||
export const ContinueButton = (): JSX.Element => { | ||
const handleClick = async () => { | ||
console.log("TODO: THIS"); | ||
}; | ||
|
||
return ( | ||
<Button | ||
variant="primary" | ||
style={{ justifyContent: "center", width: "15%" }} | ||
onPress={handleClick} | ||
> | ||
Continue | ||
</Button> | ||
); | ||
}; |
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
23 changes: 23 additions & 0 deletions
23
desktop/src/renderer/src/components/file-list/SelectFolderButton.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,23 @@ | ||
import { useState } from "react"; | ||
import { Button } from "@bcgov/design-system-react-components"; | ||
|
||
export const SelectFolderButton = ({ onRowChange }): JSX.Element => { | ||
const [api] = useState(window.api); // preload scripts | ||
|
||
const handleClick = async () => { | ||
const result = await api.selectDirectory(); | ||
|
||
onRowChange(result); | ||
return result; | ||
}; | ||
|
||
return ( | ||
<Button | ||
variant="primary" | ||
style={{ justifyContent: "center", width: "15%" }} | ||
onPress={handleClick} | ||
> | ||
Select Folder(s) | ||
</Button> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from "./FolderDisplayGrid"; | ||
export * from "./SelectFolderButton"; | ||
export * from "./ContinueButton"; |
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 |
---|---|---|
@@ -1,24 +1,101 @@ | ||
import { Box, useTheme } from "@mui/material"; | ||
import { FolderDisplayGrid, type FolderRow } from "@renderer/components/file-list"; | ||
import { | ||
FolderDisplayGrid, | ||
type FolderRow, | ||
SelectFolderButton, | ||
ContinueButton, | ||
} from "@renderer/components/file-list"; | ||
import { useState } from "react"; | ||
import { useGridApiRef } from "@mui/x-data-grid"; | ||
|
||
export const FileListPage = () => { | ||
const [rows, setRows] = useState<FolderRow[]>([]); | ||
const theme = useTheme(); | ||
const apiRef = useGridApiRef(); | ||
|
||
const onFolderDelete = (folder: string) => { | ||
alert(folder); // TBD | ||
}; | ||
|
||
const handleAddPathArrayToRows = (inputPaths: string[]) => { | ||
const newRows: FolderRow[] = [...rows]; | ||
let index = rows.length; // Start IDs based on the current rows | ||
const newRowIds: number[] = []; // Track IDs of the newly added rows | ||
|
||
try { | ||
for (let i = 0; i < inputPaths.length; i++) { | ||
const currentFolderPath = inputPaths[i]; | ||
let skipFlag = false; | ||
|
||
// check if file path is already in the rows | ||
for (let j = 0; j < rows.length; j++) { | ||
if (currentFolderPath === rows[j].folder) skipFlag = true; | ||
} | ||
// if the path is already in the list, skip it | ||
if (skipFlag === true) continue; | ||
|
||
const curFolderRow: FolderRow = { | ||
id: index, // Unique IDs for new rows | ||
folder: currentFolderPath, | ||
schedule: "", | ||
classification: "", | ||
file: "", | ||
opr: false, | ||
startDate: null, | ||
endDate: null, | ||
soDate: null, | ||
fdDate: null, | ||
progress: 0, | ||
}; | ||
// Track new row IDs | ||
newRowIds.push(index); | ||
index++; | ||
// add new folder row to list to be displayed | ||
newRows.push(curFolderRow); | ||
} | ||
// set the new list of folder rows | ||
setRows(newRows); | ||
|
||
// Set all newly added rows to edit mode | ||
if (apiRef.current && newRowIds.length > 0) { | ||
setTimeout(() => { | ||
newRowIds.forEach((rowId) => { | ||
apiRef.current.startRowEditMode({ id: rowId }); | ||
}); | ||
}); | ||
} | ||
} catch (error) { | ||
setRows(rows); // Revert rows on error | ||
console.log("Hit error:", error); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
height: "100vh", | ||
padding: 2, | ||
flexShrink: 0, | ||
background: `${theme.palette.primary}`, | ||
}} | ||
> | ||
<FolderDisplayGrid rows={rows} onFolderDelete={onFolderDelete} /> | ||
</Box> | ||
<> | ||
<Box | ||
sx={{ | ||
minHeight: "7vh", | ||
display: "flex", | ||
justifyContent: "flex-end", | ||
gap: 1, | ||
padding: 2, | ||
flexShrink: 0, | ||
background: `${theme.palette.primary}`, | ||
}} | ||
> | ||
<SelectFolderButton onRowChange={handleAddPathArrayToRows} /> | ||
<ContinueButton /> | ||
</Box> | ||
<Box | ||
sx={{ | ||
height: "90vh", | ||
padding: 2, | ||
flexShrink: 0, | ||
background: `${theme.palette.primary}`, | ||
}} | ||
> | ||
<FolderDisplayGrid rows={rows} onFolderDelete={onFolderDelete} apiRef={apiRef} /> | ||
</Box> | ||
</> | ||
); | ||
}; |