Skip to content

feat: added get credential pages #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0252d16
feat: added get credential pages
deepessh May 30, 2024
abe11a8
fix: md-lint issues
deepessh May 30, 2024
9a3a063
fix: remove http-proxy-middleware
deepessh May 30, 2024
2168bae
Merge remote-tracking branch 'origin/main' into get-credentials-phase2
deepessh Jun 3, 2024
38c212f
feat: upgrade theme to latest, bug fixes
deepessh Jun 5, 2024
d273af6
feat: upgrade to latest theme
deepessh Jun 6, 2024
6cfb6c2
fix: fixes in layout
deepessh Jun 6, 2024
388149e
Merge remote-tracking branch 'origin/main' into get-credentials-phase2
deepessh Jun 24, 2024
be41a56
Merge remote-tracking branch 'origin/main' into get-credentials-phase2
deepessh Jul 9, 2024
5352265
chore: upgrade tolates
deepessh Jul 9, 2024
cb0b32f
Update deploy.yml
timkim Jul 9, 2024
ad3121e
chore: upgrade to latest
deepessh Jul 9, 2024
894dcbe
chore: navbar links to get credential pages
deepessh Jul 9, 2024
964add6
fix: sync component files with latest from example
deepessh Jul 9, 2024
fef20f8
Merge remote-tracking branch 'origin/main' into get-credentials-phase2
deepessh Aug 19, 2024
9a72ff2
fix: update get credential sample to latest
deepessh Aug 19, 2024
652029c
Fix : Creatial issues
BaskarMitrah Oct 8, 2024
f504ad1
Fix : Removed config
BaskarMitrah Oct 8, 2024
fc9169a
Fix : Update theme
BaskarMitrah Oct 8, 2024
e7483af
Test : Credential
BaskarMitrah Oct 8, 2024
1c46222
Fix : Removed unwanted code
BaskarMitrah Oct 9, 2024
2fdd3fa
Fix : Showed card details as dynamically based on Orderby
BaskarMitrah Oct 9, 2024
3c898d4
Fix : Orderby issues in the card
BaskarMitrah Oct 9, 2024
616e7fb
Fix : Added static data
BaskarMitrah Oct 9, 2024
99afa2e
Fix : Passed Dynamic value
BaskarMitrah Oct 9, 2024
7cb00b9
Fix : Static content update
BaskarMitrah Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* governing permissions and limitations under the License.
*/



