Skip to content

Commit 1306652

Browse files
heliocastroamritkv
authored andcommitted
Merge pull request eclipse-sw360#181 from toshiba/release/fix-change-page-size
fix(Table): Fix change page size error when server pagination is not defined
2 parents 947545c + 9e471f4 commit 1306652

File tree

9 files changed

+323
-50
lines changed

9 files changed

+323
-50
lines changed

messages/en.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
"Darcs": "Darcs",
194194
"Decision report": "Decision report",
195195
"Default vendor": "Default vendor",
196+
"Delete Project": "Delete Project",
196197
"Delete Attachment": "Delete Attachment",
197198
"Delete component success!": "Delete component success!",
198199
"Delete Component": "Delete Component",
@@ -210,6 +211,7 @@
210211
"Delete": "Delete",
211212
"Delete Vulnerability": "Delete Vulnerability",
212213
"Do you really want to delete the vulnerability?": "Do you really want to delete the vulnerability <strong>{id}</strong>?",
214+
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
213215
"Do you really want to delete the component?": "Do you really want to delete the component <strong>{name}</strong>?",
214216
"Do you really want to delete the release?": "Do you really want to delete the release: <strong>{name}</strong>?",
215217
"Document Id": "Document Id",
@@ -748,6 +750,10 @@
748750
"Creator Group": "Creator Group",
749751
"ECC Assessor": "ECC Assessor",
750752
"ECC Assessor Group": "ECC Assessor Group",
751-
"ECC Assessment Date": "ECC Assessment Date"
753+
"ECC Assessment Date": "ECC Assessment Date",
754+
"This project contains": "This project <strong>{name}</strong> contains:",
755+
"Delete project successful!": "Delete project successful!",
756+
"The project cannot be deleted, since it is used by another project!": "The project cannot be deleted, since it is used by another project!",
757+
"Moderation request is created!": "Moderation request is created!"
752758
}
753759
}

messages/ja.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
"Deselect All": "Deselect All",
203203
"Design document": "設計書",
204204
"Do not create monitoring list, but use list from external id": "監視リストを作成せず、外部IDからのリストを使用します。",
205+
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
205206
"Do you really want to delete the attachment?": "您确实要删除该附件吗?",
206207
"Do you really want to delete the component?": "本当にコンポーネント <strong>{name}</strong> を削除しますか?",
207208
"Do you really want to delete the release?": "本当にリリース: <strong>{name}</strong>?",
@@ -749,6 +750,11 @@
749750
"Creator Group": "Creator Group",
750751
"ECC Assessor": "ECC Assessor",
751752
"ECC Assessor Group": "ECC Assessor Group",
752-
"ECC Assessment Date": "ECC Assessment Date"
753+
"ECC Assessment Date": "ECC Assessment Date",
754+
"Delete Project": "プロジェクトの削除",
755+
"This project contains": "このプロジェクト <strong>{name}</strong> には次のものが含まれます:",
756+
"Delete project successful!": "プロジェクトの削除が成功しました。",
757+
"The project cannot be deleted, since it is used by another project!": "プロジェクトは別のプロジェクトで使用されているため削除できません。",
758+
"Moderation request is created!": "モデレーションリクエストが作成されました。"
753759
}
754760
}

messages/pt-BR.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
"Design document": "-Documento de Concepção do FIP",
204204
"Do not create monitoring list, but use list from external id": "Não criar lista de monitoramento, mas usar lista de id externo",
205205
"Do you really want to delete the attachment?": "Tem certeza de que deseja excluir este anexo?",
206+
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
206207
"Do you really want to delete the component?": "Deseja realmente excluir o componente <strong>{name}</strong>?",
207208
"Do you really want to delete the release?": "Deseja realmente excluir a versão: <strong>{name}</strong>?",
208209
"Do you really want to delete the vulnerability?": "Deseja realmente excluir a vulnerabilidade <strong>{id}</strong>?",
@@ -748,6 +749,11 @@
748749
"Creator Group": "Creator Group",
749750
"ECC Assessor": "ECC Assessor",
750751
"ECC Assessor Group": "ECC Assessor Group",
751-
"ECC Assessment Date": "ECC Assessment Date"
752+
"ECC Assessment Date": "ECC Assessment Date",
753+
"Delete Project": "Excluir projeto",
754+
"This project contains": "Este projeto <strong>{name}</strong> contém:",
755+
"Delete project successful": "Excluir projeto com sucesso!",
756+
"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!",
757+
"Moderation request is created!": "A solicitação de moderação foi criada !"
752758
}
753759
}

