Skip to content

Commit

Permalink
feat(release): Add release - Add search dialog 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 bbef84c commit 12b0689
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 5 deletions.
3 changes: 2 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions messages/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions messages/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 24 additions & 1 deletion src/components/ReleaseSummary/ReleaseSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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<HTMLSelectElement | HTMLInputElement | HTMLTextAreaElement>) => {
setReleasePayload({
...releasePayload,
Expand Down Expand Up @@ -248,6 +264,13 @@ const ReleaseSummary = ({
readOnly={true}
name='mainLicenseIds'
value={mainLicensesId.fullName ?? ''}
onClick={handleClickSearchMainLicenses}
/>
<MainLicensesDiaglog
show={dialogOpenMainLicenses}
setShow={setDialogOpenMainLicenses}
session={session}
selectLicenses={setMainLicenses}
/>
</div>
</div>
Expand Down
138 changes: 138 additions & 0 deletions src/components/sw360/SearchMainLicenses/MainLicensesDialog.tsx
Original file line number Diff line number Diff line change
@@ -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<React.SetStateAction<boolean>>
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<Licenses>()
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 (
<Modal show={show} onHide={handleCloseDialog} backdrop='static' centered size='lg'>
<Modal.Header closeButton>
<Modal.Title>{t('Search Licenses')}</Modal.Title>
</Modal.Header>
<Modal.Body>
<div className='modal-body'>
<div className='row'>
<div className='col-lg-8'>
<input
type='text'
className='form-control'
placeholder={t('Enter search text')}
aria-describedby='Search Licenses'
/>
</div>
<div className='col-lg-4'>
<button
type='button'
className={`fw-bold btn btn-light button-plain me-2`}
onClick={searchVendor}
>
{t('Search')}
</button>
<button type='button' className={`fw-bold btn btn-light button-plain me-2`}>
{t('Reset')}
</button>
</div>
</div>
<div className='row mt-3'>
<SelectTableMainLicenses licenseDatas={licenseDatas} setLicenses={getLicenses} fullnames={licenses} />
</div>
</div>
</Modal.Body>
<Modal.Footer className='justify-content-end'>
<Button
type='button'
data-bs-dismiss='modal'
className={`fw-bold btn btn-light button-plain me-2`}
onClick={handleCloseDialog}
>
{t('Close')}
</Button>
<Button
type='button'
className={`btn btn-primary`}
onClick={handleClickSelectModerators}
>
{t('Select Licenses')}
</Button>
</Modal.Footer>
</Modal>
)
}

export default MainLicensesDiaglog
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}

Expand Down Expand Up @@ -50,6 +51,7 @@ const SelectTableMainLicenses = ({ licenseDatas, setLicenses, fullnames }: Props

const columns = [
{
id: 'licenseId',
name: '',
formatter: (item: string) =>
_(
Expand All @@ -61,10 +63,13 @@ const SelectTableMainLicenses = ({ licenseDatas, setLicenses, fullnames }: Props
}}
></Form.Check>
),
width: '5%'
},
{
name: 'FullName',
id: 'license',
name: 'License',
sort: true,
width: '95%'
},
]

Expand Down
13 changes: 13 additions & 0 deletions src/object-types/LicensesType.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 12b0689

Please sign in to comment.