Skip to content

Commit

Permalink
Merge pull request eclipse-sw360#127 from toshiba/release/fix_eslint_…
Browse files Browse the repository at this point in the history
…edit_release

feat(eslint): Fix eslint errors for Edit Release page
  • Loading branch information
heliocastro authored Sep 27, 2023
2 parents 978eef4 + d55ee85 commit 626e1f6
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { useRouter } from 'next/navigation'
import { COMMON_NAMESPACE } from '@/object-types/Constants'
import { useTranslations } from 'next-intl'
import DeleteReleaseModal from '../../../detail/[id]/components/DeleteReleaseModal'
import ReleaseDetail from '@/object-types/ReleaseDetail'

interface Props {
session?: Session
Expand All @@ -53,19 +54,19 @@ const EditRelease = ({ session, releaseId }: Props) => {
const t = useTranslations(COMMON_NAMESPACE)
const [selectedTab, setSelectedTab] = useState<string>(CommonTabIds.SUMMARY)
const [tabList, setTabList] = useState(ReleaseEditTabs.WITHOUT_COMMERCIAL_DETAILS)
const [release, setRelease] = useState<any>(undefined)
const [release, setRelease] = useState<ReleaseDetail>()
const [componentId, setComponentId] = useState('')
const [deletingRelease, setDeletingRelease] = useState('')
const [deleteModalOpen, setDeleteModalOpen] = useState(false)

const fetchData: any = useCallback(
const fetchData = 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
const release = (await response.json()) as ReleaseDetail
return release
} else if (response.status == HttpStatus.UNAUTHORIZED) {
signOut()
return signOut()
} else {
return null
}
Expand All @@ -74,7 +75,7 @@ const EditRelease = ({ session, releaseId }: Props) => {
)

useEffect(() => {
fetchData(`releases/${releaseId}`).then((release: any) => {
void fetchData(`releases/${releaseId}`).then((release: ReleaseDetail) => {
setRelease(release)
setDeletingRelease(releaseId)
setComponentId(CommonUtils.getIdFromUrl(release['_links']['sw360:component']['href']))
Expand All @@ -84,67 +85,22 @@ const EditRelease = ({ session, releaseId }: Props) => {
}

if (typeof release.eccInformation !== 'undefined') {
const eccInformation: ECCInformation = {
eccStatus: release.eccInformation.eccStatus,
al: release.eccInformation.al,
eccn: release.eccInformation.eccn,
assessorContactPerson: release.eccInformation.assessorContactPerson,
assessorDepartment: release.eccInformation.assessorDepartment,
eccComment: release.eccInformation.eccComment,
materialIndexNumber: release.eccInformation.materialIndexNumber,
assessmentDate: release.eccInformation.assessmentDate,
}
const eccInformation: ECCInformation = release.eccInformation
setEccInformation(eccInformation)
}

if (typeof release['_embedded']['sw360:cotsDetails'] !== 'undefined') {
const cotsDetails: COTSDetails = {
usedLicense: release['_embedded']['sw360:cotsDetails'][0].usedLicense,
licenseClearingReportURL: release['_embedded']['sw360:cotsDetails'][0].licenseClearingReportURL,
containsOSS: release['_embedded']['sw360:cotsDetails'][0].containsOSS,
ossContractSigned: release['_embedded']['sw360:cotsDetails'][0].ossContractSigned,
ossInformationURL: release['_embedded']['sw360:cotsDetails'][0].ossInformationURL,
usageRightAvailable: release['_embedded']['sw360:cotsDetails'][0].usageRightAvailable,
cotsResponsible: release['_embedded']['sw360:cotsDetails'][0].cotsResponsible,
clearingDeadline: release['_embedded']['sw360:cotsDetails'][0].clearingDeadline,
sourceCodeAvailable: release['_embedded']['sw360:cotsDetails'][0].sourceCodeAvailable,
}
if (typeof release['_embedded']['sw360:cotsDetail'] !== 'undefined') {
const cotsDetails: COTSDetails = release['_embedded']['sw360:cotsDetail']
const cotsResponsible: ComponentOwner = {
email: release['_embedded']['sw360:cotsDetails'][0]._embedded['sw360:cotsResponsible'].email,
fullName: release['_embedded']['sw360:cotsDetails'][0]._embedded['sw360:cotsResponsible'].fullName,
email: cotsDetails._embedded['sw360:cotsResponsible'].email,
fullName: cotsDetails._embedded['sw360:cotsResponsible'].fullName,
}
setCotsResponsible(cotsResponsible)
setCotsDetails(cotsDetails)
}

if (typeof release.clearingInformation !== 'undefined') {
const clearingInformation: ClearingInformation = {
externalSupplierID: release.clearingInformation.externalSupplierID,
additionalRequestInfo: release.clearingInformation.additionalRequestInfo,
evaluated: release.clearingInformation.evaluated,
procStart: release.clearingInformation.procStart,
requestID: release.clearingInformation.requestID,
binariesOriginalFromCommunity: release.clearingInformation.binariesOriginalFromCommunity,
binariesSelfMade: release.clearingInformation.binariesSelfMade,
componentLicenseInformation: release.clearingInformation.componentLicenseInformation,
sourceCodeDelivery: release.clearingInformation.sourceCodeDelivery,
sourceCodeOriginalFromCommunity: release.clearingInformation.sourceCodeOriginalFromCommunity,
sourceCodeToolMade: release.clearingInformation.sourceCodeToolMade,
sourceCodeSelfMade: release.clearingInformation.sourceCodeSelfMade,
sourceCodeCotsAvailable: release.clearingInformation.sourceCodeCotsAvailable,
screenshotOfWebSite: release.clearingInformation.screenshotOfWebSite,
finalizedLicenseScanReport: release.clearingInformation.finalizedLicenseScanReport,
licenseScanReportResult: release.clearingInformation.licenseScanReportResult,
legalEvaluation: release.clearingInformation.legalEvaluation,
licenseAgreement: release.clearingInformation.licenseAgreement,
scanned: release.clearingInformation.scanned,
componentClearingReport: release.clearingInformation.componentClearingReport,
clearingStandard: release.clearingInformation.clearingStandard,
readmeOssAvailable: release.clearingInformation.readmeOssAvailable,
comment: release.clearingInformation.comment,
countOfSecurityVn: release.clearingInformation.countOfSecurityVn,
externalUrl: release.clearingInformation.externalUrl,
}
const clearingInformation: ClearingInformation = release.clearingInformation
setClearingInformation(clearingInformation)
}
})
Expand Down Expand Up @@ -280,14 +236,14 @@ const EditRelease = ({ session, releaseId }: Props) => {
const submit = async () => {
const response = await ApiUtils.PATCH(`releases/${releaseId}`, releasePayload, session.user.access_token)
if (response.status == HttpStatus.OK) {
const data = await response.json()
const release = (await response.json()) as ReleaseDetail
alert(
true,
'Success',
`success:Release ${release.name} (${release.version}) updated successfully!`,
`Success: Release ${release.name} (${release.version}) updated successfully!`,
'success'
)
const releaseId: string = CommonUtils.getIdFromUrl(data._links.self.href)
const releaseId: string = CommonUtils.getIdFromUrl(release._links.self.href)
router.push('/components/releases/detail/' + releaseId)
} else {
alert(true, 'Error', t('Release Create failed'), 'danger')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ import ReleasePayload from '@/object-types/ReleasePayload'
import { Session } from '@/object-types/Session'
import Vendor from '@/object-types/Vendor'
import DocumentTypes from '@/object-types/enums/DocumentTypes'
import HttpStatus from '@/object-types/enums/HttpStatus'
import ApiUtils from '@/utils/api/api.util'
import CommonUtils from '@/utils/common.utils'
import { signOut } from 'next-auth/react'
import { useTranslations } from 'next-intl'
import { notFound } from 'next/navigation'
import { useCallback, useEffect, useState } from 'react'
import { useEffect, useState } from 'react'
import InputKeyValue from '@/object-types/InputKeyValue'
import ReleaseDetail from '@/object-types/ReleaseDetail'

interface Props {
session?: Session
release?: any
release?: ReleaseDetail
releaseId?: string
actionType?: string
releasePayload?: ReleasePayload
Expand All @@ -50,9 +47,9 @@ interface Props {
setContributor?: React.Dispatch<React.SetStateAction<Moderators>>
moderator?: Moderators
setModerator?: React.Dispatch<React.SetStateAction<Moderators>>
cotsDetails: COTSDetails
eccInformation: ECCInformation
clearingInformation: ClearingInformation
cotsDetails?: COTSDetails
eccInformation?: ECCInformation
clearingInformation?: ClearingInformation
}

export default function ReleaseEditSummary({
Expand Down Expand Up @@ -104,20 +101,6 @@ export default function ReleaseEditSummary({
roles: roleDatas,
})
}
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 {
notFound()
}
},
[session.user.access_token]
)

useEffect(() => {
if (typeof release.roles !== 'undefined') {
Expand All @@ -132,37 +115,37 @@ export default function ReleaseEditSummary({
setAddtionalData(CommonUtils.convertObjectToMap(release.additionalData))
}

if (typeof release['_embedded']['sw360:moderators'] !== 'undefined') {
setModerator(CommonUtils.getObjectModerators(release['_embedded']['sw360:moderators']))
if (typeof release._embedded['sw360:moderators'] !== 'undefined') {
setModerator(CommonUtils.getObjectModerators(release._embedded['sw360:moderators']))
}

if (typeof release['_embedded']['sw360:contributors'] !== 'undefined') {
setContributor(CommonUtils.getObjectContributors(release['_embedded']['sw360:contributors']))
if (typeof release._embedded['sw360:contributors'] !== 'undefined') {
setContributor(CommonUtils.getObjectContributors(release._embedded['sw360:contributors']))
}

let vendorId = ''
if (typeof release['_embedded']['sw360:vendors'] !== 'undefined') {
vendorId = CommonUtils.getIdFromUrl(release['_embedded']['sw360:vendors'][0]._links.self.href)
if (typeof release._embedded['sw360:vendors'] !== 'undefined') {
vendorId = CommonUtils.getIdFromUrl(release._embedded['sw360:vendors'][0]._links.self.href)
const vendor: Vendor = {
id: vendorId,
fullName: release['_embedded']['sw360:vendors'][0].fullName,
fullName: release._embedded['sw360:vendors'][0].fullName,
}
setVendor(vendor)
}

let modifiedBy = ''
if (typeof release['_embedded']['sw360:modifiedBy'] !== 'undefined') {
modifiedBy = release['_embedded']['sw360:modifiedBy']['fullName']
if (typeof release._embedded['sw360:modifiedBy'] !== 'undefined') {
modifiedBy = release._embedded['sw360:modifiedBy'].fullName
}

let createBy = ''
if (typeof release['_embedded']['sw360:createdBy'] !== 'undefined') {
createBy = release['_embedded']['sw360:createdBy']['fullName']
if (typeof release._embedded['sw360:createdBy'] !== 'undefined') {
createBy = release._embedded['sw360:createdBy'].fullName
}

let componentId = ''
if (typeof release['_links']['sw360:component']['href'] !== 'undefined') {
componentId = CommonUtils.getIdFromUrl(release['_links']['sw360:component']['href'])
if (typeof release._links['sw360:component'].href !== 'undefined') {
componentId = CommonUtils.getIdFromUrl(release._links['sw360:component'].href)
}

const releasePayload: ReleasePayload = {
Expand All @@ -175,12 +158,12 @@ export default function ReleaseEditSummary({
additionalData: release.additionalData,
clearingState: release.clearingState,
mainlineState: release.mainlineState,
contributors: CommonUtils.getEmailsModerators(release['_embedded']['sw360:contributors']),
contributors: CommonUtils.getEmailsModerators(release._embedded['sw360:contributors']),
createdOn: release.createdOn,
createBy: createBy,
modifiedBy: modifiedBy,
modifiedOn: release.modifiedOn,
moderators: CommonUtils.getEmailsModerators(release['_embedded']['sw360:moderators']),
moderators: CommonUtils.getEmailsModerators(release._embedded['sw360:moderators']),
roles: CommonUtils.convertRoles(CommonUtils.convertObjectToMapRoles(release.roles)),
mainLicenseIds: release.mainLicenseIds,
otherLicenseIds: release.otherLicenseIds,
Expand All @@ -199,7 +182,6 @@ export default function ReleaseEditSummary({
setReleasePayload(releasePayload)
}, [
releaseId,
fetchData,
release,
cotsDetails,
eccInformation,
Expand Down
70 changes: 70 additions & 0 deletions src/object-types/ReleaseDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 AttachmentDetail from './AttachmentDetail'
import COTSDetails from './COTSDetails'
import ClearingInformation from './ClearingInformation'
import ECCInformation from './ECCInformation'
import ReleaseLink from './ReleaseLink'
import Repository from './Repository'
import Vendor from './Vendor'
import EmbeddedUser from './EmbeddedUser'

export default interface ReleaseDetail {
name?: string
version?: string
releaseDate?: string
componentType?: string
externalIds?: string
additionalData?: string
createdOn?: string
repository?: Repository
mainlineState?: string
clearingState?: string
createdBy?: string
roles?: string
mainLicenseIds?: string[]
otherLicenseIds?: string[]
clearingInformation?: ClearingInformation
languages?: string[]
operatingSystems?: string[]
softwarePlatforms?: string[]
sourceCodeDownloadurl?: string
binaryDownloadurl?: string
releaseIdToRelationship?: Map<string, string>
modifiedOn?: string
cpeId?: string
eccInformation?: ECCInformation
_links?: {
'sw360:component': {
href: string
}
self: {
href: string
}
curies: [
{
href: string
name: string
templated: boolean
}
]
}
_embedded?: {
'sw360:modifiedBy'?: EmbeddedUser
'sw360:createdBy'?: EmbeddedUser
'sw360:moderators'?: EmbeddedUser[]
'sw360:vendors'?: Vendor[]
'sw360:contributors'?: EmbeddedUser[]
'sw360:cotsDetail'?: COTSDetails
'sw360:releaseLinks'?: ReleaseLink[]
'sw360:attachments'?: AttachmentDetail[]
}
}
19 changes: 10 additions & 9 deletions src/utils/common.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// SPDX-License-Identifier: EPL-2.0
// License-Filename: LICENSE

import EmbeddedUser from '@/object-types/EmbeddedUser'
import InputKeyValue from '@/object-types/InputKeyValue'
import Moderators from '@/object-types/Moderators'

Expand Down Expand Up @@ -49,13 +50,13 @@ const getIdFromUrl = (url: string): string => {
return url.split('/').at(-1)
}

const getObjectModerators = (emails: any[]) => {
const getObjectModerators = (users: EmbeddedUser[]) => {
const fullNames: string[] = []
const moderatorsEmail: string[] = []
if (emails.length == 0) {
if (users.length == 0) {
return
}
emails.forEach((item) => {
users.forEach((item: EmbeddedUser) => {
fullNames.push(item.fullName)
moderatorsEmail.push(item.email)
})
Expand All @@ -67,13 +68,13 @@ const getObjectModerators = (emails: any[]) => {
return moderatorsResponse
}

const getObjectContributors = (emails: any[]) => {
const getObjectContributors = (users: EmbeddedUser[]) => {
const fullNames: string[] = []
const contributorsEmail: string[] = []
if (emails.length == 0) {
if (users.length == 0) {
return
}
emails.forEach((item) => {
users.forEach((item: EmbeddedUser) => {
fullNames.push(item.fullName)
contributorsEmail.push(item.email)
})
Expand All @@ -85,12 +86,12 @@ const getObjectContributors = (emails: any[]) => {
return contributorsResponse
}

const getEmailsModerators = (emails: any[]) => {
const getEmailsModerators = (users: EmbeddedUser[]) => {
const moderatorsEmail: string[] = []
if (typeof emails === 'undefined') {
if (typeof users === 'undefined') {
return
}
emails.forEach((item) => {
users.forEach((item: EmbeddedUser) => {
moderatorsEmail.push(item.email)
})

Expand Down

0 comments on commit 626e1f6

Please sign in to comment.