Skip to content

Commit

Permalink
Merge pull request #223 from toshiba/release/license_detail
Browse files Browse the repository at this point in the history
Implement License detail page
  • Loading branch information
heliocastro authored Feb 27, 2024
2 parents 60a70a6 + 53d3afa commit d99b5d9
Show file tree
Hide file tree
Showing 23 changed files with 1,590 additions and 137 deletions.
28 changes: 27 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
"Delete release success!": "Delete release success!",
"Delivery start": "Delivery start",
"Delivery start date": "Delivery start date",
"Details": "Details",
"Deparment Name": "Deparment Name",
"Department": "Department",
"DependencyNotes": "Dependency Notes",
Expand Down Expand Up @@ -254,7 +255,9 @@
"Edit User Secondary Departments And Role": "Edit User Secondary Departments And Role",
"Edit Vendor": "Edit Vendor",
"Edit component": "Edit component",
"Edit License": "Edit License",
"Edit release": "Edit release",
"Edit Whitelist": "Edit Whitelist",
"Email": "Email",
"Email Address": "Email Address",
"Embedded Software": "Embedded Software",
Expand Down Expand Up @@ -338,6 +341,7 @@
"External URL": "External URL",
"External URLs": "External URLs",
"External ids": "External ids",
"External link for more information": "External link for more information",
"Field Name": "Field Name",
"File name": "File name",
"Finalized License Scan Report": "Finalized License Scan Report",
Expand All @@ -347,6 +351,9 @@
"Found source attachment": "Found source attachment",
"Freeware": "Freeware",
"Full Name": "Full Name",
"Fullname": "Fullname",
"FSF Free/Libre?": "FSF Free/Libre?",
"Further properties": "Further properties",
"GNU arch": "GNU arch",
"General": "General",
"General Information": "General Information",
Expand Down Expand Up @@ -391,6 +398,8 @@
"Internal": "Internal",
"Internal Project": "Internal Project",
"Is Checked": "Is Checked",
"Is checked": "Is checked",
"Is Checked?": "Is Checked?",
"Is a subproject": "Is a subproject",
"Key User": "Key User",
"Keyword Search": "Keyword Search",
Expand Down Expand Up @@ -427,8 +436,13 @@
"License Shortname": "License Shortname",
"License Type": "License Type",
"License Types": "License Types",
"License Text": "License Text",
"Licenses": "Licenses",
"License Details": "License Details",
"Licenses uploaded successfully": "Licenses uploaded successfully",
"License removed successfully!": "License removed successfully!",
"License updated successfully!": "License updated successfully!",
"License updated failed!": "License updated failed!",
"Lifecycle": "Lifecycle",
"Link Projects": "Link Projects",
"Link Release to Project": "Link Release to Project",
Expand Down Expand Up @@ -488,9 +502,13 @@
"NoProjectsFound": "There are no projects found with your selection.",
"NoTasksAssigned": "There are no tasks assigned to you.",
"None": "None",
"Note": "Note",
"Not Applicable": "Not Applicable",
"NotOwnComponent": "You do not own any components.",
"Number of Security Vulnerabilities": "Number of Security Vulnerabilities",
"Obligation": "Obligation",
"Obligation Type": "Obligation Type",
"Obligation Title": "Obligation Title",
"OAuth Client": "OAuth Client",
"OPEN": "Open",
"OPTIONAL": "Optional",
Expand All @@ -510,6 +528,7 @@
"Owner Accounting Unit": "Owner Accounting Unit",
"Owner Billing Group": "Owner Billing Group",
"Owner Country": "Owner Country",
"OSI Approved?": "OSI Approved?",
"PARTIAL": "PARTIAL",
"PHASEOUT": "Phaseout",
"PROJECTS": "PROJECTS",
Expand Down Expand Up @@ -614,6 +633,7 @@
"Revoke Token": "Revoke Token",
"Revoke token sucessfully": "Revoke token sucessfully",
"Roles": "Roles",
"Save": "Save",
"SAP Design Time Repository (DTR)": "SAP Design Time Repository (DTR)",
"SBOM": "SBOM",
"SCAN_AVAILABLE": "Scan available",
Expand Down Expand Up @@ -668,6 +688,7 @@
"Set To Outdated": "Set To Outdated",
"Set to default text": "Set to default text",
"Short Name": "Short Name",
"Shortname": "Shortname",
"Show": "Show",
"Show All": "Show All",
"Show Assessment Summary Info": "Show Assessment Summary Info",
Expand Down Expand Up @@ -728,6 +749,7 @@
"This function is meant to be followed by a new license import": "This function is meant to be followed by a new license import.",
"This project contains": "This project <strong>{name}</strong> contains",
"This release contains": "This release <strong>{name}</strong> contains: ",
"This license is": "This license is",
"Title": "Title",
"To": "To",
"Toggle": "Toggle",
Expand All @@ -748,6 +770,9 @@
"Update Setting": "Update Setting",
"Update Vulnerability": "Update Vulnerability",
"Update create comment": "Update create comment",
"Update Whitelist": "Update Whitelist",
"Update External Link Success!": "Update External Link Success!",
"Update External Link Failed!": "Update External Link Failed!",
"Upload": "Upload",
"Upload Attachment": "Upload Attachment",
"Upload BOM document as": "Upload BOM document as",
Expand Down Expand Up @@ -837,6 +862,7 @@
"project_cannot_be_created": "Project cannot be created/updated",
"to edit the project relation": "to edit the project relation",
"vector": "vector",
"wrong_spdx_information": "If the wrong SPDX is entered, the information will not be registered correctly"
"wrong_spdx_information": "If the wrong SPDX is entered, the information will not be registered correctly",
"(n/a)": "(n/a)"
}
}
123 changes: 0 additions & 123 deletions src/app/[locale]/licenses/LicensePage.tsx

