123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- import {Fragment, useCallback} from 'react';
- import styled from '@emotion/styled';
- import Alert from 'sentry/components/alert';
- import {useDismissable} from 'sentry/components/banner';
- import {Button} from 'sentry/components/button';
- import {feedbackClient} from 'sentry/components/featureFeedback/feedbackModal';
- import {t} from 'sentry/locale';
- import ConfigStore from 'sentry/stores/configStore';
- import {space} from 'sentry/styles/space';
- import type {Organization} from 'sentry/types/organization';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import {useFeedbackForm} from 'sentry/utils/useFeedbackForm';
- import type {Incident} from 'sentry/views/alerts/types';
- interface AnomalyDetectionFeedbackProps {
- id: string;
- organization: Organization;
- selectedIncident: Incident;
- }
- export default function AnomalyDetectionFeedbackBanner({
- id,
- organization,
- selectedIncident,
- }: AnomalyDetectionFeedbackProps) {
- const [isSubmitted, submit] = useDismissable(id);
- const openFeedbackForm = useFeedbackForm();
- const handleClick = useCallback(
- (anomalyCorrectlyIdentified: boolean) => {
- trackAnalytics('anomaly-detection.feedback-submitted', {
- choice_selected: anomalyCorrectlyIdentified,
- organization,
- incident_id: id,
- });
- feedbackClient.captureEvent({
- request: {
- url: window.location.href, // gives the full url (origin + pathname)
- },
- tags: {
- featureName: 'anomaly-detection-alerts-feedback',
- choice_selected: anomalyCorrectlyIdentified,
- incident_id: id,
- alert_rule_id: selectedIncident.alertRule.id,
- metric: selectedIncident.alertRule.query,
- sensitivity: selectedIncident.alertRule.sensitivity,
- direction: selectedIncident.alertRule.thresholdType,
- time_window: selectedIncident.alertRule.timeWindow,
- },
- user: ConfigStore.get('user'),
- level: 'info',
- message: 'Anomaly Detection Alerts Banner Feedback',
- });
- if (!anomalyCorrectlyIdentified && openFeedbackForm) {
- openFeedbackForm({
- messagePlaceholder: t('Why was this anomaly incorrect?'),
- tags: {
- ['feedback.source']: 'anomaly_detection_false_positive',
- ['feedback.owner']: 'ml-ai',
- },
- });
- }
- submit();
- },
- [
- id,
- organization,
- selectedIncident.alertRule.id,
- selectedIncident.alertRule.query,
- selectedIncident.alertRule.sensitivity,
- selectedIncident.alertRule.thresholdType,
- selectedIncident.alertRule.timeWindow,
- submit,
- openFeedbackForm,
- ]
- );
- if (isSubmitted) {
- return null;
- }
- return (
- <StyledAlert
- type="info"
- trailingItems={
- <Fragment>
- <StyledButton borderless onClick={() => handleClick(true)}>
- {t('Yes')}
- </StyledButton>
- <StyledButton borderless onClick={() => handleClick(false)}>
- {t('No')}
- </StyledButton>
- </Fragment>
- }
- showIcon
- >
- {t('Was the anomaly correctly identified?')}
- </StyledAlert>
- );
- }
- const StyledButton = styled(Button)`
- background-color: transparent;
- color: ${p => p.theme.alert.info.color};
- border: 1px solid ${p => p.theme.alert.info.border};
- &:hover,
- &:focus,
- &:active {
- color: ${p => p.theme.alert.info.color};
- border-color: ${p => p.theme.alert.info.borderHover};
- }
- `;
- const StyledAlert = styled(Alert)`
- margin: 0;
- padding-top: ${space(3)};
- padding-bottom: ${space(3)};
- `;
|