Skip to content

Commit

Permalink
fix(Projects): fix bugs in Project list
Browse files Browse the repository at this point in the history
  • Loading branch information
duonglq-tsdv committed Dec 3, 2024
1 parent 83ab7c9 commit a7c28d5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
32 changes: 28 additions & 4 deletions src/app/[locale]/projects/components/Projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import { useEffect, useState } from 'react'
import { Dropdown, OverlayTrigger, Spinner, Tooltip } from 'react-bootstrap'
import { FaClipboard, FaPencilAlt, FaTrashAlt } from 'react-icons/fa'
import { MdOutlineTask } from 'react-icons/md'
import CreateClearingRequestModal from '../detail/[id]/components/CreateClearingRequestModal'
import DeleteProjectDialog from './DeleteProjectDialog'
import ImportSBOMModal from './ImportSBOMModal'
import MessageService from '@/services/message.service'

type EmbeddedProjects = Embedded<TypeProject, 'sw360:projects'>

Expand Down Expand Up @@ -95,6 +97,9 @@ function Project(): JSX.Element {
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false)
const [importSBOMMetadata, setImportSBOMMetadata] = useState<ImportSBOMMetadata>({ show: false, importType: 'SPDX' })

const [showClearingRequestModal, setShowClearingRequestModal] = useState(false)
const [clearingRequestProjectId, setClearingRequestProjectId] = useState('')

const handleDeleteProject = (projectId: string) => {
setDeleteProjectId(projectId)
setDeleteDialogOpen(true)
Expand All @@ -104,6 +109,11 @@ function Project(): JSX.Element {
router.push('/projects/add')
}

const handleEditProject = (projectId: string) => {
router.push(`/projects/edit/${projectId}`)
MessageService.success(t('You are editing the original document'))
}

const columns = [
{
id: 'projects.name',
Expand Down Expand Up @@ -185,13 +195,22 @@ function Project(): JSX.Element {
<>
<span className='d-flex justify-content-evenly'>
<OverlayTrigger overlay={<Tooltip>{t('Edit')}</Tooltip>}>
<Link href={`/projects/edit/${id}`} className='overlay-trigger'>
<span
className='d-inline-block'
onClick={() => handleEditProject(id)}
>
<FaPencilAlt className='btn-icon' />
</Link>
</span>
</OverlayTrigger>

<OverlayTrigger overlay={<Tooltip>{t('Create Clearing Request')}</Tooltip>}>
<span className='d-inline-block'>
<OverlayTrigger overlay={<Tooltip>{t("Create Clearing Request")}</Tooltip>}>
<span
className='d-inline-block'
onClick={() => {
setClearingRequestProjectId(id)
setShowClearingRequestModal(true)
}}
>
<MdOutlineTask className='btn-icon overlay-trigger' />
</span>
</OverlayTrigger>
Expand Down Expand Up @@ -390,6 +409,11 @@ function Project(): JSX.Element {
</div>
</div>
</div>
<CreateClearingRequestModal
show={showClearingRequestModal}
setShow={setShowClearingRequestModal}
projectId={clearingRequestProjectId}
/>
</>
)
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/[locale]/projects/detail/[id]/components/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ export default function Summary({ summaryData }: { summaryData: SummaryDataType

<tr>
<td>{t('Owner Country')}:</td>
<td>{summaryData.ownerCountry !== undefined ? new Intl.DisplayNames(['en'], { type: 'region' }).of(summaryData.ownerCountry) : ''}</td>
<td>
{(summaryData.ownerCountry != null) && /^[A-Z]{2}$/.test(summaryData.ownerCountry)
? new Intl.DisplayNames(['en'], { type: 'region' }).of(summaryData.ownerCountry)
: ''}
</td>
</tr>
<tr>
<td>{t('Lead Architect')}:</td>
Expand Down
16 changes: 15 additions & 1 deletion src/app/[locale]/projects/edit/[id]/components/EditProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { notFound, useRouter, useSearchParams } from 'next/navigation'
import { useEffect, useState } from 'react'
import { Button, Col, ListGroup, Row, Tab } from 'react-bootstrap'
import Obligations from '../../../components/Obligations/Obligations'
import DeleteProjectDialog from '../../../components/DeleteProjectDialog'

interface LinkedReleaseProps {
release?: string
Expand Down Expand Up @@ -52,6 +53,12 @@ function EditProject({ projectId }: { projectId: string }): JSX.Element {
const DEFAULT_ACTIVE_TAB = 'summary'
const [activeKey, setActiveKey] = useState(DEFAULT_ACTIVE_TAB)

const [deleteDialogOpen, setDeleteDialogOpen] = useState(false)

const handleDeleteProject = () => {
setDeleteDialogOpen(true)
}

useEffect(() => {
let tab = searchParams.get('tab')
if (tab === null || TABS.indexOf(tab) === -1) {
Expand Down Expand Up @@ -346,6 +353,13 @@ function EditProject({ projectId }: { projectId: string }): JSX.Element {

return (
<div className='container page-content'>
{projectId && (
<DeleteProjectDialog
projectId={projectId}
show={deleteDialogOpen}
setShow={setDeleteDialogOpen}
/>
)}
<form
action=''
id='form_submit'
Expand Down Expand Up @@ -395,7 +409,7 @@ function EditProject({ projectId }: { projectId: string }): JSX.Element {
variant='danger'
type='submit'
className='me-2 col-auto'
onClick={handleCancelClick}
onClick={handleDeleteProject}
>
{t('Delete Project')}
</Button>
Expand Down

0 comments on commit a7c28d5

Please sign in to comment.