Browse Source

frontend: handle token prefixes (#63627)

We were incorrectly adding in a `sntrys_` prefix when displaying the
token preview for user API tokens.

This PR sets parameter for the prefix that defaults to an empty string.
This should do for now until the backend starts returning prefixes for
the various types of tokens.

**BEFORE**
_Notice the token previews are prefixed with `sntrys_`. This is
misleading. Actual user tokens do not have this prefix._

![image](https://github.com/getsentry/sentry/assets/20070360/34a4ddf3-e73e-415b-8a34-9043d015f1e9)

**AFTER**
_No misleading prefix._ 🙂

![image](https://github.com/getsentry/sentry/assets/20070360/f5778803-7b1a-4c83-9fe9-bd4bdf1921f4)
Matthew T 1 year ago
parent
commit
2519b183fe

+ 4 - 2
static/app/views/settings/account/apiTokenRow.tsx

@@ -13,11 +13,12 @@ import {tokenPreview} from 'sentry/views/settings/organizationAuthTokens';
 type Props = {
   onRemove: (token: InternalAppApiToken) => void;
   token: InternalAppApiToken;
+  tokenPrefix?: string;
 };
 
 // TODO: After the BE portion of code changes have been released, remove the conditional rendering of the token.
 // We are currently doing the conditional logic to do safe blue/green deploys and handle contract changes.
-function ApiTokenRow({token, onRemove}: Props) {
+function ApiTokenRow({token, onRemove, tokenPrefix = ''}: Props) {
   return (
     <StyledPanelItem>
       <Controls>
@@ -26,7 +27,8 @@ function ApiTokenRow({token, onRemove}: Props) {
             getDynamicText({
               value: token.tokenLastCharacters,
               fixed: 'ABCD',
-            })
+            }),
+            tokenPrefix
           )}
         </TokenPreview>
         <ButtonWrapper>

+ 2 - 1
static/app/views/settings/organizationAuthTokens/authTokenRow.tsx

@@ -106,7 +106,8 @@ export function OrganizationAuthTokensAuthTokenRow({
               getDynamicText({
                 value: token.tokenLastCharacters,
                 fixed: 'ABCD',
-              })
+              }),
+              'sntrys_'
             )}
           </TokenPreview>
         )}

+ 2 - 2
static/app/views/settings/organizationAuthTokens/index.tsx

@@ -204,8 +204,8 @@ export function OrganizationAuthTokensIndex({
   );
 }
 
-export function tokenPreview(tokenLastCharacters: string) {
-  return `sntrys_************${tokenLastCharacters}`;
+export function tokenPreview(tokenLastCharacters: string, tokenPrefix = '') {
+  return `${tokenPrefix}************${tokenLastCharacters}`;
 }
 
 export default withOrganization(OrganizationAuthTokensIndex);