Skip to content

Commit

Permalink
Merge pull request #181 from toshiba/release/fix-change-page-size
Browse files Browse the repository at this point in the history
fix(Table): Fix change page size error when server pagination is not defined
  • Loading branch information
heliocastro authored and amritkv committed Dec 4, 2023
2 parents 947545c + 9e471f4 commit 1306652
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 50 deletions.
8 changes: 7 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"Darcs": "Darcs",
"Decision report": "Decision report",
"Default vendor": "Default vendor",
"Delete Project": "Delete Project",
"Delete Attachment": "Delete Attachment",
"Delete component success!": "Delete component success!",
"Delete Component": "Delete Component",
Expand All @@ -210,6 +211,7 @@
"Delete": "Delete",
"Delete Vulnerability": "Delete Vulnerability",
"Do you really want to delete the vulnerability?": "Do you really want to delete the vulnerability <strong>{id}</strong>?",
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
"Do you really want to delete the component?": "Do you really want to delete the component <strong>{name}</strong>?",
"Do you really want to delete the release?": "Do you really want to delete the release: <strong>{name}</strong>?",
"Document Id": "Document Id",
Expand Down Expand Up @@ -748,6 +750,10 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"This project contains": "This project <strong>{name}</strong> contains:",
"Delete project successful!": "Delete project successful!",
"The project cannot be deleted, since it is used by another project!": "The project cannot be deleted, since it is used by another project!",
"Moderation request is created!": "Moderation request is created!"
}
}
8 changes: 7 additions & 1 deletion messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
"Deselect All": "Deselect All",
"Design document": "設計書",
"Do not create monitoring list, but use list from external id": "監視リストを作成せず、外部IDからのリストを使用します。",
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
"Do you really want to delete the attachment?": "您确实要删除该附件吗?",
"Do you really want to delete the component?": "本当にコンポーネント <strong>{name}</strong> を削除しますか?",
"Do you really want to delete the release?": "本当にリリース: <strong>{name}</strong>?",
Expand Down Expand Up @@ -749,6 +750,11 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"Delete Project": "プロジェクトの削除",
"This project contains": "このプロジェクト <strong>{name}</strong> には次のものが含まれます:",
"Delete project successful!": "プロジェクトの削除が成功しました。",
"The project cannot be deleted, since it is used by another project!": "プロジェクトは別のプロジェクトで使用されているため削除できません。",
"Moderation request is created!": "モデレーションリクエストが作成されました。"
}
}
8 changes: 7 additions & 1 deletion messages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
"Design document": "-Documento de Concepção do FIP",
"Do not create monitoring list, but use list from external id": "Não criar lista de monitoramento, mas usar lista de id externo",
"Do you really want to delete the attachment?": "Tem certeza de que deseja excluir este anexo?",
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
"Do you really want to delete the component?": "Deseja realmente excluir o componente <strong>{name}</strong>?",
"Do you really want to delete the release?": "Deseja realmente excluir a versão: <strong>{name}</strong>?",
"Do you really want to delete the vulnerability?": "Deseja realmente excluir a vulnerabilidade <strong>{id}</strong>?",
Expand Down Expand Up @@ -748,6 +749,11 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"Delete Project": "Excluir projeto",
"This project contains": "Este projeto <strong>{name}</strong> contém:",
"Delete project successful": "Excluir projeto com sucesso!",
"The project cannot be deleted, since it is used by another project!": "O projeto não pode ser excluído, pois está sendo utilizado por outro projeto!",
"Moderation request is created!": "A solicitação de moderação foi criada !"
}
}
8 changes: 7 additions & 1 deletion messages/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
"Design document": "Thiết kế văn bản",
"Do not create monitoring list, but use list from external id": "Không tạo danh sách theo dõi mà sử dụng danh sách từ id bên ngoài",
"Do you really want to delete the attachment?": "Bạn có thực sự muốn xóa tệp đính kèm không?",
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
"Do you really want to delete the component?": "Bạn có thực sự muốn xóa thành phần <strong>{name}</strong> không?",
"Do you really want to delete the release?": "Bạn có thực sự muốn xóa bản phát hành: <strong>{name}</strong> không?",
"Do you really want to delete the vulnerability?": "Bạn có thực sự muốn xóa lỗ hổng <strong>{id}</strong> không?",
Expand Down Expand Up @@ -747,6 +748,11 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"Delete Project": "Xóa dự án",
"This project contains": "Dự án này <strong>{name</strong> bao gồm:",
"Delete project successful!": "Xóa dự án thành công!",
"The project cannot be deleted, as it is used by another project!": "Dự án không thể bị xóa vì nó được sử dụng bởi một dự án khác!",
"Moderation request is created!": "Yêu cầu kiểm duyệt được tạo!"
}
}
8 changes: 7 additions & 1 deletion messages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
"Design document": "设计文件",
"Do not create monitoring list, but use list from external id": "不创建监控列表,而是使用外部 id 的列表",
"Do you really want to delete the attachment?": "您确实要删除该附件吗?",
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
"Do you really want to delete the component?": "您确实要删除组件<strong>{name}</strong>吗?",
"Do you really want to delete the release?": "您确实要删除版本:<strong>{name}</strong>吗?",
"Do you really want to delete the vulnerability?": "您确实要删除漏洞<strong>{id}</strong>吗?",
Expand Down Expand Up @@ -747,6 +748,11 @@
"Creator Group": "Creator Group",
"ECC Assessor": "ECC Assessor",
"ECC Assessor Group": "ECC Assessor Group",
"ECC Assessment Date": "ECC Assessment Date"
"ECC Assessment Date": "ECC Assessment Date",
"Delete Project": "删除项目",
"This project contains": "该项目<strong>{name}</strong>包含:",
"Delete project successful": "删除项目成功!",
"The project cannot be deleted, as it is used by another project!": "該項目無法刪除,因為它已被另一個項目使用!",
"Moderation request is created!": "审核请求已创建!"
}
}
216 changes: 216 additions & 0 deletions src/app/[locale]/projects/components/DeleteProjectDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// Copyright (C) Siemens AG, 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