messages/vi.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
"Design document": "Thiết kế văn bản",
278278
"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",
279279
"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?",
280+
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
280281
"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?",
281282
"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?",
282283
"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?",
@@ -747,6 +748,11 @@
747748
"Creator Group": "Creator Group",
748749
"ECC Assessor": "ECC Assessor",
749750
"ECC Assessor Group": "ECC Assessor Group",
750-
"ECC Assessment Date": "ECC Assessment Date"
751+
"ECC Assessment Date": "ECC Assessment Date",
752+
"Delete Project": "Xóa dự án",
753+
"This project contains": "Dự án này <strong>{name</strong> bao gồm:",
754+
"Delete project successful!": "Xóa dự án thành công!",
755+
"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!",
756+
"Moderation request is created!": "Yêu cầu kiểm duyệt được tạo!"
751757
}
752758
}

messages/zh-CN.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278
"Design document": "设计文件",
279279
"Do not create monitoring list, but use list from external id": "不创建监控列表,而是使用外部 id 的列表",
280280
"Do you really want to delete the attachment?": "您确实要删除该附件吗?",
281+
"Do you really want to delete the project?": "Do you really want to delete the project <strong>{name}</strong>?",
281282
"Do you really want to delete the component?": "您确实要删除组件<strong>{name}</strong>吗?",
282283
"Do you really want to delete the release?": "您确实要删除版本:<strong>{name}</strong>吗?",
283284
"Do you really want to delete the vulnerability?": "您确实要删除漏洞<strong>{id}</strong>吗?",
@@ -747,6 +748,11 @@
747748
"Creator Group": "Creator Group",
748749
"ECC Assessor": "ECC Assessor",
749750
"ECC Assessor Group": "ECC Assessor Group",
750-
"ECC Assessment Date": "ECC Assessment Date"
751+
"ECC Assessment Date": "ECC Assessment Date",
752+
"Delete Project": "删除项目",
753+
"This project contains": "该项目<strong>{name}</strong>包含:",
754+
"Delete project successful": "删除项目成功!",
755+
"The project cannot be deleted, as it is used by another project!": "該項目無法刪除,因為它已被另一個項目使用!",
756+
"Moderation request is created!": "审核请求已创建!"
751757
}
752758
}
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
// Copyright (C) Siemens AG, 2023. Part of the SW360 Frontend Project.
2+
3+
// This program and the accompanying materials are made
4+
// available under the terms of the Eclipse Public License 2.0
5+
// which is available at https://www.eclipse.org/legal/epl-2.0/
6+
7+
// SPDX-License-Identifier: EPL-2.0
8+
// License-Filename: LICENSE
9+
10+
'use client'
11+
12+
import { HttpStatus, Project } from '@/object-types'
13+
import { ApiUtils } from '@/utils'
14+
import { signOut, useSession } from 'next-auth/react'
15+
import { useTranslations } from 'next-intl'
16+
import { useRouter } from 'next/navigation'
17+
import { useCallback, useEffect, useState } from 'react'
18+
import { Alert, Button, Form, Modal } from 'react-bootstrap'
19+
import { AiOutlineQuestionCircle } from 'react-icons/ai'
20+
21+
const DEFAULT_PROJECT_DATA: Project = {
22+
name: '',
23+
_embedded: {
24+
'sw360:releases': [],
25+
'sw360:projects': [],
26+
'sw360:attachments': [],
27+
},
28+
}
29+
interface Data {
30+
attachment?: number
31+
project?: number
32+
release?: number
33+
}
34+
35+
interface Props {
36+
projectId?: string
37+
show?: boolean
38+
setShow?: React.Dispatch<React.SetStateAction<boolean>>
39+
}
40+
41+
const DeleteProjectDialog = ({ projectId, show, setShow }: Props) => {
42+
const { data: session } = useSession()
43+
const t = useTranslations('default')
44+
const router = useRouter()
45+
const [project, setProject] = useState<Project>(DEFAULT_PROJECT_DATA)
46+
const [internalData, setInternalData] = useState<Data>({ attachment: 0, project: 0, release: 0 })
47+
const [variant, setVariant] = useState('success')
48+
const [message, setMessage] = useState('')
49+
const [showMessage, setShowMessage] = useState(false)
50+
const [reloadPage, setReloadPage] = useState(false)
51+
const [hasSubProject, setHasSubProject] = useState(false)
52+
const [comment, setComment] = useState('')
53+
54+
const displayMessage = (variant: string, message: string) => {
55+
setVariant(variant)
56+
setMessage(message)
57+
setShowMessage(true)
58+
}
59+
60+
const handleError = useCallback(() => {
61+
displayMessage('danger', t('Error when processing'))
62+
setReloadPage(true)
63+
}, [t])
64+
65+
const deleteProject = async () => {
66+
const response = await ApiUtils.DELETE(`projects/${projectId}`, session.user.access_token)
67+
try {
68+
if (response.status == HttpStatus.OK) {
69+
displayMessage('success', t('Delete project successful!'))
70+
router.push('/projects')
71+
setReloadPage(true)
72+
} else if (response.status == HttpStatus.ACCEPTED) {
73+
displayMessage('info', t('Moderation request is created!'))
74+
} else if (response.status == HttpStatus.CONFLICT) {
75+
displayMessage('danger', t('The project cannot be deleted, since it is used by another project!'))
76+
} else if (response.status == HttpStatus.UNAUTHORIZED) {
77+
await signOut()
78+
} else {
79+
displayMessage('danger', t('Error when processing'))
80+
}
81+
} catch (err) {
82+
handleError()
83+
}
84+
}
85+
86+
const fetchData = useCallback(
87+
async (signal: AbortSignal) => {
88+
if (session) {
89+
const projectsResponse = await ApiUtils.GET(`projects/${projectId}`, session.user.access_token, signal)
90+
if (projectsResponse.status == HttpStatus.OK) {
91+
const project = (await projectsResponse.json()) as Project
92+
setProject(project)
93+
handleInternalDataCount()
94+
} else if (projectsResponse.status == HttpStatus.UNAUTHORIZED) {
95+
await signOut()
96+
} else {
97+
setProject(DEFAULT_PROJECT_DATA)
98+
handleError()
99+
}
100+
}
101+
},
102+
[projectId, handleError, session]
103+
)
104+
105+
useEffect(() => {
106+
const controller = new AbortController()
107+
const signal = controller.signal
108+
fetchData(signal).catch((err) => {
109+
console.error(err)
110+
})
111+
112+
return () => {
113+
controller.abort()
114+
}
115+
}, [show, projectId, fetchData])
116+
117+
const handleSubmit = () => {
118+
deleteProject().catch((err) => {
119+
console.log(err)
120+
})
121+
}
122+
123+
const handleCloseDialog = () => {
124+
setShow(!show)
125+
setShowMessage(false)
126+
setComment('')
127+
if (reloadPage === true) {
128+
window.location.reload()
129+
}
130+
}
131+
132+
const handleInternalDataCount = () => {
133+
const dataCount: Data = {}
134+
if (project._embedded['sw360:attachments']) {
135+
const attachmentCount = project._embedded['sw360:attachments'].length
136+
dataCount.attachment = attachmentCount
137+
} else if (project._embedded['sw360:projects']) {
138+
const projectCount = project._embedded['sw360:projects'].length
139+
dataCount.project = projectCount
140+
setHasSubProject(true)
141+
} else if (project._embedded['sw360:releases']) {
142+
const releaseCount = project._embedded['sw360:releases'].length
143+
dataCount.release = releaseCount
144+
}
145+
setInternalData(dataCount)
146+
}
147+
148+
const handleUserComment = (e: any) => {
149+
setComment(e.target.value)
150+
}
151+
152+
return (
153+
<Modal show={show} onHide={handleCloseDialog} backdrop='static' centered size='lg'>
154+
<Modal.Header closeButton style={{ color: 'red' }}>
155+
<Modal.Title>
156+
<AiOutlineQuestionCircle style={{ marginBottom: '5px' }} />
157+
{t('Delete Project')} ?
158+
</Modal.Title>
159+
</Modal.Header>
160+
<Modal.Body>
161+
<Alert variant={variant} onClose={() => setShowMessage(false)} dismissible show={showMessage}>
162+
{message}
163+
</Alert>
164+
<Form>
165+
<Form.Group>
166+
<Form.Label className='mb-3'>
167+
{t.rich('Do you really want to delete the project?', {
168+
name: project.name,
169+
strong: (data) => <b>{data}</b>,
170+
})}
171+
</Form.Label>
172+
<Form.Label className='mb-3' visuallyHidden={hasSubProject}>
173+
{t.rich('This project contains', {
174+
name: project.name,
175+
strong: (data) => <b>{data}</b>,
176+
hasSubProject,
177+
})}
178+
<ul>
179+
{Object.entries(internalData).map(([key, value]) => (
180+
<li key={key}>{`${value} linked ${key}`}</li>
181+
))}
182+
</ul>
183+
</Form.Label>
184+
</Form.Group>
185+
<hr />
186+
<Form.Group className='mb-3'>
187+
<Form.Label style={{ fontWeight: 'bold' }}>{t('Please comment your changes')}</Form.Label>
188+
<Form.Control
189+
as='textarea'
190+
aria-label='With textarea'
191+
placeholder='Comment your message...'
192+
onChange={handleUserComment}
193+
/>
194+
</Form.Group>
195+
</Form>
196+
</Modal.Body>
197+
<Modal.Footer className='justify-content-end'>
198+
<Button className='delete-btn' variant='light' onClick={handleCloseDialog}>
199+
{' '}
200+
{t('Close')}{' '}
201+
</Button>
202+
<Button
203+
className='login-btn'
204+
variant='danger'
205+
disabled={!comment}
206+
onClick={() => handleSubmit()}
207+
hidden={reloadPage}
208+
>
209+
{t('Delete Project')}
210+
</Button>
211+
</Modal.Footer>
212+
</Modal>
213+
)
214+
}
215+
216+
export default DeleteProjectDialog

0 commit comments

Comments
 (0)