1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-09 13:47:13 +02:00

chore: call signal endpoint example (#6611)

Adds a "call signal endpoint" example to the token dialog.


![image](https://github.com/Unleash/unleash/assets/14320932/9cd2b46e-dca7-4ae1-b389-c83f910cb377)
This commit is contained in:
Nuno Góis 2024-03-19 15:53:41 +00:00 committed by GitHub
parent 085adaaa51
commit 899d9fe57f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 73 additions and 26 deletions

View File

@ -284,6 +284,7 @@ export const SignalEndpointsTokens = ({
open={tokenOpen} open={tokenOpen}
setOpen={setTokenOpen} setOpen={setTokenOpen}
token={newToken} token={newToken}
signalEndpoint={signalEndpoint}
/> />
<Dialogue <Dialogue
open={deleteOpen} open={deleteOpen}

View File

@ -1,37 +1,78 @@
import { Alert, styled, Typography } from '@mui/material'; import { Alert, styled, Typography } from '@mui/material';
import { UserToken } from 'component/admin/apiToken/ConfirmToken/UserToken/UserToken'; import { UserToken } from 'component/admin/apiToken/ConfirmToken/UserToken/UserToken';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { Dialogue } from 'component/common/Dialogue/Dialogue'; import { Dialogue } from 'component/common/Dialogue/Dialogue';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import type { ISignalEndpoint } from 'interfaces/signal';
const StyledAlert = styled(Alert)(({ theme }) => ({ const StyledAlert = styled(Alert)(({ theme }) => ({
marginBottom: theme.spacing(3), marginBottom: theme.spacing(3),
})); }));
const StyledCodeBlock = styled('pre')(({ theme }) => ({
backgroundColor: theme.palette.background.elevation1,
padding: theme.spacing(2),
borderRadius: theme.shape.borderRadius,
overflow: 'auto',
fontSize: theme.fontSizes.smallerBody,
}));
interface ISignalEndpointsTokensDialogProps { interface ISignalEndpointsTokensDialogProps {
open: boolean; open: boolean;
setOpen: React.Dispatch<React.SetStateAction<boolean>>; setOpen: React.Dispatch<React.SetStateAction<boolean>>;
token?: string; token?: string;
signalEndpoint?: ISignalEndpoint;
} }
export const SignalEndpointsTokensDialog = ({ export const SignalEndpointsTokensDialog = ({
open, open,
setOpen, setOpen,
token, token,
}: ISignalEndpointsTokensDialogProps) => ( signalEndpoint,
<Dialogue }: ISignalEndpointsTokensDialogProps) => {
open={open} const { uiConfig } = useUiConfig();
secondaryButtonText='Close'
onClose={(_, muiCloseReason?: string) => { return (
if (!muiCloseReason) { <Dialogue
setOpen(false); open={open}
} secondaryButtonText='Close'
}} onClose={(_, muiCloseReason?: string) => {
title='Signal endpoint token created' if (!muiCloseReason) {
> setOpen(false);
<StyledAlert severity='info'> }
Make sure to copy your signal endpoint token now. You won't be able }}
to see it again! title='Signal endpoint token created'
</StyledAlert> >
<Typography variant='body1'>Your token:</Typography> <StyledAlert severity='info'>
<UserToken token={token || ''} /> Make sure to copy your signal endpoint token now. You won't be
</Dialogue> able to see it again!
); </StyledAlert>
<Typography variant='body1'>Your token:</Typography>
<UserToken token={token || ''} />
<ConditionallyRender
condition={Boolean(signalEndpoint)}
show={() => (
<>
<Typography
variant='body1'
sx={{ marginTop: 3, marginBottom: 2 }}
>
You can call your signal endpoint with the newly
created token like this:
</Typography>
<StyledCodeBlock>
{`curl --request POST '${
uiConfig.unleashUrl
}/api/signal-endpoint/${signalEndpoint!.name}' \\
--header 'Authorization: Bearer ${token || 'YOUR_TOKEN'}' \\
--header 'Content-Type: application/json' \\
--data-raw '{
"Jason": "json"
}'`}
</StyledCodeBlock>
</>
)}
/>
</Dialogue>
);
};

View File

@ -52,7 +52,7 @@ interface ISignalEndpointsModalProps {
signalEndpoint?: ISignalEndpoint; signalEndpoint?: ISignalEndpoint;
open: boolean; open: boolean;
setOpen: React.Dispatch<React.SetStateAction<boolean>>; setOpen: React.Dispatch<React.SetStateAction<boolean>>;
newToken: (token: string) => void; newToken: (token: string, signalEndpoint: ISignalEndpoint) => void;
onOpenSignals: () => void; onOpenSignals: () => void;
} }
@ -120,12 +120,15 @@ export const SignalEndpointsModal = ({
if (editing) { if (editing) {
await updateSignalEndpoint(signalEndpoint.id, payload); await updateSignalEndpoint(signalEndpoint.id, payload);
} else { } else {
const { id } = await addSignalEndpoint(payload); const signalEndpoint = await addSignalEndpoint(payload);
if (tokenGeneration === TokenGeneration.NOW) { if (tokenGeneration === TokenGeneration.NOW) {
const { token } = await addSignalEndpointToken(id, { const { token } = await addSignalEndpointToken(
name: tokenName, signalEndpoint.id,
}); {
newToken(token); name: tokenName,
},
);
newToken(token, signalEndpoint);
} }
} }
setToastData({ setToastData({

View File

@ -259,8 +259,9 @@ export const SignalEndpointsTable = () => {
signalEndpoint={selectedSignalEndpoint} signalEndpoint={selectedSignalEndpoint}
open={modalOpen} open={modalOpen}
setOpen={setModalOpen} setOpen={setModalOpen}
newToken={(token: string) => { newToken={(token: string, signalEndpoint: ISignalEndpoint) => {
setNewToken(token); setNewToken(token);
setSelectedSignalEndpoint(signalEndpoint);
setTokenDialog(true); setTokenDialog(true);
}} }}
onOpenSignals={() => { onOpenSignals={() => {
@ -281,6 +282,7 @@ export const SignalEndpointsTable = () => {
open={tokenDialog} open={tokenDialog}
setOpen={setTokenDialog} setOpen={setTokenDialog}
token={newToken} token={newToken}
signalEndpoint={selectedSignalEndpoint}
/> />
<SignalEndpointsDeleteDialog <SignalEndpointsDeleteDialog
signalEndpoint={selectedSignalEndpoint} signalEndpoint={selectedSignalEndpoint}