Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ const ReleaseOverview = ({ componentId, calledFromModerationRequestDetail }: Pro
</Link>
</OverlayTrigger>
<OverlayTrigger overlay={<Tooltip>{t('Duplicate')}</Tooltip>}>
<BsClipboard
className='btn-icon'
size={20}
/>
<Link href={`/components/editRelease/${id}?duplicate=true`}>
<BsClipboard
className='btn-icon'
size={20}
/>
</Link>
</OverlayTrigger>
<OverlayTrigger overlay={<Tooltip>{t('Link Project')}</Tooltip>}>
<BsLink45Deg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ const EditRelease = ({ releaseId, isSPDXFeatureEnabled }: Props): ReactNode => {
const router = useRouter()
const t = useTranslations('default')
const params = useSearchParams()
const isDuplicate = params.get('duplicate') === 'true'
const [release, setRelease] = useState<ReleaseDetail>()
const [componentId, setComponentId] = useState('')
const [deletingRelease, setDeletingRelease] = useState('')
const [deleteModalOpen, setDeleteModalOpen] = useState(false)
const [showCommentModal, setShowCommentModal] = useState<boolean>(false)
const { status } = useSession()
const { data: session, status } = useSession()
const [activeKey, setActiveKey] = useState(CommonTabIds.SUMMARY)

useEffect(() => {
Expand Down Expand Up @@ -467,6 +468,44 @@ const EditRelease = ({ releaseId, isSPDXFeatureEnabled }: Props): ReactNode => {
}
}

const createDuplicate = async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Releases page has only 2 tabs, this one has some unnecessary ones

if (CommonUtils.isNullOrUndefined(session)) {
MessageService.error(t('Session has expired'))
return signOut()
}
try {
const eccInfo = releasePayload.eccInformation
const sanitizedEccInformation: ECCInformation | undefined = eccInfo
? {
...eccInfo,
eccStatus: eccInfo.eccStatus?.trim() !== '' ? eccInfo.eccStatus : undefined,
}
: undefined
const { linkedPackages, clearingState, ...cleanPayload } = releasePayload

const finalPayload: Release = {
...cleanPayload,
eccInformation: sanitizedEccInformation,
}
const response = await ApiUtils.POST('releases', finalPayload, session.user.access_token)

if (response.status === StatusCodes.CREATED) {
const newRelease = (await response.json()) as ReleaseDetail
const newReleaseId = CommonUtils.getIdFromUrl(newRelease._links.self.href)
MessageService.success(`Release ${newRelease.name} (${newRelease.version}) created successfully!`)
router.push('/components/releases/detail/' + newReleaseId)
} else if (response.status === StatusCodes.CONFLICT) {
MessageService.warn(t('Release is Duplicate'))
} else {
const data = await response.json()
MessageService.error(data.message)
}
} catch (e) {
const msg = e instanceof Error ? e.message : String(e)
MessageService.error(msg)
}
}

const checkUpdateEligibility = async (releaseId: string) => {
const session = await getSession()
if (CommonUtils.isNullOrUndefined(session)) return signOut()
Expand Down Expand Up @@ -515,25 +554,46 @@ const EditRelease = ({ releaseId, isSPDXFeatureEnabled }: Props): ReactNode => {
setDeleteModalOpen(true)
}

const headerButtons = {
'Update Release': {
link: '',
type: 'primary',
onClick: checkPreRequisite,
name: t('Update Release'),
},
'Delete Release': {
link: '',
type: 'danger',
onClick: handleDeleteRelease,
name: t('Delete Release'),
},
Cancel: {
link: '/components/releases/detail/' + releaseId,
type: 'secondary',
name: t('Cancel'),
},
}
const headerButtons: {
[key: string]: {
link: string
name: string
type: string
onClick?: () => void
}
} = isDuplicate
? {
'Create Release': {
link: '',
type: 'primary',
onClick: createDuplicate,
name: t('Create Release'),
},
Cancel: {
link: '/components/releases/detail/' + releaseId,
type: 'secondary',
name: t('Cancel'),
},
}
: {
'Update Release': {
link: '',
type: 'primary',
onClick: checkPreRequisite,
name: t('Update Release'),
},
'Delete Release': {
link: '',
type: 'danger',
onClick: handleDeleteRelease,
name: t('Delete Release'),
},
Cancel: {
link: '/components/releases/detail/' + releaseId,
type: 'secondary',
name: t('Cancel'),
},
}

const param = useParams()
const locale = (param.locale as string) || 'en'
Expand Down
Loading