Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eslint errors for components in component details page #124

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@
"Number of Security Vulnerabilities": "Number of Security Vulnerabilities",
"number_of_attachments_not_match_condition": "There has to be exactly one source attachment, but there are {count} at this release. Please come back once you corrected that.",
"New Project": "New Project",
"New Components": "New Components",
"New Release": "New Release",
"Name of the component": "Name of the component",
"NAME_COMPONENT": "Name of the component",
"Obligations": "Obligations",
Expand Down Expand Up @@ -570,6 +572,7 @@
"to edit the project relation": "to edit the project relation",
"Test Manager": "Test Manager",
"The component cannot be deleted, since it contains releases Please delete the releases first": "The component <strong>{name}</strong> cannot be deleted, since it contains <strong>{releaseCount}</strong> releases. Please delete the releases first.",
"The new Component and new Release will be created, do you want to import?": "The new Component and new Release will be created, do you want to import?",
"This release contains": "This release <strong>{name}</strong> contains: ",
"This currently only supports SPDX RDF/XML files with a uniq described top level node": "This currently only supports SPDX RDF/XML files with a uniq described top level node",
"The release has been successfully linked to project": "The release <strong>{releaseName}</strong> has been successfully linked to project <strong>{projectName}</strong>",
Expand Down
3 changes: 3 additions & 0 deletions messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@
"Number of Security Vulnerabilities": "セキュリティ脆弱性の数",
"number_of_attachments_not_match_condition": "There has to be exactly one source attachment, but there are {count} at this release. Please come back once you corrected that.",
"New Project": "NOT TRANSLATED",
"New Components": "New Components",
"New Release": "New Release",
"Obligations": "Obligations",
"OPEN": "開く",
"Open": "NOT TRANSLATED",
Expand Down Expand Up @@ -563,6 +565,7 @@
"Tag": "NOT TRANSLATED",
"Test and Diagnostics": "NOT TRANSLATED",
"The component cannot be deleted, since it contains releases Please delete the releases first": "コンポーネント <strong>{name}</strong> は <strong>{releaseCount}</strong> を持つため消去できない.最初にリリースを消去してください",
"The new Component and new Release will be created, do you want to import?": "The new Component and new Release will be created, do you want to import?",
"This release contains": "このリリース <strong>{name}</strong> には次の内容が含まれています:",
"This currently only supports SPDX RDF/XML files with a uniq described top level node": "This currently only supports SPDX RDF/XML files with a uniq described top level node",
"The release has been successfully linked to project": "The release <strong>{releaseName}</strong> has been successfully linked to project <strong>{projectName}</strong>",
Expand Down
3 changes: 3 additions & 0 deletions messages/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@
"number_of_attachments_not_match_condition": "There has to be exactly one source attachment, but there are {count} at this release. Please come back once you corrected that.",
"None": "NOT TRANSLATED",
"New Project": "NOT TRANSLATED",
"New Components": "New Components",
"New Release": "New Release",
"Obligations": "Obligations",
"OPEN": "Mở",
"Open": "NOT TRANSLATED",
Expand Down Expand Up @@ -561,6 +563,7 @@
"Tag": "NOT TRANSLATED",
"Test and Diagnostics": "NOT TRANSLATED",
"The component cannot be deleted, since it contains releases Please delete the releases first": "Thành phần <strong>{name}</strong> không thể bị xóa, vì nó chứa <strong>{releaseCount}</strong> bản phát hành. Vui lòng xóa các bản phát hành trước.",
"The new Component and new Release will be created, do you want to import?": "The new Component and new Release will be created, do you want to import?",
"This release contains": "Bản phát hành <strong>{name}</strong> này chứa: ",
"This currently only supports SPDX RDF/XML files with a uniq described top level node": "This currently only supports SPDX RDF/XML files with a uniq described top level node",
"The release has been successfully linked to project": "The release <strong>{releaseName}</strong> has been successfully linked to project <strong>{projectName}</strong>",
Expand Down
3 changes: 3 additions & 0 deletions messages/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@
"No attachments yet": "还没有附件。",
"None": "NOT TRANSLATED",
"New Project": "NOT TRANSLATED",
"New Components": "New Components",
"New Release": "New Release",
"Obligations": "Obligations",
"OPEN": "打开",
"Open": "NOT TRANSLATED",
Expand Down Expand Up @@ -556,6 +558,7 @@
"Technical writer": "NOT TRANSLATED",
"Tag": "NOT TRANSLATED",
"The projects have been successfully linked to project": "The projects have been successfully linked to project",
"The new Component and new Release will be created, do you want to import?": "The new Component and new Release will be created, do you want to import?",
"Test and Diagnostics": "NOT TRANSLATED",
"to edit the project relation": "to edit the project relation",
"The component cannot be deleted, since it contains releases Please delete the releases first": "组件 <strong>{name}</strong> 无法被删除,因为它包含发行版本 <strong>{releaseCount}</strong>。请先删除发行版本。",
Expand Down
75 changes: 41 additions & 34 deletions src/app/[locale]/components/components/ComponentIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,122 +37,125 @@ const ComponentIndex = ({ session }: Props) => {

const headerbuttons = {
'Add Component': { link: '/components/add', type: 'primary' },
'Import SBOM': { link: '#', type: 'secondary', onClick: handleClickImportSBOM }
'Import SBOM': { link: '#', type: 'secondary', onClick: handleClickImportSBOM },
}

const advancedSearch = [
{
fieldName: 'Component Name',
value: '',
paramName: 'name'
paramName: 'name',
},
{
fieldName: 'Categories',
value: '',
paramName: 'categories'
paramName: 'categories',
},
{
fieldName: 'Component Type',
value: [
{
key: 'OSS',
text: 'OSS'
text: 'OSS',
},
{
key: 'COTS',
text: 'COTS'
text: 'COTS',
},
{
key: 'INTERNAL',
text: 'Internal'
text: 'Internal',
},
{
key: 'INNER_SOURCE',
text: 'Inner Source'
text: 'Inner Source',
},
{
key: 'SERVICE',
text: 'Service'
text: 'Service',
},
{
key: 'FREESOFTWARE',
text: 'Freeware'
text: 'Freeware',
},
{
key: 'CODE_SNIPPET',
text: 'Code Snippet'
}
text: 'Code Snippet',
},
],
paramName: 'type'
paramName: 'type',
},
{
fieldName: 'Group',
value: [
{
key: 'None',
text: 'None'
}
text: 'None',
},
],
paramName: 'group'
paramName: 'group',
},
{
fieldName: 'Languages',
value: '',
paramName: 'languages'
paramName: 'languages',
},
{
fieldName: 'Software Platforms',
value: '',
paramName: 'softwarePlatform'
paramName: 'softwarePlatform',
},
{
fieldName: 'Vendors',
value: '',
paramName: 'vendors'
paramName: 'vendors',
},
{
fieldName: 'Operating Systems',
value: '',
paramName: 'operatingSystem'
paramName: 'operatingSystem',
},
{
fieldName: 'Main Licenses',
value: '',
paramName: 'mainLicenses'
paramName: 'mainLicenses',
},
{
fieldName: 'Created By (Email)',
value: '',
paramName: 'createdBy'
paramName: 'createdBy',
},
{
fieldName: 'Created On',
value: [
{
key: 'EQUAL',
text: '='
text: '=',
},
{
key: 'LESS_THAN_OR_EQUAL_TO',
text: '<='
text: '<=',
},
{
key: 'GREATER_THAN_OR_EQUAL_TO',
text: '>='
text: '>=',
},
{
key: 'BETWEEN',
text: 'Between'
}
text: 'Between',
},
],
paramName: 'createdOn'
}
paramName: 'createdOn',
},
]

