From 899d9fe57ffa6a64615c184021450c5320bf2cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Tue, 19 Mar 2024 15:53:41 +0000 Subject: [PATCH] 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) --- .../SignalEndpointsTokens.tsx | 1 + .../SignalEndpointsTokensDialog.tsx | 79 ++++++++++++++----- .../SignalEndpointsModal.tsx | 15 ++-- .../SignalEndpointsTable.tsx | 4 +- 4 files changed, 73 insertions(+), 26 deletions(-) diff --git a/frontend/src/component/signals/SignalEndpointsModal/SignalEndpointsForm/SignalEndpointsTokens/SignalEndpointsTokens.tsx b/frontend/src/component/signals/SignalEndpointsModal/SignalEndpointsForm/SignalEndpointsTokens/SignalEndpointsTokens.tsx index 1beb020d17..26fc31799a 100644 --- a/frontend/src/component/signals/SignalEndpointsModal/SignalEndpointsForm/SignalEndpointsTokens/SignalEndpointsTokens.tsx +++ b/frontend/src/component/signals/SignalEndpointsModal/SignalEndpointsForm/SignalEndpointsTokens/SignalEndpointsTokens.tsx @@ -284,6 +284,7 @@ export const SignalEndpointsTokens = ({ open={tokenOpen} setOpen={setTokenOpen} token={newToken} + signalEndpoint={signalEndpoint} /> ({ 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 { open: boolean; setOpen: React.Dispatch>; token?: string; + signalEndpoint?: ISignalEndpoint; } export const SignalEndpointsTokensDialog = ({ open, setOpen, token, -}: ISignalEndpointsTokensDialogProps) => ( - { - if (!muiCloseReason) { - setOpen(false); - } - }} - title='Signal endpoint token created' - > - - Make sure to copy your signal endpoint token now. You won't be able - to see it again! - - Your token: - - -); + signalEndpoint, +}: ISignalEndpointsTokensDialogProps) => { + const { uiConfig } = useUiConfig(); + + return ( + { + if (!muiCloseReason) { + setOpen(false); + } + }} + title='Signal endpoint token created' + > + + Make sure to copy your signal endpoint token now. You won't be + able to see it again! + + Your token: + + ( + <> + + You can call your signal endpoint with the newly + created token like this: + + + {`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" + }'`} + + + )} + /> + + ); +}; diff --git a/frontend/src/component/signals/SignalEndpointsModal/SignalEndpointsModal.tsx b/frontend/src/component/signals/SignalEndpointsModal/SignalEndpointsModal.tsx index 28a27f9ee6..3f25780d24 100644 --- a/frontend/src/component/signals/SignalEndpointsModal/SignalEndpointsModal.tsx +++ b/frontend/src/component/signals/SignalEndpointsModal/SignalEndpointsModal.tsx @@ -52,7 +52,7 @@ interface ISignalEndpointsModalProps { signalEndpoint?: ISignalEndpoint; open: boolean; setOpen: React.Dispatch>; - newToken: (token: string) => void; + newToken: (token: string, signalEndpoint: ISignalEndpoint) => void; onOpenSignals: () => void; } @@ -120,12 +120,15 @@ export const SignalEndpointsModal = ({ if (editing) { await updateSignalEndpoint(signalEndpoint.id, payload); } else { - const { id } = await addSignalEndpoint(payload); + const signalEndpoint = await addSignalEndpoint(payload); if (tokenGeneration === TokenGeneration.NOW) { - const { token } = await addSignalEndpointToken(id, { - name: tokenName, - }); - newToken(token); + const { token } = await addSignalEndpointToken( + signalEndpoint.id, + { + name: tokenName, + }, + ); + newToken(token, signalEndpoint); } } setToastData({ diff --git a/frontend/src/component/signals/SignalEndpointsTable/SignalEndpointsTable.tsx b/frontend/src/component/signals/SignalEndpointsTable/SignalEndpointsTable.tsx index 1a87eea4db..370a72ad4c 100644 --- a/frontend/src/component/signals/SignalEndpointsTable/SignalEndpointsTable.tsx +++ b/frontend/src/component/signals/SignalEndpointsTable/SignalEndpointsTable.tsx @@ -259,8 +259,9 @@ export const SignalEndpointsTable = () => { signalEndpoint={selectedSignalEndpoint} open={modalOpen} setOpen={setModalOpen} - newToken={(token: string) => { + newToken={(token: string, signalEndpoint: ISignalEndpoint) => { setNewToken(token); + setSelectedSignalEndpoint(signalEndpoint); setTokenDialog(true); }} onOpenSignals={() => { @@ -281,6 +282,7 @@ export const SignalEndpointsTable = () => { open={tokenDialog} setOpen={setTokenDialog} token={newToken} + signalEndpoint={selectedSignalEndpoint} />