Skip to content

Commit

Permalink
Merge pull request #291 from siemens/feat/open_clearing_request
Browse files Browse the repository at this point in the history
feat(CR): Handled deleted project scenario in open CR table
  • Loading branch information
hoangnt2 authored Jul 18, 2024
2 parents d3fb43b + d96a963 commit ebe98ad
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 21 deletions.
2 changes: 2 additions & 0 deletions messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "Es gibt keine Aufgaben, die Ihnen zugewiesen werden.",
"None": "Keine",
"Not Applicable": "Nicht anwendbar",
"Not Available": "Nicht verfügbar",
"Not Checked": "Nicht geprüft",
"NotOwnComponent": "Sie besitzen keine Komponenten.",
"Note": "",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "Programmiersprachen",
"Project": "Projekt",
"Project Clearing State": "Projekt Clearing State",
"Project Deleted": "Projekt gelöscht",
"Project Mainline State": "Projekt Mainline State",
"Project Manager": "Projektleiter",
"Project Name": "Projektname",
Expand Down
2 changes: 2 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "There are no tasks assigned to you.",
"None": "None",
"Not Applicable": "Not Applicable",
"Not Available": "Not Available",
"Not Checked": "Not Checked",
"NotOwnComponent": "You do not own any components.",
"Note": "Note",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "Programming Languages",
"Project": "Project",
"Project Clearing State": "Project Clearing State",
"Project Deleted": "Project Deleted",
"Project Mainline State": "Project Mainline State",
"Project Manager": "Project Manager",
"Project Name": "Project Name",
Expand Down
2 changes: 2 additions & 0 deletions messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "No hay tareas asignadas a usted.",
"None": "Ninguno",
"Not Applicable": "No aplicable",
"Not Available": "No disponible",
"Not Checked": "Sin revisar",
"NotOwnComponent": "No tienes ningún componente.",
"Note": "",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "Idiomas de programación",
"Project": "Proyecto",
"Project Clearing State": "Project Clearing State",
"Project Deleted": "Proyecto eliminado",
"Project Mainline State": "Estado de la línea principal del proyecto",
"Project Manager": "Project Manager",
"Project Name": "Nombre del proyecto",
Expand Down
2 changes: 2 additions & 0 deletions messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "Il n'y a pas de tâches qui vous sont assignées.",
"None": "Aucune",
"Not Applicable": "Sans objet",
"Not Available": "Pas disponible",
"Not Checked": "Non vérifié",
"NotOwnComponent": "Vous ne possédez aucun composant.",
"Note": "",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "Langues de programmation",
"Project": "Projet",
"Project Clearing State": "État responsable du projet",
"Project Deleted": "Projet supprimé",
"Project Mainline State": "État de la ligne principale du projet",
"Project Manager": "Gestionnaire de projet",
"Project Name": "Nom du projet",
Expand Down
2 changes: 2 additions & 0 deletions messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "あなたに割り当てられたタスクはありません。",
"None": "なし",
"Not Applicable": "適用できない",
"Not Available": "利用不可",
"Not Checked": "未検査",
"NotOwnComponent": "あなたはコンポーネントを所有していません。",
"Note": "",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "プログラミング言語",
"Project": "プロジェクト",
"Project Clearing State": "プロジェクトのクリア状態",
"Project Deleted": "プロジェクトが削除されました",
"Project Mainline State": "プロジェクトのメインラインの状態",
"Project Manager": "プロジェクトマネージャー",
"Project Name": "プロジェクト名",
Expand Down
2 changes: 2 additions & 0 deletions messages/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "당신에게 할당 된 작업이 없습니다.",
"None": "이름 *",
"Not Applicable": "적용 대상",
"Not Available": "사용 불가",
"Not Checked": "확인되지 않은",
"NotOwnComponent": "당신은 어떤 성분을 소유하지 않습니다.",
"Note": "",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "언어 선택",
"Project": "프로젝트",
"Project Clearing State": "프로젝트 정리 국가",
"Project Deleted": "프로젝트가 삭제되었습니다.",
"Project Mainline State": "프로젝트 메인라인 상태",
"Project Manager": "프로젝트 매니저",
"Project Name": "프로젝트 이름",
Expand Down
2 changes: 2 additions & 0 deletions messages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "Não há tarefas atribuídas a você.",
"None": "Nenhum",
"Not Applicable": "Não Aplicável",
"Not Available": "Não disponível",
"Not Checked": "Não checado",
"NotOwnComponent": "Você não possui nenhum componente.",
"Note": "",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "Linguagens de Programação",
"Project": "Projeto",
"Project Clearing State": "Estado de compensação do projeto",
"Project Deleted": "Projeto excluído",
"Project Mainline State": "Estado da linha principal do projeto",
"Project Manager": "Gestor do Projeto",
"Project Name": "Nome do Projeto",
Expand Down
2 changes: 2 additions & 0 deletions messages/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "Không có nhiệm vụ nào được giao cho bạn.",
"None": "Không có",
"Not Applicable": "Không áp dụng",
"Not Available": "Không có sẵn",
"Not Checked": "Chưa được kiểm tra",
"NotOwnComponent": "Bạn không sở hữu bất kỳ thành phần nào.",
"Note": "",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "Ngôn ngữ lập trình",
"Project": "Dự án",
"Project Clearing State": "Trạng thái thanh toán dự án",
"Project Deleted": "Dự án đã xóa",
"Project Mainline State": "Trạng thái tuyến chính của dự án",
"Project Manager": "Quản lý dự án",
"Project Name": "Tên dự án",
Expand Down
2 changes: 2 additions & 0 deletions messages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "没有任务分配给您。",
"None": "没有任何",
"Not Applicable": "不适用",
"Not Available": "无法使用",
"Not Checked": "未勾选",
"NotOwnComponent": "您不拥有任何组件。",
"Note": "",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "编程语言",
"Project": "项目",
"Project Clearing State": "项目清算状态",
"Project Deleted": "项目已删除",
"Project Mainline State": "项目主线状态",
"Project Manager": "专案经理",
"Project Name": "项目名",
Expand Down
2 changes: 2 additions & 0 deletions messages/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
"NoTasksAssigned": "您沒有被指派任何工作 。",
"None": "",
"Not Applicable": "不适用",
"Not Available": "無法使用",
"Not Checked": "未勾選",
"NotOwnComponent": "您沒有任何元件 。",
"Note": "",
Expand Down Expand Up @@ -670,6 +671,7 @@
"Programming Languages": "編程語言",
"Project": "專案",
"Project Clearing State": "專案清除狀態",
"Project Deleted": "項目已刪除",
"Project Mainline State": "專案主線狀態",
"Project Manager": "專案管理員",
"Project Name": "專案名稱",
Expand Down
167 changes: 146 additions & 21 deletions src/app/[locale]/requests/components/OpenClearingRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,105 @@ import { Table, _ } from "next-sw360"
import { useTranslations } from 'next-intl'
import { ApiUtils } from '@/utils/index'
import { Embedded, HttpStatus } from '@/object-types'
import { signOut, useSession } from 'next-auth/react'
import { getSession, signOut, useSession } from 'next-auth/react'
import { notFound } from 'next/navigation'
import { ClearingRequest } from '@/object-types'
import { Spinner } from 'react-bootstrap'

