From 6406fa9a5f09a0efd8b2e00af1d54aef2a917122 Mon Sep 17 00:00:00 2001 From: deo002 Date: Wed, 27 Nov 2024 13:18:00 +0530 Subject: [PATCH] refactor(requests): Refactor requests folder --- messages/de.json | 1 + messages/en.json | 1 + messages/es.json | 1 + messages/fr.json | 1 + messages/ja.json | 1 + messages/ko.json | 1 + messages/pt-BR.json | 1 + messages/vi.json | 1 + messages/zh-CN.json | 1 + messages/zh-TW.json | 1 + package-lock.json | 120 +++++++ .../[id]/components/ClearingComments.tsx | 120 +++---- .../[id]/components/ClearingDecision.tsx | 12 +- .../[id]/components/ClearingRequestDetail.tsx | 8 +- .../[id]/components/ClearingRequestInfo.tsx | 14 +- .../clearingRequest/detail/[id]/page.tsx | 2 +- .../[id]/components/EditClearingDecision.tsx | 276 +++++++-------- .../[id]/components/EditClearingRequest.tsx | 67 ++-- .../components/EditClearingRequestInfo.tsx | 12 +- .../ReopenClosedClearingRequestModal.tsx | 327 +++++++++--------- .../clearingRequest/edit/[id]/page.tsx | 2 +- .../BulkDeclineModerationRequestModal.tsx | 59 ++-- .../components/ClosedClearingRequest.tsx | 33 +- .../components/ClosedModerationRequest.tsx | 33 +- .../components/OpenClearingRequest.tsx | 160 +++++---- .../components/OpenModerationRequest.tsx | 33 +- .../[locale]/requests/components/Requests.tsx | 86 ++--- .../[id]/components/ModerationDecision.tsx | 6 +- .../components/ModerationRequestDetail.tsx | 6 +- .../[id]/components/ModerationRequestInfo.tsx | 7 +- .../[id]/components/ProposedChanges.tsx | 4 +- .../CurrentComponentDetail.tsx | 18 +- .../currentProject/CurrentProjectDetail.tsx | 18 +- .../currentRelease/CurrentReleaseDetail.tsx | 36 +- .../requests/moderationRequest/[id]/page.tsx | 2 +- src/object-types/ClearingRequestDetails.ts | 2 +- 36 files changed, 798 insertions(+), 675 deletions(-) diff --git a/messages/de.json b/messages/de.json index f53c0f6cd..8188b6cd8 100644 --- a/messages/de.json +++ b/messages/de.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/Gruppe", "default": { "(n/a)": "", "A package with the same name and version already exists": "Ein Paket mit demselben Namen und derselben Version ist bereits vorhanden", diff --git a/messages/en.json b/messages/en.json index 53ee97639..1f0a01994 100644 --- a/messages/en.json +++ b/messages/en.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/Group", "default": { "(n/a)": "(n/a)", "A package with the same name and version already exists": "A package with the same name and version already exists", diff --git a/messages/es.json b/messages/es.json index 001fe8ea0..211221585 100644 --- a/messages/es.json +++ b/messages/es.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/Grupo", "default": { "(n/a)": "", "A package with the same name and version already exists": "Ya existe un paquete con el mismo nombre y versión.", diff --git a/messages/fr.json b/messages/fr.json index 037d6ffde..f8a15ccb8 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/Groupe", "default": { "(n/a)": "", "A package with the same name and version already exists": "Un package avec le même nom et la même version existe déjà", diff --git a/messages/ja.json b/messages/ja.json index adcde8639..719435dd7 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/グループ", "default": { "(n/a)": "", "A package with the same name and version already exists": "同じ名前とバージョンのパッケージがすでに存在します", diff --git a/messages/ko.json b/messages/ko.json index 8cb7ec6ac..7d6de52c1 100644 --- a/messages/ko.json +++ b/messages/ko.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/그룹", "default": { "(n/a)": "", "A package with the same name and version already exists": "이름과 버전이 같은 패키지가 이미 존재합니다.", diff --git a/messages/pt-BR.json b/messages/pt-BR.json index 9f6b15ffc..106d63b9c 100644 --- a/messages/pt-BR.json +++ b/messages/pt-BR.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/Grupo", "default": { "(n/a)": "", "A package with the same name and version already exists": "Já existe um pacote com o mesmo nome e versão", diff --git a/messages/vi.json b/messages/vi.json index 7d58c4424..8284af4d7 100644 --- a/messages/vi.json +++ b/messages/vi.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/Nhóm", "default": { "(n/a)": "", "A package with the same name and version already exists": "Đã tồn tại gói có cùng tên và phiên bản", diff --git a/messages/zh-CN.json b/messages/zh-CN.json index 12180aa02..796b11aa8 100644 --- a/messages/zh-CN.json +++ b/messages/zh-CN.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/组", "default": { "(n/a)": "", "A package with the same name and version already exists": "已存在同名同版本的包", diff --git a/messages/zh-TW.json b/messages/zh-TW.json index 1ec6aff6a..055b92116 100644 --- a/messages/zh-TW.json +++ b/messages/zh-TW.json @@ -1,4 +1,5 @@ { + "BA-BL/Group": "BA-BL/組", "default": { "(n/a)": "", "A package with the same name and version already exists": "已存在同名同版本的包", diff --git a/package-lock.json b/package-lock.json index 4a7e4fe3f..93d03b549 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1111,6 +1111,126 @@ "node": ">= 10" } }, + "node_modules/@next/swc-darwin-x64": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.18.tgz", + "integrity": "sha512-uJCEjutt5VeJ30jjrHV1VIHCsbMYnEqytQgvREx+DjURd/fmKy15NaVK4aR/u98S1LGTnjq35lRTnRyygglxoA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.18.tgz", + "integrity": "sha512-IL6rU8vnBB+BAm6YSWZewc+qvdL1EaA+VhLQ6tlUc0xp+kkdxQrVqAnh8Zek1ccKHlTDFRyAft0e60gteYmQ4A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.18.tgz", + "integrity": "sha512-RCaENbIZqKKqTlL8KNd+AZV/yAdCsovblOpYFp0OJ7ZxgLNbV5w23CUU1G5On+0fgafrsGcW+GdMKdFjaRwyYA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.18.tgz", + "integrity": "sha512-3kmv8DlyhPRCEBM1Vavn8NjyXtMeQ49ID0Olr/Sut7pgzaQTo4h01S7Z8YNE0VtbowyuAL26ibcz0ka6xCTH5g==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.18.tgz", + "integrity": "sha512-mliTfa8seVSpTbVEcKEXGjC18+TDII8ykW4a36au97spm9XMPqQTpdGPNBJ9RySSFw9/hLuaCMByluQIAnkzlw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.18.tgz", + "integrity": "sha512-J5g0UFPbAjKYmqS3Cy7l2fetFmWMY9Oao32eUsBPYohts26BdrMUyfCJnZFQkX9npYaHNDOWqZ6uV9hSDPw9NA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.18.tgz", + "integrity": "sha512-Ynxuk4ZgIpdcN7d16ivJdjsDG1+3hTvK24Pp8DiDmIa2+A4CfhJSEHHVndCHok6rnLUzAZD+/UOKESQgTsAZGg==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-x64-msvc": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.18.tgz", + "integrity": "sha512-dtRGMhiU9TN5nyhwzce+7c/4CCeykYS+ipY/4mIrGzJ71+7zNo55ZxCB7cAVuNqdwtYniFNR2c9OFQ6UdFIMcg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", diff --git a/src/app/[locale]/requests/clearingRequest/detail/[id]/components/ClearingComments.tsx b/src/app/[locale]/requests/clearingRequest/detail/[id]/components/ClearingComments.tsx index a68ac4693..986c70db5 100644 --- a/src/app/[locale]/requests/clearingRequest/detail/[id]/components/ClearingComments.tsx +++ b/src/app/[locale]/requests/clearingRequest/detail/[id]/components/ClearingComments.tsx @@ -14,18 +14,18 @@ import { ClearingRequestComments, Embedded, HttpStatus } from '@/object-types' import MessageService from '@/services/message.service' import { ApiUtils, CommonUtils } from '@/utils/index' import parse from 'html-react-parser' -import { getSession, signOut } from 'next-auth/react' +import { getSession, signOut, useSession } from 'next-auth/react' import { useTranslations } from 'next-intl' import Link from 'next/link' import { notFound } from 'next/navigation' -import { ReactElement, useCallback, useEffect, useState } from 'react' +import { ReactNode, useCallback, useEffect, useState } from 'react' import { Spinner } from 'react-bootstrap' type EmbeddedClearingRequestComments = Embedded export default function ClearingComments({ clearingRequestId, -}: Readonly<{ clearingRequestId: string | undefined }>): ReactElement | undefined { +}: Readonly<{ clearingRequestId: string | undefined }>): ReactNode | undefined { const t = useTranslations('default') const [loading, setLoading] = useState(true) const [comments, setComments] = useState>([]) @@ -33,9 +33,10 @@ export default function ClearingComments({ const [commentPayload, setCommentPayload] = useState({ text: '', }) + const { status } = useSession() - const formatDate = (timestamp: number | undefined): string | null => { - if (timestamp == null) { + const formatDate = (timestamp: number | undefined) : string | null => { + if (timestamp === undefined) { return null } const date = new Date(timestamp) @@ -108,79 +109,80 @@ export default function ClearingComments({ if (status === 'unauthenticated') { signOut() } else { - return ( - <> - {loading == false ? ( - - - - - - - - - - - - {t('Preferred Clearing Date')} : - + + + {' '} + { t('reopen clearing request')} + + + + setShowMessage(false)} + show={showMessage} + dismissible> + {message} + + + + + {t('Please enter details to re-open clearing request')} + +
+
+
+ +
+ + + {t('Preferred Clearing Date')} : + + * + + + +
+ + {' '}{t('Learn more about preferred clearing date')}. +
+
+ + + + + {t('Clearing Type')} : + + * + + + - * - - - -
- {' '} - {t('Learn more about preferred clearing date')}. -
-
- - - - - {t('Clearing Type')} : - - * - - - - - - - -
- {' '} - {t('Learn more about clearing request type')}. -
-
- - - - - {t('Critical')} - - - - {t('Comments')} : - - - - - - - - - - ) - } + {t('Reopen Clearing Request')} + + + + + )} } diff --git a/src/app/[locale]/requests/clearingRequest/edit/[id]/page.tsx b/src/app/[locale]/requests/clearingRequest/edit/[id]/page.tsx index 0cd5bd194..1a6a46246 100644 --- a/src/app/[locale]/requests/clearingRequest/edit/[id]/page.tsx +++ b/src/app/[locale]/requests/clearingRequest/edit/[id]/page.tsx @@ -18,7 +18,7 @@ export const metadata: Metadata = { title: 'Requests', } -const EditClearingRequestPage = async ({ params }: Context) => { +const EditClearingRequestPage = ({ params }: Context): JSX.Element => { return } diff --git a/src/app/[locale]/requests/components/BulkDeclineModerationRequestModal.tsx b/src/app/[locale]/requests/components/BulkDeclineModerationRequestModal.tsx index afc5fcb77..94d3159ec 100644 --- a/src/app/[locale]/requests/components/BulkDeclineModerationRequestModal.tsx +++ b/src/app/[locale]/requests/components/BulkDeclineModerationRequestModal.tsx @@ -13,20 +13,23 @@ import { HttpStatus, ModerationRequestPayload } from '@/object-types' import { ApiUtils, CommonUtils } from '@/utils/index' import { useTranslations } from 'next-intl' import Link from 'next/link' -import { Dispatch, SetStateAction, useEffect, useState } from 'react' +import { Dispatch, SetStateAction, useEffect, useState, ReactNode } from 'react' import { Form, Modal, OverlayTrigger, Spinner, Tooltip } from 'react-bootstrap' import { AiOutlineQuestionCircle } from 'react-icons/ai' import MessageService from '@/services/message.service' -import { signOut, getSession } from 'next-auth/react' +import { signOut, getSession, useSession } from 'next-auth/react' import { _, Table } from 'next-sw360' import { BiCheckCircle, BiInfoCircle, BiXCircle } from 'react-icons/bi' import { BsFillExclamationCircleFill } from 'react-icons/bs' - interface propType { [key: string]: string } +interface ModerationRequestRow { + moderationRequestId: string, documentName: string +} + export default function BulkDeclineModerationRequestModal({ show, setShow, @@ -35,14 +38,16 @@ export default function BulkDeclineModerationRequestModal({ show: boolean setShow: Dispatch> mrIdNameMap: propType -}) { +}) : ReactNode { const t = useTranslations('default') const [loading, setLoading] = useState(true) const [disableAcceptMr, setDisableAcceptMr] = useState(false) const [disableDeclineMr, setDisableDeclineMr] = useState(false) const [statusCheck, setStatusCheck] = useState() - const [tableData, setTableData] = useState>([]) + const [tableData, setTableData] = useState>([]) const [hasComment, setHasComment] = useState(false) + const { status } = useSession() const [moderationRequestPayload, setModerationRequestPayload] = useState({ action: '', @@ -221,11 +226,12 @@ export default function BulkDeclineModerationRequestModal({ const progressStatus = computeProgress(response.status) setTableData((prevData) => { const updatedData = prevData.map((row) => { - if (row[0].moderationRequestId === singleMrId) { + const r = row[0] as ModerationRequestRow + if (r.moderationRequestId === singleMrId) { return [ { - moderationRequestId: row[0].moderationRequestId, - documentName: row[0].documentName, + moderationRequestId: r.moderationRequestId, + documentName: r.documentName, }, { progressStatus } ] @@ -242,11 +248,12 @@ export default function BulkDeclineModerationRequestModal({ const progressStatus = computeProgress(response.status) setTableData((prevData) => { const updatedData = prevData.map((row) => { - if (row[0].moderationRequestId === singleMrId) { + const r = row[0] as ModerationRequestRow + if (r.moderationRequestId === singleMrId) { return [ { - moderationRequestId: row[0].moderationRequestId, - documentName: row[0].documentName, + moderationRequestId: r.moderationRequestId, + documentName: r.documentName, }, { progressStatus } ] @@ -263,11 +270,12 @@ export default function BulkDeclineModerationRequestModal({ const progressStatus = computeProgress(response.status) setTableData((prevData) => { const updatedData = prevData.map((row) => { - if (row[0].moderationRequestId === singleMrId) { + const r = row[0] as ModerationRequestRow + if (r.moderationRequestId === singleMrId) { return [ { - moderationRequestId: row[0].moderationRequestId, - documentName: row[0].documentName, + moderationRequestId: r.moderationRequestId, + documentName: r.documentName, }, { progressStatus } ] @@ -313,11 +321,12 @@ export default function BulkDeclineModerationRequestModal({ const progressStatus = computeProgress(response.status) setTableData((prevData) => { const updatedData = prevData.map((row) => { - if (row[0].moderationRequestId === singleMrId) { + const r = row[0] as ModerationRequestRow + if (r.moderationRequestId === singleMrId) { return [ { - moderationRequestId: row[0].moderationRequestId, - documentName: row[0].documentName, + moderationRequestId: r.moderationRequestId, + documentName: r.documentName, }, { progressStatus } ] @@ -334,11 +343,12 @@ export default function BulkDeclineModerationRequestModal({ const progressStatus = computeProgress(response.status) setTableData((prevData) => { const updatedData = prevData.map((row) => { - if (row[0].moderationRequestId === singleMrId) { + const r = row[0] as ModerationRequestRow + if (r.moderationRequestId === singleMrId) { return [ { - moderationRequestId: row[0].moderationRequestId, - documentName: row[0].documentName, + moderationRequestId: r.moderationRequestId, + documentName: r.documentName, }, { progressStatus } ] @@ -355,11 +365,12 @@ export default function BulkDeclineModerationRequestModal({ const progressStatus = computeProgress(response.status) setTableData((prevData) => { const updatedData = prevData.map((row) => { - if (row[0].moderationRequestId === singleMrId) { + const r = row[0] as ModerationRequestRow + if (r.moderationRequestId === singleMrId) { return [ { - moderationRequestId: row[0].moderationRequestId, - documentName: row[0].documentName, + moderationRequestId: r.moderationRequestId, + documentName: r.documentName, }, { progressStatus } ] @@ -413,7 +424,7 @@ export default function BulkDeclineModerationRequestModal({ if (status === 'unauthenticated') { - signOut() + return signOut() } else { return ( <> diff --git a/src/app/[locale]/requests/components/ClosedClearingRequest.tsx b/src/app/[locale]/requests/components/ClosedClearingRequest.tsx index ca8b1e767..71e903b87 100644 --- a/src/app/[locale]/requests/components/ClosedClearingRequest.tsx +++ b/src/app/[locale]/requests/components/ClosedClearingRequest.tsx @@ -9,14 +9,14 @@ 'use client' -import { ClearingRequest, Embedded, HttpStatus } from '@/object-types' -import { ApiUtils, CommonUtils } from '@/utils/index' -import { getSession, signOut } from 'next-auth/react' -import { useTranslations } from 'next-intl' -import { Table, _ } from 'next-sw360' import Link from 'next/link' +import { ReactNode, useCallback, useEffect, useState } from 'react' +import { Table, _ } from "next-sw360" +import { useTranslations } from 'next-intl' +import { ApiUtils, CommonUtils } from '@/utils/index' +import { Embedded, HttpStatus, ClearingRequest } from '@/object-types' +import { signOut, getSession, useSession } from 'next-auth/react' import { notFound } from 'next/navigation' -import { useCallback, useEffect, useState } from 'react' import { Button, OverlayTrigger, Spinner, Tooltip } from 'react-bootstrap' import { FaPencilAlt } from 'react-icons/fa' @@ -28,11 +28,13 @@ interface ProjectData { projectName?: string } -function ClosedClearingRequest() { +function ClosedClearingRequest(): ReactNode { + const t = useTranslations('default') const [loading, setLoading] = useState(true) - const [tableData, setTableData] = useState>([]) + const [tableData, setTableData] = useState>([]) const [isProjectDeleted, setIsProjectDeleted] = useState(false) + const { status } = useSession() const columns = [ { @@ -60,16 +62,13 @@ function ClosedClearingRequest() { sort: true, formatter: (projectData: ProjectData) => _( - projectData.isProjectDeleted ?? false ? ( - t('Project Deleted') - ) : ( - + (projectData.isProjectDeleted !== undefined && projectData.isProjectDeleted === true) ? t('Project Deleted') : + <> + {projectData.projectName} - ), + , ), }, { @@ -245,7 +244,7 @@ function ClosedClearingRequest() { }, [fetchData]) if (status === 'unauthenticated') { - signOut() + void signOut() } else { return (
diff --git a/src/app/[locale]/requests/components/ClosedModerationRequest.tsx b/src/app/[locale]/requests/components/ClosedModerationRequest.tsx index 962a4ac4c..ec3a75e23 100644 --- a/src/app/[locale]/requests/components/ClosedModerationRequest.tsx +++ b/src/app/[locale]/requests/components/ClosedModerationRequest.tsx @@ -9,14 +9,14 @@ 'use client' -import { Embedded, HttpStatus, ModerationRequest } from '@/object-types' import { ApiUtils, CommonUtils } from '@/utils/index' -import { getSession, signOut } from 'next-auth/react' +import { signOut, getSession, useSession } from 'next-auth/react' import { useTranslations } from 'next-intl' import { Table, _ } from 'next-sw360' import Link from 'next/link' +import { useEffect, useState, useCallback, ReactNode } from 'react' +import { Embedded, HttpStatus, ModerationRequest } from '@/object-types' import { notFound } from 'next/navigation' -import { useCallback, useEffect, useState } from 'react' import { Spinner } from 'react-bootstrap' import ExpandingModeratorCell from './ExpandingModeratorCell' @@ -25,11 +25,12 @@ interface ModerationRequestMap { [key: string]: string } -function ClosedModerationRequest() { +function ClosedModerationRequest(): ReactNode { + const { status } = useSession() const t = useTranslations('default') const [loading, setLoading] = useState(true) - const [tableData, setTableData] = useState>([]) - const moderationRequestStatus: ModerationRequestMap = { + const [tableData, setTableData] = useState<(string | object | string[])[][]>([]) + const moderationRequestStatus : ModerationRequestMap = { INPROGRESS: t('In Progress'), APPROVED: t('APPROVED'), PENDING: t('Pending'), @@ -37,7 +38,7 @@ function ClosedModerationRequest() { } const formatDate = (timestamp: number | undefined): string | null => { - if (timestamp == null) { + if (timestamp === undefined) { return null } const date = new Date(timestamp) @@ -72,13 +73,14 @@ function ClosedModerationRequest() { if (filteredModerationRequests !== undefined) { setTableData( filteredModerationRequests.map((item: ModerationRequest) => [ - formatDate(item.timestamp), - item.componentType, - _({item.documentName}), - item.requestingUser, - item.requestingUserDepartment, - item.moderators, - item.moderationState !== undefined ? moderationRequestStatus[item.moderationState] : undefined, + formatDate(item.timestamp) ?? '', + item.componentType ?? '', + { id: item.id, documentName: item.documentName }, + item.requestingUser ?? '', + item.requestingUserDepartment ?? '', + item.moderators ?? [], + item.moderationState !== undefined ? + moderationRequestStatus[item.moderationState]: '', '', ]), ) @@ -101,6 +103,7 @@ function ClosedModerationRequest() { { id: 'closedModerationRequest.documentName', name: t('Document Name'), + formatter: ({ id, documentName }: { id: string, documentName: string }) => _({documentName}), sort: true, }, { @@ -141,7 +144,7 @@ function ClosedModerationRequest() { ] if (status === 'unauthenticated') { - signOut() + void signOut() } else { return (
diff --git a/src/app/[locale]/requests/components/OpenClearingRequest.tsx b/src/app/[locale]/requests/components/OpenClearingRequest.tsx index f6b3805e5..a4a5ab862 100644 --- a/src/app/[locale]/requests/components/OpenClearingRequest.tsx +++ b/src/app/[locale]/requests/components/OpenClearingRequest.tsx @@ -9,14 +9,14 @@ 'use client' -import { ClearingRequest, Embedded, HttpStatus } from '@/object-types' -import { ApiUtils, CommonUtils } from '@/utils/index' -import { signOut, useSession } from 'next-auth/react' -import { useTranslations } from 'next-intl' -import { Table, _ } from 'next-sw360' import Link from 'next/link' +import { ReactNode, useCallback, useEffect, useState } from 'react' +import { Table, _ } from "next-sw360" +import { useTranslations } from 'next-intl' +import { ApiUtils, CommonUtils } from '@/utils/index' +import { Embedded, HttpStatus, UserGroupType, ClearingRequest } from '@/object-types' +import { getSession, signOut, useSession } from 'next-auth/react' import { notFound } from 'next/navigation' -import { useCallback, useEffect, useState } from 'react' import { Button, OverlayTrigger, Spinner, Tooltip } from 'react-bootstrap' import { FaPencilAlt } from 'react-icons/fa' @@ -40,14 +40,14 @@ interface ProjectData { projectName?: string } -function LicenseClearing(licenseClearing: LicenseClearing) { +function LicenseClearing(licenseClearing: LicenseClearing): ReactNode | undefined { const [lcData, setLcData] = useState(null) const { data: session, status } = useSession() useEffect(() => { const controller = new AbortController() const signal = controller.signal - ;(async () => { + void (async () => { try { if (!session) { return signOut() @@ -64,7 +64,7 @@ function LicenseClearing(licenseClearing: LicenseClearing) { return notFound() } - const data = await response.json() + const data = await response.json() as LicenseClearingData setLcData(data) } catch (e) { @@ -76,16 +76,21 @@ function LicenseClearing(licenseClearing: LicenseClearing) { }, [licenseClearing.projectId]) if (status === 'unauthenticated') { - signOut() + void signOut() } else { - return ( - <> - {lcData ? ( - <> - {(licenseClearing.openReleases ?? false) && lcData['Release Count'] ? ( -
{`${lcData['Release Count']}`}
- ) : null} - {licenseClearing.clearingProgress ?? false ? ( + return ( + <> + { lcData ? ( + <> + { + licenseClearing.openReleases !== undefined && lcData['Release Count']? ( +
+ {`${lcData['Release Count']}`} +
+ ) : null + } + { + licenseClearing.clearingProgress !== undefined ? (
{`${lcData['Approved Count']}/${lcData['Release Count']}`}
@@ -101,27 +106,31 @@ function LicenseClearing(licenseClearing: LicenseClearing) { } } -function OpenClearingRequest() { +function OpenClearingRequest(): ReactNode { + const t = useTranslations('default') const { data: session, status } = useSession() const [loading, setLoading] = useState(true) const [isProjectDeleted, setIsProjectDeleted] = useState(false) - const [tableData, setTableData] = useState>([]) + const [tableData, setTableData] = useState<(object | string)[][]>([]) - const fetchData = useCallback(async (url: string) => { - if (CommonUtils.isNullOrUndefined(session)) { - return signOut() - } - const response = await ApiUtils.GET(url, session.user.access_token) - if (response.status == HttpStatus.OK) { - const data = (await response.json()) as EmbeddedClearingRequest - return data - } else if (response.status == HttpStatus.UNAUTHORIZED) { - return signOut() - } else { - notFound() - } - }, []) + const fetchData = useCallback( + async (url: string) => { + const session = await getSession() + if (CommonUtils.isNullOrUndefined(session)){ + return signOut() + } + const response = await ApiUtils.GET(url, session.user.access_token) + if (response.status == HttpStatus.OK) { + const data = await response.json() as EmbeddedClearingRequest + return data + } else if (response.status == HttpStatus.UNAUTHORIZED) { + return signOut() + } else { + notFound() + } + },[] + ) useEffect(() => { setLoading(true) @@ -214,32 +223,25 @@ function OpenClearingRequest() { sort: true, formatter: (projectData: ProjectData) => _( - projectData.isProjectDeleted ?? false ? ( - t('Project Deleted') - ) : ( - + (projectData.isProjectDeleted !== undefined && projectData.isProjectDeleted) ? t('Project Deleted') : + <> + {projectData.projectName} - ), + , ), }, { id: 'openClearingRequest.openReleases', name: t('Open Releases'), sort: true, - formatter: (licenseClearing: LicenseClearing) => - _( - licenseClearing.isProjectDeleted ?? false ? ( - t('Not Available') - ) : ( - - ), + formatter: (licenseClearing: LicenseClearing) => + _( + (licenseClearing.isProjectDeleted !== undefined && licenseClearing.isProjectDeleted) ? t('Not Available') : + ), }, { @@ -347,16 +349,12 @@ function OpenClearingRequest() { id: 'openClearingRequest.clearingProgress', name: t('Clearing Progress'), sort: true, - formatter: (licenseClearing: LicenseClearing) => - _( - licenseClearing.isProjectDeleted ?? false ? ( - t('Not Available') - ) : ( - - ), + formatter: (licenseClearing: LicenseClearing) => + _( + (licenseClearing.isProjectDeleted !== undefined && licenseClearing.isProjectDeleted) ? t('Not Available') : + ), }, { @@ -400,28 +398,28 @@ function OpenClearingRequest() { sort: true, formatter: ({ requestId, requestingUser }: { requestId: string; requestingUser: string }) => _( - {t('Edit')}}> - - , - ), - }, + <> + + {t('Edit')} + }> + + + + + ) + } ] if (status === 'unauthenticated') { - signOut() + void signOut() } else { return (
diff --git a/src/app/[locale]/requests/components/OpenModerationRequest.tsx b/src/app/[locale]/requests/components/OpenModerationRequest.tsx index ef1f10fbb..fe1bcdf3d 100644 --- a/src/app/[locale]/requests/components/OpenModerationRequest.tsx +++ b/src/app/[locale]/requests/components/OpenModerationRequest.tsx @@ -9,14 +9,14 @@ 'use client' -import { Embedded, HttpStatus, ModerationRequest } from '@/object-types' import { ApiUtils, CommonUtils } from '@/utils/index' -import { signOut, useSession } from 'next-auth/react' +import { getSession, signOut, useSession } from 'next-auth/react' import { useTranslations } from 'next-intl' import { Table, _ } from 'next-sw360' import Link from 'next/link' +import { useEffect, useState, useCallback, ReactNode } from 'react' +import { Embedded, HttpStatus, ModerationRequest } from '@/object-types' import { notFound } from 'next/navigation' -import { useCallback, useEffect, useState } from 'react' import { Spinner } from 'react-bootstrap' import BulkDeclineModerationRequestModal from './BulkDeclineModerationRequestModal' import ExpandingModeratorCell from './ExpandingModeratorCell' @@ -26,12 +26,12 @@ interface ModerationRequestMap { [key: string]: string } -function OpenModerationRequest() { +function OpenModerationRequest(): ReactNode { const t = useTranslations('default') const [loading, setLoading] = useState(true) const { data: session, status } = useSession() const [mrIdArray, setMrIdArray] = useState>([]) - const [tableData, setTableData] = useState>([]) + const [tableData, setTableData] = useState<(object | string | string[])[][]>([]) const [disableBulkDecline, setDisableBulkDecline] = useState(true) const [bulkDeclineMRModal, setBulkDeclineMRModal] = useState(false) const [mrIdNameMap, setMrIdNameMap] = useState<{ [key: string]: string }>({}) @@ -43,7 +43,7 @@ function OpenModerationRequest() { } const formatDate = (timestamp: number | undefined): string | null => { - if (timestamp == null) { + if(timestamp === undefined){ return null } const date = new Date(timestamp) @@ -55,7 +55,9 @@ function OpenModerationRequest() { const fetchData = useCallback( async (url: string) => { - if (CommonUtils.isNullOrUndefined(session)) return signOut() + const session = await getSession() + if (CommonUtils.isNullOrUndefined(session)) + return signOut() const response = await ApiUtils.GET(url, session.user.access_token) if (response.status == HttpStatus.OK) { const data = (await response.json()) as EmbeddedModerationRequest @@ -81,18 +83,17 @@ function OpenModerationRequest() { setTableData( filteredModerationRequests.map((item: ModerationRequest) => { return [ - formatDate(item.timestamp), - item.documentType, + formatDate(item.timestamp) ?? '', + item.documentType ?? '', { id: item.id, documentName: item.documentName, }, - item.requestingUser, - item.requestingUserDepartment, - item.moderators, - item.moderationState !== undefined - ? moderationRequestStatus[item.moderationState] - : undefined, + item.requestingUser ?? '', + item.requestingUserDepartment ?? '', + item.moderators ?? [], + item.moderationState !== undefined ? + moderationRequestStatus[item.moderationState] : '', { moderationRequestId: item.id, documentName: item.documentName, @@ -203,7 +204,7 @@ function OpenModerationRequest() { ] if (status === 'unauthenticated') { - signOut() + void signOut() } else { return ( <> diff --git a/src/app/[locale]/requests/components/Requests.tsx b/src/app/[locale]/requests/components/Requests.tsx index 8860b33dc..2b05be493 100644 --- a/src/app/[locale]/requests/components/Requests.tsx +++ b/src/app/[locale]/requests/components/Requests.tsx @@ -16,10 +16,10 @@ import OpenModerationRequest from './OpenModerationRequest' import ClosedModerationRequest from './ClosedModerationRequest' import OpenClearingRequest from './OpenClearingRequest' import ClosedClearingRequest from './ClosedClearingRequest' -import { useCallback, useEffect, useState } from 'react' +import { ReactNode, useEffect, useState } from 'react' import { ApiUtils, CommonUtils } from '@/utils/index' import { ClearingRequest, Embedded, HttpStatus, ModerationRequest } from '@/object-types' -import { signOut, useSession } from 'next-auth/react' +import { signOut, useSession, getSession } from 'next-auth/react' import { notFound } from 'next/navigation' @@ -27,7 +27,7 @@ type EmbeddedModerationRequest = Embedded -function Requests() { +function Requests(): ReactNode { const t = useTranslations('default') const { data: session, status } = useSession() @@ -138,47 +138,44 @@ function Requests() { } ] - const fetchData = useCallback( - async (url: string) => { - if (CommonUtils.isNullOrUndefined(session)) - return signOut() - const response = await ApiUtils.GET(url, session.user.access_token) - if (response.status == HttpStatus.OK) { - const data = await response.json() - return data - } else if (response.status == HttpStatus.UNAUTHORIZED) { - return signOut() - } else { - notFound() - } - },[session] - ) - useEffect(() => { - void fetchData('moderationrequest') - .then((moderationRequests: EmbeddedModerationRequest) => { - let openMRCount = 0 - let closedMRCount = 0 - moderationRequests['_embedded']['sw360:moderationRequests'] - .filter((item: ModerationRequest) => { - if (item.moderationState === 'PENDING' || - item.moderationState === 'INPROGRESS') { - openMRCount++; - } - else if (item.moderationState === 'APPROVED' || - item.moderationState === 'REJECTED') { - closedMRCount++; - } - }) + const controller = new AbortController() + const signal = controller.signal + void (async () => { + try { + const session = await getSession() + if(CommonUtils.isNullOrUndefined(session)) + return signOut() + const moderationRequestsPrmosies = ApiUtils.GET('moderationrequest', session.user.access_token, signal) + const clearingRequestsPromises = ApiUtils.GET('clearingrequests', session.user.access_token, signal) + + const responses = await Promise.all([moderationRequestsPrmosies, clearingRequestsPromises]) + if(responses[0].status !== HttpStatus.OK || responses[1].status !== HttpStatus.OK) { + return notFound() + } + + const moderationRequests = await responses[0].json() as EmbeddedModerationRequest + let openMRCount = 0 + let closedMRCount = 0 + moderationRequests['_embedded']['sw360:moderationRequests'] + .map((item: ModerationRequest) => { + if (item.moderationState === 'PENDING' || + item.moderationState === 'INPROGRESS') { + openMRCount++; + } + else if (item.moderationState === 'APPROVED' || + item.moderationState === 'REJECTED') { + closedMRCount++; + } + }) setOpenModerationRequestCount(openMRCount) setClosedModerationRequestCount(closedMRCount) - }) - void fetchData('clearingrequests') - .then((clearingRequests: EmbeddedClearingRequest) => { + + const clearingRequests = await responses[1].json() as EmbeddedClearingRequest let openCRCount = 0 let closedCRCount = 0 clearingRequests['_embedded']['sw360:clearingRequests'] - .filter((item: ClearingRequest) => { + .map((item: ClearingRequest) => { if (item.clearingState === 'NEW' || item.clearingState === 'ACCEPTED' || item.clearingState === 'IN_QUEUE' || @@ -196,11 +193,18 @@ function Requests() { }) setOpenClearingRequestCount(openCRCount) setClosedClearingRequestCount(closedCRCount) - }) - }, [fetchData, session]) + + } catch(e) { + console.error(e) + } + })() + return () => { + controller.abort() + } + }, [session]) if (status === 'unauthenticated') { - signOut() + void signOut() } else { return ( <> diff --git a/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationDecision.tsx b/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationDecision.tsx index 51683e043..e8d93e6ba 100644 --- a/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationDecision.tsx +++ b/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationDecision.tsx @@ -10,6 +10,7 @@ 'use client' import { ModerationRequestDetails, ModerationRequestPayload } from '@/object-types' +import { ReactNode } from 'react' import { useTranslations } from 'next-intl' import Link from 'next/link' @@ -23,7 +24,10 @@ interface Props { setModerationRequestPayload: React.Dispatch> } -export default function ModerationDecision({ data, moderationRequestPayload, setModerationRequestPayload }: Props) { +export default function ModerationDecision({ data, + moderationRequestPayload, + setModerationRequestPayload }: Props ): ReactNode { + const t = useTranslations('default') const moderationRequestStatus: ModerationRequestMap = { INPROGRESS: t('In Progress'), diff --git a/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationRequestDetail.tsx b/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationRequestDetail.tsx index ad5547b90..be9740b13 100644 --- a/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationRequestDetail.tsx +++ b/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationRequestDetail.tsx @@ -19,7 +19,7 @@ import { ApiUtils, CommonUtils } from '@/utils/index' import { signOut, useSession } from 'next-auth/react' import { useTranslations } from 'next-intl' import { notFound, useRouter } from 'next/navigation' -import { useCallback, useEffect, useRef, useState } from 'react' +import { useCallback, useEffect, useRef, useState, ReactNode } from 'react' import { Button, Card, Col, Collapse, Row, Tab } from 'react-bootstrap' import ModerationDecision from './ModerationDecision' import ModerationRequestInfo from './ModerationRequestInfo' @@ -28,7 +28,7 @@ import CurrentComponentDetail from './currentComponent/CurrentComponentDetail' import CurrentProjectDetail from './currentProject/CurrentProjectDetail' import CurrentReleaseDetail from './currentRelease/CurrentReleaseDetail' -function ModerationRequestDetail({ moderationRequestId }: { moderationRequestId: string }) { +function ModerationRequestDetail({ moderationRequestId }: { moderationRequestId: string }): ReactNode | undefined { const t = useTranslations('default') const [openCardIndex, setOpenCardIndex] = useState(0) const { data: session, status } = useSession() @@ -227,7 +227,7 @@ function ModerationRequestDetail({ moderationRequestId }: { moderationRequestId: } if (status === 'unauthenticated') { - signOut() + return signOut() } else { return (
diff --git a/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationRequestInfo.tsx b/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationRequestInfo.tsx index f9aa5f551..6a3185aae 100644 --- a/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationRequestInfo.tsx +++ b/src/app/[locale]/requests/moderationRequest/[id]/components/ModerationRequestInfo.tsx @@ -12,13 +12,14 @@ import Link from 'next/link' import { useTranslations } from 'next-intl' import { ModerationRequestDetails } from '@/object-types' +import { ReactNode } from 'react' -export default function ModerationRequestInfo({ data }: { data: ModerationRequestDetails | undefined }) { +export default function ModerationRequestInfo({ data }: { data: ModerationRequestDetails | undefined }): ReactNode { const t = useTranslations('default') const formatDate = (timestamp: number | undefined): string | null => { - if(timestamp == null){ + if(timestamp == undefined){ return null } const date = new Date(timestamp); @@ -41,7 +42,7 @@ export default function ModerationRequestInfo({ data }: { data: ModerationReques
diff --git a/src/app/[locale]/requests/moderationRequest/[id]/components/ProposedChanges.tsx b/src/app/[locale]/requests/moderationRequest/[id]/components/ProposedChanges.tsx index bbca02a85..b804262b4 100644 --- a/src/app/[locale]/requests/moderationRequest/[id]/components/ProposedChanges.tsx +++ b/src/app/[locale]/requests/moderationRequest/[id]/components/ProposedChanges.tsx @@ -44,7 +44,7 @@ export default function ProposedChanges({ moderationRequestData, }: { moderationRequestData: ModerationRequestDetails | undefined -}) { +}): ReactNode | undefined { const t = useTranslations('default') const { data: session, status } = useSession() const dafaultTitle = t('BASIC FIELD CHANGES') @@ -344,7 +344,7 @@ export default function ProposedChanges({ }, [moderationRequestData]) if (status === 'unauthenticated') { - signOut() + return signOut() } else { return ( <> diff --git a/src/app/[locale]/requests/moderationRequest/[id]/components/currentComponent/CurrentComponentDetail.tsx b/src/app/[locale]/requests/moderationRequest/[id]/components/currentComponent/CurrentComponentDetail.tsx index 01f374037..f094a2d21 100644 --- a/src/app/[locale]/requests/moderationRequest/[id]/components/currentComponent/CurrentComponentDetail.tsx +++ b/src/app/[locale]/requests/moderationRequest/[id]/components/currentComponent/CurrentComponentDetail.tsx @@ -11,6 +11,9 @@ import ReleaseOverview from '@/app/[locale]/components/detail/[id]/components/ReleaseOverview' import Summary from '@/app/[locale]/components/detail/[id]/components/Summary' +import { signOut, useSession } from 'next-auth/react' +import { useTranslations } from 'next-intl' +import { useCallback, useEffect, useState, ReactNode } from 'react' import Attachments from '@/components/Attachments/Attachments' import ChangeLogDetail from '@/components/ChangeLog/ChangeLogDetail/ChangeLogDetail' import ChangeLogList from '@/components/ChangeLog/ChangeLogList/ChangeLogList' @@ -26,19 +29,16 @@ import { LinkedVulnerability, } from '@/object-types' import { ApiUtils, CommonUtils } from '@/utils' -import { signOut, useSession } from 'next-auth/react' -import { useTranslations } from 'next-intl' import { notFound } from 'next/navigation' -import { useCallback, useEffect, useState } from 'react' type EmbeddedChangelogs = Embedded type EmbeddedVulnerabilities = Embedded interface Props { - componentId: string | undefined + componentId: string } -const CurrentComponentDetail = ({ componentId }: Props): JSX.Element => { +const CurrentComponentDetail = ({ componentId }: Props): ReactNode => { const t = useTranslations('default') const { data: session } = useSession() const [selectedTab, setSelectedTab] = useState(CommonTabIds.SUMMARY) @@ -117,7 +117,7 @@ const CurrentComponentDetail = ({ componentId }: Props): JSX.Element => { >
{ hidden={selectedTab !== ComponentTabIds.RELEASE_OVERVIEW} >
@@ -134,7 +134,7 @@ const CurrentComponentDetail = ({ componentId }: Props): JSX.Element => { hidden={selectedTab != CommonTabIds.ATTACHMENTS} > @@ -149,7 +149,7 @@ const CurrentComponentDetail = ({ componentId }: Props): JSX.Element => { > diff --git a/src/app/[locale]/requests/moderationRequest/[id]/components/currentProject/CurrentProjectDetail.tsx b/src/app/[locale]/requests/moderationRequest/[id]/components/currentProject/CurrentProjectDetail.tsx index ff26ad6c8..180440689 100644 --- a/src/app/[locale]/requests/moderationRequest/[id]/components/currentProject/CurrentProjectDetail.tsx +++ b/src/app/[locale]/requests/moderationRequest/[id]/components/currentProject/CurrentProjectDetail.tsx @@ -18,13 +18,13 @@ import Summary from '@/app/[locale]/projects/detail/[id]/components/Summary' import VulnerabilityTrackingStatusComponent from '@/app/[locale]/projects/detail/[id]/components/VulnerabilityTrackingStatus' import { AdministrationDataType, HttpStatus, SummaryDataType } from '@/object-types' import { ApiUtils, CommonUtils } from '@/utils' -import { signOut, useSession } from 'next-auth/react' +import { signOut, useSession, getSession } from 'next-auth/react' import { useTranslations } from 'next-intl' import { notFound } from 'next/navigation' -import { useEffect, useState } from 'react' +import { ReactNode, useEffect, useState } from 'react' import { Col, ListGroup, Row, Spinner, Tab } from 'react-bootstrap' -export default function CurrentProjectDetail({ projectId }: Readonly<{ projectId: string }>) { +export default function CurrentProjectDetail({ projectId }: Readonly<{ projectId: string }>): ReactNode { const t = useTranslations('default') const { data: session, status } = useSession() const [summaryData, setSummaryData] = useState(undefined) @@ -34,8 +34,10 @@ export default function CurrentProjectDetail({ projectId }: Readonly<{ projectId const controller = new AbortController() const signal = controller.signal - ;(async () => { - if (CommonUtils.isNullOrUndefined(session)) return signOut() + void (async () => { + const session = await getSession() + if (CommonUtils.isNullOrUndefined(session)) + return signOut() try { const response = await ApiUtils.GET( `projects/${projectId}/summaryAdministration`, @@ -48,10 +50,10 @@ export default function CurrentProjectDetail({ projectId }: Readonly<{ projectId return notFound() } - const data = await response.json() + const data = await response.json() as SummaryDataType | AdministrationDataType - setSummaryData({ id: projectId, ...data }) - setAdministrationData(data) + setSummaryData({ ...data, id: projectId } as SummaryDataType) + setAdministrationData(data as AdministrationDataType) } catch (e) { console.error(e) } diff --git a/src/app/[locale]/requests/moderationRequest/[id]/components/currentRelease/CurrentReleaseDetail.tsx b/src/app/[locale]/requests/moderationRequest/[id]/components/currentRelease/CurrentReleaseDetail.tsx index 6fd96c7b8..b78e3105f 100644 --- a/src/app/[locale]/requests/moderationRequest/[id]/components/currentRelease/CurrentReleaseDetail.tsx +++ b/src/app/[locale]/requests/moderationRequest/[id]/components/currentRelease/CurrentReleaseDetail.tsx @@ -31,7 +31,7 @@ import { } from '@/object-types' import { ApiUtils, CommonUtils } from '@/utils' import { signOut, useSession } from 'next-auth/react' -import { useCallback, useEffect, useState } from 'react' +import { useCallback, useEffect, useState, ReactNode } from 'react' type EmbeddedChangelogs = Embedded @@ -39,7 +39,7 @@ interface Props { releaseId: string } -const CurrentReleaseDetail = ({ releaseId }: Props): JSX.Element => { +const CurrentReleaseDetail = ({ releaseId }: Props): ReactNode => { const { data: session } = useSession() const [selectedTab, setSelectedTab] = useState(CommonTabIds.SUMMARY) const [release, setRelease] = useState() @@ -51,26 +51,30 @@ const CurrentReleaseDetail = ({ releaseId }: Props): JSX.Element => { const [tabList] = useState(ReleaseDetailTabs.MODERATION_REQUEST) const fetchData = useCallback( - async (url: string) => { - if (CommonUtils.isNullOrUndefined(session)) return signOut() - const response = await ApiUtils.GET(url, session.user.access_token) - if (response.status == HttpStatus.OK) { - const data = await response.json() - return data - } else if (response.status == HttpStatus.UNAUTHORIZED) { - return signOut() - } else { - return null + async (url: string, signal: AbortSignal) => { + try { + if (CommonUtils.isNullOrUndefined(session)) return signOut() + const response = await ApiUtils.GET(url, session.user.access_token, signal) + if (response.status == HttpStatus.OK) { + const data = await response.json() as ReleaseDetail & EmbeddedChangelogs + return data + } else if (response.status == HttpStatus.UNAUTHORIZED) { + void signOut() + } + } catch(e) { + console.error(e) } }, [session], ) useEffect(() => { - fetchData(`releases/${releaseId}`) + const controller = new AbortController() + const signal = controller.signal + + fetchData(`releases/${releaseId}`, signal) .then((release: ReleaseDetail | undefined) => { setRelease(release) - if ( !CommonUtils.isNullOrUndefined(release?._embedded) && !CommonUtils.isNullOrUndefined(release._embedded['sw360:attachments']) @@ -81,7 +85,7 @@ const CurrentReleaseDetail = ({ releaseId }: Props): JSX.Element => { }) .catch((err) => console.error(err)) - fetchData(`changelog/document/${releaseId}`) + fetchData(`changelog/document/${releaseId}`, signal) .then((changeLogs: EmbeddedChangelogs | undefined) => { changeLogs && setChangeLogList( @@ -91,6 +95,8 @@ const CurrentReleaseDetail = ({ releaseId }: Props): JSX.Element => { ) }) .catch((err) => console.error(err)) + + return () => controller.abort() }, [fetchData, releaseId]) return release ? ( diff --git a/src/app/[locale]/requests/moderationRequest/[id]/page.tsx b/src/app/[locale]/requests/moderationRequest/[id]/page.tsx index f8d767a62..acc4e129d 100644 --- a/src/app/[locale]/requests/moderationRequest/[id]/page.tsx +++ b/src/app/[locale]/requests/moderationRequest/[id]/page.tsx @@ -18,7 +18,7 @@ export const metadata: Metadata = { title: 'Requests', } -const ModerationRequestDetailsPage = async ({ params }: Context) => { +const ModerationRequestDetailsPage = ({ params }: Context): JSX.Element => { return } diff --git a/src/object-types/ClearingRequestDetails.ts b/src/object-types/ClearingRequestDetails.ts index 6dbf14517..10e381995 100644 --- a/src/object-types/ClearingRequestDetails.ts +++ b/src/object-types/ClearingRequestDetails.ts @@ -7,7 +7,7 @@ // SPDX-License-Identifier: EPL-2.0 // License-Filename: LICENSE -import Project from './Project' +import { Project } from './Project' import { User } from './User' export default interface ClearingRequestDetails{
{t('Comments')}
- - diff --git a/src/app/[locale]/requests/clearingRequest/edit/[id]/components/EditClearingRequestInfo.tsx b/src/app/[locale]/requests/clearingRequest/edit/[id]/components/EditClearingRequestInfo.tsx index ddb034862..9656bd4f8 100644 --- a/src/app/[locale]/requests/clearingRequest/edit/[id]/components/EditClearingRequestInfo.tsx +++ b/src/app/[locale]/requests/clearingRequest/edit/[id]/components/EditClearingRequestInfo.tsx @@ -10,10 +10,10 @@ 'use client' import { useTranslations } from 'next-intl' -import { ClearingRequestDetails, UpdateClearingRequestPayload } from '@/object-types' +import { ClearingRequestDetails, UpdateClearingRequestPayload, UserGroupType } from '@/object-types' import styles from '@/app/[locale]/requests/requestDetail.module.css' import { signOut, useSession } from 'next-auth/react' -import { useEffect, useState } from 'react' +import { ReactNode, useEffect, useState } from 'react' import { SelectUsersDialog, ShowInfoOnHover } from 'next-sw360' interface Props { @@ -28,7 +28,7 @@ interface DataTypeProp { export default function EditClearingRequestInfo({ clearingRequestData, updateClearingRequestPayload, - setUpdateClearingRequestPayload }: Props) { + setUpdateClearingRequestPayload }: Props): ReactNode { const t = useTranslations('default') const { data:session, status } = useSession() const [minDate, setMinDate] = useState('') @@ -60,7 +60,7 @@ export default function EditClearingRequestInfo({ clearingRequestData, if (status === 'unauthenticated') { - signOut() + void signOut() } else { return ( <> @@ -82,7 +82,7 @@ export default function EditClearingRequestInfo({ clearingRequestData, name='requestingUser' onClick={() => setDialogOpenRequestingUser(true)} value={updateClearingRequestPayload.requestingUser} - disabled={session?.user.userGroup === "USER"} + disabled={session === null || session.user.userGroup === UserGroupType.USER} /> diff --git a/src/app/[locale]/requests/clearingRequest/edit/[id]/components/ReopenClosedClearingRequestModal.tsx b/src/app/[locale]/requests/clearingRequest/edit/[id]/components/ReopenClosedClearingRequestModal.tsx index 7f86657ef..348eac3fb 100644 --- a/src/app/[locale]/requests/clearingRequest/edit/[id]/components/ReopenClosedClearingRequestModal.tsx +++ b/src/app/[locale]/requests/clearingRequest/edit/[id]/components/ReopenClosedClearingRequestModal.tsx @@ -9,20 +9,22 @@ 'use client' -import { CreateClearingRequestPayload } from '@/object-types' -import { signOut, useSession } from 'next-auth/react' -import { useTranslations } from 'next-intl' -import { ShowInfoOnHover } from 'next-sw360' -import { Dispatch, SetStateAction, useCallback, useEffect, useState } from 'react' -import { Alert, Button, Col, Form, Modal, Row } from 'react-bootstrap' -import { FaRegQuestionCircle } from 'react-icons/fa' +import { signOut, useSession } from "next-auth/react" +import { useTranslations } from "next-intl" +import { Dispatch, ReactNode, SetStateAction, useCallback, useEffect, useState } from "react" +import { Alert, Button, Col, Form, Modal, Row } from "react-bootstrap" +import { CreateClearingRequestPayload } from "@/object-types" +import { FaRegQuestionCircle } from "react-icons/fa" +import { ShowInfoOnHover } from "next-sw360" interface Props { show: boolean setShow: Dispatch> } -export default function ReopenClosedClearingRequestModal({ show, setShow }: Props) { +export default function ReopenClosedClearingRequestModal({ show, + setShow + }: Props): ReactNode { const t = useTranslations('default') const { status } = useSession() const [message, setMessage] = useState('') @@ -113,171 +115,156 @@ export default function ReopenClosedClearingRequestModal({ show, setShow }: Prop } if (status === 'unauthenticated') { - signOut() + void signOut() } else { return ( - { - setShow(false) - }} - aria-labelledby={t('Reopen Clearing Request')} - scrollable - > - + { + setShow(false) + }} + aria-labelledby={t('Reopen Clearing Request')} + scrollable > - - {' '} - {t('reopen clearing request')} - - - - setShowMessage(false)} - show={showMessage} - dismissible - > - {message} - -
- - - {t('Please enter details to re-open clearing request')} - -
-
-
- -
{t('Requesting User')}: {((data?.requestingUser) != null) - ? {data?.requestingUser} + ? {data.requestingUser} : ''}