import {Fragment, useState} from 'react';
import styled from '@emotion/styled';
import Alert from 'sentry/components/alert';
import Button, {ButtonLabel} from 'sentry/components/button';
import Clipboard from 'sentry/components/clipboard';
import ExternalLink from 'sentry/components/links/externalLink';
import {CONFIG_DOCS_URL} from 'sentry/constants';
import {IconChevron, IconCopy} from 'sentry/icons';
import {t, tct} from 'sentry/locale';
import space from 'sentry/styles/space';
import {selectText} from 'sentry/utils/selectText';
const installText = (features: string[], featureName: string): string =>
`# ${t('Enables the %s feature', featureName)}\n${features
.map(f => `SENTRY_FEATURES['${f}'] = True`)
.join('\n')}`;
type Props = {
/**
* The English name of the feature. This is used in the comment that will
* be outputted above the example line of code to enable the feature.
*/
featureName: string;
/**
* The feature flag keys that should be displayed in the code example for
* enabling the feature.
*/
features: string[];
/**
* Render the disabled message within a warning Alert. A custom Alert
* component may be provided.
*
* Attaches additional styles to the FeatureDisabled component to make it
* look consistent within the Alert.
*/
alert?: boolean | React.ElementType;
/**
* Do not show the help toggle. The description will always be rendered.
*/
hideHelpToggle?: boolean;
/**
* A custom message to display. Defaults to a generic disabled message.
*/
message?: string;
};
/**
* DisabledInfo renders a component informing that a feature has been disabled.
*
* By default this component will render a help button which toggles more
* information about why the feature is disabled, showing the missing feature
* flag and linking to documentation for managing sentry server feature flags.
*/
function FeatureDisabled({
features,
featureName,
alert,
hideHelpToggle,
message = t('This feature is not enabled on your Sentry installation.'),
}: Props) {
const [showHelp, setShowHelp] = useState(false);
function renderHelp() {
return (
{tct(
`Enable this feature on your sentry installation by adding the
following configuration into your [configFile:sentry.conf.py].
See [configLink:the configuration documentation] for more
details.`,
{
configFile: ,
configLink: ,
}
)}
}>
{t('Copy to Clipboard')}
selectText(e.target as HTMLElement)}>
{installText(features, featureName)}