-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copy login command modal for external oidc login command
- Loading branch information
1 parent
a74d182
commit c3b29dc
Showing
9 changed files
with
100 additions
and
56 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
19 changes: 0 additions & 19 deletions
19
frontend/packages/console-shared/src/hoc/withRequestTokenURL.tsx
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
24 changes: 24 additions & 0 deletions
24
frontend/packages/console-shared/src/hooks/useCopyCodeModal.tsx
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,24 @@ | ||
import * as React from 'react'; | ||
import { useModal } from '@console/dynamic-plugin-sdk/src/lib-core'; | ||
import { CopyToClipboard } from '@console/internal/components/utils'; | ||
import { Modal } from '@console/shared/src/components/modal'; | ||
import { ModalComponent } from 'packages/console-dynamic-plugin-sdk/src/app/modal-support/ModalProvider'; | ||
|
||
const CopyCodeModal: CopyCodeModalComponent = ({ title, snippet, closeModal }) => ( | ||
<Modal isOpen onClose={closeModal} showClose title={title} variant="medium"> | ||
<CopyToClipboard key={snippet} value={snippet} /> | ||
</Modal> | ||
); | ||
|
||
export const useCopyCodeModal: UseCopyCodeModal = (title, snippet) => { | ||
const launcher = useModal(); | ||
return React.useCallback(() => (snippet ? launcher(CopyCodeModal, { title, snippet }) : null), [ | ||
launcher, | ||
snippet, | ||
title, | ||
]); | ||
}; | ||
|
||
type CopyCodeModalProps = { title: string; snippet: string }; | ||
type CopyCodeModalComponent = ModalComponent<CopyCodeModalProps>; | ||
type UseCopyCodeModal = (title: string, snippet: string) => () => void; |
36 changes: 36 additions & 0 deletions
36
frontend/packages/console-shared/src/hooks/useCopyLoginCommands.ts
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,36 @@ | ||
import * as React from 'react'; | ||
import { consoleFetchJSON as coFetchJSON } from '@console/dynamic-plugin-sdk/src/utils/fetch'; | ||
import { FLAGS } from '../constants'; | ||
import { useFlag } from './flag'; | ||
|
||
const COPY_LOGIN_COMMANDS_ENDPOINT = '/api/copy-login-commands'; | ||
|
||
export const useCopyLoginCommands = (): [string, string] => { | ||
const [requestTokenURL, setRequestTokenURL] = React.useState<string>(); | ||
const [externalLoginCommand, setExternalLoginCommand] = React.useState<string>(); | ||
const authEnabled = useFlag(FLAGS.AUTH_ENABLED); | ||
React.useEffect(() => { | ||
if (authEnabled) { | ||
coFetchJSON(COPY_LOGIN_COMMANDS_ENDPOINT, 'GET', {}, 5000) | ||
.then((resp) => { | ||
const newRequestTokenURL = resp?.requestTokenURL ?? ''; | ||
const newExternalLoginCommand = resp?.externalLoginCommands ?? ''; | ||
if (newRequestTokenURL) { | ||
setRequestTokenURL(newRequestTokenURL); | ||
setExternalLoginCommand(''); | ||
} else if (newExternalLoginCommand) { | ||
setExternalLoginCommand(newExternalLoginCommand); | ||
setRequestTokenURL(''); | ||
} | ||
}) | ||
.catch((err) => { | ||
// eslint-disable-next-line no-console | ||
console.warn(`Could not get request token URL: ${err}`); | ||
setRequestTokenURL(''); | ||
setExternalLoginCommand(''); | ||
}); | ||
} | ||
}, [authEnabled]); | ||
|
||
return [requestTokenURL, externalLoginCommand]; | ||
}; |
26 changes: 0 additions & 26 deletions
26
frontend/packages/console-shared/src/hooks/useRequestTokenURL.ts
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
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