@@ -44,6 +44,9 @@ class CompareEnvironments extends Component {
4444 }
4545
4646 fetch = ( ) => {
47+ if ( ! this . state . environmentLeft || ! this . state . environmentRight ) {
48+ return
49+ }
4750 this . setState ( { isLoading : true } )
4851 return Promise . all ( [
4952 data . get (
@@ -66,70 +69,76 @@ class CompareEnvironments extends Component {
6669 data . get (
6770 `${ Project . api } environments/${ this . state . environmentRight } /featurestates/?page_size=999` ,
6871 ) ,
69- ] ) . then (
70- ( [
71- environmentLeftProjectFlags ,
72- environmentRightProjectFlags ,
73- environmentLeftFlags ,
74- environmentRightFlags ,
75- ] ) => {
76- const changes = [ ]
77- const same = [ ]
78- _ . each (
79- _ . sortBy ( environmentLeftProjectFlags . results , ( p ) => p . name ) ,
80- ( projectFlagLeft ) => {
81- const projectFlagRight = environmentRightProjectFlags . results ?. find (
82- ( projectFlagRight ) => projectFlagRight . id === projectFlagLeft . id ,
83- )
84- const leftSide = environmentLeftFlags . results . find (
85- ( v ) => v . feature === projectFlagLeft . id ,
86- )
87- const rightSide = environmentRightFlags . results . find (
88- ( v ) => v . feature === projectFlagLeft . id ,
89- )
90- const change = {
91- leftEnabled : leftSide . enabled ,
92- leftEnvironmentFlag : leftSide ,
93- leftValue : leftSide . feature_state_value ,
94- projectFlagLeft,
95- projectFlagRight,
96- rightEnabled : rightSide . enabled ,
97- rightEnvironmentFlag : rightSide ,
98- rightValue : rightSide . feature_state_value ,
99- }
100- change . enabledChanged = change . rightEnabled !== change . leftEnabled
101- change . valueChanged = change . rightValue !== change . leftValue
102- if (
103- change . enabledChanged ||
104- change . valueChanged ||
105- projectFlagLeft . num_identity_overrides ||
106- projectFlagLeft . num_segment_overrides ||
107- projectFlagRight . num_identity_overrides ||
108- projectFlagRight . num_segment_overrides
109- ) {
110- changes . push ( change )
111- } else {
112- same . push ( change )
113- }
114- } ,
115- )
116- this . setState ( {
117- changes,
118- environmentLeftFlags : _ . keyBy (
119- environmentLeftFlags . results ,
120- 'feature' ,
121- ) ,
122- environmentRightFlags : _ . keyBy (
123- environmentRightFlags . results ,
124- 'feature' ,
125- ) ,
126- isLoading : false ,
127- projectFlagsLeft : environmentLeftProjectFlags . results ,
128- projectFlagsRight : environmentLeftProjectFlags . results ,
129- same,
130- } )
131- } ,
132- )
72+ ] )
73+ . then (
74+ ( [
75+ environmentLeftProjectFlags ,
76+ environmentRightProjectFlags ,
77+ environmentLeftFlags ,
78+ environmentRightFlags ,
79+ ] ) => {
80+ const changes = [ ]
81+ const same = [ ]
82+ _ . each (
83+ _ . sortBy ( environmentLeftProjectFlags . results , ( p ) => p . name ) ,
84+ ( projectFlagLeft ) => {
85+ const projectFlagRight =
86+ environmentRightProjectFlags . results ?. find (
87+ ( projectFlagRight ) =>
88+ projectFlagRight . id === projectFlagLeft . id ,
89+ )
90+ const leftSide = environmentLeftFlags . results . find (
91+ ( v ) => v . feature === projectFlagLeft . id ,
92+ )
93+ const rightSide = environmentRightFlags . results . find (
94+ ( v ) => v . feature === projectFlagLeft . id ,
95+ )
96+ const change = {
97+ leftEnabled : leftSide . enabled ,
98+ leftEnvironmentFlag : leftSide ,
99+ leftValue : leftSide . feature_state_value ,
100+ projectFlagLeft,
101+ projectFlagRight,
102+ rightEnabled : rightSide . enabled ,
103+ rightEnvironmentFlag : rightSide ,
104+ rightValue : rightSide . feature_state_value ,
105+ }
106+ change . enabledChanged = change . rightEnabled !== change . leftEnabled
107+ change . valueChanged = change . rightValue !== change . leftValue
108+ if (
109+ change . enabledChanged ||
110+ change . valueChanged ||
111+ projectFlagLeft . num_identity_overrides ||
112+ projectFlagLeft . num_segment_overrides ||
113+ projectFlagRight . num_identity_overrides ||
114+ projectFlagRight . num_segment_overrides
115+ ) {
116+ changes . push ( change )
117+ } else {
118+ same . push ( change )
119+ }
120+ } ,
121+ )
122+ this . setState ( {
123+ changes,
124+ environmentLeftFlags : _ . keyBy (
125+ environmentLeftFlags . results ,
126+ 'feature' ,
127+ ) ,
128+ environmentRightFlags : _ . keyBy (
129+ environmentRightFlags . results ,
130+ 'feature' ,
131+ ) ,
132+ isLoading : false ,
133+ projectFlagsLeft : environmentLeftProjectFlags . results ,
134+ projectFlagsRight : environmentLeftProjectFlags . results ,
135+ same,
136+ } )
137+ } ,
138+ )
139+ . catch ( ( ) => {
140+ this . setState ( { isLoading : false } )
141+ } )
133142 }
134143
135144 onSave = ( ) => this . fetch ( )
0 commit comments