Skip to content

Commit

Permalink
feat(release): Add release - Add Table Main Licenses
Browse files Browse the repository at this point in the history
Signed-off-by: tuannn2 <[email protected]>
  • Loading branch information
tuannn2 committed Aug 28, 2023
1 parent dcf2520 commit bbef84c
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/components/sw360/SearchMainLicenses/MainLicensesTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) TOSHIBA CORPORATION, 2023. Part of the SW360 Frontend Project.
// Copyright (C) Toshiba Software Development (Vietnam) Co., Ltd., 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

import { memo } from 'react'
import Table from '../Table/Table'


interface Props {
data: any
columns: any
}

const compare = (preState: any, nextState: any) => {
return Object.entries(preState.data).sort().toString() === Object.entries(nextState.data).sort().toString()
}

const MainLicensesTable = memo(function LicensesTable({ columns, data }: Props) {
return <Table columns={columns} data={data} />
}, compare)

export default MainLicensesTable
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (C) TOSHIBA CORPORATION, 2023. Part of the SW360 Frontend Project.
// Copyright (C) Toshiba Software Development (Vietnam) Co., Ltd., 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 { Form } from 'react-bootstrap'
import React from 'react'
import { _ } from '@/components/sw360'
import LicensesTable from './MainLicensesTable'
import Licenses from '@/object-types/Licenses'

interface Props {
licenseDatas?: any[]
setLicenses?: (licenses: Licenses) => void
fullnames?: any[]
}

const SelectTableMainLicenses = ({ licenseDatas, setLicenses, fullnames }: Props) => {
const handlerRadioButton = (item: any) => {
if (fullnames.includes(item)) {
const index = fullnames.indexOf(item)
fullnames.splice(index, 1)
} else {
fullnames.push(item)
}
const fullNameLicenses: string[] = []
const licensesId: string[] = []
fullnames.forEach((item) => {
fullNameLicenses.push(item.fullName)
licensesId.push(handleId(item._links.self.href))
})
const licensesName: string = fullNameLicenses.join(' , ')
const licensesResponse: Licenses = {
fullName: licensesName,
id: licensesId,
}
setLicenses(licensesResponse)
}

const handleId = (id: string): string => {
return id.split('/').at(-1)
}

const columns = [
{
name: '',
formatter: (item: string) =>
_(
<Form.Check
name='licenseId'
type='checkbox'
onClick={() => {
handlerRadioButton(item)
}}
></Form.Check>
),
},
{
name: 'FullName',
sort: true,
},
]

return (
<>
<div className='row'>
<LicensesTable data={licenseDatas} columns={columns} />
</div>
</>
)
}

export default React.memo(SelectTableMainLicenses)

0 comments on commit bbef84c

Please sign in to comment.