Skip to content
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

Merged
merged 43 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9236f53
feat: update rate limit
vichannnnn Jun 11, 2023
3c40421
Merge branches 'dev' and 'dev' of https://github.com/vichannnnn/holy-…
SebassNoob Jun 14, 2023
43f7044
Merge branch 'dev' of https://github.com/vichannnnn/holy-grail into dev
SebassNoob Jun 16, 2023
e57972e
Merge branch 'dev' of https://github.com/vichannnnn/holy-grail into dev
SebassNoob Jun 17, 2023
ea81e86
feat: add search and pagination to dev page
SebassNoob Jun 15, 2023
5032d3a
fix: page overflow while searching
SebassNoob Jun 16, 2023
6a00261
fix: fix pr comments
SebassNoob Jun 17, 2023
e5df24b
fix: incorrect override for HStackStyles
SebassNoob Jun 17, 2023
afb164b
fix: remove unnecessary comments, imports
SebassNoob Jun 17, 2023
29d11eb
fix: cleanup editmodal code
SebassNoob Jun 18, 2023
8e637a2
feat: add edit note button on lib for admins
SebassNoob Jun 18, 2023
eae808b
new FE (desktop)
ddaarrrryyll Jun 18, 2023
1c9ed9f
updated FE for mobile
ddaarrrryyll Jun 18, 2023
767f092
ran yarn format
ddaarrrryyll Jun 18, 2023
552dccc
update cards
ddaarrrryyll Jun 18, 2023
e818bd8
fix: use mui for Box component
SebassNoob Jun 19, 2023
a70ac4a
Merge pull request #16 from vichannnnn/feat/lib-edit-admin
ddaarrrryyll Jun 19, 2023
f746812
fix: implement tabcontent design changes
SebassNoob Jun 19, 2023
5ab7059
fix: rewrite in mui
SebassNoob Jun 19, 2023
fe1e3d0
fix: rewrite in mui
SebassNoob Jun 20, 2023
3e56fe2
fix: do approvalscreen
SebassNoob Jun 20, 2023
1e1c211
adjust spacing between text fields
ddaarrrryyll Jun 20, 2023
b568d05
Merge pull request #15 from vichannnnn/fix/cleanup-editmodal
ddaarrrryyll Jun 20, 2023
bbe493b
new FE (desktop)
ddaarrrryyll Jun 18, 2023
ce7eac6
updated FE for mobile
ddaarrrryyll Jun 18, 2023
8bbb575
ran yarn format
ddaarrrryyll Jun 18, 2023
b5d8612
update cards
ddaarrrryyll Jun 18, 2023
f4adbde
Merge branch 'new-FE' of https://github.com/vichannnnn/holy-grail int…
ddaarrrryyll Jun 20, 2023
a9ac095
Merge pull request #17 from vichannnnn/new-FE
ddaarrrryyll Jun 20, 2023
fe90cde
fix: rewrite in mui
SebassNoob Jun 20, 2023
7bb989d
fix: do approvalscreen
SebassNoob Jun 20, 2023
318ec18
Merge branch 'fix/remove-chakra-admin' of https://github.com/vichannn…
ddaarrrryyll Jun 20, 2023
b455721
rebase dev
ddaarrrryyll Jun 20, 2023
c799732
Merge branch 'dev' into fix/remove-chakra-admin
ddaarrrryyll Jun 20, 2023
4f692d2
Merge pull request #18 from vichannnnn/fix/remove-chakra-admin
ddaarrrryyll Jun 20, 2023
a835a5c
feat: add search and pagination to dev page
SebassNoob Jun 15, 2023
26d6fca
fix: page overflow while searching
SebassNoob Jun 16, 2023
76a559b
fix: fix pr comments
SebassNoob Jun 17, 2023
25fb7a4
fix: incorrect override for HStackStyles
SebassNoob Jun 17, 2023
8023247
fix: remove unnecessary comments, imports
SebassNoob Jun 17, 2023
306a263
fix: implement tabcontent design changes
SebassNoob Jun 19, 2023
f33f7e5
Merge branch 'feat/developer-search-paginate' of https://github.com/v…
ddaarrrryyll Jun 20, 2023
6b77973
rebase
ddaarrrryyll Jun 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions holy-grail-frontend/src/components/Pagination/Pagination.tsx
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;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you yarn format?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep i did

Copy link
Owner

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

Copy link
Collaborator

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 from PaginationProps, Allow Pagination to take in new prop styles

interface PaginationProps {
pageInfo: { page: number; size: number; total: number; pages: number };
handlePageChange: (newPage: number) => void;
HStackStyles?: HStackStyles;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this optional parameter to customise Hstack properties

Copy link
Owner

Choose a reason for hiding this comment

The 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 HStack straight

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 pagination component. hence the reasoning for this addition

}

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}
Copy link
Owner

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Owner

Choose a reason for hiding this comment

The 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

Copy link
Collaborator

Choose a reason for hiding this comment

The 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%"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after adding styles prop just change to mt={styles?.mt ? styles.mt : "10%"}

imo this 10% warrants a review but just do ^ first

>
<Button
onClick={() => debouncedHandlePageChange(pageInfo.page - 1)}
isDisabled={pageInfo.page === 1}
Expand Down
63 changes: 59 additions & 4 deletions holy-grail-frontend/src/features/Developer/TabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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%" }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can styles={{ mt: "0%" }} after everything above

/>
</ChakraProvider>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data.map((item) => (
{(handlePaging()[page] || []).map((item) => (
<TableRow key={item.id}>
<TableCell component="th" scope="row">
{item.name}
Expand Down