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 search dialog Main Licenses
Signed-off-by: tuannn2 <[email protected]>
- Loading branch information
Showing
8 changed files
with
191 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
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
138 changes: 138 additions & 0 deletions
138
src/components/sw360/SearchMainLicenses/MainLicensesDialog.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,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 |
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
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,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 |