-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/developer search paginate #13
Changes from 9 commits
9236f53
3c40421
43f7044
e57972e
ea81e86
5032d3a
6a00261
e5df24b
afb164b
29d11eb
8e637a2
eae808b
1c9ed9f
767f092
552dccc
e818bd8
a70ac4a
f746812
5ab7059
fe1e3d0
3e56fe2
1e1c211
b568d05
bbe493b
ce7eac6
8bbb575
b5d8612
f4adbde
a9ac095
fe90cde
7bb989d
318ec18
b455721
c799732
4f692d2
a835a5c
26d6fca
76a559b
25fb7a4
8023247
306a263
f33f7e5
6b77973
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
import { Button, HStack, Text } from "@chakra-ui/react"; | ||
import debounce from "lodash/debounce"; | ||
|
||
interface HStackStyles { | ||
spacing?: number; | ||
mt?: string; | ||
} | ||
interface PaginationProps { | ||
pageInfo: { page: number; size: number; total: number; pages: number }; | ||
handlePageChange: (newPage: number) => void; | ||
HStackStyles?: HStackStyles; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added this optional parameter to customise Hstack properties There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think no need ba, just straight away pass it in, this one abit verbose since you can just pass into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im not sure what you mean, but i dont think i can pass styles into Hstack directly via the |
||
} | ||
|
||
export const Pagination = ({ pageInfo, handlePageChange }: PaginationProps) => { | ||
export const Pagination = ({ | ||
pageInfo, | ||
handlePageChange, | ||
HStackStyles, | ||
}: PaginationProps) => { | ||
const debouncedHandlePageChange = debounce(handlePageChange, 100); | ||
|
||
return ( | ||
<HStack spacing={4} justifyContent="center" mt="10%"> | ||
<HStack | ||
spacing={HStackStyles?.spacing ? HStackStyles.spacing : 4} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need a new data structure just to do spacing for hstacks? just declare the values by itself here lo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i just dont want to break anything, so previous implementations have a default value of 4 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea you can just pass in directly and do a conditional for default spacing 4 if spacing doesn't exist here, no need for new interface just to pass this in also make sure that when you change screen components this way, it doesn't mess up the mobile design because its supposed to be responsive There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pagination should be consistent throughout, just keep it as 4 |
||
justifyContent="center" | ||
mt={HStackStyles?.mt ? HStackStyles.mt : "10%"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after adding imo this 10% warrants a review but just do ^ first |
||
> | ||
<Button | ||
onClick={() => debouncedHandlePageChange(pageInfo.page - 1)} | ||
isDisabled={pageInfo.page === 1} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,12 @@ import { | |
TableContainer, | ||
TableHead, | ||
TableRow, | ||
OutlinedInput, | ||
} from "@mui/material"; | ||
import EditIcon from "@mui/icons-material/Edit"; | ||
import React from "react"; | ||
import { useState, ChangeEvent, MouseEvent } from "react"; | ||
import { ChakraProvider, Flex } from "@chakra-ui/react"; | ||
import { Pagination } from "../../components/Pagination/Pagination"; | ||
|
||
type DataTypeKey = "categories" | "subjects" | "types"; | ||
|
||
|
@@ -33,23 +36,75 @@ export const TabContent = ({ | |
handleAdd, | ||
type, | ||
}: TabContentProps) => { | ||
const [query, setQuery] = useState<string>(""); | ||
const [page, setPage] = useState<number>(0); | ||
const [chunkSize, setChunkSize] = useState<number>(10); | ||
|
||
const handleEditClick = (id: number) => { | ||
handleEdit(id, type); | ||
}; | ||
|
||
const handleFilterContent = () => { | ||
let validData: Array<CategoryType | SubjectType | DocumentType> = | ||
data.filter((option) => { | ||
return option.name.toLowerCase().includes(query.toLowerCase()); | ||
}); | ||
return validData; | ||
}; | ||
|
||
const handlePaging = () => { | ||
let pagedData: Array<Array<CategoryType | SubjectType | DocumentType>> = []; | ||
let validData: Array<CategoryType | SubjectType | DocumentType> = | ||
handleFilterContent(); | ||
for (let i = 0; i < validData.length; i += chunkSize) { | ||
pagedData.push(validData.slice(i, i + chunkSize)); | ||
} | ||
return pagedData; | ||
}; | ||
|
||
return ( | ||
<TableContainer component={Paper}> | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>{title}</TableCell> | ||
<TableCell> | ||
<OutlinedInput | ||
sx={{ width: "120%" }} | ||
placeholder={`Search for ${title}`} | ||
onChange={(event: ChangeEvent<HTMLInputElement>) => { | ||
setQuery(event.target.value); | ||
//go back to first page to prevent overflow | ||
setPage(0); | ||
handleFilterContent(); | ||
}} | ||
/> | ||
</TableCell> | ||
|
||
<TableCell align="right"> | ||
<Button onClick={handleAdd}>+</Button> | ||
<Button onClick={handleAdd}>+ {title}</Button> | ||
</TableCell> | ||
</TableRow> | ||
<TableRow> | ||
<TableCell colSpan={2}> | ||
<ChakraProvider> | ||
<Pagination | ||
pageInfo={{ | ||
page: page + 1, | ||
size: chunkSize, | ||
total: handleFilterContent().length, | ||
pages: handlePaging().length, | ||
}} | ||
handlePageChange={(newPage: number) => { | ||
setPage(newPage - 1); | ||
}} | ||
HStackStyles={{ spacing: 10, mt: "0%" }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can |
||
/> | ||
</ChakraProvider> | ||
</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{data.map((item) => ( | ||
{(handlePaging()[page] || []).map((item) => ( | ||
<TableRow key={item.id}> | ||
<TableCell component="th" scope="row"> | ||
{item.name} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you yarn format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep i did
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok nvm, i think is some inconsistent styling, usually it should have at least some space in between different code component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this new interface, remove
HStackStyles
fromPaginationProps
, AllowPagination
to take in new propstyles