From 12b06898f6861f9be0f89b070bf2b8caaaa3dd03 Mon Sep 17 00:00:00 2001 From: tuannn2 Date: Mon, 28 Aug 2023 15:51:42 +0700 Subject: [PATCH] feat(release): Add release - Add search dialog Main Licenses Signed-off-by: tuannn2 --- messages/en.json | 3 +- messages/ja.json | 2 + messages/vi.json | 2 + messages/zh.json | 2 + .../ReleaseSummary/ReleaseSummary.tsx | 25 +++- .../SearchMainLicenses/MainLicensesDialog.tsx | 138 ++++++++++++++++++ .../SelectTableMainLicenses.tsx | 11 +- src/object-types/LicensesType.ts | 13 ++ 8 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 src/components/sw360/SearchMainLicenses/MainLicensesDialog.tsx create mode 100644 src/object-types/LicensesType.ts 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/components/ReleaseSummary/ReleaseSummary.tsx b/src/components/ReleaseSummary/ReleaseSummary.tsx index f5be25b1..fac912eb 100644 --- a/src/components/ReleaseSummary/ReleaseSummary.tsx +++ b/src/components/ReleaseSummary/ReleaseSummary.tsx @@ -10,7 +10,7 @@ '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' @@ -21,6 +21,7 @@ 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 @@ -74,6 +75,21 @@ const ReleaseSummary = ({ }: 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, @@ -248,6 +264,13 @@ const ReleaseSummary = ({ readOnly={true} name='mainLicenseIds' value={mainLicensesId.fullName ?? ''} + onClick={handleClickSearchMainLicenses} + /> + diff --git a/src/components/sw360/SearchMainLicenses/MainLicensesDialog.tsx b/src/components/sw360/SearchMainLicenses/MainLicensesDialog.tsx new file mode 100644 index 00000000..4b887e33 --- /dev/null +++ b/src/components/sw360/SearchMainLicenses/MainLicensesDialog.tsx @@ -0,0 +1,138 @@ +// 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 Modal from 'react-bootstrap/Modal' +import Button from 'react-bootstrap/Button' +import { Session } from '@/object-types/Session' +import ApiUtils from '@/utils/api/api.util' +import HttpStatus from '@/object-types/enums/HttpStatus' +import { useCallback, useEffect, useState } from 'react' +import CommonUtils from '@/utils/common.utils' +import { useTranslations } from 'next-intl' +import { COMMON_NAMESPACE } from '@/object-types/Constants' +import Licenses from '@/object-types/Licenses' +import SelectTableMainLicenses from './SelectTableMainLicenses' +import { LicensesType } from '@/object-types/LicensesType' + +interface Props { + show?: boolean + setShow?: React.Dispatch> + session?: Session + selectLicenses?: LicensesType +} + +const MainLicensesDiaglog = ({ show, setShow, session, selectLicenses }: Props) => { + const t = useTranslations(COMMON_NAMESPACE) + const [data, setData] = useState([]) + const [licenses, setLicenses] = useState([]) + const [licensesResponse, setLicensesResponse] = useState() + const [licenseDatas, setLicenseDatas] = useState([]) + + const handleCloseDialog = () => { + setShow(!show) + } + + const searchVendor = () => { + setLicenseDatas(data) + } + + const fetchData: any = useCallback(async (url: string) => { + const response = await ApiUtils.GET(url, session.user.access_token) + if (response.status == HttpStatus.OK) { + const data = await response.json() + return data + } else { + return [] + } + }, []) + + useEffect(() => { + fetchData(`licenses`).then((licenses: any) => { + if(typeof licenses == "undefined") { + setData([]); + return; + } + if ( + !CommonUtils.isNullOrUndefined(licenses['_embedded']) && + !CommonUtils.isNullOrUndefined(licenses['_embedded']['sw360:licenses']) + ){ + const data = licenses['_embedded']['sw360:licenses'].map((item: any) => [ + item, + item.fullName, + ]) + setData(data) + } + }) + }, []) + + const handleClickSelectModerators = () => { + selectLicenses(licensesResponse) + setShow(!show) + } + + const getLicenses: LicensesType = useCallback((licenses: Licenses) => setLicensesResponse(licenses), []) + + return ( + + + {t('Search Licenses')} + + +
+
+
+ +
+
+ + +
+
+
+ +
+
+
+ + + + +
+ ) +} + +export default MainLicensesDiaglog diff --git a/src/components/sw360/SearchMainLicenses/SelectTableMainLicenses.tsx b/src/components/sw360/SearchMainLicenses/SelectTableMainLicenses.tsx index bde596ef..39c73ef9 100644 --- a/src/components/sw360/SearchMainLicenses/SelectTableMainLicenses.tsx +++ b/src/components/sw360/SearchMainLicenses/SelectTableMainLicenses.tsx @@ -12,13 +12,14 @@ import { Form } from 'react-bootstrap' import React from 'react' -import { _ } from '@/components/sw360' +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?: (licenses: Licenses) => void + setLicenses?: LicensesType fullnames?: any[] } @@ -50,6 +51,7 @@ const SelectTableMainLicenses = ({ licenseDatas, setLicenses, fullnames }: Props const columns = [ { + id: 'licenseId', name: '', formatter: (item: string) => _( @@ -61,10 +63,13 @@ const SelectTableMainLicenses = ({ licenseDatas, setLicenses, fullnames }: Props }} > ), + width: '5%' }, { - name: 'FullName', + id: 'license', + name: 'License', sort: true, + width: '95%' }, ] 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