Skip to content

Commit

Permalink
Merge pull request eclipse-sw360#106 from toshiba/release/set_value_f…
Browse files Browse the repository at this point in the history
…or_release_summary

feat(release): Edit Release - Set value for Release summary
  • Loading branch information
hoangnt2 authored Sep 6, 2023
2 parents fc224ee + 0688d3b commit e396079
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import COTSDetails from '@/object-types/COTSDetails'
import ToastData from '@/object-types/ToastData'
import { ToastContainer } from 'react-bootstrap'
import ToastMessage from '@/components/sw360/ToastContainer/Toast'
import CommonUtils from '@/utils/common.utils'

interface Props {
session?: Session
Expand Down Expand Up @@ -161,16 +162,12 @@ const AddRelease = ({ session, componentId }: Props) => {
})
}, [componentId, fetchData])

const handleId = (id: string): string => {
return id.split('/').at(-1)
}

const submit = async () => {
const response = await ApiUtils.POST('releases', releasePayload, session.user.access_token)
if (response.status == HttpStatus.CREATED) {
const data = await response.json()
alert(true, 'Success', t('Release is created'), 'success')
const releaseId: string = handleId(data._links.self.href)
const releaseId: string = CommonUtils.getIdFromUrl(data._links.self.href)
router.push('/components/releases/detail/' + releaseId)
} else if (response.status == HttpStatus.CONFLICT) {
alert(true, 'Duplicate', t('Release is Duplicate'), 'warning')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
import { PageButtonHeader, SideBar } from '@/components/sw360'
import { Session } from '@/object-types/Session'
import CommonTabIds from '@/object-types/enums/CommonTabsIds'
import { useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import ReleaseEditTabs from './ReleaseEditTabs'
import ReleaseEditSummary from './ReleaseEditSummary'
import Vendor from '@/object-types/Vendor'
import Licenses from '@/object-types/Licenses'
import Moderators from '@/object-types/Moderators'
import ReleasePayload from '@/object-types/ReleasePayload'
import ApiUtils from '@/utils/api/api.util'
import HttpStatus from '@/object-types/enums/HttpStatus'
import { signOut } from 'next-auth/react'
import ActionType from '@/object-types/enums/ActionType'

interface Props {
session?: Session
Expand All @@ -28,6 +32,28 @@ interface Props {
const EditRelease = ({ session, releaseId }: Props) => {
const [selectedTab, setSelectedTab] = useState<string>(CommonTabIds.SUMMARY)
const [tabList, setTabList] = useState(ReleaseEditTabs.WITH_COMMERCIAL_DETAILS)
const [release, setRelease] = useState<any>(undefined)

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 if (response.status == HttpStatus.UNAUTHORIZED) {
signOut()
} else {
return null
}
},
[session.user.access_token]
)

useEffect(() => {
fetchData(`releases/${releaseId}`).then((release: any) => {
setRelease(release)
})
}, [releaseId])

const [releasePayload, setReleasePayload] = useState<ReleasePayload>({
name: '',
Expand Down Expand Up @@ -93,8 +119,7 @@ const EditRelease = ({ session, releaseId }: Props) => {
}

return (
<>
{' '}
release && (
<div className='container' style={{ maxWidth: '98vw', marginTop: '10px' }}>
<div className='row'>
<div className='col-2 sidebar'>
Expand All @@ -107,7 +132,9 @@ const EditRelease = ({ session, releaseId }: Props) => {
<div className='row' hidden={selectedTab !== CommonTabIds.SUMMARY ? true : false}>
<ReleaseEditSummary
session={session}
release={release}
releaseId={releaseId}
actionType={ActionType.EDIT}
releasePayload={releasePayload}
setReleasePayload={setReleasePayload}
vendor={vendor}
Expand All @@ -125,7 +152,7 @@ const EditRelease = ({ session, releaseId }: Props) => {
</div>
</div>
</div>
</>
)
)
}

Expand Down
Loading

0 comments on commit e396079

Please sign in to comment.