import {Component, Fragment} from 'react'; import styled from '@emotion/styled'; import Field from 'sentry/components/forms/field'; import TextCopyInput from 'sentry/components/forms/textCopyInput'; import ExternalLink from 'sentry/components/links/externalLink'; import Link from 'sentry/components/links/link'; import {t, tct} from 'sentry/locale'; import space from 'sentry/styles/space'; import getDynamicText from 'sentry/utils/getDynamicText'; import {ProjectKey} from 'sentry/views/settings/project/projectKeys/types'; const DEFAULT_PROPS = { showDsn: true, showDsnPublic: true, showSecurityEndpoint: true, showMinidump: true, showUnreal: true, showPublicKey: false, showSecretKey: false, showProjectId: false, }; type Props = { data: ProjectKey; projectId: string; } & typeof DEFAULT_PROPS; type State = { showDeprecatedDsn: boolean; }; class ProjectKeyCredentials extends Component { static defaultProps = DEFAULT_PROPS; state: State = { showDeprecatedDsn: false, }; toggleDeprecatedDsn = () => { this.setState(state => ({ showDeprecatedDsn: !state.showDeprecatedDsn, })); }; render() { const {showDeprecatedDsn} = this.state; const { projectId, data, showDsn, showDsnPublic, showSecurityEndpoint, showMinidump, showUnreal, showPublicKey, showSecretKey, showProjectId, } = this.props; return ( {showDsnPublic && ( {showDeprecatedDsn ? t('Hide deprecated DSN') : t('Show deprecated DSN')} ) : null, })} > {getDynamicText({ value: data.dsn.public, fixed: '__DSN__', })} {showDeprecatedDsn && ( {getDynamicText({ value: data.dsn.secret, fixed: '__DSN_DEPRECATED__', })} )} )} {/* this edge case should imho not happen, but just to be sure */} {!showDsnPublic && showDsn && ( {getDynamicText({ value: data.dsn.secret, fixed: '__DSN_DEPRECATED__', })} )} {showSecurityEndpoint && ( {getDynamicText({ value: data.dsn.security, fixed: '__SECURITY_HEADER_ENDPOINT__', })} )} {showMinidump && ( minidump crash reports ), } )} inline={false} flexibleControlStateSize > {getDynamicText({ value: data.dsn.minidump, fixed: '__MINIDUMP_ENDPOINT__', })} )} {showUnreal && ( {getDynamicText({ value: data.dsn.unreal || '', fixed: '__UNREAL_ENDPOINT__', })} )} {showPublicKey && ( {getDynamicText({ value: data.public, fixed: '__PUBLICKEY__', })} )} {showSecretKey && ( {getDynamicText({ value: data.secret, fixed: '__SECRETKEY__', })} )} {showProjectId && ( {getDynamicText({ value: projectId, fixed: '__PROJECTID__', })} )} ); } } const StyledField = styled(Field)` padding: ${space(0.5)} 0 0 0; `; export default ProjectKeyCredentials;