Skip to content

Commit

Permalink
Merge pull request #187 from WangLiNaruto/feature/credential_api_doc
Browse files Browse the repository at this point in the history
show credentials openapi documentation in add/update credentials UI
  • Loading branch information
swaroopar committed Sep 6, 2023
2 parents 073a70a + 687c00e commit 32066a8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/content/credential/AddCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { CredentialTip } from './CredentialTip';
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
import { cspMap } from '../order/formElements/CspSelect';
import { CredentialApiDoc } from './CredentialApiDoc';

function AddCredential({
credentialsQuery,
Expand Down Expand Up @@ -339,6 +340,12 @@ function AddCredential({

return (
<div className={'credential-from'}>
<CredentialApiDoc
csp={currentCsp ?? CredentialVariables.csp.HUAWEI}
credentialType={currentType ?? CredentialVariables.type.VARIABLES}
styleClass={'add-credential-api-doc'}
/>

<Form
form={form}
labelCol={{ span: 4 }}
Expand Down
36 changes: 36 additions & 0 deletions src/components/content/credential/CredentialApiDoc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/

import { LinkOutlined } from '@ant-design/icons';
import '../../../styles/app.css';
import { CredentialsManagementService, CredentialVariables, Link } from '../../../xpanse-api/generated';

export function CredentialApiDoc({
csp,
credentialType,
styleClass,
}: {
csp: CredentialVariables.csp;
credentialType: CredentialVariables.type;
styleClass: string;
}): JSX.Element {
function onclick() {
CredentialsManagementService.getCredentialOpenApi(csp, credentialType)
.then((link: Link) => {
if (link.href !== undefined) {
window.open(link.href);
}
})
.catch((error) => {
console.error(error);
});
}

return (
<button className={styleClass} onClick={onclick}>
<LinkOutlined /> API Documentation
</button>
);
}
6 changes: 6 additions & 0 deletions src/components/content/credential/UpdateCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import '../../../styles/credential.css';
import { CredentialTip } from './CredentialTip';
import { useMutation, UseQueryResult } from '@tanstack/react-query';
import { cspMap } from '../order/formElements/CspSelect';
import { CredentialApiDoc } from './CredentialApiDoc';

function UpdateCredential({
createCredential,
Expand Down Expand Up @@ -190,6 +191,11 @@ function UpdateCredential({

return (
<div className={'credential-from'}>
<CredentialApiDoc
csp={createCredential.csp}
credentialType={createCredential.type}
styleClass={'update-credential-api-doc'}
/>
<Form
form={form}
labelCol={{ span: 4 }}
Expand Down
26 changes: 26 additions & 0 deletions src/styles/credential.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,29 @@
display: flex;
justify-content: center;
}

.add-credential-api-doc{
font-size: 6px;
font-weight: bold;
float: right;
background-color: transparent;
border: none;
cursor: pointer;
display: inline;
padding: 0;
margin-top: -27px;
margin-right: 240px;
}

.update-credential-api-doc{
font-size: 6px;
font-weight: bold;
float: right;
background-color: transparent;
border: none;
cursor: pointer;
display: inline;
padding: 0;
margin-top: -27px;
margin-right: 250px;
}

0 comments on commit 32066a8

Please sign in to comment.