@@ -6,9 +6,8 @@ import {injectGlobal} from 'emotion';
66import Cookies from 'js-cookie' ;
77import PropTypes from 'prop-types' ;
88import React from 'react' ;
9- import Reflux from 'reflux' ;
10- import createReactClass from 'create-react-class' ;
119import keydown from 'react-keydown' ;
10+ import { isEqual } from 'lodash' ;
1211
1312import { openCommandPalette } from 'app/actionCreators/modal' ;
1413import { t } from 'app/locale' ;
@@ -27,6 +26,7 @@ import OrganizationsStore from 'app/stores/organizationsStore';
2726import getRouteStringFromRoutes from 'app/utils/getRouteStringFromRoutes' ;
2827import theme from 'app/utils/theme' ;
2928import withApi from 'app/utils/withApi' ;
29+ import withConfig from 'app/utils/withConfig' ;
3030
3131function getAlertTypeForProblem ( problem ) {
3232 switch ( problem . severity ) {
@@ -37,35 +37,33 @@ function getAlertTypeForProblem(problem) {
3737 }
3838}
3939
40- const App = createReactClass ( {
41- displayName : 'App' ,
42-
43- propTypes : {
40+ class App extends React . Component {
41+ static propTypes = {
4442 api : PropTypes . object . isRequired ,
4543 routes : PropTypes . array ,
46- } ,
44+ config : PropTypes . object . isRequired ,
45+ } ;
4746
48- childContextTypes : {
47+ static childContextTypes = {
4948 location : PropTypes . object ,
50- } ,
51-
52- mixins : [ Reflux . listenTo ( ConfigStore , 'onConfigStoreChange' ) ] ,
49+ } ;
5350
54- getInitialState ( ) {
51+ constructor ( props ) {
52+ super ( props ) ;
5553 const user = ConfigStore . get ( 'user' ) ;
56- return {
54+ this . state = {
5755 loading : false ,
5856 error : false ,
5957 needsUpgrade : user && user . isSuperuser && ConfigStore . get ( 'needsUpgrade' ) ,
6058 newsletterConsentPrompt : user && user . flags . newsletter_consent_prompt ,
6159 } ;
62- } ,
60+ }
6361
6462 getChildContext ( ) {
6563 return {
6664 location : this . props . location ,
6765 } ;
68- } ,
66+ }
6967
7068 componentWillMount ( ) {
7169 this . props . api . request ( '/organizations/' , {
@@ -144,26 +142,31 @@ const App = createReactClass({
144142 if ( user ) {
145143 HookStore . get ( 'analytics:init-user' ) . map ( cb => cb ( user ) ) ;
146144 }
147- } ,
145+ }
148146
149147 componentDidMount ( ) {
150148 this . updateTracing ( ) ;
151- } ,
149+ }
150+
151+ componentDidUpdate ( prevProps ) {
152+ const { config} = this . props ;
153+ if ( ! isEqual ( config , prevProps . config ) ) {
154+ this . handleConfigStoreChange ( config ) ;
155+ }
152156
153- componentDidUpdate ( ) {
154157 this . updateTracing ( ) ;
155- } ,
158+ }
156159
157160 componentWillUnmount ( ) {
158161 OrganizationsStore . load ( [ ] ) ;
159- } ,
162+ }
160163
161164 updateTracing ( ) {
162165 const route = getRouteStringFromRoutes ( this . props . routes ) ;
163166 Tracing . startTrace ( getCurrentHub ( ) , route ) ;
164- } ,
167+ }
165168
166- onConfigStoreChange ( config ) {
169+ handleConfigStoreChange ( config ) {
167170 const newState = { } ;
168171 if ( config . needsUpgrade !== undefined ) {
169172 newState . needsUpgrade = config . needsUpgrade ;
@@ -174,27 +177,27 @@ const App = createReactClass({
174177 if ( Object . keys ( newState ) . length > 0 ) {
175178 this . setState ( newState ) ;
176179 }
177- } ,
180+ }
178181
179182 @keydown ( 'meta+shift+p' , 'meta+k' )
180183 openCommandPalette ( e ) {
181184 openCommandPalette ( ) ;
182185 e . preventDefault ( ) ;
183186 e . stopPropagation ( ) ;
184- } ,
187+ }
185188
186189 onConfigured ( ) {
187190 this . setState ( { needsUpgrade : false } ) ;
188- } ,
191+ }
189192
190- onNewsletterConsent ( ) {
193+ handleNewsletterConsent = ( ) => {
191194 // this is somewhat hackish
192195 this . setState ( {
193196 newsletterConsentPrompt : false ,
194197 } ) ;
195- } ,
198+ } ;
196199
197- handleGlobalModalClose ( ) {
200+ handleGlobalModalClose = ( ) => {
198201 if ( ! this . mainContainerRef ) {
199202 return ;
200203 }
@@ -204,7 +207,7 @@ const App = createReactClass({
204207
205208 // Focus the main container to get hotkeys to keep working after modal closes
206209 this . mainContainerRef . focus ( ) ;
207- } ,
210+ } ;
208211
209212 renderBody ( ) {
210213 const { needsUpgrade, newsletterConsentPrompt} = this . state ;
@@ -213,11 +216,11 @@ const App = createReactClass({
213216 }
214217
215218 if ( newsletterConsentPrompt ) {
216- return < NewsletterConsent onSubmitSuccess = { this . onNewsletterConsent } /> ;
219+ return < NewsletterConsent onSubmitSuccess = { this . handleNewsletterConsent } /> ;
217220 }
218221
219222 return this . props . children ;
220- } ,
223+ }
221224
222225 render ( ) {
223226 if ( this . state . loading ) {
@@ -243,10 +246,10 @@ const App = createReactClass({
243246 </ div >
244247 </ ThemeProvider >
245248 ) ;
246- } ,
247- } ) ;
249+ }
250+ }
248251
249- export default withApi ( App ) ;
252+ export default withApi ( withConfig ( App ) ) ;
250253
251254injectGlobal `
252255body {
0 commit comments