Skip to content

Commit

Permalink
feat(Project): Added delete feature to linked Package while creating …
Browse files Browse the repository at this point in the history
…a project
  • Loading branch information
amritkv authored and heliocastro committed Jan 22, 2025
1 parent d1f3523 commit b83c39c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
48 changes: 47 additions & 1 deletion src/components/ProjectAddSummary/LinkedPackages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { useTranslations } from 'next-intl'
import { useEffect, useState } from 'react'
import LinkPackagesModal from '@/components/sw360/LinkedPackagesModal/LinkPackagesModal'
import Link from 'next/link'
import { OverlayTrigger, Tooltip } from 'react-bootstrap'
import { FaTrashAlt } from 'react-icons/fa'

interface Props {
projectPayload: ProjectPayload
Expand Down Expand Up @@ -58,12 +60,56 @@ export default function LinkedPackages({ projectPayload,
name: t('Package Manager'),
sort: true,
},
{
id: 'linkedPackagesData.deleteLinkedPackage',
name: t('Actions'),
sort: true,
formatter: (packageId: string) =>
_(
<>
<OverlayTrigger overlay={
<Tooltip>
{t('Delete')}
</Tooltip>}
>
<span className='d-inline-block'>
<FaTrashAlt
className='btn-icon'
onClick={() => handleDeletePackage(packageId)}
style={{ color: 'gray', fontSize: '18px' }}
/>
</span>
</OverlayTrigger>
</>
),
},
]

const handleDeletePackage = (packageId : string) => {
const updatedProjectPayload = { ...projectPayload }
linkedPackageData.forEach((_, key) => {
if (key === packageId){
linkedPackageData.delete(key)
if (updatedProjectPayload.packageIds &&
updatedProjectPayload.packageIds.includes(key)){
updatedProjectPayload.packageIds.splice(
updatedProjectPayload.packageIds.indexOf(key), 1 )
setProjectPayload(updatedProjectPayload)
}
const updatedTableData = extractDataFromMap(linkedPackageData)
setTableData(updatedTableData)
}
})
}

const extractDataFromMap = (linkedPackageData: Map<string, LinkedPackageData>) => {
const extractedData: Array<RowData> = []
linkedPackageData.forEach((value, ) => {
extractedData.push([[value.name, value.packageId], value.version, value.licenseIds, value.packageManager])
extractedData.push([[value.name, value.packageId],
value.version,
value.licenseIds,
value.packageManager,
value.packageId])
})
return extractedData
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ export default function LinkPackagesModal({
}
else {
for (const [packageId, ] of linkedPackagePayloadData) {
updatedProjectPayload.packageIds.push(packageId)
if (!updatedProjectPayload.packageIds.includes(packageId))
updatedProjectPayload.packageIds.push(packageId)
}
}
setProjectPayload(updatedProjectPayload)
Expand Down

0 comments on commit b83c39c

Please sign in to comment.