'use client'

import { HttpStatus, Project } from '@/object-types'
import { ApiUtils } from '@/utils'
import { signOut, useSession } from 'next-auth/react'
import { useTranslations } from 'next-intl'
import { useRouter } from 'next/navigation'
import { useCallback, useEffect, useState } from 'react'
import { Alert, Button, Form, Modal } from 'react-bootstrap'
import { AiOutlineQuestionCircle } from 'react-icons/ai'

const DEFAULT_PROJECT_DATA: Project = {
name: '',
_embedded: {
'sw360:releases': [],
'sw360:projects': [],
'sw360:attachments': [],
},
}
interface Data {
attachment?: number
project?: number
release?: number
}

interface Props {
projectId?: string
show?: boolean
setShow?: React.Dispatch<React.SetStateAction<boolean>>
}

const DeleteProjectDialog = ({ projectId, show, setShow }: Props) => {
const { data: session } = useSession()
const t = useTranslations('default')
const router = useRouter()
const [project, setProject] = useState<Project>(DEFAULT_PROJECT_DATA)
const [internalData, setInternalData] = useState<Data>({ attachment: 0, project: 0, release: 0 })
const [variant, setVariant] = useState('success')
const [message, setMessage] = useState('')
const [showMessage, setShowMessage] = useState(false)
const [reloadPage, setReloadPage] = useState(false)
const [hasSubProject, setHasSubProject] = useState(false)
const [comment, setComment] = useState('')

const displayMessage = (variant: string, message: string) => {
setVariant(variant)
setMessage(message)
setShowMessage(true)
}

const handleError = useCallback(() => {
displayMessage('danger', t('Error when processing'))
setReloadPage(true)
}, [t])

const deleteProject = async () => {
const response = await ApiUtils.DELETE(`projects/${projectId}`, session.user.access_token)
try {
if (response.status == HttpStatus.OK) {
displayMessage('success', t('Delete project successful!'))
router.push('/projects')
setReloadPage(true)
} else if (response.status == HttpStatus.ACCEPTED) {
displayMessage('info', t('Moderation request is created!'))
} else if (response.status == HttpStatus.CONFLICT) {
displayMessage('danger', t('The project cannot be deleted, since it is used by another project!'))
} else if (response.status == HttpStatus.UNAUTHORIZED) {
await signOut()
} else {
displayMessage('danger', t('Error when processing'))
}
} catch (err) {
handleError()
}
}

const fetchData = useCallback(
async (signal: AbortSignal) => {
if (session) {
const projectsResponse = await ApiUtils.GET(`projects/${projectId}`, session.user.access_token, signal)
if (projectsResponse.status == HttpStatus.OK) {
const project = (await projectsResponse.json()) as Project
setProject(project)
handleInternalDataCount()
} else if (projectsResponse.status == HttpStatus.UNAUTHORIZED) {
await signOut()
} else {
setProject(DEFAULT_PROJECT_DATA)
handleError()
}
}
},
[projectId, handleError, session]
)

useEffect(() => {
const controller = new AbortController()
const signal = controller.signal
fetchData(signal).catch((err) => {
console.error(err)
})

return () => {
controller.abort()
}
}, [show, projectId, fetchData])

const handleSubmit = () => {
deleteProject().catch((err) => {
console.log(err)
})
}

const handleCloseDialog = () => {
setShow(!show)
setShowMessage(false)
setComment('')
if (reloadPage === true) {
window.location.reload()
}
}

const handleInternalDataCount = () => {
const dataCount: Data = {}
if (project._embedded['sw360:attachments']) {
const attachmentCount = project._embedded['sw360:attachments'].length
dataCount.attachment = attachmentCount
} else if (project._embedded['sw360:projects']) {
const projectCount = project._embedded['sw360:projects'].length
dataCount.project = projectCount
setHasSubProject(true)
} else if (project._embedded['sw360:releases']) {
const releaseCount = project._embedded['sw360:releases'].length
dataCount.release = releaseCount
}
setInternalData(dataCount)
}

const handleUserComment = (e: any) => {
setComment(e.target.value)
}

return (
<Modal show={show} onHide={handleCloseDialog} backdrop='static' centered size='lg'>
<Modal.Header closeButton style={{ color: 'red' }}>
<Modal.Title>
<AiOutlineQuestionCircle style={{ marginBottom: '5px' }} />
{t('Delete Project')} ?
</Modal.Title>
</Modal.Header>
<Modal.Body>
<Alert variant={variant} onClose={() => setShowMessage(false)} dismissible show={showMessage}>
{message}
</Alert>
<Form>
<Form.Group>
<Form.Label className='mb-3'>
{t.rich('Do you really want to delete the project?', {
name: project.name,
strong: (data) => <b>{data}</b>,
})}
</Form.Label>
<Form.Label className='mb-3' visuallyHidden={hasSubProject}>
{t.rich('This project contains', {
name: project.name,
strong: (data) => <b>{data}</b>,
hasSubProject,
})}
<ul>
{Object.entries(internalData).map(([key, value]) => (
<li key={key}>{`${value} linked ${key}`}</li>
))}
</ul>
</Form.Label>
</Form.Group>
<hr />
<Form.Group className='mb-3'>
<Form.Label style={{ fontWeight: 'bold' }}>{t('Please comment your changes')}</Form.Label>
<Form.Control
as='textarea'
aria-label='With textarea'
placeholder='Comment your message...'
onChange={handleUserComment}
/>
</Form.Group>
</Form>
</Modal.Body>
<Modal.Footer className='justify-content-end'>
<Button className='delete-btn' variant='light' onClick={handleCloseDialog}>
{' '}
{t('Close')}{' '}
</Button>
<Button
className='login-btn'
variant='danger'
disabled={!comment}
onClick={() => handleSubmit()}
hidden={reloadPage}
>
{t('Delete Project')}
</Button>
</Modal.Footer>
</Modal>
)
}

export default DeleteProjectDialog
Loading

0 comments on commit 1306652

Please sign in to comment.