-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(onboarding): Add alert rule configuration onboarding (#17357)
- Loading branch information
1 parent
7a78dcf
commit 7e11627
Showing
13 changed files
with
1,098 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/sentry/static/sentry/app/actionCreators/onboardingTasks.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {Client} from 'app/api'; | ||
import {Organization, OnboardingTask} from 'app/types'; | ||
import OrganizationActions from 'app/actions/organizationActions'; | ||
|
||
/** | ||
* Update an onboarding task. | ||
* | ||
* If no API client is provided the task will not be updated on the server side | ||
* and will only update in the organization store. | ||
*/ | ||
export async function updateOnboardingTask( | ||
api: Client | null, | ||
organization: Organization, | ||
updatedTask: Pick<OnboardingTask, 'task' | 'status' | 'data'> | ||
) { | ||
if (api !== null) { | ||
await api.requestPromise(`/organizations/${organization.slug}/onboarding-tasks/`, { | ||
method: 'POST', | ||
data: updatedTask, | ||
}); | ||
} | ||
|
||
const hasSkippedTask = organization.onboardingTasks.find( | ||
task => task.task === updatedTask.task | ||
); | ||
|
||
const onboardingTasks = hasSkippedTask | ||
? organization.onboardingTasks.map(task => | ||
task.task === updatedTask.task ? {...task, ...updatedTask} : task | ||
) | ||
: [...organization.onboardingTasks, updatedTask]; | ||
|
||
OrganizationActions.update({onboardingTasks}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/sentry/static/sentry/app/views/settings/projectAlerts/onboardingHovercard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React from 'react'; | ||
import {Location} from 'history'; | ||
import styled from '@emotion/styled'; | ||
|
||
import Button from 'app/components/button'; | ||
import Hovercard from 'app/components/hovercard'; | ||
import {t} from 'app/locale'; | ||
import space from 'app/styles/space'; | ||
import withApi from 'app/utils/withApi'; | ||
import {Client} from 'app/api'; | ||
import {Organization, OnboardingTaskKey} from 'app/types'; | ||
import {updateOnboardingTask} from 'app/actionCreators/onboardingTasks'; | ||
|
||
type Props = { | ||
api: Client; | ||
organization: Organization; | ||
location: Location; | ||
children: React.ReactNode; | ||
}; | ||
|
||
type State = { | ||
dismissed: boolean; | ||
}; | ||
|
||
class OnboardingHovercard extends React.Component<Props, State> { | ||
state: State = { | ||
dismissed: false, | ||
}; | ||
|
||
get shouldShowHovercard() { | ||
const {organization} = this.props; | ||
const {dismissed} = this.state; | ||
|
||
const hasCompletedTask = organization.onboardingTasks.find( | ||
task => task.task === OnboardingTaskKey.ALERT_RULE && task.status === 'complete' | ||
); | ||
|
||
const query = this.props.location?.query || {}; | ||
|
||
return ( | ||
!hasCompletedTask && | ||
!dismissed && | ||
Object.prototype.hasOwnProperty.call(query, 'onboardingTask') | ||
); | ||
} | ||
|
||
skipTask = () => { | ||
const {api, organization} = this.props; | ||
|
||
updateOnboardingTask(api, organization, { | ||
task: OnboardingTaskKey.ALERT_RULE, | ||
status: 'complete', | ||
data: {accepted_defaults: true}, | ||
}); | ||
|
||
this.setState({dismissed: true}); | ||
}; | ||
|
||
render() { | ||
const {children, organization, location, ...props} = this.props; | ||
|
||
if (!this.shouldShowHovercard) { | ||
return children; | ||
} | ||
|
||
const hovercardBody = ( | ||
<HovercardBody> | ||
<h1>{t('Configure custom alerting')}</h1> | ||
|
||
<p> | ||
{t( | ||
`Add custom alert rules to configure under what conditions | ||
you receive notifications from Sentry.` | ||
)} | ||
</p> | ||
|
||
<Button size="xsmall" onClick={this.skipTask}> | ||
{t('The default rule looks good!')} | ||
</Button> | ||
</HovercardBody> | ||
); | ||
|
||
return ( | ||
<Hovercard show position="left" body={hovercardBody} {...props}> | ||
{children} | ||
</Hovercard> | ||
); | ||
} | ||
} | ||
|
||
const HovercardBody = styled('div')` | ||
h1 { | ||
font-size: ${p => p.theme.fontSizeLarge}; | ||
margin-bottom: ${space(1.5)}; | ||
} | ||
p { | ||
font-size: ${p => p.theme.fontSizeMedium}; | ||
} | ||
`; | ||
|
||
export default withApi(OnboardingHovercard); |
Oops, something went wrong.