-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7338 from mabashian/cred-plugin-test-button
Hook up Test button on Metadata step in credential plugin wizard Reviewed-by: John Hill <johill@redhat.com> https://github.com/unlikelyzero
- Loading branch information
Showing
17 changed files
with
297 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
.../CredentialFormFields/CredentialPlugins/CredentialPluginPrompt/CredentialPluginPrompt.jsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ialPlugins/CredentialPluginField.test.jsx → ...ialPlugins/CredentialPluginField.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...ens/Credential/shared/CredentialPlugins/CredentialPluginPrompt/CredentialPluginPrompt.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import React, { useCallback } from 'react'; | ||
import { func, shape } from 'prop-types'; | ||
import { Formik, useField } from 'formik'; | ||
import { withI18n } from '@lingui/react'; | ||
import { t } from '@lingui/macro'; | ||
import { | ||
Button, | ||
Tooltip, | ||
Wizard, | ||
WizardContextConsumer, | ||
WizardFooter, | ||
} from '@patternfly/react-core'; | ||
import CredentialsStep from './CredentialsStep'; | ||
import MetadataStep from './MetadataStep'; | ||
import { CredentialsAPI } from '../../../../../api'; | ||
import useRequest from '../../../../../util/useRequest'; | ||
import { CredentialPluginTestAlert } from '..'; | ||
|
||
function CredentialPluginWizard({ i18n, handleSubmit, onClose }) { | ||
const [selectedCredential] = useField('credential'); | ||
const [inputValues] = useField('inputs'); | ||
|
||
const { | ||
result: testPluginSuccess, | ||
error: testPluginError, | ||
request: testPluginMetadata, | ||
} = useRequest( | ||
useCallback( | ||
async () => | ||
CredentialsAPI.test(selectedCredential.value.id, { | ||
metadata: inputValues.value, | ||
}), | ||
[selectedCredential, inputValues] | ||
), | ||
null | ||
); | ||
|
||
const steps = [ | ||
{ | ||
id: 1, | ||
name: i18n._(t`Credential`), | ||
key: 'credential', | ||
component: <CredentialsStep />, | ||
enableNext: !!selectedCredential.value, | ||
}, | ||
{ | ||
id: 2, | ||
name: i18n._(t`Metadata`), | ||
key: 'metadata', | ||
component: <MetadataStep />, | ||
canJumpTo: !!selectedCredential.value, | ||
}, | ||
]; | ||
|
||
const CustomFooter = ( | ||
<WizardFooter> | ||
<WizardContextConsumer> | ||
{({ activeStep, onNext, onBack }) => ( | ||
<> | ||
<Button | ||
id="credential-plugin-prompt-next" | ||
variant="primary" | ||
onClick={onNext} | ||
isDisabled={!selectedCredential.value} | ||
> | ||
{activeStep.key === 'metadata' ? i18n._(t`OK`) : i18n._(t`Next`)} | ||
</Button> | ||
{activeStep && activeStep.key === 'metadata' && ( | ||
<> | ||
<Tooltip | ||
content={i18n._( | ||
t`Click this button to verify connection to the secret management system using the selected credential and specified inputs.` | ||
)} | ||
position="right" | ||
> | ||
<Button | ||
id="credential-plugin-prompt-test" | ||
variant="secondary" | ||
onClick={() => testPluginMetadata()} | ||
> | ||
{i18n._(t`Test`)} | ||
</Button> | ||
</Tooltip> | ||
|
||
<Button | ||
id="credential-plugin-prompt-back" | ||
variant="secondary" | ||
onClick={onBack} | ||
> | ||
{i18n._(t`Back`)} | ||
</Button> | ||
</> | ||
)} | ||
<Button | ||
id="credential-plugin-prompt-cancel" | ||
variant="link" | ||
onClick={onClose} | ||
> | ||
{i18n._(t`Cancel`)} | ||
</Button> | ||
</> | ||
)} | ||
</WizardContextConsumer> | ||
</WizardFooter> | ||
); | ||
|
||
return ( | ||
<> | ||
<Wizard | ||
isOpen | ||
onClose={onClose} | ||
title={i18n._(t`External Secret Management System`)} | ||
steps={steps} | ||
onSave={handleSubmit} | ||
footer={CustomFooter} | ||
/> | ||
{selectedCredential.value && ( | ||
<CredentialPluginTestAlert | ||
credentialName={selectedCredential.value.name} | ||
successResponse={testPluginSuccess} | ||
errorResponse={testPluginError} | ||
/> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
function CredentialPluginPrompt({ i18n, onClose, onSubmit, initialValues }) { | ||
return ( | ||
<Formik | ||
initialValues={{ | ||
credential: initialValues?.credential || null, | ||
inputs: initialValues?.inputs || {}, | ||
}} | ||
onSubmit={onSubmit} | ||
> | ||
{({ handleSubmit }) => ( | ||
<CredentialPluginWizard | ||
handleSubmit={handleSubmit} | ||
i18n={i18n} | ||
onClose={onClose} | ||
/> | ||
)} | ||
</Formik> | ||
); | ||
} | ||
|
||
CredentialPluginPrompt.propTypes = { | ||
onClose: func.isRequired, | ||
onSubmit: func.isRequired, | ||
initialValues: shape({}), | ||
}; | ||
|
||
CredentialPluginPrompt.defaultProps = { | ||
initialValues: {}, | ||
}; | ||
|
||
export default withI18n()(CredentialPluginPrompt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.