From f269e266a4c6d210a6bf133d73426cd6756a4d47 Mon Sep 17 00:00:00 2001 From: Jeong Heum Date: Mon, 16 Oct 2023 21:44:23 +0900 Subject: [PATCH] feat: History.jsx - Add function for flexible amount of Scan(#211) Signed-off-by: ByunJeongHeum Co-authored-by: Han Kyuhyun Co-authored-by: June Saehwan Co-authored-by: jongmin Lee --- frontend/src/pages/History.jsx | 229 +++++++++++++-------------------- 1 file changed, 87 insertions(+), 142 deletions(-) diff --git a/frontend/src/pages/History.jsx b/frontend/src/pages/History.jsx index 8a35289c..2fce5a01 100644 --- a/frontend/src/pages/History.jsx +++ b/frontend/src/pages/History.jsx @@ -25,6 +25,12 @@ export const History= () => { const [isLoggedIn, setIsLoggedIn] = useState(false); const [username, setUsername] = useState(""); + const [selectedSize, setSelectedSize] = useState(null); + + useEffect(() => { + setSelectedSize(5); +}, []); + useEffect(() => { axios.get("/user/login") .then((loginresponse) => { @@ -52,7 +58,6 @@ export const History= () => { axios .get(`/history/${type}/${name}?page=${page}`) .then((response) => { - console.log(response.data) setlpvsHistories(response.data); }) .catch(function(error) { @@ -64,7 +69,7 @@ export const History= () => { navigate(`/history/send/${username?.nickname}?page=0`); } }); - }, [type, name, page]); + }, [type, name, page, selectedSize]); const handlePageChange = (pageNumber) => { navigate(`/history/${type}/${name}?page=${pageNumber}`); @@ -79,8 +84,6 @@ export const History= () => { setIsHistoriesEmpty(false); } }, [lpvsHistories, page]); - - console.log(lpvsHistories) const navigateToOrg = () => { if (!username?.organization || username?.organization.trim() === "") { @@ -100,10 +103,8 @@ export const History= () => { const [currentPage, setCurrentPage] = useState(1); useEffect(()=> { - setPageCount(Math.ceil(lpvsHistories?.count/5)) - }, [lpvsHistories?.count, currentPage]); - - console.log(pageCount); + setPageCount(Math.ceil(lpvsHistories?.count/selectedSize)); +}, [lpvsHistories?.count, selectedSize]); const check_page_plus =()=> { if(currentPage <= pageCount) { @@ -114,8 +115,7 @@ export const History= () => { return } } - console.log(page); - console.log(currentPage); + const check_page_minus =(page)=> { if(page <=4) { return setCurrentPage(currentPage) @@ -142,7 +142,6 @@ export const History= () => { return 'Scan-completed'; } } - console.log(lpvsHistories?.lpvsHistories[0]?.status) if (!lpvsHistories) { return
Loading...
; @@ -161,7 +160,76 @@ export const History= () => { return false; } } - console.log(isHistoriesEmpty) + + +const renderHistories = (size) => { + return Array.from({ length: size }).map((_, index) => { + const history = lpvsHistories.lpvsHistories[index]; + if (history?.status !== undefined) { + return ( + +
+
+
+ {history?.repositoryName} +
+
+
+ {status_check(history?.hasIssue)} +
+
+
+
+
{history?.pullNumber}
+
+
+
+
+
{history?.url}
+
{history?.scanDate}
+
+
+
+ + ); + } + return null; + }); +}; + +const SIZE_DATA = [ + { id: null, value: 'Choose view Size.' }, + { id: '5', value: '5' }, + { id: '10', value: '10' }, + { id: '20', value: '20' }, + { id: '50', value: '50' }, +]; + +const SizeDropdown = () => { + const handleChange = (e) => { + setSelectedSize(e.target.value); + setCurrentPage(1); + }; + + return ( +
+ {selectedSize && View Items {selectedSize}} + +
+ ); +}; + + return (
@@ -201,6 +269,11 @@ export const History= () => {
+ +
+ {renderHistories(selectedSize ?? 5)} +
+
{ @@ -216,137 +289,10 @@ export const History= () => { {trueOrFalse(currentPage+5) ? {check_page_plus(); handlePageChange(currentPage + 4); }}style={{ cursor: "pointer" }}/> : } +
-
-
- {lpvsHistories.lpvsHistories[4]?.status !== undefined ? ( - -
-
-
- {lpvsHistories.lpvsHistories[4]?.repositoryName} -
-
-
- {status_check(lpvsHistories.lpvsHistories[4]?.hasIssue)} -
-
-
-
-
{lpvsHistories.lpvsHistories[4]?.pullNumber}
-
-
-
-
-
- -
{lpvsHistories.lpvsHistories[4]?.url}
-
{lpvsHistories.lpvsHistories[4]?.scanDate}
-
-
): null} - - {lpvsHistories.lpvsHistories[3]?.status !== undefined ? ( - -
-
-
- {lpvsHistories.lpvsHistories[3]?.repositoryName} -
-
-
{status_check(lpvsHistories.lpvsHistories[3]?.hasIssue)}
-
-
-
-
-
{lpvsHistories.lpvsHistories[3]?.pullNumber}
-
-
- -
-
-
{lpvsHistories.lpvsHistories[3]?.url}
-
{lpvsHistories.lpvsHistories[3]?.scanDate}
-
-
- ): null} - - {lpvsHistories.lpvsHistories[2]?.status !== undefined ? ( - -
-
-
- {lpvsHistories.lpvsHistories[2]?.repositoryName} -
-
-
{status_check(lpvsHistories.lpvsHistories[2]?.hasIssue)}
-
-
-
-
-
{lpvsHistories.lpvsHistories[2]?.pullNumber}
-
-
-
-
-
{lpvsHistories.lpvsHistories[2]?.url}
-
{lpvsHistories.lpvsHistories[2]?.scanDate}
-
-
- - ): null} - - {lpvsHistories.lpvsHistories[1]?.status !== undefined ? ( - -
-
-
- {lpvsHistories.lpvsHistories[1]?.repositoryName} -
-
-
{status_check(lpvsHistories.lpvsHistories[1]?.hasIssue)}
-
-
-
-
-
{lpvsHistories.lpvsHistories[1]?.pullNumber}
-
-
-
-
-
{lpvsHistories.lpvsHistories[1]?.url}
-
{lpvsHistories.lpvsHistories[1]?.scanDate}
-
-
- - ) : null} - {lpvsHistories.lpvsHistories[0]?.status !== undefined ? ( - -
-
-
- {lpvsHistories.lpvsHistories[0]?.repositoryName} -
-
-
{status_check(lpvsHistories.lpvsHistories[0]?.hasIssue)}
-
-
-
-
-
{lpvsHistories.lpvsHistories[0]?.pullNumber}
-
-
-
-
-
{lpvsHistories.lpvsHistories[0]?.url}
-
{lpvsHistories.lpvsHistories[0]?.scanDate}
-
-
- - ): null} -
-
@@ -364,8 +310,7 @@ export const History= () => {
-
Dashboard
-
+
History