forked from eclipse-sw360/sw360-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(release): Add release - Add Table Main Licenses
Signed-off-by: tuannn2 <[email protected]>
- Loading branch information
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/components/sw360/SearchMainLicenses/MainLicensesTable.tsx
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,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 |
80 changes: 80 additions & 0 deletions
80
src/components/sw360/SearchMainLicenses/SelectTableMainLicenses.tsx
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,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) |