1- import { browserHistory , RouteComponentProps } from 'react-router' ;
1+ import { browserHistory } from 'react-router' ;
22
33import Breadcrumbs from 'sentry/components/breadcrumbs' ;
44import * as Layout from 'sentry/components/layouts/thirds' ;
5+ import LoadingError from 'sentry/components/loadingError' ;
6+ import LoadingIndicator from 'sentry/components/loadingIndicator' ;
7+ import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle' ;
58import { t } from 'sentry/locale' ;
6- import { Organization } from 'sentry/types' ;
9+ import { useQuery , useQueryClient } from 'sentry/utils/queryClient' ;
10+ import useOrganization from 'sentry/utils/useOrganization' ;
11+ import { useParams } from 'sentry/utils/useParams' ;
712import { normalizeUrl } from 'sentry/utils/withDomainRequired' ;
8- import withOrganization from 'sentry/utils/withOrganization' ;
9- import AsyncView from 'sentry/views/asyncView' ;
1013
1114import MonitorForm from './components/monitorForm' ;
1215import { Monitor } from './types' ;
1316
14- type Props = AsyncView [ 'props' ] &
15- RouteComponentProps < { monitorSlug : string } , { } > & {
16- organization : Organization ;
17- } ;
17+ export default function EditMonitor ( ) {
18+ const { monitorSlug} = useParams ( ) ;
19+ const organization = useOrganization ( ) ;
20+ const queryClient = useQueryClient ( ) ;
1821
19- type State = AsyncView [ 'state' ] & {
20- monitor : Monitor | null ;
21- } ;
22+ const queryKeyUrl = `/organizations/${ organization . slug } /monitors/${ monitorSlug } /` ;
2223
23- class EditMonitor extends AsyncView < Props , State > {
24- get orgSlug ( ) {
25- return this . props . organization . slug ;
26- }
27-
28- getEndpoints ( ) : ReturnType < AsyncView [ 'getEndpoints' ] > {
29- const { params} = this . props ;
30- return [
31- [ 'monitor' , `/organizations/${ this . orgSlug } /monitors/${ params . monitorSlug } /` ] ,
32- ] ;
33- }
24+ const {
25+ isLoading,
26+ isError,
27+ data : monitor ,
28+ refetch,
29+ } = useQuery < Monitor > ( [ queryKeyUrl ] , {
30+ staleTime : 0 ,
31+ } ) ;
3432
35- onSubmitSuccess = ( data : Monitor ) =>
33+ function onSubmitSuccess ( data : Monitor ) {
34+ queryClient . setQueryData ( [ queryKeyUrl ] , data ) ;
3635 browserHistory . push (
37- normalizeUrl ( `/organizations/${ this . orgSlug } /crons/${ data . slug } /` )
36+ normalizeUrl ( `/organizations/${ organization . slug } /crons/${ data . slug } /` )
3837 ) ;
38+ }
3939
40- getTitle ( ) {
41- if ( this . state . monitor ) {
42- return `${ this . state . monitor . name } - Crons - ${ this . orgSlug } ` ;
40+ function getTitle ( ) {
41+ if ( monitor ) {
42+ return `${ monitor . name } - Crons - ${ organization . slug } ` ;
4343 }
44- return `Crons - ${ this . orgSlug } ` ;
44+ return `Crons - ${ organization . slug } ` ;
4545 }
4646
47- renderBody ( ) {
48- const { monitor} = this . state ;
47+ if ( isLoading ) {
48+ return < LoadingIndicator /> ;
49+ }
4950
50- if ( monitor === null ) {
51- return null ;
52- }
51+ if ( isError ) {
52+ return < LoadingError onRetry = { refetch } message = "Failed to load monitor." /> ;
53+ }
5354
54- return (
55+ return (
56+ < SentryDocumentTitle title = { getTitle ( ) } >
5557 < Layout . Page >
5658 < Layout . Header >
5759 < Layout . HeaderContent >
5860 < Breadcrumbs
5961 crumbs = { [
6062 {
6163 label : t ( 'Crons' ) ,
62- to : `/organizations/${ this . orgSlug } /crons/` ,
64+ to : `/organizations/${ organization . slug } /crons/` ,
6365 } ,
6466 {
6567 label : t ( 'Editing %s' , monitor . name ) ,
@@ -74,14 +76,12 @@ class EditMonitor extends AsyncView<Props, State> {
7476 < MonitorForm
7577 monitor = { monitor }
7678 apiMethod = "PUT"
77- apiEndpoint = { `/organizations/${ this . orgSlug } /monitors/${ monitor . slug } /` }
78- onSubmitSuccess = { this . onSubmitSuccess }
79+ apiEndpoint = { `/organizations/${ organization . slug } /monitors/${ monitor . slug } /` }
80+ onSubmitSuccess = { onSubmitSuccess }
7981 />
8082 </ Layout . Main >
8183 </ Layout . Body >
8284 </ Layout . Page >
83- ) ;
84- }
85+ </ SentryDocumentTitle >
86+ ) ;
8587}
86-
87- export default withOrganization ( EditMonitor ) ;
0 commit comments