-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add service template history view to the ISV view (#1402)
- Loading branch information
1 parent
1395daa
commit 8f0aba4
Showing
7 changed files
with
288 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/components/content/catalog/services/history/ServiceTemplateHistory.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { HistoryOutlined } from '@ant-design/icons'; | ||
import { Button, Modal } from 'antd'; | ||
import React, { useState } from 'react'; | ||
import catalogStyles from '../../../../../styles/catalog.module.css'; | ||
import { ServiceTemplateDetailVo, ServiceTemplateRequestHistory } from '../../../../../xpanse-api/generated'; | ||
import ServiceTemplateHistoryTable from './ServiceTemplateHistoryTable'; | ||
import useServiceTemplateHistoryQuery from './useServiceTemplateHistoryQuery'; | ||
|
||
function ServiceTemplateHistory({ | ||
serviceTemplateDetailVo, | ||
}: { | ||
serviceTemplateDetailVo: ServiceTemplateDetailVo; | ||
}): React.JSX.Element { | ||
const serviceTemplateHistoryQuery = useServiceTemplateHistoryQuery(serviceTemplateDetailVo.serviceTemplateId); | ||
const [isServiceTemplateHistoryModalOpen, setIsServiceTemplateHistoryModalOpen] = useState(false); | ||
|
||
let serviceTemplateRequestHistoryList: ServiceTemplateRequestHistory[] = []; | ||
if (serviceTemplateHistoryQuery.isSuccess) { | ||
serviceTemplateRequestHistoryList = serviceTemplateHistoryQuery.data; | ||
} | ||
|
||
const handleServiceTemplateHistoryOpenModal = () => { | ||
setIsServiceTemplateHistoryModalOpen(true); | ||
}; | ||
|
||
const handleServiceTemplateHistoryModalClose = () => { | ||
setIsServiceTemplateHistoryModalOpen(false); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{isServiceTemplateHistoryModalOpen && serviceTemplateRequestHistoryList.length > 0 ? ( | ||
<Modal | ||
title={'Service Template History'} | ||
width={1600} | ||
footer={null} | ||
open={isServiceTemplateHistoryModalOpen} | ||
onCancel={handleServiceTemplateHistoryModalClose} | ||
> | ||
<ServiceTemplateHistoryTable data={serviceTemplateRequestHistoryList} /> | ||
</Modal> | ||
) : null} | ||
{serviceTemplateHistoryQuery.isSuccess && serviceTemplateHistoryQuery.data.length > 0 ? ( | ||
<Button | ||
icon={<HistoryOutlined />} | ||
type='primary' | ||
onClick={() => { | ||
handleServiceTemplateHistoryOpenModal(); | ||
}} | ||
className={catalogStyles.catalogManageBtnClass} | ||
> | ||
History | ||
</Button> | ||
) : null} | ||
</div> | ||
); | ||
} | ||
|
||
export default ServiceTemplateHistory; |
167 changes: 167 additions & 0 deletions
167
src/components/content/catalog/services/history/ServiceTemplateHistoryTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { InfoCircleOutlined } from '@ant-design/icons'; | ||
import { Alert, Button, Modal, Skeleton, Table, Tag } from 'antd'; | ||
import { ColumnsType } from 'antd/es/table'; | ||
import React, { useState } from 'react'; | ||
import catalogStyles from '../../../../../styles/catalog.module.css'; | ||
import { ServiceTemplateRequestHistory } from '../../../../../xpanse-api/generated'; | ||
import { isHandleKnownErrorResponse } from '../../../common/error/isHandleKnownErrorResponse'; | ||
import DisplayOclData from '../../../common/ocl/DisplayOclData'; | ||
import useRequestedServiceTemplateQuery from './useRequestedServiceTemplateQuery'; | ||
|
||
function ServiceTemplateHistoryTable({ data }: { data: ServiceTemplateRequestHistory[] }): React.JSX.Element { | ||
const [isRequestedServiceTemplateQuery, setIsRequestedServiceTemplateQuery] = useState<boolean>(false); | ||
const [serviceTemplateRequestId, setServiceTemplateRequestHistoryId] = useState<string | undefined>(undefined); | ||
const requestedServiceTemplateQuery = useRequestedServiceTemplateQuery(serviceTemplateRequestId); | ||
|
||
const columns: ColumnsType<ServiceTemplateRequestHistory> = [ | ||
{ | ||
title: 'RequestId', | ||
dataIndex: 'requestId', | ||
align: 'center', | ||
}, | ||
{ | ||
title: 'RequestType', | ||
dataIndex: 'requestType', | ||
align: 'center', | ||
render: (_text, record) => { | ||
if (record.requestType === 'register') { | ||
return <Tag color='default'>{record.requestType}</Tag>; | ||
} else if (record.requestType === 'republish') { | ||
return <Tag color='success'>{record.requestType}</Tag>; | ||
} else if (record.requestType === 'unpublish') { | ||
return <Tag color='error'>{record.requestType}</Tag>; | ||
} else { | ||
return <Tag color='processing'>{record.requestType}</Tag>; | ||
} | ||
}, | ||
}, | ||
{ | ||
title: 'Status', | ||
dataIndex: 'status', | ||
align: 'center', | ||
render: (_text, record) => { | ||
if (record.status === 'in-review') { | ||
return <Tag color='#ffa366'>{record.status}</Tag>; | ||
} else if (record.status === 'accepted') { | ||
return <Tag color='#87d068'>{record.status}</Tag>; | ||
} else if (record.status === 'rejected') { | ||
return <Tag color='#ff6666'>{record.status}</Tag>; | ||
} else { | ||
return <Tag color='default'>{record.status}</Tag>; | ||
} | ||
}, | ||
}, | ||
{ | ||
title: 'ReviewComment', | ||
dataIndex: 'reviewComment', | ||
align: 'center', | ||
}, | ||
{ | ||
title: 'CreatedTime', | ||
dataIndex: 'createTime', | ||
align: 'center', | ||
}, | ||
{ | ||
title: 'LastModifiedTime', | ||
dataIndex: 'lastModifiedTime', | ||
align: 'center', | ||
}, | ||
{ | ||
title: 'Service Template', | ||
dataIndex: 'service template', | ||
render: (_text: string, record) => { | ||
return ( | ||
<> | ||
<Button | ||
type='primary' | ||
icon={<InfoCircleOutlined />} | ||
onClick={() => { | ||
handleRequestedServiceTemplateOpenModal(record); | ||
}} | ||
> | ||
request template | ||
</Button> | ||
</> | ||
); | ||
}, | ||
align: 'center', | ||
}, | ||
]; | ||
|
||
const handleRequestedServiceTemplateOpenModal = (record: ServiceTemplateRequestHistory) => { | ||
setIsRequestedServiceTemplateQuery(true); | ||
setServiceTemplateRequestHistoryId(record.requestId); | ||
}; | ||
|
||
const handleRequestedServiceTemplateModalClose = () => { | ||
setIsRequestedServiceTemplateQuery(false); | ||
setServiceTemplateRequestHistoryId(undefined); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{requestedServiceTemplateQuery.isLoading ? ( | ||
<Modal | ||
title={'Requested Service Template'} | ||
width={1600} | ||
footer={null} | ||
open={isRequestedServiceTemplateQuery} | ||
onCancel={handleRequestedServiceTemplateModalClose} | ||
> | ||
<Skeleton active /> | ||
</Modal> | ||
) : requestedServiceTemplateQuery.isSuccess ? ( | ||
<Modal | ||
title={'Requested Service Template'} | ||
width={1600} | ||
footer={null} | ||
open={isRequestedServiceTemplateQuery} | ||
onCancel={handleRequestedServiceTemplateModalClose} | ||
> | ||
<DisplayOclData ocl={requestedServiceTemplateQuery.data} /> | ||
</Modal> | ||
) : requestedServiceTemplateQuery.isError ? ( | ||
<div className={catalogStyles.requestedServiceTemplateHistoryError}> | ||
{isHandleKnownErrorResponse(requestedServiceTemplateQuery.error) ? ( | ||
<Alert | ||
message={ | ||
<> | ||
Request Service Template with requestId <strong>{serviceTemplateRequestId}</strong>{' '} | ||
error | ||
</> | ||
} | ||
description={String(requestedServiceTemplateQuery.error.body.details)} | ||
showIcon | ||
type={'error'} | ||
closable={true} | ||
onClose={handleRequestedServiceTemplateModalClose} | ||
/> | ||
) : ( | ||
<Alert | ||
message={ | ||
<> | ||
Request Service Template with requestId <strong>{serviceTemplateRequestId}</strong>{' '} | ||
error | ||
</> | ||
} | ||
description={requestedServiceTemplateQuery.error.message} | ||
showIcon | ||
type={'error'} | ||
closable={true} | ||
onClose={handleRequestedServiceTemplateModalClose} | ||
/> | ||
)} | ||
</div> | ||
) : null} | ||
|
||
<Table columns={columns} dataSource={data} rowKey={'id'} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default ServiceTemplateHistoryTable; |
24 changes: 24 additions & 0 deletions
24
src/components/content/catalog/services/history/useRequestedServiceTemplateQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { useQuery } from '@tanstack/react-query'; | ||
import { | ||
getRequestedServiceTemplateByRequestId, | ||
GetRequestedServiceTemplateByRequestIdData, | ||
} from '../../../../../xpanse-api/generated'; | ||
|
||
export default function useRequestedServiceTemplateQuery(requestId: string | undefined) { | ||
return useQuery({ | ||
queryKey: ['getRequestedServiceTemplateByRequestId', requestId], | ||
queryFn: () => { | ||
const data: GetRequestedServiceTemplateByRequestIdData = { | ||
requestId: requestId ?? '', | ||
}; | ||
return getRequestedServiceTemplateByRequestId(data); | ||
}, | ||
refetchOnWindowFocus: false, | ||
enabled: requestId !== undefined, | ||
}); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/components/content/catalog/services/history/useServiceTemplateHistoryQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
import { useQuery } from '@tanstack/react-query'; | ||
import { | ||
getServiceTemplateRequestHistoryByServiceTemplateId, | ||
GetServiceTemplateRequestHistoryByServiceTemplateIdData, | ||
} from '../../../../../xpanse-api/generated'; | ||
|
||
export default function useServiceTemplateHistoryQuery(serviceTemplateId: string) { | ||
return useQuery({ | ||
queryKey: ['getServiceTemplateRequestHistoryByServiceTemplateId', serviceTemplateId], | ||
queryFn: () => { | ||
const data: GetServiceTemplateRequestHistoryByServiceTemplateIdData = { | ||
serviceTemplateId: serviceTemplateId, | ||
}; | ||
return getServiceTemplateRequestHistoryByServiceTemplateId(data); | ||
}, | ||
refetchOnWindowFocus: false, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,6 @@ | |
height: 26px; | ||
display: inline-block; | ||
} | ||
.requested-service-template-history-error { | ||
margin-bottom: 10px; | ||
} |