Skip to content

Commit

Permalink
Merge pull request eclipse-sw360#81 from siemens/projects/add-project…
Browse files Browse the repository at this point in the history
…/summary

feat(project): Added external urls integration while creating project
  • Loading branch information
hoangnt2 authored Aug 22, 2023
2 parents a06da6a + 2cd0ffa commit cb4cd96
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
17 changes: 17 additions & 0 deletions src/app/[locale]/projects/add/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export default function AddProjects() {
id: '',
fullName: ''
})
const [externalUrls, setExternalUrls] = useState<Input[]>([{
key: '',
value:''
}])
const [projectPayload, setProjectPayload] = useState<ProjectPayload>({
name: '',
description: '',
Expand All @@ -41,6 +45,7 @@ export default function AddProjects() {
domain: '',
leadArchitect: '',
defaultVendorId: '',
externalUrls: null,
state: 'ACTIVE',
phaseOutSince: '',
moderators: null,
Expand All @@ -54,6 +59,15 @@ export default function AddProjects() {
theme: 'colored',
})

const setExternalUrlsData = (externalUrls: Map<string, string>) => {
const obj = Object.fromEntries(externalUrls)
setProjectPayload({
...projectPayload,
externalUrls: obj,
})
}


const createProject = async () => {
const response = await ApiUtils.POST('projects',
projectPayload,
Expand Down Expand Up @@ -128,6 +142,9 @@ export default function AddProjects() {
<Summary token={AUTH_TOKEN}
vendor={vendor}
setVendor={setVendor}
externalUrls={externalUrls}
setExternalUrls={setExternalUrls}
setExternalUrlsData={setExternalUrlsData}
projectPayload={projectPayload}
setProjectPayload={setProjectPayload}
/>
Expand Down
17 changes: 16 additions & 1 deletion src/components/ProjectAddSummary/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,28 @@ import ProjectPayload from "@/object-types/CreateProjectPayload"
import { COMMON_NAMESPACE } from '@/object-types/Constants'
import { useTranslations } from "next-intl"
import Vendor from '@/object-types/Vendor'
import { AddtionalDataType } from '@/object-types/AddtionalDataType'

interface Props{
token: string
vendor: Vendor
setVendor: React.Dispatch<React.SetStateAction<Vendor>>
externalUrls: Input[]
setExternalUrls: React.Dispatch<React.SetStateAction<Input[]>>
setExternalUrlsData: AddtionalDataType
projectPayload: ProjectPayload
setProjectPayload: React.Dispatch<React.SetStateAction<ProjectPayload>>
}

export default function Summary({token, vendor, setVendor, projectPayload, setProjectPayload}: Props) {
export default function Summary({token,
vendor,
setVendor,
externalUrls,
setExternalUrls,
setExternalUrlsData,
projectPayload,
setProjectPayload
}: Props) {

const t = useTranslations(COMMON_NAMESPACE)

Expand All @@ -45,6 +57,9 @@ export default function Summary({token, vendor, setVendor, projectPayload, setPr
<AddKeyValueComponent
header={t('External URLs')}
keyName={t('External URL')}
data={externalUrls}
setData={setExternalUrls}
setObject={setExternalUrlsData}
/>
</div>
<Roles/>
Expand Down
12 changes: 7 additions & 5 deletions src/components/ProjectAddSummary/component/AddKeyValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { COMMON_NAMESPACE } from '@/object-types/Constants'
interface Props {
header: string
keyName: string
setData?: AddtionalDataType
data?: Input[]
setData?: React.Dispatch<React.SetStateAction<Input[]>>
setObject?: AddtionalDataType
}

interface Input {
Expand All @@ -37,13 +39,13 @@ export default function AddKeyValueComponent(props: Props) {
const { name, value } = e.target
const list: Input[] = [...inputList]
list[index][name as keyof Input] = value
setInputList(list)
if(props.setData) {
props.setData(list)
if(props.setObject) {
const map = new Map<string, string>()
list.forEach((item) => {
map.set(item.key, item.value)
})
props.setData(map)
props.setObject(map)
}
}

Expand Down Expand Up @@ -87,7 +89,7 @@ export default function AddKeyValueComponent(props: Props) {
className='form-control'
placeholder={t(`Enter ${props.keyName.toLowerCase()} value`)}
required
aria-describedby={t(`${props.keyName.toLowerCase()} value`)}
aria-describedby={`${props.keyName.toLowerCase()} value`}
/>
</div>
<div className='col-lg-1'>
Expand Down
21 changes: 11 additions & 10 deletions src/object-types/CreateProjectPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@

export default interface ProjectPayload {
name: string
description: string
version: string
description?: string
version?: string
visibility: string
projectType: string
tag: string
domain: string
leadArchitect: string
defaultVendorId: string
state: string
phaseOutSince: string
moderators: string[]
contributors: string[]
tag?: string
domain?: string
leadArchitect?: string
defaultVendorId?: string
externalUrls?: object
state?: string
phaseOutSince?: string
moderators?: string[]
contributors?: string[]
}

0 comments on commit cb4cd96

Please sign in to comment.