type EmbeddedClearingRequest = Embedded<ClearingRequest, 'sw360:clearingRequests'>

interface ClearingRequestStatusMap {
[key: string]: string;
}

interface ClearingRequestPriorityMap {
[key: string]: string;
}

interface ClearingRequestTypeMap {
[key: string]: string;
}

interface LicenseClearingData {
'Release Count': number
'Approved Count': number
}

interface LicenseClearing {
isProjectDeleted?: boolean,
projectId?: string,
clearingProgress?: boolean,
openReleases?: boolean
}

interface ProjectData {
isProjectDeleted?: boolean,
projectId?: string,
projectName?: string
}

function LicenseClearing(licenseClearing: LicenseClearing) {
const [lcData, setLcData] = useState<LicenseClearingData | null>(null)
useEffect(() => {
const controller = new AbortController()
const signal = controller.signal

;(async () => {
try {
const session = await getSession()
if (!session) {
return signOut()
}

const response = await ApiUtils.GET(
`projects/${licenseClearing.projectId}/licenseClearingCount`,
session.user.access_token,
signal
)
if (response.status === HttpStatus.UNAUTHORIZED) {
return signOut()
} else if (response.status !== HttpStatus.OK) {
return notFound()
}

const data = await response.json()

setLcData(data)
} catch (e) {
console.error(e)
}
})()

return () => controller.abort()
}, [licenseClearing.projectId])

return (
<>
{ lcData ? (
<>
{
licenseClearing.openReleases && lcData['Release Count']? (
<div className='text-center'>
{`${lcData['Release Count']}`}
</div>
) : null
}
{
licenseClearing.clearingProgress ? (
<div className='text-center'>
{`${lcData['Approved Count']}/${lcData['Release Count']}`}
</div>
) : null
}
</>
):(
<div className='col-12 text-center'>
<Spinner className='spinner' />
</div>
)}
</>
)
}