module.exports = {
siteMetadata: {
pages: [
Expand Down Expand Up @@ -224,5 +226,6 @@ module.exports = {
]
},
plugins: [`@adobe/gatsby-theme-aio`],
pathPrefix: process.env.PATH_PREFIX || "/developer-console/docs/"
pathPrefix: process.env.PATH_PREFIX || "/developer-console/docs/",

};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"url": "https://github.com/icaraps"
},
"dependencies": {
"@adobe/gatsby-theme-aio": "^4.14.4",
"@adobe/gatsby-theme-aio": "^4.14.12",
"gatsby": "4.22.0",
"http-proxy-middleware": "^3.0.3",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React, { useContext, useEffect, useState } from 'react';
import { css } from '@emotion/react';
import { ProgressCircle } from "@adobe/gatsby-theme-aio/src/components/ProgressCircle";
import { Button } from "@adobe/gatsby-theme-aio/src/components/Button";
import { CopyIcon } from '../Icons';
import { Toast } from '@adobe/gatsby-theme-aio/src/components/Toast';
import GetCredentialContext from '../GetCredentialContext';
import { generateToken, getCredentialSecrets } from '../Service';
import { ActionButton } from '@adobe/gatsby-theme-aio/src/components/ActionButton';

const AccessToken = ({ accessToken, response, scopesDetails }) => {
const [credentialToken, setCredentialToken] = useState(null);
const { selectedOrganization } = useContext(GetCredentialContext);
const [isCopiedTooltip, setIsCopiedTooltip] = useState(false);
const [isHoveringCopyButton, setIsHoveringCopyButton] = useState(false);

const handleGenerateToken = async () => {
setCredentialToken('loading');
const secrets = await getCredentialSecrets(response, selectedOrganization);
if (secrets) {
let clientId = response?.workspaces ? response?.workspaces[0]?.credentials[0]?.clientId : response?.apiKey;
const tokenVal = await generateToken(clientId, secrets?.clientSecret, scopesDetails);
navigator.clipboard.writeText(tokenVal);
setCredentialToken(tokenVal);
}
};

const handleSecretCopyCode = (copiedVal) => {
setIsCopiedTooltip(true);
navigator.clipboard.writeText(copiedVal);
setTimeout(() => setIsCopiedTooltip(false), 1000); // Hide tooltip after 1 second
};

useEffect(() => {
setCredentialToken(null);
}, [response]);

return (
<>
{accessToken && (
<div
css={css`
display: flex;
flex-direction: column;
gap: 16px;
`}>
{accessToken?.heading && (
<h4 className="spectrum-Heading spectrum-Heading--sizeS">{accessToken?.heading}</h4>
)}
{credentialToken === null ? (
accessToken?.buttonLabel && (
<div
data-cy="generate-token"
onClick={() => handleGenerateToken()}
css={css`
width: fit-content;
& > button {
background-color : #0265dc !important;
}
`}>
<Button variant="accent" style="fill">
{accessToken?.buttonLabel}
</Button>
</div>
)
) : (
credentialToken === 'loading' ? (
<ProgressCircle size="S" aria-label="Loading…" isIndeterminate />
) : (
<div
css={css`
display: flex;
align-items: center;
gap: 16px;
`}>
<p
className="spectrum-Body spectrum-Body--sizeS"
css={css`
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #000000;
width: 320px;
`}>
{credentialToken}
</p>
<div
data-cy="copy-token"
onClick={() => handleSecretCopyCode(credentialToken)}
css={css`
position: relative;
& > button {
border: 1px solid rgba(177, 177, 177) !important;
padding: 4px !important;
border-radius: 2px !important;
}
`}>
<ActionButton
onMouseEnter={() => setIsHoveringCopyButton(true)}
onMouseLeave={() => setIsHoveringCopyButton(false)}
>
<CopyIcon />
</ActionButton>
{isHoveringCopyButton && (
<div
className="spectrum-Tooltip spectrum-Tooltip--top is-open"
css={css`
position: absolute;
top: -30px;
transform: translateX(-50%);
background: #333;
color: #fff;
border-radius: 4px;
white-space: nowrap;
z-index: 10;
`}
>
<div className="spectrum-Tooltip-label">Copy</div>
<div className="spectrum-Tooltip-tip" ></div>
</div>
)}
</div >
</div >
)
)}
</div >
)}
{
isCopiedTooltip && (
<Toast
variant="success"
message="Copied to clipboard"
disable={1000}
customDisableFunction={setIsCopiedTooltip}
/>
)
}
</>
);
};

export { AccessToken };
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ShowCard from './ShowCard';

const CardAPIKey = ({ cardAPIKey, apiKey }) => {
return (
<ShowCard heading={cardAPIKey?.heading} value={apiKey} />
)
}

export { CardAPIKey };
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ShowCard from './ShowCard';

const CardAllowedOrigins = ({ cardAllowedOrigins, allowedOrigins }) => {
return (
<ShowCard heading={cardAllowedOrigins?.heading} value={allowedOrigins} />
)
}

export { CardAllowedOrigins };
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { useContext } from 'react';
import { css } from "@emotion/react";
import { CardAPIKey } from './CardAPIKey';
import { CardClientId } from './CardClientId';
import { CardAllowedOrigins } from './CardAllowedOrigins';
import { CardClientSecret } from './CardClientSecret';
import { CardOrganizationName } from './CardOrganizationName';
import { CardScopes } from './CardScopes';
import { CardImsOrgID } from './CardImsOrgID';
import GetCredentialContext from '../GetCredentialContext';

const CardClientDetails = ({
clientDetails,
clientIdDetails,
clientSecretDetails,
organizationDetails,
scopesDetails,
apiKeyDetails,
allowedOriginsDetails,
organizationName,
allowedOrigins,
response,
imsOrgID
}) => {

const { selectedOrganization } = useContext(GetCredentialContext);

const splitedOrderBy = clientDetails?.orderBy ? clientDetails?.orderBy?.split(',') : [];

return (
<div
css={css`
display: flex;
flex-direction: column;
gap: 32px;
`}>
<h4 className="spectrum-Heading spectrum-Heading--sizeS">{clientDetails?.heading}</h4>

{
splitedOrderBy?.length > 0 ?
<>
{splitedOrderBy?.map((list) => {
if (list === "APIKey") {
return apiKeyDetails && <CardAPIKey cardClientDetails={clientDetails} cardAPIKey={apiKeyDetails} apiKey={response?.['apiKey']} />
}
if (list === "AllowedOrigins") {
return allowedOrigins && <CardAllowedOrigins cardClientDetails={clientDetails} cardAllowedOrigins={allowedOrigins} allowedOrigins={allowedOriginsDetails} />
}
if (list === "ImsOrgID") {
return imsOrgID && <CardImsOrgID cardClientDetails={clientDetails} cardImsOrgID={imsOrgID} imsOrgId={selectedOrganization?.code} />
}
if (list === "OrganizationName") {
return organizationDetails && <CardOrganizationName cardClientDetails={clientDetails} cardOrganizationName={organizationDetails} organization={organizationName?.name} />
}
if (list === "ClientId") {
return clientIdDetails && <CardClientId cardClientDetails={clientDetails} cardClientId={clientIdDetails} clientId={response?.['apiKey']} />
}
if (list === "ClientSecret") {
return clientSecretDetails && <CardClientSecret cardClientDetails={clientDetails} cardClientSecret={clientSecretDetails} response={response} />
}
if (list === "Scopes") {
return scopesDetails && <CardScopes cardClientDetails={clientDetails} cardScopes={scopesDetails} />
}
})}
</>
:
<>
{apiKeyDetails && (<CardAPIKey cardClientDetails={clientDetails} cardAPIKey={apiKeyDetails} apiKey={response?.['apiKey']} />)}
{clientIdDetails && (<CardClientId cardClientDetails={clientDetails} cardClientId={clientIdDetails} clientId={response?.['apiKey']} />)}
{allowedOrigins && (<CardAllowedOrigins cardClientDetails={clientDetails} cardAllowedOrigins={allowedOrigins} allowedOrigins={allowedOriginsDetails} />)}
{clientSecretDetails && (<CardClientSecret cardClientDetails={clientDetails} cardClientSecret={clientSecretDetails} response={response} />)}
{organizationDetails && (<CardOrganizationName cardClientDetails={clientDetails} cardOrganizationName={organizationDetails} organization={organizationName?.name} />)}
{scopesDetails && <CardScopes cardClientDetails={clientDetails} cardScopes={scopesDetails} />}
{imsOrgID && (<CardImsOrgID cardClientDetails={clientDetails} cardImsOrgID={imsOrgID} imsOrgId={selectedOrganization?.code} />)}
</>
}

</div>
);
};

export { CardClientDetails };
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ShowCard from './ShowCard'

const CardClientId = ({ cardClientId, clientId }) => {
return (
<ShowCard heading={cardClientId?.heading} value={clientId} />
)
}

export { CardClientId }
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ShowCard from './ShowCard';

const CardClientSecret = ({ cardClientSecret, response }) => {
return (
<ShowCard heading={cardClientSecret?.heading} isClientSecret buttonLabel={cardClientSecret?.buttonLabel} response={response} />
)
}

export { CardClientSecret };
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ShowCard from './ShowCard';

const CardImsOrgID = ({ cardImsOrgID, imsOrgId }) => {
return <ShowCard heading={cardImsOrgID?.heading} value={imsOrgId} />;
};

export { CardImsOrgID };
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ShowCard from './ShowCard';

const CardOrganizationName = ({ cardOrganizationName, organization }) => {
return (
<ShowCard heading={cardOrganizationName?.heading} value={organization} isOraganization />
)
}

export { CardOrganizationName };
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import ShowCard from './ShowCard';

const CardScopes = ({ cardScopes }) => {
return (
<ShowCard heading={cardScopes?.heading} value={cardScopes?.scope} />
)
}
export { CardScopes };
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { useContext } from 'react';
import { css } from '@emotion/react';
import { MAX_TABLET_SCREEN_WIDTH, MIN_MOBILE_WIDTH } from '../FormFields';
import GetCredentialContext from '../GetCredentialContext';
import { LinkOut } from '../Icons';

const DevConsoleLink = ({ devConsoleLinkHeading, credentialName, projectId }) => {

const { selectedOrganization } = useContext(GetCredentialContext);

return (
<>
<div
css={css`
display: flex;
flex-direction: column;
gap: 16px;
`}>
{devConsoleLinkHeading && (
<h4 className="spectrum-Heading spectrum-Heading--sizeS">
{devConsoleLinkHeading}
</h4>
)}

<a
css={css`
display: flex;
`}
target='_blank'
href={`/console/projects/${selectedOrganization?.id}/${projectId}/overview`}
data-cy="credentialName-link">
<div>
<p
className="spectrum-Body spectrum-Body--sizeS"
css={css`
font-family: Source Code Pro, Monaco, monospace;
white-space: normal;
overflow-wrap: anywhere;
max-width: 300px;
color: #0265dc;
`}>
{credentialName}
</p>
</div>
<div
css={css`
margin-left:10px;
@media screen and (min-width:${MIN_MOBILE_WIDTH}) and (max-width:${MAX_TABLET_SCREEN_WIDTH}){
display:none;
}
}`}>
<LinkOut />
</div>
</a>
</div>
</>
);
};

export { DevConsoleLink };
Loading
Loading