const handleExportComponent = (withLinkedReleases: boolean) => {
const handleExportComponent = (withLinkedReleases: string) => {
const currentDate = new Date().toISOString().split('T')[0]
DownloadService.download(`reports?withlinkedreleases=${withLinkedReleases}&mimetype=xlsx&mailrequest=false&module=components`,
session, `components-${currentDate}.xlsx`)
DownloadService.download(
`reports?withlinkedreleases=${withLinkedReleases}&mimetype=xlsx&mailrequest=false&module=components`,
session,
`components-${currentDate}.xlsx`
)
}

return (
Expand All @@ -169,16 +172,20 @@ const ComponentIndex = ({ session }: Props) => {
{t('Export Spreadsheet')}
</Dropdown.Toggle>
<Dropdown.Menu>
<Dropdown.Item onClick={() => handleExportComponent(false)}>{t('Components only')}</Dropdown.Item>
<Dropdown.Item onClick={() => handleExportComponent(true)}>{t('Components with releases')}</Dropdown.Item>
<Dropdown.Item onClick={() => handleExportComponent('false')}>
{t('Components only')}
</Dropdown.Item>
<Dropdown.Item onClick={() => handleExportComponent('true')}>
{t('Components with releases')}
</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</div>
</PageButtonHeader>
<div className='row' style={{ marginBottom: '20px' }}>
<ComponentsTable session={session} setNumberOfComponent={setNumberOfComponent} />
</div>
<ImportSBOMModal show={importModalOpen} setShow={setImportModalOpen} session={session}/>
<ImportSBOMModal show={importModalOpen} setShow={setImportModalOpen} session={session} />
</div>
</div>
</div>
Expand Down
62 changes: 35 additions & 27 deletions src/app/[locale]/components/components/ComponentsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import CommonUtils from '@/utils/common.utils'
import { FaTrashAlt, FaPencilAlt } from 'react-icons/fa'
import Link from 'next/link'
import { useEffect, useState } from 'react'
import React, { useEffect, useState } from 'react'
import styles from '../components.module.css'
import { signOut } from 'next-auth/react'
import ApiUtils from '@/utils/api/api.util'
import HttpStatus from '@/object-types/enums/HttpStatus'
import { useSearchParams } from 'next/navigation'
Expand All @@ -25,6 +24,9 @@ import { COMMON_NAMESPACE } from '@/object-types/Constants'
import { Session } from '@/object-types/Session'
import { Spinner } from 'react-bootstrap'
import { Table, _ } from '@/components/sw360'
import { EmbeddedComponents } from '@/object-types/EmbeddedComponents'
import { EmbeddedComponent } from '@/object-types/EmbeddedComponent'
import { signOut } from 'next-auth/react'

interface Props {
session?: Session
Expand All @@ -36,24 +38,24 @@ const ComponentsTable = ({ session, setNumberOfComponent }: Props) => {
const t = useTranslations(COMMON_NAMESPACE)
const [componentData, setComponentData] = useState([])
const [loading, setLoading] = useState(true)
const [deletingComponent, setDeletingComponent] = useState('')
const [deletingComponent, setDeletingComponent] = useState<string>('')
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false)

const handleClickDelete = (componentId: any) => {
const handleClickDelete = (componentId: string) => {
setDeletingComponent(componentId)
setDeleteDialogOpen(true)
}

const fetchData: any = useCallback(
async (queryUrl: string, signal: any) => {
const fetchData = useCallback(
async (queryUrl: string, signal: AbortSignal) => {
const componentsResponse = await ApiUtils.GET(queryUrl, session.user.access_token, signal)
if (componentsResponse.status == HttpStatus.OK) {
const components = await componentsResponse.json()
const components = (await componentsResponse.json()) as EmbeddedComponents
return components
} else if (componentsResponse.status == HttpStatus.UNAUTHORIZED) {
signOut()
return signOut()
} else {
return []
return undefined
}
},
[session.user.access_token]
Expand All @@ -65,7 +67,7 @@ const ComponentsTable = ({ session, setNumberOfComponent }: Props) => {
const queryUrl = CommonUtils.createUrlWithParams('components', searchParams)
const data: Array<unknown> = []

const parseTableRowData = (item: any) => {
const parseTableRowData = (item: EmbeddedComponent) => {
data.push([
!CommonUtils.isNullOrUndefined(item.defaultVendor) ? item.defaultVendor.shortName : '',
[item.id, item.name],
Expand All @@ -78,14 +80,18 @@ const ComponentsTable = ({ session, setNumberOfComponent }: Props) => {
const controller = new AbortController()
const signal = controller.signal

fetchData(queryUrl, signal).then((components: any) => {
if (!CommonUtils.isNullOrUndefined(components['_embedded']['sw360:components'])) {
components['_embedded']['sw360:components'].forEach(parseTableRowData)
setComponentData(data)
setNumberOfComponent(data.length)
setLoading(false)
}
})
fetchData(queryUrl, signal)
.then((components: EmbeddedComponents) => {
if (!CommonUtils.isNullOrUndefined(components['_embedded']['sw360:components'])) {
components['_embedded']['sw360:components'].forEach(parseTableRowData)
setComponentData(data)
setNumberOfComponent(data.length)
setLoading(false)
}
})
.catch(() => {
console.error('False to fetch components')
})

return () => {
controller.abort()
Expand All @@ -101,7 +107,7 @@ const ComponentsTable = ({ session, setNumberOfComponent }: Props) => {
{
id: 'name',
name: t('Component Name'),
formatter: ([id, name]: any) =>
formatter: ([id, name]: Array<string>) =>
_(
<Link href={'/components/detail/' + id} className='link'>
{name}
Expand All @@ -112,17 +118,19 @@ const ComponentsTable = ({ session, setNumberOfComponent }: Props) => {
{
id: 'mainLicenses',
name: t('Main Licenses'),
formatter: (licenseIds: any) =>
formatter: (licenseIds: Array<string>) =>
licenseIds.length > 0 &&
_(
Object.entries(licenseIds)
.map(([, item]: any) => (
<Link key={item} className='link' href={'/licenses/' + item}>
{' '}
{item}{' '}
</Link>
))
.reduce((prev, curr): any => [prev, ', ', curr])
.map(
([, item]: Array<string>): React.ReactNode => (
<Link key={item} className='link' href={'/licenses/' + item}>
{' '}
{item}{' '}
</Link>
)
)
.reduce((prev, curr): React.ReactNode[] => [prev, ', ', curr])
),
sort: true,
},
Expand Down
Loading