From a26529225c9294fbee0dcc618ebffeff896b9443 Mon Sep 17 00:00:00 2001 From: amritkv Date: Fri, 27 Oct 2023 10:27:59 +0530 Subject: [PATCH] feat(add_project): Added dropdown for project relationship in link project, while creating a project --- messages/en.json | 4 +- messages/ja.json | 5 +- messages/pt-BR.json | 4 +- messages/vi.json | 4 +- messages/zh.json | 4 +- src/app/[locale]/projects/add/page.tsx | 11 ++- .../LinkedProjects.tsx | 78 +++++++++++++++---- .../LinkedProjectsModal/LinkProjectsModal.tsx | 7 +- 8 files changed, 87 insertions(+), 30 deletions(-) diff --git a/messages/en.json b/messages/en.json index 64cb1de7..7fb81d20 100644 --- a/messages/en.json +++ b/messages/en.json @@ -734,6 +734,8 @@ "Import Export": "Import & Export", "Admin": "Admin", "Error when processing": "Error when processing", - "Created moderation request": "Created moderation request" + "Created moderation request": "Created moderation request", + "Related": "Related", + "Is a subproject": "Is a subproject" } } diff --git a/messages/ja.json b/messages/ja.json index d88f7357..beb702a9 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -734,6 +734,9 @@ "ENTER_VALUE_KEY": "値を入力キー", "Import Export": "輸入", "Schedule": "スケジュール", - "VALUE": "価値" + "VALUE": "価値", + "Complexitty": "複雑", + "Related": "NOT TRANSLATED", + "Is a subproject": "NOT TRANSLATED" } } diff --git a/messages/pt-BR.json b/messages/pt-BR.json index 0ea9b619..9b60606e 100644 --- a/messages/pt-BR.json +++ b/messages/pt-BR.json @@ -734,6 +734,8 @@ "ENTER_VALUE_KEY": "Insira a chave do valor", "Import Export": "Importar / Exportar", "Schedule": "Agendar", - "VALUE": "Valor" + "VALUE": "Valor", + "Related": "NOT TRANSLATED", + "Is a subproject": "NOT TRANSLATED" } } diff --git a/messages/vi.json b/messages/vi.json index c8a47e62..a2d48aaa 100644 --- a/messages/vi.json +++ b/messages/vi.json @@ -733,6 +733,8 @@ "ENTER_VALUE_KEY": "Nhập khóa giá trị", "Import Export": "Nhập khẩu", "Schedule": "Lịch trình", - "VALUE": "giá trị" + "VALUE": "giá trị", + "Related": "NOT TRANSLATED", + "Is a subproject": "NOT TRANSLATED" } } diff --git a/messages/zh.json b/messages/zh.json index 76b971a1..0073ea7a 100644 --- a/messages/zh.json +++ b/messages/zh.json @@ -733,6 +733,8 @@ "ENTER_VALUE_KEY": "输入值键", "Import Export": "进口", "Schedule": "日程", - "VALUE": "价值" + "VALUE": "价值", + "Related": "NOT TRANSLATED", + "Is a subproject": "NOT TRANSLATED" } } diff --git a/src/app/[locale]/projects/add/page.tsx b/src/app/[locale]/projects/add/page.tsx index 3a23b619..e33f61b6 100644 --- a/src/app/[locale]/projects/add/page.tsx +++ b/src/app/[locale]/projects/add/page.tsx @@ -9,18 +9,17 @@ 'use client' -import { signOut, useSession } from 'next-auth/react' -import { useTranslations } from 'next-intl' -import { useRouter } from 'next/navigation' -import { useState } from 'react' -import { Button, Col, ListGroup, Row, Tab, ToastContainer } from 'react-bootstrap' - import Administration from '@/components/ProjectAddSummary/Administration' import LinkedReleasesAndProjects from '@/components/ProjectAddSummary/LinkedReleasesAndProjects' import Summary from '@/components/ProjectAddSummary/Summary' import { HttpStatus, InputKeyValue, Project, ToastData, Vendor } from '@/object-types' import { ApiUtils } from '@/utils' +import { signOut, useSession } from 'next-auth/react' +import { useTranslations } from 'next-intl' import { ToastMessage } from 'next-sw360' +import { useRouter } from 'next/navigation' +import { useState } from 'react' +import { Button, Col, ListGroup, Row, Tab, ToastContainer } from 'react-bootstrap' function AddProjects() { const router = useRouter() diff --git a/src/components/ProjectAddSummary/component/LinkedReleasesAndProjects/LinkedProjects.tsx b/src/components/ProjectAddSummary/component/LinkedReleasesAndProjects/LinkedProjects.tsx index 7369a93e..035974f8 100644 --- a/src/components/ProjectAddSummary/component/LinkedReleasesAndProjects/LinkedProjects.tsx +++ b/src/components/ProjectAddSummary/component/LinkedReleasesAndProjects/LinkedProjects.tsx @@ -9,12 +9,11 @@ 'use client' -import { useTranslations } from 'next-intl' -import { useState } from 'react' - +import { Table, _ } from '@/components/sw360' import LinkProjectsModal from '@/components/sw360/LinkedProjectsModal/LinkProjectsModal' import { Project } from '@/object-types' -import { Table } from 'next-sw360' +import { useTranslations } from 'next-intl' +import { useEffect, useState } from 'react' interface Props { projectPayload: Project @@ -25,36 +24,85 @@ export default function LinkedProjects({ projectPayload, setProjectPayload }: Pr const t = useTranslations('default') const [showLinkedProjectsModal, setShowLinkedProjectsModal] = useState(false) const [linkedProjectData, setLinkedProjectData] = useState>(new Map()) + const [tableData, setTableData] = useState>([]) + + const updateProjectData = ( + projectId: string, + updatedProjectRelationship: string, + linkedProjectData: Map + ) => { + try { + if (linkedProjectData.has(projectId)) { + linkedProjectData.forEach((value, key) => { + if (key === projectId) { + value.projectRelationship = updatedProjectRelationship + setLinkedProjectData(linkedProjectData) + projectPayload.linkedProjects[projectId].projectRelationship = updatedProjectRelationship + const data: any = extractDataFromMap(linkedProjectData) + setTableData(data) + } + }) + } + } catch (e) { + console.error(e) + } + } const columns = [ { - id: 'tableData.name', + id: 'linkedProjectData.name', name: t('Name'), sort: true, }, { - id: 'tableData.version', + id: 'linkedProjectData.version', name: t('Version'), sort: true, }, { - id: 'tableData.projectRelationship', + id: 'linkedProjectData.projectRelationship', name: t('Project Relationship'), sort: true, + formatter: ({ projectRelationship, key }: { projectRelationship: string; key: string }) => + _( +
+ +
+ ), }, { - id: 'tableData.enableSvm', + id: 'linkedProjectData.enableSvm', name: t('Enable SVM'), sort: true, }, ] - const extractDataFromMap = (map: Map) => { + useEffect(() => { + const data = extractDataFromMap(linkedProjectData) + setTableData(data) + }, [linkedProjectData]) + + const extractDataFromMap = (linkedProjectData: Map) => { const extractedData: any = [] - map.forEach((value, key) => { - const interimData: any = [] - interimData.push(value.name, value.version, value.projectRelationship, value.enableSvm, key) - extractedData.push(interimData) + linkedProjectData.forEach((value, key) => { + const updatedProjectRelationship = value.projectRelationship + extractedData.push([value.name, value.version, { updatedProjectRelationship, key }, value.enableSvm]) }) return extractedData } @@ -76,7 +124,7 @@ export default function LinkedProjects({ projectPayload, setProjectPayload }: Pr
- +
@@ -85,7 +133,7 @@ export default function LinkedProjects({ projectPayload, setProjectPayload }: Pr className='btn btn-secondary' onClick={() => setShowLinkedProjectsModal(true)} > - Link Projects + Add Projects
diff --git a/src/components/sw360/LinkedProjectsModal/LinkProjectsModal.tsx b/src/components/sw360/LinkedProjectsModal/LinkProjectsModal.tsx index 95247f03..94300d44 100644 --- a/src/components/sw360/LinkedProjectsModal/LinkProjectsModal.tsx +++ b/src/components/sw360/LinkedProjectsModal/LinkProjectsModal.tsx @@ -9,17 +9,16 @@ 'use client' +import { HttpStatus, Project } from '@/object-types' +import { ApiUtils, CommonUtils } from '@/utils' import { signOut, useSession } from 'next-auth/react' import { useTranslations } from 'next-intl' +import { Table, _ } from 'next-sw360' import { notFound } from 'next/navigation' import { useRef, useState } from 'react' import { Alert, Button, Col, Form, Modal, OverlayTrigger, Row, Tooltip } from 'react-bootstrap' import { FaInfoCircle } from 'react-icons/fa' -import { HttpStatus, Project } from '@/object-types' -import { ApiUtils, CommonUtils } from '@/utils' -import { Table, _ } from 'next-sw360' - interface AlertData { variant: string message: JSX.Element