-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from toshiba/release/license_detail
Implement License detail page
- Loading branch information
Showing
23 changed files
with
1,590 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.