diff --git a/messages/en.json b/messages/en.json index 059ff348..b07aeaa8 100644 --- a/messages/en.json +++ b/messages/en.json @@ -462,7 +462,8 @@ "SPDX Attachments": "SPDX Attachments", "Security Assessment": "Security Assessment", "Supplemental Information": "Supplemental Information", - "Source Code Available": "Source Code Available", + "Search Licenses": "Search Licenses", + "Select Licenses": "Select Licenses", "Team Foundation Server": "Team Foundation Server", "Technical writer": "Technical writer", "Test Manager": "Test Manager", diff --git a/messages/ja.json b/messages/ja.json index cc266caf..6469999b 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -445,6 +445,8 @@ "Subversion (SVN)": "転覆 (SVN)", "Success! Please reload page to see the changes!": "成功! 変更点を確認するには、ページをリロードしてください!", "Supplemental Information": "補足情報", + "Search Licenses": "Search Licenses", + "Select Licenses": "Select Licenses", "Team Foundation Server": "チームファンデーションサーバー", "Test Manager": "NOT TRANSLATED", "Technical writer": "NOT TRANSLATED", diff --git a/messages/vi.json b/messages/vi.json index cb30db29..1caba0a5 100644 --- a/messages/vi.json +++ b/messages/vi.json @@ -445,6 +445,8 @@ "Supplemental Information": "Thông tin bổ sung", "Subversion (SVN)": "Lật đổ (SVN)", "SAP Design Time Repository (DTR)": "Kho lưu trữ thời gian thiết kế SAP (DTR)", + "Search Licenses": "Search Licenses", + "Select Licenses": "Select Licenses", "Test Manager": "NOT TRANSLATED", "Technical writer": "NOT TRANSLATED", "Tag": "NOT TRANSLATED", diff --git a/messages/zh.json b/messages/zh.json index f764bc0e..b82e0c83 100644 --- a/messages/zh.json +++ b/messages/zh.json @@ -442,6 +442,8 @@ "Supplemental Information": "补充信息", "Subversion (SVN)": "颠覆(SVN)", "SAP Design Time Repository (DTR)": "SAP 设计时存储库 (DTR)", + "Search Licenses": "Search Licenses", + "Select Licenses": "Select Licenses", "Test Manager": "NOT TRANSLATED", "Technical writer": "NOT TRANSLATED", "Tag": "NOT TRANSLATED", diff --git a/src/app/[locale]/components/edit/[id]/release/add/releases/ReleaseAddSummary.tsx b/src/app/[locale]/components/edit/[id]/release/add/releases/ReleaseAddSummary.tsx index 4f95b851..9d7fe18a 100644 --- a/src/app/[locale]/components/edit/[id]/release/add/releases/ReleaseAddSummary.tsx +++ b/src/app/[locale]/components/edit/[id]/release/add/releases/ReleaseAddSummary.tsx @@ -22,6 +22,7 @@ import Vendor from '@/object-types/Vendor' import Licenses from '@/object-types/Licenses' import Moderators from '@/object-types/Moderators' import Repository from '@/object-types/Repository' +import { useState } from 'react' interface Props { session?: Session @@ -71,7 +72,19 @@ export default function ReleaseAddSummary({ }} >
- +
diff --git a/src/components/ReleaseSummary/ReleaseSummary.tsx b/src/components/ReleaseSummary/ReleaseSummary.tsx index 1fc96ae3..fac912eb 100644 --- a/src/components/ReleaseSummary/ReleaseSummary.tsx +++ b/src/components/ReleaseSummary/ReleaseSummary.tsx @@ -10,11 +10,33 @@ 'use client' import styles from './ReleaseSummary.module.css' -import React, { useState } from 'react' +import React, { useCallback, useState } from 'react' import { useTranslations } from 'next-intl' import { COMMON_NAMESPACE } from '@/object-types/Constants' import { OverlayTrigger, Tooltip } from 'react-bootstrap' import { BiInfoCircle } from 'react-icons/bi' +import { Session } from '@/object-types/Session' +import Vendor from '@/object-types/Vendor' +import Licenses from '@/object-types/Licenses' +import ModeratorsDiaglog from '../sw360/SearchModerators/ModeratorsDiaglog' +import Moderators from '@/object-types/Moderators' +import ReleasePayload from '@/object-types/ReleasePayload' +import MainLicensesDiaglog from '../sw360/SearchMainLicenses/MainLicensesDialog' +interface Props { + session?: Session + releasePayload: ReleasePayload + setReleasePayload: React.Dispatch> + vendor?: Vendor + setVendor?: React.Dispatch> + mainLicensesId?: Licenses + setMainLicensesId?: React.Dispatch> + otherLicensesId?: Licenses + setOtherLicensesId?: React.Dispatch> + contributor?: Moderators + setContributor?: React.Dispatch> + moderator?: Moderators + setModerator?: React.Dispatch> +} const getDate = () => { const today = new Date() @@ -36,9 +58,56 @@ const ShowInfoOnHover = ({ text }: { text: string }) => { ); }; -const ReleaseSummary = () => { +const ReleaseSummary = ({ + session, + releasePayload, + setReleasePayload, + vendor, + setVendor, + mainLicensesId, + setMainLicensesId, + otherLicensesId, + setOtherLicensesId, + contributor, + setContributor, + moderator, + setModerator, +}: Props) => { const t = useTranslations(COMMON_NAMESPACE) const [currentDate, setCurrentDate] = useState(getDate()) + const [dialogOpenMainLicenses, setDialogOpenMainLicenses] = useState(false) + const handleClickSearchMainLicenses = useCallback(() => setDialogOpenMainLicenses(true), []) + + const setMainLicenses = (licenseResponse: Licenses) => { + const mainLicenses: Licenses = { + id: licenseResponse.id, + fullName: licenseResponse.fullName, + } + setMainLicensesId(mainLicenses) + setReleasePayload({ + ...releasePayload, + mainLicenseIds: mainLicenses.id, + }) + } + + const updateField = (e: React.ChangeEvent) => { + setReleasePayload({ + ...releasePayload, + [e.target.name]: e.target.value, + }) + } + + const setArrayData = (e: React.ChangeEvent) => { + const data: string[] = splitValueCategories(e.target.value) + setReleasePayload({ + ...releasePayload, + [e.target.name]: data, + }) + } + + const splitValueCategories = (valueCatergories: string) => { + return valueCatergories.split(',') + } return ( <> @@ -62,7 +131,9 @@ const ReleaseSummary = () => { aria-describedby='Vendor' readOnly={true} name='defaultVendorId' + value={vendor.fullName ?? ''} /> + x
@@ -110,6 +183,7 @@ const ReleaseSummary = () => { id='programming_languages' aria-describedby='programming_languages' name='languages' + onChange={setArrayData} />
@@ -123,6 +197,7 @@ const ReleaseSummary = () => { id='operating_systems' aria-describedby='operating_systems' name='operatingSystems' + onChange={setArrayData} />
@@ -136,6 +211,7 @@ const ReleaseSummary = () => { id='tag' aria-describedby='Tag' name='cpeid' + onChange={updateField} />
@@ -156,6 +232,7 @@ const ReleaseSummary = () => { id='blog_url' aria-describedby='blog_url' name='softwarePlatforms' + onChange={setArrayData} />
@@ -169,6 +246,7 @@ const ReleaseSummary = () => { id='releaseDate' aria-describedby='releaseDate' name='releaseDate' + onChange={updateField} />
@@ -185,6 +263,14 @@ const ReleaseSummary = () => { aria-describedby='Vendor' readOnly={true} name='mainLicenseIds' + value={mainLicensesId.fullName ?? ''} + onClick={handleClickSearchMainLicenses} + /> +
@@ -204,10 +290,8 @@ const ReleaseSummary = () => { aria-describedby='Vendor' readOnly={true} name='otherLicenseIds' + value={otherLicensesId.fullName ?? ''} /> -
- -
@@ -233,6 +318,7 @@ const ReleaseSummary = () => { id='binaryDownloadurl' aria-describedby='wiki_url' name='binaryDownloadurl' + onChange={updateField} />
@@ -253,7 +339,7 @@ const ReleaseSummary = () => {
+
+
+ + +
+ +
+ +
+ + + + + + + + ) +} + +export default MainLicensesDiaglog diff --git a/src/components/sw360/SearchMainLicenses/MainLicensesTable.tsx b/src/components/sw360/SearchMainLicenses/MainLicensesTable.tsx new file mode 100644 index 00000000..d9fc0d86 --- /dev/null +++ b/src/components/sw360/SearchMainLicenses/MainLicensesTable.tsx @@ -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 +}, compare) + +export default MainLicensesTable diff --git a/src/components/sw360/SearchMainLicenses/SelectTableMainLicenses.tsx b/src/components/sw360/SearchMainLicenses/SelectTableMainLicenses.tsx new file mode 100644 index 00000000..39c73ef9 --- /dev/null +++ b/src/components/sw360/SearchMainLicenses/SelectTableMainLicenses.tsx @@ -0,0 +1,85 @@ +// 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 { Table, _ } from '@/components/sw360' +import LicensesTable from './MainLicensesTable' +import Licenses from '@/object-types/Licenses' +import { LicensesType } from '@/object-types/LicensesType' + +interface Props { + licenseDatas?: any[] + setLicenses?: LicensesType + 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 = [ + { + id: 'licenseId', + name: '', + formatter: (item: string) => + _( + { + handlerRadioButton(item) + }} + > + ), + width: '5%' + }, + { + id: 'license', + name: 'License', + sort: true, + width: '95%' + }, + ] + + return ( + <> +
+ +
+ + ) +} + +export default React.memo(SelectTableMainLicenses) diff --git a/src/object-types/LicensesType.ts b/src/object-types/LicensesType.ts new file mode 100644 index 00000000..0f9307f4 --- /dev/null +++ b/src/object-types/LicensesType.ts @@ -0,0 +1,13 @@ +// 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 Licenses from "./Licenses"; + +export type LicensesType = (licenses: Licenses) => void