@@ -15,6 +15,7 @@ import { Tab } from 'bootstrap';
1515import * as ace from 'ace-builds/src-noconflict/ace' ;
1616import AceDiff from 'ace-diff' ;
1717import * as API from '../api.js' ;
18+ import * as Environments from '../environments/environments.js' ;
1819import * as Utils from '../utils.js' ;
1920import thingsDiffHTML from './thingsDiff.html' ;
2021import * as Things from './things.js' ;
@@ -73,6 +74,8 @@ export function ThingsDiff(targetTab) {
7374 tabLink = document . querySelector ( `a[data-bs-target="#${ tabId } "]` ) ;
7475 tabLink . addEventListener ( 'shown.bs.tab' , onTabActivated ) ;
7576
77+ Environments . addChangeListener ( onEnvironmentChanged ) ;
78+
7679 Utils . getAllElementsById ( dom ) ;
7780
7881 // Left revision controls
@@ -129,13 +132,21 @@ export function ThingsDiff(targetTab) {
129132 cancelActiveProbe ( ) ;
130133 probeOldestRevision ( thing . thingId ) ;
131134
132- if ( tabLink && tabLink . classList . contains ( 'active' ) ) {
135+ if ( isAnyDiffTabActive ( ) ) {
133136 fetchAndDiff ( ) ;
134137 } else {
135138 viewDirty = true ;
136139 }
137140 } ;
138141
142+ function isAnyDiffTabActive ( ) : boolean {
143+ if ( tabLink && tabLink . classList . contains ( 'active' ) ) return true ;
144+ return subDiffs . some ( ( s ) => {
145+ const link = s . subDiff . getTabLink ( ) ;
146+ return link && link . classList . contains ( 'active' ) ;
147+ } ) ;
148+ }
149+
139150 const addSubDiff = ( subDiff , kind : 'attributes' | 'feature' ) => {
140151 subDiffs . push ( { subDiff, kind } ) ;
141152 subDiff . setOnActivated ( ( link ) => syncTabs ( link ) ) ;
@@ -218,6 +229,20 @@ export function ThingsDiff(targetTab) {
218229 }
219230 }
220231
232+ function onEnvironmentChanged ( modifiedField ) {
233+ if ( [ 'pinnedThings' , 'filterList' , 'messageTemplates' , 'recentPolicyIds' ] . includes ( modifiedField ) ) {
234+ return ;
235+ }
236+ cancelActiveProbe ( ) ;
237+ destroyDiff ( ) ;
238+ currentThingId = null ;
239+ currentMinRevision = 1 ;
240+ currentMaxRevision = 1 ;
241+ lastLeftJson = null ;
242+ lastRightJson = null ;
243+ viewDirty = false ;
244+ }
245+
221246 function probeOldestRevision ( thingId : string ) {
222247 const probe = Things . probeOldestRevision ( thingId ) ;
223248 activeProbe = probe ;
@@ -293,6 +318,16 @@ export function ThingsDiff(targetTab) {
293318 ] ) . then ( ( results ) => {
294319 if ( token !== fetchToken ) return ; // stale response
295320
321+ if ( results [ 0 ] . status === 'rejected' ) {
322+ console . warn ( `Diff: failed to fetch left revision ${ leftRev } ` , results [ 0 ] . reason ) ;
323+ }
324+ if ( results [ 1 ] . status === 'rejected' ) {
325+ console . warn ( `Diff: failed to fetch right revision ${ rightRev } ` , results [ 1 ] . reason ) ;
326+ }
327+ if ( results [ 0 ] . status === 'rejected' && results [ 1 ] . status === 'rejected' ) {
328+ Utils . showError ( `Failed to fetch both revisions (${ leftRev } , ${ rightRev } ) for diff` ) ;
329+ }
330+
296331 const leftJson = results [ 0 ] . status === 'fulfilled' ? results [ 0 ] . value : { } ;
297332 const rightJson = results [ 1 ] . status === 'fulfilled' ? results [ 1 ] . value : { } ;
298333 lastLeftJson = leftJson ;
0 commit comments