From 732d5ac30b3ebb39aef04661fd0e72a6ee58743c Mon Sep 17 00:00:00 2001 From: hoangnt2 Date: Tue, 24 Sep 2024 17:51:22 +0700 Subject: [PATCH] fix(Code): Fix linter error component/release pages Signed-off-by: hoangnt2 --- messages/de.json | 5 +- messages/en.json | 5 +- messages/es.json | 5 +- messages/fr.json | 5 +- messages/ja.json | 5 +- messages/ko.json | 5 +- messages/pt-BR.json | 5 +- messages/vi.json | 5 +- messages/zh-CN.json | 5 +- messages/zh-TW.json | 5 +- nextauth.d.ts | 2 +- .../add/components/AddComponent.tsx | 14 +- src/app/[locale]/components/add/page.tsx | 3 +- .../components/components/ComponentIndex.tsx | 6 +- .../components/components/ComponentsTable.tsx | 7 +- .../components/DeleteComponentDialog.tsx | 62 +- .../components/components/ImportSBOMModal.tsx | 53 +- .../[id]/components/ComponentGeneral.tsx | 19 +- .../[id]/components/DeleteReleaseModal.tsx | 111 +- .../detail/[id]/components/DetailOverview.tsx | 44 +- .../[id]/components/ReleaseAggregate.tsx | 4 +- .../[id]/components/ReleaseOverview.tsx | 50 +- .../detail/[id]/components/Summary.tsx | 7 +- .../detail/[id]/components/SummaryRole.tsx | 14 +- .../[locale]/components/detail/[id]/page.tsx | 3 +- .../[id]/components/ComponentEditSummary.tsx | 53 +- .../edit/[id]/components/EditComponent.tsx | 38 +- .../edit/[id]/components/Releases.tsx | 22 +- .../[locale]/components/edit/[id]/page.tsx | 3 +- .../release/add/components/AddRelease.tsx | 22 +- .../add/components/ReleaseAddSummary.tsx | 8 +- .../components/edit/[id]/release/add/page.tsx | 3 +- .../[id]/components/ClearingDetails.tsx | 7 +- .../[id]/components/EditClearingDetails.tsx | 7 +- .../[id]/components/EditECCDetails.tsx | 4 +- .../[id]/components/EditRelease.tsx | 49 +- .../[id]/components/EditSPDXDocument.tsx | 53 +- .../[id]/components/ReleaseEditSummary.tsx | 28 +- .../[id]/components/RequestInformation.tsx | 7 +- .../components/SupplementalInformation.tsx | 7 +- .../AnnotationInformation/AnnotationDate.tsx | 13 +- .../spdx/AnnotationInformation/Annotator.tsx | 13 +- .../spdx/DocumentCreationInfo/Created.tsx | 9 +- .../spdx/DocumentCreationInfo/Creators.tsx | 13 +- .../spdx/EditAnnotationInformation.tsx | 66 +- .../spdx/EditDocumentCreationInformation.tsx | 794 +++---- .../EditOtherLicensingInformationDetected.tsx | 362 ++- .../spdx/EditPackageInformation.tsx | 1978 +++++++++-------- ...tionshipbetweenSPDXElementsInformation.tsx | 204 +- .../spdx/EditSnippetInformation.tsx | 78 +- .../[id]/components/spdx/OtherLicenseName.tsx | 14 +- .../spdx/PackageInformation/BuiltDate.tsx | 6 +- .../spdx/PackageInformation/CheckSums.tsx | 9 +- .../PackageAllLicensesInformation.tsx | 46 +- .../PackageConcludedLicense.tsx | 22 +- .../PackageCopyrightText.tsx | 22 +- .../PackageDeclaredLicense.tsx | 22 +- .../PackageDownloadLocation.tsx | 22 +- .../PackageInformation/PackageHomePage.tsx | 22 +- .../PackageInformation/PackageOriginator.tsx | 119 +- .../PackageInformation/PackageSupplier.tsx | 119 +- .../spdx/PackageInformation/ReleaseDate.tsx | 11 +- .../PackageInformation/ValidUntilDate.tsx | 9 +- .../SnippetConcludedLicense.tsx | 22 +- .../SnippetCopyrightText.tsx | 24 +- .../SnippetFileSPDXIdentifier.tsx | 71 +- .../SnippetLicenseInformation.tsx | 22 +- .../spdx/SnippetInformation/SnippetRanges.tsx | 11 +- .../components/editRelease/[id]/page.tsx | 4 +- src/app/[locale]/components/page.tsx | 3 +- .../[id]/components/AssessmentSummaryInfo.tsx | 24 +- .../[id]/components/ClearingDetails.tsx | 12 +- .../components/ClearingInformationStatus.tsx | 26 +- .../[id]/components/CommercialDetails.tsx | 3 +- .../CommercialDetailsAdministration.tsx | 14 +- .../[id]/components/CotsOssInformation.tsx | 8 +- .../detail/[id]/components/DetailOverview.tsx | 60 +- .../detail/[id]/components/ECCDetails.tsx | 21 +- .../detail/[id]/components/LinkedReleases.tsx | 51 +- .../detail/[id]/components/ReleaseGeneral.tsx | 33 +- .../detail/[id]/components/ReleaseVendor.tsx | 10 +- .../[id]/components/RequestInformation.tsx | 6 +- .../[id]/components/SPDXAttachments.tsx | 46 +- .../[id]/components/SPDXLicenseView.tsx | 17 +- .../detail/[id]/components/Summary.tsx | 3 +- .../components/SupplementalInformation.tsx | 6 +- .../components/spdx/AnnotationInformation.tsx | 100 +- .../spdx/DocumentCreationInformation.tsx | 65 +- ...therLicensingInformationDetectedDetail.tsx | 21 +- .../spdx/PackageInformationDetail.tsx | 53 +- ...tionshipbetweenSPDXElementsInformation.tsx | 147 +- .../[id]/components/spdx/SPDXDocumentTab.tsx | 30 +- .../components/spdx/SnippetInformation.tsx | 298 ++- .../components/releases/detail/[id]/page.tsx | 3 +- .../GeneralInfoComponent.tsx | 8 +- .../ResourcesUsing/ComponentsUsing.tsx | 6 +- .../ResourcesUsing/ResoucesUsing.tsx | 9 +- .../RolesInformation/RolesInformation.tsx | 12 +- .../AddAdditionalRoles/AddAdditionalRoles.tsx | 3 +- .../sw360/AddKeyValue/AddKeyValue.tsx | 6 +- src/object-types/Attachment.ts | 2 +- src/object-types/ComponentPayLoad.ts | 14 +- src/object-types/Embedded.ts | 8 +- src/object-types/Links.ts | 2 +- src/object-types/Release.ts | 28 +- src/object-types/ReleaseDetail.ts | 10 +- src/object-types/constants/AttachmentTypes.ts | 36 + .../{enums => constants}/CommonTabsIds.ts | 12 +- .../{enums => constants}/ComponentTabIds.ts | 4 +- .../{enums => constants}/HttpStatus.ts | 24 +- .../{enums => constants}/ReleaseTabIds.ts | 12 +- src/object-types/enums/AttachmentTypes.ts | 36 - src/object-types/index.ts | 12 +- .../spdx/DocumentCreationInformation.ts | 34 +- src/object-types/spdx/PackageInformation.ts | 70 +- src/object-types/spdx/SPDX.ts | 6 +- src/services/download.service.ts | 8 +- src/utils/common.utils.ts | 13 +- 118 files changed, 3263 insertions(+), 3059 deletions(-) create mode 100644 src/object-types/constants/AttachmentTypes.ts rename src/object-types/{enums => constants}/CommonTabsIds.ts (70%) rename src/object-types/{enums => constants}/ComponentTabIds.ts (88%) rename src/object-types/{enums => constants}/HttpStatus.ts (64%) rename src/object-types/{enums => constants}/ReleaseTabIds.ts (67%) delete mode 100644 src/object-types/enums/AttachmentTypes.ts diff --git a/messages/de.json b/messages/de.json index fda1abef9..0dea29a5b 100644 --- a/messages/de.json +++ b/messages/de.json @@ -347,8 +347,8 @@ "Download License Archive": "Lizenzarchiv herunterladen", "Drop a File Here": "Eine Datei hier fallen lassen", "Duplicate": "Duplikat", - "Dynamically linked": "Dynamisch verknüpft", "Duplicated Releases": "Doppelte Veröffentlichungen", + "Dynamically linked": "Dynamisch verknüpft", "E-Mail Notification Preferences": "", "ECC": "ECC", "ECC Assessment Date": "ECC Zeitpunkt", @@ -583,6 +583,7 @@ "License Fullname": "Vollständiger Name", "License Info": "Lizenzinformationen", "License Info Header": "Lizenz Info Header", + "License Name": "Lizenzname", "License Obligation": "Lizenzpflicht", "License Scan Report Result": "Lizenz Scan Report Ergebnis", "License Shortname": "Kurzbezeichnung", @@ -972,9 +973,11 @@ "Source Code Original from Community": "Quelle Code Original aus der Gemeinschaft", "Source Code Self-Made": "Quelle Code Self-Made", "Source Code Tool-Made": "Quelle Code Tool-Made", + "Source File List": "Liste der Quelldateien", "Source file": "Quelldatei", "Source file (Self-made)": "Quelle-Datei (Self-made)", "Source file information not found in CLI": "Informationen zur Quelldatei wurden in der CLI nicht gefunden", + "Source file information not found in ISR": "Informationen zur Quelldatei wurden im ISR nicht gefunden", "Special risk Open Source Software": "Spezialrisiko Open Source Software", "Special risks 3rd party software": "Sonderrisiken Software für Dritte", "Specific": "Spezifisch", diff --git a/messages/en.json b/messages/en.json index 13411a1a6..a4534162e 100644 --- a/messages/en.json +++ b/messages/en.json @@ -347,8 +347,8 @@ "Download License Archive": "Download License Archive", "Drop a File Here": "Drop a File Here", "Duplicate": "Duplicate", - "Dynamically linked": "Dynamically linked", "Duplicated Releases": "Duplicated Releases", + "Dynamically linked": "Dynamically linked", "E-Mail Notification Preferences": "E-Mail Notification Preferences", "ECC": "ECC", "ECC Assessment Date": "ECC Assessment Date", @@ -583,6 +583,7 @@ "License Fullname": "License Fullname", "License Info": "License Info", "License Info Header": "License Info Header", + "License Name": "License Name", "License Obligation": "License Obligation", "License Scan Report Result": "License Scan Report Result", "License Shortname": "License Shortname", @@ -972,9 +973,11 @@ "Source Code Original from Community": "Source Code Original from Community", "Source Code Self-Made": "Source Code Self-Made", "Source Code Tool-Made": "Source Code Tool-Made", + "Source File List": "Source File List", "Source file": "Source file", "Source file (Self-made)": "Source file (Self-made)", "Source file information not found in CLI": "Source file information not found in CLI", + "Source file information not found in ISR": "Source file information not found in ISR", "Special risk Open Source Software": "Special risk Open Source Software", "Special risks 3rd party software": "Special risks 3rd party software", "Specific": "Specific", diff --git a/messages/es.json b/messages/es.json index f4734ed47..0ddaf9fbb 100644 --- a/messages/es.json +++ b/messages/es.json @@ -347,8 +347,8 @@ "Download License Archive": "Descargar Archivo de la licencia", "Drop a File Here": "Suelte un archivo aquí", "Duplicate": "Duplicar", - "Dynamically linked": "Vinculado dinámicamente", "Duplicated Releases": "Lanzamientos duplicados", + "Dynamically linked": "Vinculado dinámicamente", "E-Mail Notification Preferences": "", "ECC": "ECC", "ECC Assessment Date": "ECC Fecha de evaluación", @@ -583,6 +583,7 @@ "License Fullname": "Licencia Nombre completo", "License Info": "Información de licencia", "License Info Header": "Información de licencia", + "License Name": "Nombre de licencia", "License Obligation": "Obligación de licencia", "License Scan Report Result": "Informe de exploración de licencias Resultado", "License Shortname": "Licencia Nombre", @@ -972,9 +973,11 @@ "Source Code Original from Community": "Código original de la comunidad", "Source Code Self-Made": "Código de Fuente Auto-Made", "Source Code Tool-Made": "Fuente Code Tool-Made", + "Source File List": "Lista de archivos fuente", "Source file": "Archivo fuente", "Source file (Self-made)": "Archivo fuente (auto-hecha)", "Source file information not found in CLI": "La información del archivo fuente no se encuentra en la CLI", + "Source file information not found in ISR": "La información del archivo fuente no se encuentra en ISR", "Special risk Open Source Software": "Riesgo especial Software de código abierto", "Special risks 3rd party software": "Riesgos especiales Software de terceros", "Specific": "Específico", diff --git a/messages/fr.json b/messages/fr.json index dd10295b3..442fe67a4 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -347,8 +347,8 @@ "Download License Archive": "Télécharger l'archive des licences", "Drop a File Here": "Déposer un fichier ici", "Duplicate": "Dupliquer", - "Dynamically linked": "Lié dynamiquement", "Duplicated Releases": "Versions dupliquées", + "Dynamically linked": "Lié dynamiquement", "E-Mail Notification Preferences": "", "ECC": "CCE", "ECC Assessment Date": "CCE Date d'évaluation", @@ -583,6 +583,7 @@ "License Fullname": "Nom complet de licence", "License Info": "Informations sur la licence", "License Info Header": "En-tête des informations de licence", + "License Name": "Nom de la licence", "License Obligation": "Obligation de licence", "License Scan Report Result": "Résultat du rapport d'analyse de licence", "License Shortname": "Nom abrégé de licence", @@ -972,9 +973,11 @@ "Source Code Original from Community": "Code source Original de la Communauté", "Source Code Self-Made": "Code source Auto-Fait", "Source Code Tool-Made": "Outil de code source", + "Source File List": "Liste des fichiers sources", "Source file": "Fichier source", "Source file (Self-made)": "Fichier source (auto-fait)", "Source file information not found in CLI": "Informations sur le fichier source introuvables dans la CLI", + "Source file information not found in ISR": "Informations sur le fichier source introuvables dans ISR", "Special risk Open Source Software": "Risque spécial Logiciel Open Source", "Special risks 3rd party software": "Risques spéciaux Logiciels tiers", "Specific": "Spécifique", diff --git a/messages/ja.json b/messages/ja.json index a9a1032a5..8edc3c70e 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -347,8 +347,8 @@ "Download License Archive": "ライセンスアーカイブのダウンロード", "Drop a File Here": "Drop a File Here", "Duplicate": "Duplicate", - "Dynamically linked": "動的にリンクされる", "Duplicated Releases": "重複したリリース", + "Dynamically linked": "動的にリンクされる", "E-Mail Notification Preferences": "", "ECC": "ECC", "ECC Assessment Date": "ECC Assessment Date", @@ -583,6 +583,7 @@ "License Fullname": "ライセンスのフルネーム", "License Info": "ライセンス情報", "License Info Header": "License Info Header", + "License Name": "ライセンス名", "License Obligation": "ライセンスの義務", "License Scan Report Result": "ライセンススキャンレポート結果", "License Shortname": "ライセンスの短縮名", @@ -972,9 +973,11 @@ "Source Code Original from Community": "ソースコード コミュニティからのオリジナル", "Source Code Self-Made": "独自・自作のソースコード", "Source Code Tool-Made": "ツール生成のソースコード", + "Source File List": "ソースファイルリスト", "Source file": "ソースファイル", "Source file (Self-made)": "ソースファイル(自作)", "Source file information not found in CLI": "CLI でソース ファイル情報が見つかりません", + "Source file information not found in ISR": "ソース ファイル情報が ISR に見つかりません", "Special risk Open Source Software": "特別なリスク オープンソース ソフトウェア", "Special risks 3rd party software": "特別なリスクがあるサードパーティ製ソフトウェア", "Specific": "特定の", diff --git a/messages/ko.json b/messages/ko.json index 6481f0d4c..99001a004 100644 --- a/messages/ko.json +++ b/messages/ko.json @@ -347,8 +347,8 @@ "Download License Archive": "다운로드 License Archive", "Drop a File Here": "파일 삭제", "Duplicate": "기타 제품", - "Dynamically linked": "동적으로 연결됨", "Duplicated Releases": "중복된 릴리스", + "Dynamically linked": "동적으로 연결됨", "E-Mail Notification Preferences": "", "ECC": "사이트맵", "ECC Assessment Date": "사이트맵 평가 날짜", @@ -583,6 +583,7 @@ "License Fullname": "라이센스 Fullname", "License Info": "라이센스 정보", "License Info Header": "라이센스 정보 Header", + "License Name": "라이센스 이름", "License Obligation": "라이센스 의무", "License Scan Report Result": "면허 검사 결과", "License Shortname": "라이센스 Shortname", @@ -972,9 +973,11 @@ "Source Code Original from Community": "Source Code Original from 커뮤니티", "Source Code Self-Made": "소스 코드 Self-Made", "Source Code Tool-Made": "소스 코드 Tool-Made", + "Source File List": "소스 파일 목록", "Source file": "소스 파일", "Source file (Self-made)": "소스 파일 (Self-made)", "Source file information not found in CLI": "CLI에서 소스 파일 정보를 찾을 수 없습니다.", + "Source file information not found in ISR": "ISR에서 소스 파일 정보를 찾을 수 없습니다.", "Special risk Open Source Software": "특수 위험 오픈 소스 소프트웨어", "Special risks 3rd party software": "특별 위험 3rd 파티 소프트웨어", "Specific": "특정한", diff --git a/messages/pt-BR.json b/messages/pt-BR.json index 6d5b1c3df..a90ed0227 100644 --- a/messages/pt-BR.json +++ b/messages/pt-BR.json @@ -347,8 +347,8 @@ "Download License Archive": "Baixar arquivo de licença", "Drop a File Here": "Solte um arquivo aqui ou", "Duplicate": "Duplicate", - "Dynamically linked": "Vinculado dinamicamente", "Duplicated Releases": "Versões duplicadas", + "Dynamically linked": "Vinculado dinamicamente", "E-Mail Notification Preferences": "", "ECC": "ECC", "ECC Assessment Date": "ECC Assessment Date", @@ -583,6 +583,7 @@ "License Fullname": "Nome completo da licença", "License Info": "Informações sobre licença", "License Info Header": "Cabeçalho das informações da licença", + "License Name": "Nome da licença", "License Obligation": "Obrigação de licença", "License Scan Report Result": "Resultado do relatório de digitalização da licença", "License Shortname": "Nome abreviado da licença", @@ -972,9 +973,11 @@ "Source Code Original from Community": "Código-fonte original da comunidade", "Source Code Self-Made": "Código-fonte Self-Made", "Source Code Tool-Made": "Ferramenta de código-fonte - Feita", + "Source File List": "Lista de arquivos de origem", "Source file": "Arquivo fonte", "Source file (Self-made)": "Arquivo fonte (Self-made)", "Source file information not found in CLI": "Informações do arquivo de origem não encontradas na CLI", + "Source file information not found in ISR": "Informações do arquivo de origem não encontradas no ISR", "Special risk Open Source Software": "Software de código aberto de risco especial", "Special risks 3rd party software": "Riscos especiais software DE terceiros", "Specific": "Específico", diff --git a/messages/vi.json b/messages/vi.json index c62c713f1..e7deaf5bc 100644 --- a/messages/vi.json +++ b/messages/vi.json @@ -347,8 +347,8 @@ "Download License Archive": "Tải xuống kho lưu trữ giấy phép", "Drop a File Here": "Thả một tập tin ở đây", "Duplicate": "Nhân bản", - "Dynamically linked": "Liên kết động", "Duplicated Releases": "Bản phát hành trùng lặp", + "Dynamically linked": "Liên kết động", "E-Mail Notification Preferences": "", "ECC": "ECC", "ECC Assessment Date": "ECC Assessment Date", @@ -583,6 +583,7 @@ "License Fullname": "Tên đầy đủ của giấy phép", "License Info": "Thông tin giấy phép", "License Info Header": "Tiêu đề thông tin giấy phép", + "License Name": "Tên giấy phép", "License Obligation": "Nghĩa vụ cấp phép", "License Scan Report Result": "Kết quả báo cáo quét giấy phép", "License Shortname": "Tên viết tắt giấy phép", @@ -972,9 +973,11 @@ "Source Code Original from Community": "Mã nguồn gốc từ cộng đồng", "Source Code Self-Made": "Mã nguồn tự tạo", "Source Code Tool-Made": "Mã nguồn được tạo bởi công cụ", + "Source File List": "Danh sách tệp nguồn", "Source file": "Tệp nguồn", "Source file (Self-made)": "Tệp nguồn (Tự tạo)", "Source file information not found in CLI": "Không tìm thấy thông tin tệp nguồn trong CLI", + "Source file information not found in ISR": "Không tìm thấy thông tin tệp nguồn trong ISR", "Special risk Open Source Software": "Rủi ro đặc biệt Phần mềm mã nguồn mở", "Special risks 3rd party software": "Rủi ro đặc biệt Phần mềm của bên thứ 3", "Specific": "Cụ thể", diff --git a/messages/zh-CN.json b/messages/zh-CN.json index d8a181004..faba6ee21 100644 --- a/messages/zh-CN.json +++ b/messages/zh-CN.json @@ -347,8 +347,8 @@ "Download License Archive": "下载许可证归档", "Drop a File Here": "将文件拖放到此处", "Duplicate": "复制", - "Dynamically linked": "动态链接", "Duplicated Releases": "重复发布", + "Dynamically linked": "动态链接", "E-Mail Notification Preferences": "", "ECC": "ECC", "ECC Assessment Date": "ECC Assessment Date", @@ -583,6 +583,7 @@ "License Fullname": "许可证全名", "License Info": "许可证信息", "License Info Header": "许可证信息标头", + "License Name": "许可证名称", "License Obligation": "许可义务", "License Scan Report Result": "许可证扫描报告结果", "License Shortname": "许可证简称", @@ -972,9 +973,11 @@ "Source Code Original from Community": "源码来源于社区", "Source Code Self-Made": "源码自制", "Source Code Tool-Made": "源代码工具制作", + "Source File List": "源文件列表", "Source file": "源文件", "Source file (Self-made)": "源文件(自制)", "Source file information not found in CLI": "CLI 中未找到源文件信息", + "Source file information not found in ISR": "ISR 中未找到源文件信息", "Special risk Open Source Software": "特殊风险开源软件", "Special risks 3rd party software": "特殊风险 第三方软件", "Specific": "具体的", diff --git a/messages/zh-TW.json b/messages/zh-TW.json index 062785268..eca221b0e 100644 --- a/messages/zh-TW.json +++ b/messages/zh-TW.json @@ -347,8 +347,8 @@ "Download License Archive": "下載授權檔案", "Drop a File Here": "在這裡丟下檔案", "Duplicate": "复制", - "Dynamically linked": "動態連結", "Duplicated Releases": "重複發布", + "Dynamically linked": "動態連結", "E-Mail Notification Preferences": "", "ECC": "ECC", "ECC Assessment Date": "ECC 评估日期", @@ -583,6 +583,7 @@ "License Fullname": "駕照全名", "License Info": "許可證資訊", "License Info Header": "執照資訊信頭", + "License Name": "許可證名稱", "License Obligation": "許可義務", "License Scan Report Result": "憑證掃描報告結果", "License Shortname": "牌照短名", @@ -972,9 +973,11 @@ "Source Code Original from Community": "原始碼來自社區", "Source Code Self-Made": "源碼自動程式", "Source Code Tool-Made": "來源碼工具- Made", + "Source File List": "來源檔案列表", "Source file": "來源檔案", "Source file (Self-made)": "來源檔案( 自制)", "Source file information not found in CLI": "CLI 中未找到來源文件信息", + "Source file information not found in ISR": "ISR 中未找到來源文件信息", "Special risk Open Source Software": "特殊風險開源軟體", "Special risks 3rd party software": "特殊風險 第三方軟體", "Specific": "具體的", diff --git a/nextauth.d.ts b/nextauth.d.ts index ae7dc2030..d8d27e15d 100644 --- a/nextauth.d.ts +++ b/nextauth.d.ts @@ -39,7 +39,7 @@ interface SW360User extends DefaultUser { declare module 'next-auth' { type User = SW360User interface Session { - user?: User + user: User } } diff --git a/src/app/[locale]/components/add/components/AddComponent.tsx b/src/app/[locale]/components/add/components/AddComponent.tsx index 099b1386a..ee9fab776 100644 --- a/src/app/[locale]/components/add/components/AddComponent.tsx +++ b/src/app/[locale]/components/add/components/AddComponent.tsx @@ -13,7 +13,7 @@ import { signOut, useSession } from 'next-auth/react' import { useTranslations } from 'next-intl' import { useRouter } from 'next/navigation' -import { useState } from 'react' +import { ReactNode, useState } from 'react' import GeneralInfoComponent from '@/components/GeneralInfoComponent/GeneralInfoComponent' import RolesInformation from '@/components/RolesInformation/RolesInformation' @@ -27,11 +27,11 @@ import { Vendor, } from '@/object-types' -import { ApiUtils } from '@/utils' +import { ApiUtils, CommonUtils } from '@/utils' import { AddAdditionalRoles, AddKeyValue, SearchUsersModal, SideBar } from 'next-sw360' import MessageService from '@/services/message.service' -export default function AddComponent() { +export default function AddComponent() : ReactNode { const t = useTranslations('default') const router = useRouter() const { data: session, status } = useSession() @@ -55,7 +55,7 @@ export default function AddComponent() { moderators: null, modifiedBy: '', modifiedOn: '', - componentOwner: undefined, + componentOwner: null, ownerAccountingUnit: '', ownerGroup: '', ownerCountry: '', @@ -98,9 +98,11 @@ export default function AddComponent() { } const submit = async () => { + if (CommonUtils.isNullOrUndefined(session)) + return signOut() const response = await ApiUtils.POST('components', componentPayload, session.user.access_token) - if (response.status == HttpStatus.CREATED) { + if (response.status === HttpStatus.CREATED) { const data = (await response.json()) as Component router.push('/components/edit/' + data.id) MessageService.success(t('Component is created')) @@ -110,7 +112,7 @@ export default function AddComponent() { } if (status === 'unauthenticated') { - signOut() + return signOut() } else { return ( <> diff --git a/src/app/[locale]/components/add/page.tsx b/src/app/[locale]/components/add/page.tsx index cf5838256..41190b784 100644 --- a/src/app/[locale]/components/add/page.tsx +++ b/src/app/[locale]/components/add/page.tsx @@ -10,11 +10,12 @@ import { Metadata } from 'next' import AddComponent from './components/AddComponent' +import { ReactNode } from 'react' export const metadata: Metadata = { title: 'Components', } -export default async function ComponentAddPage() { +export default function ComponentAddPage() : ReactNode { return } diff --git a/src/app/[locale]/components/components/ComponentIndex.tsx b/src/app/[locale]/components/components/ComponentIndex.tsx index 4e2bbea56..a2ce9fe31 100644 --- a/src/app/[locale]/components/components/ComponentIndex.tsx +++ b/src/app/[locale]/components/components/ComponentIndex.tsx @@ -11,7 +11,7 @@ 'use client' import { signOut, useSession } from 'next-auth/react' import { useTranslations } from 'next-intl' -import { useState } from 'react' +import { ReactNode, useState } from 'react' import { Dropdown } from 'react-bootstrap' import { AdvancedSearch, PageButtonHeader } from '@/components/sw360' @@ -19,7 +19,7 @@ import DownloadService from '@/services/download.service' import ComponentsTable from './ComponentsTable' import ImportSBOMModal from './ImportSBOMModal' -const ComponentIndex = () => { +const ComponentIndex = () : ReactNode => { const t = useTranslations('default') const [numberOfComponent, setNumberOfComponent] = useState(0) const [importModalOpen, setImportModalOpen] = useState(false) @@ -154,7 +154,7 @@ const ComponentIndex = () => { } if (status === 'unauthenticated') { - signOut() + return signOut() } else { return (
diff --git a/src/app/[locale]/components/components/ComponentsTable.tsx b/src/app/[locale]/components/components/ComponentsTable.tsx index 9cb94f4b1..35fecdb2e 100644 --- a/src/app/[locale]/components/components/ComponentsTable.tsx +++ b/src/app/[locale]/components/components/ComponentsTable.tsx @@ -11,13 +11,14 @@ 'use client' import { useSession } from 'next-auth/react' +import { Session } from 'next-auth' import { useTranslations } from 'next-intl' import Link from 'next/link' import { useSearchParams } from 'next/navigation' import React, { useState } from 'react' import { FaPencilAlt, FaTrashAlt } from 'react-icons/fa' -import { Component, Embedded, Session } from '@/object-types' +import { Component, Embedded } from '@/object-types' import { CommonUtils } from '@/utils' import { SW360_API_URL } from '@/utils/env' import { Table, _ } from 'next-sw360' @@ -102,7 +103,7 @@ function ComponentsTable({ setNumberOfComponent }: Props) { return { url: CommonUtils.createUrlWithParams(`${SW360_API_URL}/resource/api/components`, searchParams), then: (data: Embedded) => { - setNumberOfComponent(data.page.totalElements) + setNumberOfComponent(data.page ? data.page.totalElements : 0) return data._embedded['sw360:components'].map((item: Component) => [ !CommonUtils.isNullOrUndefined(item.defaultVendor) ? item.defaultVendor.shortName : '', [item.id, item.name], @@ -111,7 +112,7 @@ function ComponentsTable({ setNumberOfComponent }: Props) { item.id, ]) }, - total: (data: Embedded) => data.page.totalElements, + total: (data: Embedded) => data.page ? data.page.totalElements : 0, headers: { Authorization: `${session.user.access_token}` }, } } diff --git a/src/app/[locale]/components/components/DeleteComponentDialog.tsx b/src/app/[locale]/components/components/DeleteComponentDialog.tsx index a5d34836d..4346ed4fa 100644 --- a/src/app/[locale]/components/components/DeleteComponentDialog.tsx +++ b/src/app/[locale]/components/components/DeleteComponentDialog.tsx @@ -10,21 +10,21 @@ 'use client' -import { signOut, useSession } from 'next-auth/react' +import { signOut, getSession } from 'next-auth/react' import { useTranslations } from 'next-intl' import { useRouter } from 'next/navigation' -import { useCallback, useEffect, useState } from 'react' +import { ReactNode, useCallback, useEffect, useState } from 'react' import { Alert, Button, Form, Modal } from 'react-bootstrap' import { ActionType, Component, HttpStatus } from '@/object-types' -import { ApiUtils } from '@/utils' +import { ApiUtils, CommonUtils } from '@/utils' const DEFAULT_COMPONENT_INFO: Component = { id: '', name: '', _embedded: { 'sw360:releases': [] } } interface Props { componentId?: string - show?: boolean - setShow?: React.Dispatch> + show: boolean + setShow: React.Dispatch> actionType?: string } @@ -33,8 +33,7 @@ interface DeleteResponse { status: number } -const DeleteComponentDialog = ({ componentId, show, setShow, actionType }: Props) => { - const { data: session } = useSession() +const DeleteComponentDialog = ({ componentId, show, setShow, actionType }: Props) : ReactNode => { const t = useTranslations('default') const router = useRouter() const [component, setComponent] = useState(DEFAULT_COMPONENT_INFO) @@ -55,28 +54,31 @@ const DeleteComponentDialog = ({ componentId, show, setShow, actionType }: Props }, [t]) const deleteComponent = async () => { + const session = await getSession() + if (CommonUtils.isNullOrUndefined(session)) + return signOut() const response = await ApiUtils.DELETE(`components/${componentId}`, session.user.access_token) try { - if (response.status == HttpStatus.MULTIPLE_STATUS) { + if (response.status === HttpStatus.MULTIPLE_STATUS) { const body = (await response.json()) as Array const deleteStatus = body[0].status - if (deleteStatus == HttpStatus.OK) { + if (deleteStatus === HttpStatus.OK) { displayMessage('success', t('Delete component success!')) actionType === ActionType.EDIT && router.push('/components') setReloadPage(true) - } else if (deleteStatus == HttpStatus.CONFLICT) { + } else if (deleteStatus === HttpStatus.CONFLICT) { displayMessage( 'danger', t( 'The component cannot be deleted, since it contains releases Please delete the releases first' ) ) - } else if (deleteStatus == HttpStatus.ACCEPTED) { + } else if (deleteStatus === HttpStatus.ACCEPTED) { displayMessage('success', t('Created moderation request')) } else { displayMessage('danger', t('Error when processing')) } - } else if (response.status == HttpStatus.UNAUTHORIZED) { + } else if (response.status === HttpStatus.UNAUTHORIZED) { await signOut() } else { handleError() @@ -88,30 +90,30 @@ const DeleteComponentDialog = ({ componentId, show, setShow, actionType }: Props const fetchData = useCallback( async (signal: AbortSignal) => { - if (session) { - const componentsResponse = await ApiUtils.GET( - `components/${componentId}`, - session.user.access_token, - signal - ) - if (componentsResponse.status == HttpStatus.OK) { - const component = (await componentsResponse.json()) as Component - console.log(component.name) - setComponent(component) - } else if (componentsResponse.status == HttpStatus.UNAUTHORIZED) { - await signOut() - } else { - setComponent(DEFAULT_COMPONENT_INFO) - handleError() - } + const session = await getSession() + if (CommonUtils.isNullOrUndefined(session)) + return signOut() + const componentsResponse = await ApiUtils.GET( + `components/${componentId}`, + session.user.access_token, + signal + ) + if (componentsResponse.status === HttpStatus.OK) { + const component = (await componentsResponse.json()) as Component + setComponent(component) + } else if (componentsResponse.status === HttpStatus.UNAUTHORIZED) { + await signOut() + } else { + setComponent(DEFAULT_COMPONENT_INFO) + handleError() } }, - [componentId, handleError, session] + [componentId, handleError] ) const handleSubmit = () => { deleteComponent().catch((err) => { - console.log(err) + console.error(err) }) } diff --git a/src/app/[locale]/components/components/ImportSBOMModal.tsx b/src/app/[locale]/components/components/ImportSBOMModal.tsx index e9f19a9df..6cc2eb708 100644 --- a/src/app/[locale]/components/components/ImportSBOMModal.tsx +++ b/src/app/[locale]/components/components/ImportSBOMModal.tsx @@ -10,14 +10,14 @@ 'use client' -import { useSession } from 'next-auth/react' +import { getSession } from 'next-auth/react' import { useTranslations } from 'next-intl' import { useRouter } from 'next/navigation' -import React, { useRef, useState } from 'react' +import React, { ReactNode, useRef, useState } from 'react' import { Alert, Button, Modal } from 'react-bootstrap' import { Component, HttpStatus } from '@/object-types' -import { ApiUtils } from '@/utils' +import { ApiUtils, CommonUtils } from '@/utils' import styles from '../components.module.css' interface Props { @@ -39,21 +39,19 @@ interface PrepareImportData { releasesName?: string } -const ImportSBOMModal = ({ show, setShow }: Props) => { +const ImportSBOMModal = ({ show, setShow }: Props) : ReactNode => { const t = useTranslations('default') - const { data: session } = useSession() const [importState, setImportState] = useState(ImportSBOMState.INIT_STATE) const [prepateImportData, setPrepareImportData] = useState(undefined) const [notAllowedMessageDisplayed, setNotAllowedMessageDisplayed] = useState(false) const selectedFile = useRef(undefined) - const inputRef = useRef(undefined) + const inputRef = useRef() const router = useRouter() const handleFileChange = (e: React.ChangeEvent) => { - selectedFile.current = e.currentTarget.files[0] - if (!selectedFile) { + if (!e.currentTarget.files) return - } + selectedFile.current = e.currentTarget.files[0] if (!selectedFile.current.name.endsWith('.rdf') && !selectedFile.current.name.endsWith('.spdx')) { setNotAllowedMessageDisplayed(true) @@ -64,6 +62,11 @@ const ImportSBOMModal = ({ show, setShow }: Props) => { } const prepareImport = async () => { + if (!selectedFile.current) return + + const session = await getSession() + if (CommonUtils.isNullOrUndefined(session)) return + setNotAllowedMessageDisplayed(false) const formData = new FormData() formData.append('file', selectedFile.current, selectedFile.current.name) @@ -83,6 +86,11 @@ const ImportSBOMModal = ({ show, setShow }: Props) => { } const importFile = async () => { + if (!selectedFile.current) return + + const session = await getSession() + if (CommonUtils.isNullOrUndefined(session)) return + const formData = new FormData() formData.append('file', selectedFile.current, selectedFile.current.name) @@ -111,15 +119,13 @@ const ImportSBOMModal = ({ show, setShow }: Props) => { const handleDrop = (e: React.DragEvent) => { e.preventDefault() - if (e.dataTransfer.files && e.dataTransfer.files[0]) { - selectedFile.current = e.dataTransfer.files[0] - if (!selectedFile.current.name.endsWith('.rdf') && !selectedFile.current.name.endsWith('.spdx')) { - setNotAllowedMessageDisplayed(true) - return - } - setImportState(ImportSBOMState.IMPORTING) - prepareImport().catch((err) => console.log(err)) + selectedFile.current = e.dataTransfer.files[0] + if (!selectedFile.current.name.endsWith('.rdf') && !selectedFile.current.name.endsWith('.spdx')) { + setNotAllowedMessageDisplayed(true) + return } + setImportState(ImportSBOMState.IMPORTING) + prepareImport().catch((err) => console.log(err)) } const closeModal = () => { @@ -168,7 +174,7 @@ const ImportSBOMModal = ({ show, setShow }: Props) => {
} type='file' accept='.rdf,.spdx' onChange={handleFileChange} @@ -183,9 +189,9 @@ const ImportSBOMModal = ({ show, setShow }: Props) => { )} {importState === ImportSBOMState.IMPORTING &&

{t('Importing')}...

} - {importState === ImportSBOMState.PREPARE_IMPORT && ( + {importState === ImportSBOMState.PREPARE_IMPORT && prepateImportData && <> - {prepateImportData.message ? ( + {!CommonUtils.isNullEmptyOrUndefinedString(prepateImportData.message) ? (

{prepateImportData.message}

) : (
@@ -205,7 +211,7 @@ const ImportSBOMModal = ({ show, setShow }: Props) => {
)} - )} + } {importState === ImportSBOMState.IMPORT_ERROR && ( @@ -218,7 +224,10 @@ const ImportSBOMModal = ({ show, setShow }: Props) => { )} - {importState === ImportSBOMState.PREPARE_IMPORT && !prepateImportData.message && ( + { + importState === ImportSBOMState.PREPARE_IMPORT + && prepateImportData + && CommonUtils.isNullEmptyOrUndefinedString(prepateImportData.message) && ( @@ -203,13 +211,13 @@ const DetailOverview = ({ componentId }: Props) => { -