This file was deleted.

145 changes: 145 additions & 0 deletions src/app/[locale]/licenses/components/LicensePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright (c) Helio Chissini de Castro, 2023. Part of the SW360 Frontend Project.

// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/

// SPDX-License-Identifier: EPL-2.0
// License-Filename: LICENSE

'use client'

import { Embedded, LicensePayload, ToastData } from '@/object-types'
import DownloadService from '@/services/download.service'
import { CommonUtils } from '@/utils'
import { SW360_API_URL } from '@/utils/env'
import { signOut, useSession } from 'next-auth/react'
import { useTranslations } from 'next-intl'
import { PageButtonHeader, QuickFilter, Table, ToastMessage, _ } from 'next-sw360'
import Link from 'next/link'
import { useSearchParams } from 'next/navigation'
import React, { useEffect, useState } from 'react'
import { ToastContainer } from 'react-bootstrap'
import { BsCheck2Circle, BsXCircle } from 'react-icons/bs'

function LicensePage() {
const params = useSearchParams()
const searchParams = Object.fromEntries(params)
const t = useTranslations('default')
const [search, setSearch] = useState({})
const [numberLicense, setNumberLicense] = useState(0)
const { data: session, status } = useSession()
const deleteLicense = params.get('delete')

const [toastData, setToastData] = useState<ToastData>({
show: false,
type: '',
message: '',
contextual: '',
})

const alert = (show_data: boolean, status_type: string, message: string, contextual: string) => {
setToastData({
show: show_data,
type: status_type,
message: message,
contextual: contextual,
})
}

useEffect(() => {
if (!CommonUtils.isNullEmptyOrUndefinedString(deleteLicense)) {
alert(true, 'Success', t('License removed successfully!'), 'success')
}
}, [params])

const handleExportLicense = () => {
DownloadService.download(`reports?module=licenses`, session, `Licenses.xlsx`)
}

const headerButtons = {
'Add License': { link: '/licenses/add', type: 'primary', name: t('Add License') },
'Export Spreadsheet': {
link: '/licenses',
onClick: handleExportLicense,
type: 'secondary',
name: t('Export Spreadsheet'),
},
}

const server = {
url: CommonUtils.createUrlWithParams(`${SW360_API_URL}/resource/api/licenses`, searchParams),
then: (data: Embedded<LicensePayload, 'sw360:licenses'>) => {
setNumberLicense(data.page.totalElements)
return data._embedded['sw360:licenses'].map((item: LicensePayload) => [
item._links.self.href.split('/').pop(),
item.fullName,
_(
<center>
{item.checked ? <BsCheck2Circle color='#287d3c' size='16' /> : <BsXCircle color='#da1414' />}
</center>
),
_(<>{item.licenseType ? item.licenseType.licenseType : '--'}</>),
])
},
total: (data: Embedded<LicensePayload, 'sw360:licenses'>) => data.page.totalElements,
headers: { Authorization: `Bearer ${status === 'authenticated' ? session.user.access_token : ''}` },
}

const columns = [
{
name: t('License Shortname'),
formatter: (id: string) =>
_(
<Link href={`/licenses/detail?id=${id}`} className='link'>
{id}
</Link>
),
sort: true,
},
{ name: t('License Fullname'), width: '45%', sort: true },
{ name: t('Is Checked?'), width: '10%', sort: true },
{ name: t('License Type'), width: '15%', sort: true },
]

const doSearch = (event: React.KeyboardEvent<HTMLInputElement>) => {
setSearch({ keyword: event.currentTarget.value })
}
if (status === 'unauthenticated') {
signOut()
} else {
return (
<div className='container' style={{ maxWidth: '98vw', marginTop: '10px' }}>
<ToastContainer position='top-start'>
<ToastMessage
show={toastData.show}
type={toastData.type}
message={toastData.message}
contextual={toastData.contextual}
onClose={() => setToastData({ ...toastData, show: false })}
setShowToast={setToastData}
/>
</ToastContainer>
<div className='row'>
<div className='col-2 sidebar'>
<QuickFilter id='licensefilter' title={t('Quick Filter')} searchFunction={doSearch} />
</div>
<div className='col col-sm-9'>
<div className='col'>
<div className='row'>
<PageButtonHeader
buttons={headerButtons}
title={`${t('Licenses')} (${numberLicense})`}
/>
<Table server={server} columns={columns} search={search} selector={true} />

<div className='row mt-2'></div>
</div>
</div>
</div>
</div>
</div>
)
}
}
export default LicensePage
Loading

0 comments on commit d99b5d9

Please sign in to comment.