Skip to content

Commit a19e70b

Browse files
committed
feat(edit_project): Added edit project page
1 parent 626d9bb commit a19e70b

File tree

10 files changed

+279
-0
lines changed

10 files changed

+279
-0
lines changed

messages/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
"URL": "URL",
678678
"Unknown": "Unbekannt",
679679
"Update": "Aktualisierung",
680+
"Update Project": "Projekt aktualisieren",
680681
"Update Component": "Update Component",
681682
"Update Release": "Update Release",
682683
"Update Vulnerability": "Schwachstelle aktualisieren",

messages/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
"Delete All Licenses": "Delete All Licenses?",
197197
"Delete Attachment": "Delete Attachment",
198198
"Delete Component": "Delete Component",
199+
"Delete Project": "Delete Project",
199200
"Delete Release": "Delete Release",
200201
"Delete Vulnerability": "Delete Vulnerability",
201202
"Delete all License Information": "Delete all License Information",
@@ -663,6 +664,7 @@
663664
"The release has been successfully linked to project": "The release <strong>{releaseName}</strong> has been successfully linked to project <strong>{projectName}</strong>",
664665
"The verification of vulnerabilities will be changed to": "The verification of <strong>{number}</strong> vulnerabilities will be changed to",
665666
"There are some errors while creating project": "There are some errors while creating project",
667+
"There are some errors while updating project": "There are some errors while updating project",
666668
"This currently only supports SPDX RDF/XML files with a uniq described top level node": "This currently only supports SPDX RDF/XML files with a uniq described top level node",
667669
"This function is meant to be followed by a new license import": "This function is meant to be followed by a new license import.",
668670
"This release contains": "This release <strong>{name}</strong> contains: ",
@@ -678,6 +680,7 @@
678680
"Unknown": "Unknown",
679681
"Update": "Update",
680682
"Update Component": "Update Component",
683+
"Update Project": "Update Project",
681684
"Update Release": "Update Release",
682685
"Update Vulnerability": "Update Vulnerability",
683686
"Update create comment": "Update create comment",
@@ -736,6 +739,7 @@
736739
"Yes": "Yes",
737740
"You need a security responsible to enable monitoring": "You need a security responsible to enable monitoring",
738741
"Your project is created": "Your project is created",
742+
"Your project is updated": "Your project is updated",
739743
"additional data": "additional data",
740744
"as of": "as of",
741745
"authentication": "authentication",

messages/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
"URL": "URL",
678678
"Unknown": "Desconocido",
679679
"Update": "Actualización",
680+
"Update Project": "Proyecto de actualización",
680681
"Update Component": "Componente de actualización",
681682
"Update Release": "Actualización",
682683
"Update Vulnerability": "Actualización de la vulnerabilidad",

messages/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
"URL": "URL",
678678
"Unknown": "Inconnu",
679679
"Update": "Mise à jour",
680+
"Update Project": "Mettre à jour le projet",
680681
"Update Component": "Composante mise à jour",
681682
"Update Release": "Mise à jour",
682683
"Update Vulnerability": "Mettre à jour la vulnérabilité",

messages/ja.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
"URL": "URL",
678678
"Unknown": "未知",
679679
"Update": "アップデート",
680+
"Update Project": "プロジェクトを更新する",
680681
"Update Component": "コンポーネントの更新",
681682
"Update Release": "Update Release",
682683
"Update Vulnerability": "アップデートの脆弱性",

messages/ko.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
"URL": "사이트 맵",
678678
"Unknown": "이름 *",
679679
"Update": "(주)",
680+
"Update Project": "프로젝트 업데이트",
680681
"Update Component": "업데이트 구성",
681682
"Update Release": "업데이트",
682683
"Update Vulnerability": "업데이트 취약성",

messages/pt-BR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
"URL": "URL",
678678
"Unknown": "Desconhecido",
679679
"Update": "Atualização",
680+
"Update Project": "Atualizar projeto",
680681
"Update Component": "Atualizar componente",
681682
"Update Release": "Atualizar versão",
682683
"Update Vulnerability": "Atualizar Vulnerabilidade",

messages/vi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
"URL": "URL",
678678
"Unknown": "không xác định",
679679
"Update": "Cập nhật",
680+
"Update Project": "Cập nhật dự án",
680681
"Update Component": "Cập nhật thành phần",
681682
"Update Release": "Cập nhật bản phát hành",
682683
"Update Vulnerability": "Cập nhật lỗ hổng",

