Skip to content

Commit

Permalink
Add service template history view to the ISV view (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
WangLiNaruto authored Jan 6, 2025
1 parent 1395daa commit 8f0aba4
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { cspMap } from '../../../common/csp/CspLogo';
import { DeleteResult } from '../delete/DeleteResult';
import DeleteService from '../delete/DeleteService';
import ServiceTemplateHistory from '../history/ServiceTemplateHistory';
import { useRepublishRequest } from '../republish/RepublishMutation';
import { RepublishResult } from '../republish/RepublishResult.tsx';
import RepublishService from '../republish/RepublishService.tsx';
Expand All @@ -32,6 +33,7 @@ import UnpublishService from '../unpublish/UnpublishService.tsx';
import UpdateService from '../update/UpdateService';
import { ServiceProviderSkeleton } from './ServiceProviderSkeleton';
import ServiceTemplateDetails from './serviceTemplateDetails';

function ServiceProvider({
categoryOclData,
selectedServiceNameInTree,
Expand Down Expand Up @@ -197,6 +199,7 @@ function ServiceProvider({
serviceDetail={activeServiceDetail}
setIsViewDisabled={setIsViewDisabled}
/>
<ServiceTemplateHistory serviceTemplateDetailVo={activeServiceDetail} />
</div>
<ServiceTemplateDetails
isViewDisabled={isViewDisabled}
Expand Down
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;
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;
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,
});
}
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,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function ServiceTemplateRegisterStatus({
<Tag
bordered={false}
icon={<SyncOutlined spin={false} />}
color='processing'
color='#ffa366'
className={serviceReviewStyles.serviceTemplateStateSize}
>
{serviceRegistrationStatus.valueOf()}
Expand All @@ -31,7 +31,7 @@ export function ServiceTemplateRegisterStatus({
<Tag
bordered={false}
icon={<CloseCircleOutlined />}
color='magenta'
color='#ff6666'
className={serviceReviewStyles.serviceTemplateStateSize}
>
{serviceRegistrationStatus.valueOf()}
Expand All @@ -42,7 +42,7 @@ export function ServiceTemplateRegisterStatus({
<Tag
bordered={false}
icon={<CheckCircleOutlined />}
color='success'
color='#87d068'
className={serviceReviewStyles.serviceTemplateStateSize}
>
{serviceRegistrationStatus.valueOf()}
Expand All @@ -53,7 +53,7 @@ export function ServiceTemplateRegisterStatus({
<Tag
bordered={false}
icon={<ExclamationCircleOutlined />}
color='warning'
color='default'
className={serviceReviewStyles.serviceTemplateStateSize}
>
{serviceRegistrationStatus as unknown as string}
Expand Down
3 changes: 3 additions & 0 deletions src/styles/catalog.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@
height: 26px;
display: inline-block;
}
.requested-service-template-history-error {
margin-bottom: 10px;
}

0 comments on commit 8f0aba4

Please sign in to comment.