From 1aef8dc41e8aa3630b3de7246210b90a4c31bef6 Mon Sep 17 00:00:00 2001 From: WangLiNaruto Date: Fri, 3 Jan 2025 17:25:31 +0800 Subject: [PATCH] Add service template history view to the ISV view --- .../services/details/ServiceProvider.tsx | 3 + .../services/history/HistoryService.tsx | 61 +++++++++ .../history/ServiceTemplateHistory.tsx | 121 ++++++++++++++++++ .../history/ServiceTemplateRequested.tsx | 33 +++++ .../useRequestedServiceTemplateQuery.ts | 23 ++++ .../history/useServiceTemplateHistoryQuery.ts | 23 ++++ 6 files changed, 264 insertions(+) create mode 100644 src/components/content/catalog/services/history/HistoryService.tsx create mode 100644 src/components/content/catalog/services/history/ServiceTemplateHistory.tsx create mode 100644 src/components/content/catalog/services/history/ServiceTemplateRequested.tsx create mode 100644 src/components/content/catalog/services/history/useRequestedServiceTemplateQuery.ts create mode 100644 src/components/content/catalog/services/history/useServiceTemplateHistoryQuery.ts diff --git a/src/components/content/catalog/services/details/ServiceProvider.tsx b/src/components/content/catalog/services/details/ServiceProvider.tsx index 313227737..ea68f308d 100644 --- a/src/components/content/catalog/services/details/ServiceProvider.tsx +++ b/src/components/content/catalog/services/details/ServiceProvider.tsx @@ -32,6 +32,8 @@ import UnpublishService from '../unpublish/UnpublishService.tsx'; import UpdateService from '../update/UpdateService'; import { ServiceProviderSkeleton } from './ServiceProviderSkeleton'; import ServiceTemplateDetails from './serviceTemplateDetails'; +import HistoryService from "../history/HistoryService"; + function ServiceProvider({ categoryOclData, selectedServiceNameInTree, @@ -197,6 +199,7 @@ function ServiceProvider({ serviceDetail={activeServiceDetail} setIsViewDisabled={setIsViewDisabled} /> + { + setIsServiceTemplateHistoryModalOpen(true); + }; + + const handleServiceTemplateHistoryModalClose = () => { + setIsServiceTemplateHistoryModalOpen(false); + }; + + return ( +
+ {isServiceTemplateHistoryModalOpen && serviceTemplateRequestHistoryList.length > 0 ? ( + + + + ) : null + } + {serviceTemplateHistoryQuery.isSuccess && serviceTemplateHistoryQuery.data.length > 0 ? ( + + ) : null} +
+ ); +} + +export default historyService; diff --git a/src/components/content/catalog/services/history/ServiceTemplateHistory.tsx b/src/components/content/catalog/services/history/ServiceTemplateHistory.tsx new file mode 100644 index 000000000..9012d9762 --- /dev/null +++ b/src/components/content/catalog/services/history/ServiceTemplateHistory.tsx @@ -0,0 +1,121 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: Huawei Inc. + */ + +import { InfoCircleOutlined } from '@ant-design/icons'; +import { Button, Modal, Table, Tag } from 'antd'; +import { ColumnsType } from 'antd/es/table'; +import React, { useState } from 'react'; +import { ServiceTemplateRequestHistory } from '../../../../../xpanse-api/generated'; +import ServiceTemplateRequested from './ServiceTemplateRequested'; + +function serviceTemplateHistory({ data }: { data: ServiceTemplateRequestHistory[] }): React.JSX.Element { + const [isRequestedServiceTemplateQuery, setIsRequestedServiceTemplateQuery] = useState(false); + const [serviceTemplateRequestId, setServiceTemplateRequestHistoryId] = useState(''); + + const columns: ColumnsType = [ + { + title: 'RequestId', + dataIndex: 'requestId', + align: 'center', + }, + { + title: 'RequestType', + dataIndex: 'requestType', + align: 'center', + render: (_text, record) => { + if (record.requestType === 'register') { + return {record.requestType}; + } else if (record.requestType === 'republish') { + return {record.requestType}; + } else if (record.requestType === 'unpublish') { + return {record.requestType}; + } else { + return {record.requestType}; + } + }, + }, + { + title: 'Status', + dataIndex: 'status', + align: 'center', + render: (_text, record) => { + if (record.status === 'in-review') { + return {record.status}; + } else if (record.status === 'accepted') { + return {record.status}; + } else if (record.status === 'rejected') { + return {record.status}; + } else { + return {record.status}; + } + }, + }, + { + title: 'ReviewComment', + dataIndex: 'reviewComment', + align: 'center', + }, + { + title: 'CreateTime', + dataIndex: 'createTime', + align: 'center', + }, + { + title: 'LastModifiedTime', + dataIndex: 'lastModifiedTime', + align: 'center', + }, + { + title: 'Operation', + dataIndex: 'operation', + render: (_text: string, record) => { + return ( + <> + + + ); + }, + align: 'center', + }, + ]; + + const handleRequestedServiceTemplateOpenModal = (record: ServiceTemplateRequestHistory) => { + setIsRequestedServiceTemplateQuery(true); + setServiceTemplateRequestHistoryId(record.requestId); + }; + + const handleRequestedServiceTemplateModalClose = () => { + setIsRequestedServiceTemplateQuery(false); + setServiceTemplateRequestHistoryId(''); + }; + + return ( +
+ {isRequestedServiceTemplateQuery && serviceTemplateRequestId ? ( + + + + ) : null} + + + + ); +} + +export default serviceTemplateHistory; diff --git a/src/components/content/catalog/services/history/ServiceTemplateRequested.tsx b/src/components/content/catalog/services/history/ServiceTemplateRequested.tsx new file mode 100644 index 000000000..b5bb3d926 --- /dev/null +++ b/src/components/content/catalog/services/history/ServiceTemplateRequested.tsx @@ -0,0 +1,33 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: Huawei Inc. + */ + +import { Alert, Skeleton } from 'antd'; +import React from 'react'; +import DisplayOclData from '../../../common/ocl/DisplayOclData'; +import useRequestedServiceTemplateQuery from './useRequestedServiceTemplateQuery'; + +function serviceTemplateRequested({ requestId }: { requestId: string }): React.JSX.Element { + const requestedServiceTemplateQuery = useRequestedServiceTemplateQuery(requestId); + + return ( +
+ {requestedServiceTemplateQuery.isLoading ? ( + + ) : requestedServiceTemplateQuery.isSuccess ? ( + + ) : requestedServiceTemplateQuery.isError ? ( + + ) : null} +
+ ); +} + +export default serviceTemplateRequested; diff --git a/src/components/content/catalog/services/history/useRequestedServiceTemplateQuery.ts b/src/components/content/catalog/services/history/useRequestedServiceTemplateQuery.ts new file mode 100644 index 000000000..a781075e7 --- /dev/null +++ b/src/components/content/catalog/services/history/useRequestedServiceTemplateQuery.ts @@ -0,0 +1,23 @@ +/* + * 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) { + return useQuery({ + queryKey: ['getRequestedServiceTemplateByRequestId', requestId], + queryFn: () => { + const data: GetRequestedServiceTemplateByRequestIdData = { + requestId: requestId, + }; + return getRequestedServiceTemplateByRequestId(data); + }, + refetchOnWindowFocus: false, + }); +} diff --git a/src/components/content/catalog/services/history/useServiceTemplateHistoryQuery.ts b/src/components/content/catalog/services/history/useServiceTemplateHistoryQuery.ts new file mode 100644 index 000000000..84c1dd3a5 --- /dev/null +++ b/src/components/content/catalog/services/history/useServiceTemplateHistoryQuery.ts @@ -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, + }); +}