messages/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
"URL": "网址",
678678
"Unknown": "未知",
679679
"Update": "更新",
680+
"Update Project": "更新項目",
680681
"Update Component": "更新组件",
681682
"Update Release": "更新发布",
682683
"Update Vulnerability": "更新漏洞",
Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
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 Administration from '@/components/ProjectAddSummary/Administration'
13+
import LinkedReleasesAndProjects from '@/components/ProjectAddSummary/LinkedReleasesAndProjects'
14+
import Summary from '@/components/ProjectAddSummary/Summary'
15+
import { HttpStatus, InputKeyValue, Project, ToastData, Vendor } from '@/object-types'
16+
import { ApiUtils } from '@/utils'
17+
import { signOut, useSession } from 'next-auth/react'
18+
import { useTranslations } from 'next-intl'
19+
import { ToastMessage } from 'next-sw360'
20+
import { useRouter } from 'next/navigation'
21+
import { useState } from 'react'
22+
import { Button, Col, ListGroup, Row, Tab, ToastContainer } from 'react-bootstrap'
23+
24+
function EditProjects() {
25+
const router = useRouter()
26+
const t = useTranslations('default')
27+
const { data: session, status } = useSession()
28+
const [vendor, setVendor] = useState<Vendor>({
29+
id: '',
30+
fullName: '',
31+
})
32+
33+
const [externalUrls, setExternalUrls] = useState<InputKeyValue[]>([
34+
{
35+
key: '',
36+
value: '',
37+
},
38+
])
39+
40+
const [externalIds, setExternalIds] = useState<InputKeyValue[]>([
41+
{
42+
key: '',
43+
value: '',
44+
},
45+
])
46+
47+
const [additionalData, setAdditionalData] = useState<InputKeyValue[]>([
48+
{
49+
key: '',
50+
value: '',
51+
},
52+
])
53+
54+
const [projectPayload, setProjectPayload] = useState<Project>({
55+
name: '',
56+
description: '',
57+
version: '',
58+
visibility: 'EVERYONE',
59+
projectType: 'PRODUCT',
60+
tag: '',
61+
domain: '',
62+
leadArchitect: '',
63+
defaultVendorId: '',
64+
externalUrls: null,
65+
externalIds: null,
66+
additionalData: null,
67+
state: 'ACTIVE',
68+
phaseOutSince: '',
69+
moderators: null,
70+
contributors: null,
71+
clearingState: 'OPEN',
72+
businessUnit: 'CT',
73+
preevaluationDeadline: '',
74+
clearingSummary: '',
75+
specialRisksOSS: '',
76+
generalRisks3rdParty: '',
77+
specialRisks3rdParty: '',
78+
deliveryChannels: '',
79+
remarksAdditionalRequirements: '',
80+
systemTestStart: '',
81+
systemTestEnd: '',
82+
deliveryStart: '',
83+
licenseInfoHeaderText: '',
84+
linkedProjects: {},
85+
})
86+
87+
const [toastData, setToastData] = useState<ToastData>({
88+
show: false,
89+
type: '',
90+
message: '',
91+
contextual: '',
92+
})
93+
94+
const alert = (show_data: boolean, status_type: string, message: string, contextual: string) => {
95+
setToastData({
96+
show: show_data,
97+
type: status_type,
98+
message: message,
99+
contextual: contextual,
100+
})
101+
}
102+
103+
const setExternalUrlsData = (externalUrls: Map<string, string>) => {
104+
const obj = Object.fromEntries(externalUrls)
105+
setProjectPayload({
106+
...projectPayload,
107+
externalUrls: obj,
108+
})
109+
}
110+
111+
const setExternalIdsData = (externalIds: Map<string, string>) => {
112+
const obj = Object.fromEntries(externalIds)
113+
setProjectPayload({
114+
...projectPayload,
115+
externalIds: obj,
116+
})
117+
}
118+
119+
const setAdditionalDataObject = (additionalData: Map<string, string>) => {
120+
const obj = Object.fromEntries(additionalData)
121+
setProjectPayload({
122+
...projectPayload,
123+
additionalData: obj,
124+
})
125+
}
126+
127+
const updateProject = async () => {
128+
const response = await ApiUtils.PATCH('projects', projectPayload, session.user.access_token)
129+
130+
if (response.status == HttpStatus.OK) {
131+
await response.json()
132+
alert(true, 'success', t('Your project is updated'), 'success')
133+
// router.push('/projects')
134+
} else {
135+
alert(true, 'error', t('There are some errors while updating project'), 'danger')
136+
// router.push('/projects')
137+
}
138+
}
139+
140+
const handleCancelClick = () => {
141+
router.push('/projects')
142+
}
143+
144+
if (status === 'unauthenticated') {
145+
signOut()
146+
} else {
147+
return (
148+
<div className='container page-content'>
149+
<form
150+
action=''
151+
id='form_submit'
152+
method='post'
153+
onSubmit={(event) => {
154+
event.preventDefault()
155+
}}
156+
>
157+
<ToastContainer position='top-start'>
158+
<ToastMessage
159+
show={toastData.show}
160+
type={toastData.type}
161+
message={toastData.message}
162+
contextual={toastData.contextual}
163+
onClose={() => setToastData({ ...toastData, show: false })}
164+
setShowToast={setToastData}
165+
/>
166+
</ToastContainer>
167+
<div>
168+
<Tab.Container defaultActiveKey='summary'>
169+
<Row>
170+
<Col sm='auto' className='me-3'>
171+
<ListGroup>
172+
<ListGroup.Item action eventKey='summary'>
173+
<div className='my-2'>{t('Summary')}</div>
174+
</ListGroup.Item>
175+
<ListGroup.Item action eventKey='administration'>
176+
<div className='my-2'>{t('Administration')}</div>
177+
</ListGroup.Item>
178+
<ListGroup.Item action eventKey='linkedProjectsAndReleases'>
179+
<div className='my-2'>{t('Linked Releases and Projects')}</div>
180+
</ListGroup.Item>
181+
<ListGroup.Item action eventKey='attachments'>
182+
<div className='my-2'>{t('Attachments')}</div>
183+
</ListGroup.Item>
184+
<ListGroup.Item action eventKey='obligations'>
185+
<div className='my-2'>{t('Obligations')}</div>
186+
</ListGroup.Item>
187+
</ListGroup>
188+
</Col>
189+
<Col className='me-3'>
190+
<Row className='d-flex justify-content-between'>
191+
<Col lg={3}>
192+
<Row>
193+
<Button
194+
variant='primary'
195+
type='submit'
196+
className='me-2 col-auto'
197+
onClick={updateProject}
198+
>
199+
{t('Update Project')}
200+
</Button>
201+
<Button
202+
variant='danger'
203+
type='submit'
204+
className='me-2 col-auto'
205+
onClick={updateProject}
206+
>
207+
{t('Delete Project')}
208+
</Button>
209+
<Button
210+
variant='secondary'
211+
className='col-auto'
212+
onClick={handleCancelClick}
213+
>
214+
{t('Cancel')}
215+
</Button>
216+
</Row>
217+
</Col>
218+
<Col lg={4} className='text-truncate buttonheader-title'>
219+
{t('Update Project')}
220+
</Col>
221+
</Row>
222+
<Row className='mt-5'>
223+
<Tab.Content>
224+
<Tab.Pane eventKey='summary'>
225+
<Summary
226+
vendor={vendor}
227+
setVendor={setVendor}
228+
externalUrls={externalUrls}
229+
setExternalUrls={setExternalUrls}
230+
setExternalUrlsData={setExternalUrlsData}
231+
externalIds={externalIds}
232+
setExternalIds={setExternalIds}
233+
setExternalIdsData={setExternalIdsData}
234+
additionalData={additionalData}
235+
setAdditionalData={setAdditionalData}
236+
setAdditionalDataObject={setAdditionalDataObject}
237+
projectPayload={projectPayload}
238+
setProjectPayload={setProjectPayload}
239+
/>
240+
</Tab.Pane>
241+
<Tab.Pane eventKey='administration'>
242+
<Administration
243+
projectPayload={projectPayload}
244+
setProjectPayload={setProjectPayload}
245+
/>
246+
</Tab.Pane>
247+
<Tab.Pane eventKey='linkedProjectsAndReleases'>
248+
<LinkedReleasesAndProjects
249+
projectPayload={projectPayload}
250+
setProjectPayload={setProjectPayload}
251+
/>
252+
</Tab.Pane>
253+
<Tab.Pane eventKey='attachments'></Tab.Pane>
254+
<Tab.Pane eventKey='obligations'></Tab.Pane>
255+
</Tab.Content>
256+
</Row>
257+
</Col>
258+
</Row>
259+
</Tab.Container>
260+
</div>
261+
</form>
262+
</div>
263+
)
264+
}
265+
}
266+
267+
export default EditProjects

0 commit comments

Comments
 (0)