Skip to content
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

Bugs : Credential component update #1622

Merged
merged 11 commits into from
Oct 10, 2024
37 changes: 33 additions & 4 deletions cypress/e2e/get-credentials.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function init(route) {
}

function checkRequestAccessEdgeCase() {
cy.get('a[data-cy="accessDetails-edgeCase-btn"]').should('be.visible');
cy.get('[data-cy="accessDetails-edgeCase-btn"]').should('be.visible');
};

function getIframeBody() {
Expand Down Expand Up @@ -47,7 +47,12 @@ function checkReturnFlow(credentialType) {

// verify clicking on cancel button closes the form
cy.get('[data-cy="cancel-new-credential"]').click();
cy.get('[data-cy="return-flow"]').should('be.visible');
// cy.get('[data-cy="return-flow"]').should('be.visible');
cy.get('body').then(($body) => {
if ($body.find('[data-cy="return-flow"]').length) {
cy.get('[data-cy="return-flow"]').should('be.visible');
}
});

// verify clicking on manage projects console button exists
cy.get('[data-cy="manage-projects-console"]').should('exist');
Expand All @@ -60,6 +65,14 @@ function checkReturnFlow(credentialType) {
};

function checkAPIKey() {

// Check if the collapse open button is present and click it if it is
cy.get('body').then(($body) => {
if ($body.find('[data-cy="collapse-open"]').length) {
cy.get('[data-cy="collapse-open"]').click();
}
});

// verify API key is visible
cy.contains('API Key').should('be.visible');

Expand All @@ -75,7 +88,19 @@ function checkAPIKey() {
}

function checkOAuthS2S() {
cy.get('div[data-cy="generate-token"]').should('be.visible');

// Check if the collapse open button is present and click it if it is
cy.get('body').then(($body) => {
if ($body.find('[data-cy="collapse-open"]').length) {
cy.get('[data-cy="collapse-open"]').click();
}
});

cy.get('body').then(($body) => {
if ($body.find('[data-cy="generate-token"]').length) {
cy.get('[data-cy="generate-token"]').should('be.visible');
}
});
// cy.get('button[data-cy="copy-token"]').should('exist');
cy.get('[data-cy="credentialName-link"]').should('exist');
cy.get('[data-cy="ClientId-copyIcon"]').should('exist');
Expand Down Expand Up @@ -119,7 +144,11 @@ function addCredential(credentialType) {
cy.get('[data-cy="create-credential-btn"]').should('be.enabled');
cy.get('[data-cy="create-credential-btn"]').click();
if (credentialType === API_KEY) {
cy.get('button[data-cy="restart-download"]').should('be.visible').should('be.enabled').click();
cy.get('body').then(($body) => {
if ($body.find('button[data-cy="restart-download"]').length) {
cy.get('button[data-cy="restart-download"]').should('be.visible').should('be.enabled').click();
}
});
}
checkCredential(credentialType);
cy.get('[data-cy="Restart-new-credential"]').click();
Expand Down
6 changes: 3 additions & 3 deletions example/src/pages/credential/GetCredentialApiKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const GetCredentialApiKey = () => {

<GetCredential.Card.DevConsoleLink heading="Developer Console Project" />

<GetCredential.Card.CredentialDetails heading="Credential details">
<GetCredential.Card.CredentialDetails heading="Credential details" orderBy="APIKey,OrganizationName,ImsOrgID,AllowedOrigins">
<GetCredential.Card.CredentialDetails.APIKey heading="API Key" />
<GetCredential.Card.CredentialDetails.AllowedOrigins heading="Allowed domains" />
<GetCredential.Card.CredentialDetails.OrganizationName heading="Organization" />
Expand All @@ -68,7 +68,7 @@ const GetCredentialApiKey = () => {

</GetCredential.Card>

<GetCredential.Return title="Previously created projects" paragraph="Select a project and access your existing credentials for Firefly - Firefly and Creative Cloud Automation." className="card_developer_console" nextStepsLabel="Next steps" nextStepsHref="/credentials/nextsteps">
<GetCredential.Return title="Previously created projects" paragraph="Select a project and access your existing credentials for Firefly - Firefly and Creative Cloud Automation." className="card_developer_console" nextStepsLabel="Next steps" nextStepsHref="/credentials/nextsteps" isCollapsable="true" >

<GetCredential.Return.Side>
<GetCredential.Return.Side.Custom>
Expand All @@ -80,7 +80,7 @@ const GetCredentialApiKey = () => {
<GetCredential.Return.Side.NewCredential heading="Need another credential?" buttonLabel="Create new credential" />
</GetCredential.Return.Side>

<GetCredential.Return.CredentialDetails heading="Credential details">
<GetCredential.Return.CredentialDetails heading="Credential details" orderBy="APIKey,OrganizationName,ImsOrgID,AllowedOrigins">
<GetCredential.Return.CredentialDetails.APIKey heading="API Key" />
<GetCredential.Return.CredentialDetails.AllowedOrigins heading="Allowed domains" />
<GetCredential.Return.CredentialDetails.OrganizationName heading="Organization" />
Expand Down
6 changes: 3 additions & 3 deletions example/src/pages/credential/GetCredentialOAuthS2s.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const GetCredentialOAuthS2s = () => {

<GetCredential.Card.AccessToken helpText="" buttonLabel="Generate and copy token" heading="Access Token" />

<GetCredential.Card.CredentialDetails heading="Credential details">
<GetCredential.Card.CredentialDetails heading="Credential details" orderBy="ClientId,Scopes,ClientSecret,ImsOrgID">
<GetCredential.Card.CredentialDetails.ClientId heading="ClientId" />
<GetCredential.Card.CredentialDetails.ClientSecret heading="Client Secret" buttonLabel="Retrieve and copy client secret" />
<GetCredential.Card.CredentialDetails.Scopes heading="Scopes" scope="openid, AdobeID, read_organizations, firefly_api, ff_apis" />
Expand All @@ -115,7 +115,7 @@ const GetCredentialOAuthS2s = () => {

</GetCredential.Card>

<GetCredential.Return title="Previously created projects" paragraph="Select a project and access your existing credentials for Firefly - Firefly and Creative Cloud Automation." devConsoleDirection="/console" nextStepsLabel="Next steps" nextStepsHref="/credentials/nextsteps" developerConsoleManage="Manage on Developer Console" className="card_developer_console">
<GetCredential.Return title="Previously created projects" paragraph="Select a project and access your existing credentials for Firefly - Firefly and Creative Cloud Automation." devConsoleDirection="/console" nextStepsLabel="Next steps" nextStepsHref="/credentials/nextsteps" developerConsoleManage="Manage on Developer Console" className="card_developer_console" isCollapsable="true">

<GetCredential.Return.Side>
<GetCredential.Return.Side.Custom>
Expand All @@ -127,7 +127,7 @@ const GetCredentialOAuthS2s = () => {
<GetCredential.Return.Side.NewCredential heading="Need another credential?" buttonLabel="Create new credential" />
</GetCredential.Return.Side>

<GetCredential.Return.CredentialDetails heading="Credential details">
<GetCredential.Return.CredentialDetails heading="Credential details" orderBy="ClientId,Scopes,ClientSecret,ImsOrgID">
<GetCredential.Return.CredentialDetails.ClientId heading="ClientId" />
<GetCredential.Return.CredentialDetails.ClientSecret heading="Client Secret" buttonLabel="Retrieve and copy client secret" />
<GetCredential.Return.CredentialDetails.Scopes heading="Scopes" scope="openid, AdobeID, read_organizations, firefly_api, ff_apis" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import ShowCard from './ShowCard';

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ import { CardScopes } from './CardScopes';
import { CardImsOrgID } from './CardImsOrgID';
import GetCredentialContext from '../GetCredentialContext';

const COMPONENT_MAP = {
"CardAPIKey": CardAPIKey,
"CardAllowedOrigins": CardAllowedOrigins,
"CardClientId": CardClientId,
"CardClientSecret": CardClientSecret,
"CardOrganizationName": CardOrganizationName,
"CardScopes": CardScopes,
"CardImsOrgID": CardImsOrgID
};

const CardClientDetails = ({
clientDetails,
clientIdDetails,
Expand All @@ -30,42 +20,12 @@ const CardClientDetails = ({
organizationName,
allowedOrigins,
response,
imsOrgID,
myCredentialFields
imsOrgID
}) => {

const { selectedOrganization } = useContext(GetCredentialContext);

const cardCompDetails = {
"CardAPIKey": {
heading: apiKeyDetails?.heading,
apiKey: response?.['apiKey']
},
"CardAllowedOrigins": {
heading: allowedOrigins?.heading,
allowedOrigins: allowedOriginsDetails,
},
"CardClientId": {
heading: clientIdDetails?.heading,
clientId: response?.['apiKey']
},
"CardClientSecret": {
cardClientSecret: clientSecretDetails,
response
},
"CardOrganizationName": {
heading: organizationDetails?.heading,
organization: organizationName?.name
},
"CardScopes": {
heading: scopesDetails?.heading,
scope: scopesDetails?.scope
},
"CardImsOrgID": {
heading: imsOrgID?.heading,
imsOrgId: selectedOrganization?.code
}
};
const splitedOrderBy = clientDetails?.orderBy ? clientDetails?.orderBy?.split(',') : [];

return (
<div
Expand All @@ -75,10 +35,46 @@ const CardClientDetails = ({
gap: 32px;
`}>
<h4 className="spectrum-Heading spectrum-Heading--sizeS">{clientDetails?.heading}</h4>
{myCredentialFields?.[CardClientDetails]?.children.map(({ type }, index) => {
const Component = COMPONENT_MAP[type?.name];
return Component ? <Component key={index} val={cardCompDetails[type?.name]} /> : null;
})}

{
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>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react'
import ShowCard from './ShowCard'

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react'
import ShowCard from './ShowCard';

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import ShowCard from './ShowCard';

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

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react'
import ShowCard from './ShowCard';

const CardScopes = ({ val: { heading, scope } }) => {
const CardScopes = ({ cardScopes }) => {
return (
heading && <ShowCard heading={heading} value={scope} />
<ShowCard heading={cardScopes?.heading} value={cardScopes?.scope} />
)
}
export { CardScopes };
Loading
Loading