function OpenClearingRequest() {

Expand Down Expand Up @@ -85,27 +168,53 @@ function OpenClearingRequest() {
return item.clearingState != 'REJECTED' && item.clearingState != 'CLOSED';
});
setTableData(
filteredClearingRequests.map((item: ClearingRequest) => [
{requestId: item.id},
item.projectBU ?? '',
{ projectId: item.projectId ?? '',
projectName: item.projectName ?? '' },
'',
clearingRequestStatus[item.clearingState] ?? '',
{ priority: item.priority ?? '' },
item.requestingUser ?? '',
'',
'',
item.requestedClearingDate ?? '',
'',
clearingRequestType[item.clearingType] ?? '',
''
])
filteredClearingRequests.map((item: ClearingRequest) => {
let isProjectDeleted : boolean = false
if (!Object.hasOwn(item, 'projectId')){
isProjectDeleted = true
}
return [
{
requestId: item.id
},
item.projectBU ?? t('Not Available'),
isProjectDeleted ? {
isProjectDeleted: true
} : {
isProjectDeleted: false,
projectId: item.projectId ?? '',
projectName: item.projectName ?? ''
},
isProjectDeleted ? {
isProjectDeleted: true
} : {
isProjectDeleted: false,
projectId: item.projectId ?? '',
openReleases: true
},
clearingRequestStatus[item.clearingState] ?? '',
{
priority: item.priority ?? ''
},
item.requestingUser ?? '',
isProjectDeleted ? {
isProjectDeleted: true
} : {
isProjectDeleted: false,
projectId: item.projectId ?? '',
clearingProgress: true
},
'',
item.requestedClearingDate ?? '',
'',
clearingRequestType[item.clearingType] ?? '',
''
]
})
)
setLoading(false)
})}, [fetchData, session])


const columns = [
{
id: 'openClearingRequest.requestId',
Expand All @@ -129,11 +238,13 @@ function OpenClearingRequest() {
id: 'openClearingRequest.project',
name: t('Project'),
sort: true,
formatter: ({ projectId, projectName }: { projectId: string; projectName: string }) =>
formatter: (projectData: ProjectData) =>
_(
projectData.isProjectDeleted ? t('Project Deleted') :
<>
<Link href={`/projects/detail/${projectId}`} className='text-link'>
{projectName}
<Link href={`/projects/detail/${projectData.projectId}`}
className='text-link'>
{projectData.projectName}
</Link>
</>
),
Expand All @@ -142,6 +253,13 @@ function OpenClearingRequest() {
id: 'openClearingRequest.openReleases',
name: t('Open Releases'),
sort: true,
formatter: (licenseClearing: LicenseClearing) =>
_(
licenseClearing.isProjectDeleted ? t('Not Available') :
<LicenseClearing projectId={licenseClearing.projectId}
openReleases={licenseClearing.openReleases}
/>
),
},
{
id: 'openClearingRequest.status',
Expand Down Expand Up @@ -197,6 +315,13 @@ function OpenClearingRequest() {
id: 'openClearingRequest.clearingProgress',
name: t('Clearing Progress'),
sort: true,
formatter: (licenseClearing: LicenseClearing) =>
_(
licenseClearing.isProjectDeleted ? t('Not Available') :
<LicenseClearing projectId={licenseClearing.projectId}
clearingProgress={licenseClearing.clearingProgress}
/>
),
},
{
id: 'openClearingRequest.createdOn',
Expand Down

0 comments on commit ebe98ad

Please sign in to comment.