Skip to content

Commit

Permalink
Merge pull request eclipse-sw360#91 from toshiba/release/define_objec…
Browse files Browse the repository at this point in the history
…t_release

feat(release): Add Release - Define Object Release
  • Loading branch information
heliocastro authored Aug 28, 2023
2 parents ca08d41 + 16a42e4 commit c08294c
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,92 @@ import CommonTabIds from '@/object-types/enums/CommonTabsIds'
import { Session } from '@/object-types/Session'
import { SideBar, PageButtonHeader } from '@/components/sw360'
import ReleaseTabIds from '@/object-types/enums/ReleaseTabIds'
import { notFound } from 'next/navigation'
import { notFound, useRouter } from 'next/navigation'
import ApiUtils from '@/utils/api/api.util'
import HttpStatus from '@/object-types/enums/HttpStatus'
import { signOut } from 'next-auth/react'
import ReleaseAddSummary from './ReleaseAddSummary'
import ReleaseAddTabs from './ReleaseAddTab'
import AddCommercialDetails from '@/components/CommercialDetails/AddCommercialDetails'
import LinkedReleases from '@/components/LinkedReleases/LinkedRelesaes'
import Vendor from '@/object-types/Vendor'
import Moderators from '@/object-types/Moderators'
import Repository from '@/object-types/Repository'
import ComponentOwner from '@/object-types/ComponentOwner'
import Licenses from '@/object-types/Licenses'
import { TypeOptions, toast } from 'react-toastify'
import { useTranslations } from 'next-intl'
import { COMMON_NAMESPACE } from '@/object-types/Constants'
import ReleasePayload from '@/object-types/ReleasePayload'

interface Props {
session?: Session
componentId?: string
}

