-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create document directory table with checkboxes
- Loading branch information
1 parent
cbafe5f
commit 9b7ed82
Showing
3 changed files
with
122 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import React from "react"; | ||
import DocumentDirectoryTable from "../tables/DocumentDirectoryTable"; | ||
|
||
const DocumentDirectory = (): React.ReactElement => { | ||
return <h1>Document Directory Page</h1>; | ||
return ( | ||
<> | ||
<h1>Document Directory Page</h1> | ||
<DocumentDirectoryTable /> | ||
</> | ||
); | ||
}; | ||
export default DocumentDirectory; |
114 changes: 114 additions & 0 deletions
114
frontend/src/components/tables/DocumentDirectoryTable.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,114 @@ | ||
import React, { useState } from "react"; | ||
import { | ||
Button, | ||
Checkbox, | ||
Table, | ||
Thead, | ||
Tbody, | ||
Tr, | ||
Th, | ||
Td, | ||
TableContainer, | ||
} from "@chakra-ui/react"; | ||
|
||
// TODO: remove once connected to backend | ||
const dummyData = [ | ||
{ | ||
id: "1", | ||
name: "A", | ||
created: "2024-03-01", | ||
type: "Form", | ||
comments: "blah blah", | ||
}, | ||
{ | ||
id: "2", | ||
name: "B", | ||
created: "2024-03-02", | ||
type: "Form", | ||
comments: "blah blah", | ||
}, | ||
{ | ||
id: "3", | ||
name: "C", | ||
created: "2024-03-03", | ||
type: "Form", | ||
comments: "blah blah", | ||
}, | ||
]; | ||
|
||
const DocumentDirectoryTable = () => { | ||
const documents = dummyData; // TODO: replace with call to backend | ||
|
||
const [selectedDocumentIds, setSelectedDocumentIds] = useState<Set<string>>( | ||
new Set(), | ||
); | ||
|
||
const changeRowCheckbox = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const selectedId = event.target.id; | ||
const isChecked = event.target.checked; | ||
if (isChecked) { | ||
selectedDocumentIds.add(selectedId); | ||
} else { | ||
selectedDocumentIds.delete(selectedId); | ||
} | ||
setSelectedDocumentIds((prev) => new Set(prev)); | ||
}; | ||
|
||
const changeAllCheckboxes = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const isChecked = event.target.checked; | ||
if (isChecked) { | ||
setSelectedDocumentIds(new Set(documents.map((document) => document.id))); | ||
} else { | ||
setSelectedDocumentIds(new Set()); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<TableContainer> | ||
<Table> | ||
<Thead> | ||
<Tr> | ||
<Th> | ||
<Checkbox | ||
isChecked={selectedDocumentIds.size === documents.length} | ||
onChange={changeAllCheckboxes} | ||
/> | ||
</Th> | ||
<Th>NAME</Th> | ||
<Th>CREATED ON</Th> | ||
<Th>TYPE</Th> | ||
<Th>COMMENTS</Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{documents.map((document) => { | ||
const isChecked = selectedDocumentIds.has(document.id); | ||
return ( | ||
<Tr key={document.id}> | ||
<Td> | ||
<Checkbox | ||
id={document.id} | ||
isChecked={isChecked} | ||
onChange={changeRowCheckbox} | ||
/> | ||
</Td> | ||
<Td>{document.name}</Td> | ||
<Td>{document.created}</Td> | ||
<Td>{document.type}</Td> | ||
<Td>{document.comments}</Td> | ||
</Tr> | ||
); | ||
})} | ||
</Tbody> | ||
</Table> | ||
</TableContainer> | ||
<br /> | ||
<Button onClick={() => console.log(selectedDocumentIds)}> | ||
Log selected document ids! | ||
</Button> | ||
</> | ||
); | ||
}; | ||
|
||
export default DocumentDirectoryTable; |