const AddRelease = ({ session, componentId }: Props) => {
const router = useRouter()
const [selectedTab, setSelectedTab] = useState<string>(CommonTabIds.SUMMARY)
const [tabList, setTabList] = useState(ReleaseAddTabs.WITHOUT_COMMERCIAL_DETAILS)
const t = useTranslations(COMMON_NAMESPACE)
const [releasePayload, setReleasePayload] = useState<ReleasePayload>({
name: '',
cpeid: '',
version: '',
componentId: componentId,
releaseDate: '',
externalIds: null,
additionalData: null,
mainlineState: 'OPEN',
contributors: null,
moderators: null,
roles: null,
mainLicenseIds: null,
otherLicenseIds: null,
vendorId: '',
languages: null,
operatingSystems: null,
softwarePlatforms: null,
sourceCodeDownloadurl: '',
binaryDownloadurl: '',
repository: null,
releaseIdToRelationship: null,
})

const [vendor, setVendor] = useState<Vendor>({
id: '',
fullName: '',
})

const [mainLicensesId, setMainLicensesId] = useState<Licenses>({
id: null,
fullName: '',
})

const [otherLicensesId, setOtherLicensesId] = useState<Licenses>({
id: null,
fullName: '',
})

const [contributor, setContributor] = useState<Moderators>({
emails: null,
fullName: '',
})

const [moderator, setModerator] = useState<Moderators>({
emails: null,
fullName: '',
})

const [releaseRepository, setReleaseRepository] = useState<Repository>({
repositorytype: 'UNKNOWN',
url: '',
})

const [cotsResponsible, setCotsResponsible] = useState<ComponentOwner>({
email: '',
fullName: '',
})

const fetchData: any = useCallback(
async (url: string) => {
Expand All @@ -50,14 +119,43 @@ const AddRelease = ({ session, componentId }: Props) => {

useEffect(() => {
fetchData(`components/${componentId}`).then((component: any) => {
setReleasePayload({
...releasePayload,
name: component.name,
})
if (component.componentType === 'COTS') {
setTabList(ReleaseAddTabs.WITH_COMMERCIAL_DETAILS)
}
})
}, [componentId, fetchData])

const notify = (text: string, type: TypeOptions) =>
toast(text, {
type,
position: toast.POSITION.TOP_LEFT,
theme: 'colored',
})

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()
notify(t('Component is created'), 'success')
const releaseId: string = handleId(data._links.self.href)
router.push('/components/releases/detail/' + releaseId)
} else if (response.status == HttpStatus.CONFLICT) {
notify(t('Component is Duplicate'), 'warning')
} else {
notify(t('Create Component failed'), 'error')
}
}

const headerButtons = {
'Create Release': { link: '', type: 'primary' },
'Create Release': { link: '', type: 'primary', onClick: submit },
Cancel: { link: '/components/detail/' + componentId, type: 'secondary' },
}

Expand All @@ -73,7 +171,23 @@ const AddRelease = ({ session, componentId }: Props) => {
<PageButtonHeader buttons={headerButtons}></PageButtonHeader>
</div>
<div className='row' hidden={selectedTab !== CommonTabIds.SUMMARY ? true : false}>
<ReleaseAddSummary />
<ReleaseAddSummary
session={session}
releasePayload={releasePayload}
setReleasePayload={setReleasePayload}
vendor={vendor}
setVendor={setVendor}
mainLicensesId={mainLicensesId}
setMainLicensesId={setMainLicensesId}
otherLicensesId={otherLicensesId}
setOtherLicensesId={setOtherLicensesId}
contributor={contributor}
setContributor={setContributor}
moderator={moderator}
setModerator={setModerator}
releaseRepository={releaseRepository}
setReleaseRepository={setReleaseRepository}
/>
</div>
<div className='row' hidden={selectedTab != ReleaseTabIds.LINKED_RELEASES ? true : false}>
<LinkedReleases session={session} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,48 @@ import { useTranslations } from 'next-intl'
import { COMMON_NAMESPACE } from '@/object-types/Constants'
import ReleaseSummary from '@/components/ReleaseSummary/ReleaseSummary'
import ReleaseRepository from '@/components/ReleaseRepository/ReleaseRepository'
import ReleasePayload from '@/object-types/ReleasePayload'
import { Session } from '@/object-types/Session'
import Vendor from '@/object-types/Vendor'
import Licenses from '@/object-types/Licenses'
import Moderators from '@/object-types/Moderators'
import Repository from '@/object-types/Repository'

export default function ReleaseAddSummary() {
interface Props {
session?: Session
releasePayload?: ReleasePayload
setReleasePayload?: React.Dispatch<React.SetStateAction<ReleasePayload>>
vendor?: Vendor
setVendor?: React.Dispatch<React.SetStateAction<Vendor>>
mainLicensesId?: Licenses
setMainLicensesId?: React.Dispatch<React.SetStateAction<Licenses>>
otherLicensesId?: Licenses
setOtherLicensesId?: React.Dispatch<React.SetStateAction<Licenses>>
contributor?: Moderators
setContributor?: React.Dispatch<React.SetStateAction<Moderators>>
moderator?: Moderators
setModerator?: React.Dispatch<React.SetStateAction<Moderators>>
releaseRepository?: Repository
setReleaseRepository?: React.Dispatch<React.SetStateAction<Repository>>
}

export default function ReleaseAddSummary({
session,
releasePayload,
setReleasePayload,
vendor,
setVendor,
mainLicensesId,
setMainLicensesId,
otherLicensesId,
setOtherLicensesId,
contributor,
setContributor,
moderator,
setModerator,
releaseRepository,
setReleaseRepository,
}: Props) {
const t = useTranslations(COMMON_NAMESPACE)

return (
Expand Down
14 changes: 14 additions & 0 deletions src/object-types/Licenses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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

export default interface Licenses {
fullName?: string
id?: string[]
}
35 changes: 35 additions & 0 deletions src/object-types/ReleasePayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 Repository from "./Repository"

export default interface ReleasePayload {
name?: string
cpeid?: string
version?: string
componentId?: string
releaseDate?: string
externalIds?: any
additionalData?: any
mainlineState?: string
contributors?: string[]
moderators?: string[]
roles?: any
mainLicenseIds?: string[]
otherLicenseIds?: string[]
vendorId?: string
languages?: string[]
operatingSystems?: string[]
softwarePlatforms?: string[]
sourceCodeDownloadurl?: string
binaryDownloadurl?: string
repository?: Repository
releaseIdToRelationship?: any
}
14 changes: 14 additions & 0 deletions src/object-types/Repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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

export default interface Repository {
repositorytype?: string
url?: string
}

0 comments on commit c08294c

Please sign in to comment.