@@ -22,8 +22,9 @@ import loading from './../common/loading.js';
2222import { DetectorLockAction } from '../common/enums/DetectorLockAction.enum.js' ;
2323import { isUserAllowedRole } from './../common/userRole.js' ;
2424import { getDetectorListWithTstAtEnd , TST_DETECTOR_NAME } from '../common/detectorUtils.js' ;
25+ import { DetectorState , DetectorStateStyle } from '../common/enums/DetectorState.enum.js' ;
2526
26- const LOCK_TABLE_HEADER_KEYS = [ 'Detector' , 'Owner' ] ;
27+ const LOCK_TABLE_HEADER_KEYS = [ 'Detector' , 'Owner' , 'Active' ] ;
2728const DETECTOR_ALL = 'ALL' ;
2829
2930/**
@@ -50,7 +51,10 @@ export const content = (model) => {
5051 const { padlockState } = lockModel ;
5152 return [
5253 detectorHeader ( model ) ,
53- h ( '.text-center.scroll-y.absolute-fill' , { style : 'top: 40px' } , [
54+ h ( '.text-center.scroll-y.absolute-fill' , {
55+ style : 'top: 40px' ,
56+ oncreate : ( ) => detectorsService . getActiveDetectors ( ) ,
57+ } , [
5458 padlockState . match ( {
5559 NotAsked : ( ) => null ,
5660 Loading : ( ) => loading ( 3 ) ,
@@ -78,7 +82,7 @@ export const content = (model) => {
7882 ] ,
7983 ] ) ,
8084 ] ,
81- detectorLocksTable ( model , detectorsLocksState )
85+ detectorLocksTable ( model , detectorsLocksState , detectorsService . activeDetectors )
8286 ] )
8387 } )
8488 ] )
@@ -89,9 +93,10 @@ export const content = (model) => {
8993 * Table with lock status details, buttons to lock them, and admin actions such us "Force release"
9094 * @param {Model } model - root model of the application
9195 * @param {Object<String, DetectorLock> } detectorsLockState - state of the detectors lock
96+ * @param {RemoteData } activeDetectorsRemote - remote data with the list of active detectors
9297 * @return {vnode }
9398 */
94- const detectorLocksTable = ( model , detectorLocksState ) => {
99+ const detectorLocksTable = ( model , detectorLocksState , activeDetectorsRemote ) => {
95100 const { detectors : detectorsService , lock : lockModel } = model ;
96101 const isUserGlobal = isUserAllowedRole ( ROLES . Global ) ;
97102 const detectorKeysWithTstLast = getDetectorListWithTstAtEnd ( Object . keys ( detectorLocksState ) ) ;
@@ -104,10 +109,14 @@ const detectorLocksTable = (model, detectorLocksState) => {
104109 return ( isUserGlobal && isSelectedDetectorViewGlobalOrCurrent ) || isUserAllowedDetector ;
105110 } )
106111 . map ( ( detectorName ) => {
112+ const detectorActivityState = _getDetectorState ( activeDetectorsRemote , detectorName ) ;
107113 if ( detectorName . toLocaleUpperCase ( ) . includes ( TST_DETECTOR_NAME ) ) {
108- return [ emptyRowSeparator ( ) , detectorLockRow ( lockModel , detectorName , detectorLocksState [ detectorName ] ) ] ;
114+ return [
115+ emptyRowSeparator ( ) ,
116+ detectorLockRow ( lockModel , detectorName , detectorLocksState [ detectorName ] , detectorActivityState )
117+ ] ;
109118 } else {
110- return detectorLockRow ( lockModel , detectorName , detectorLocksState [ detectorName ] )
119+ return detectorLockRow ( lockModel , detectorName , detectorLocksState [ detectorName ] , detectorActivityState )
111120 }
112121 } ) ;
113122 return h ( 'table.table.table-sm' ,
@@ -121,7 +130,7 @@ const detectorLocksTable = (model, detectorLocksState) => {
121130 detectorRows . length > 0
122131 ? detectorRows
123132 : h ( 'tr' ,
124- h ( 'td.ph2.warning' , { colspan : 3 } , [
133+ h ( 'td.ph2.warning' , { colspan : LOCK_TABLE_HEADER_KEYS . length } , [
125134 'Missing Role permissions needed for being allowed to own locks' ,
126135 ' If you have just started your shift, please allow a few minutes for the system ' ,
127136 'to update before trying again or calling an FLP expert.'
@@ -136,20 +145,24 @@ const detectorLocksTable = (model, detectorLocksState) => {
136145 * @param {LockModel } lockModel - model of the lock state and actions
137146 * @param {String } detector - detector name
138147 * @param {DetectorLock } lockState - state of the lock {owner: {fullName: String}, isLocked: Boolean
148+ * @param {DetectorState } detectorActivityState - state of the detector as per AliECS (Active, Inactive, Unknown)
139149 * @return {vnode }
140150 */
141- const detectorLockRow = ( lockModel , detector , lockState ) => {
151+ const detectorLockRow = ( lockModel , detector , lockState , detectorActivityState ) => {
142152 const ownerName = lockState ?. owner ?. fullName || '-' ;
143153 return h ( 'tr' , {
144154 id : `detector-row-${ detector } ` ,
145155 } , [
146156 h ( 'td' ,
147157 h ( '.flex-row.g2.items-center.f5' , [
148- detectorLockButton ( lockModel , detector , lockState ) ,
158+ detectorLockButton ( lockModel , detector , lockState , false , detectorActivityState === DetectorState . ACTIVE ) ,
149159 detector
150160 ] )
151161 ) ,
152162 h ( 'td' , ownerName ) ,
163+ h ( `td` , {
164+ class : DetectorStateStyle [ detectorActivityState ]
165+ } , detectorActivityState ) ,
153166 isUserAllowedRole ( ROLES . Global ) && h ( 'td' , [
154167 detectorLockActionButton ( lockModel , detector , lockState , DetectorLockAction . RELEASE , true , 'Force Release' ) ,
155168 detectorLockActionButton ( lockModel , detector , lockState , DetectorLockAction . TAKE , true , 'Force Take' )
@@ -161,4 +174,20 @@ const detectorLockRow = (lockModel, detector, lockState) => {
161174 * Empty table row separator vnode
162175 * @return {vnode }
163176 */
164- const emptyRowSeparator = ( ) => h ( 'tr' , h ( 'td' , { colspan : 3 } , h ( 'hr' ) ) ) ;
177+ const emptyRowSeparator = ( ) => h ( 'tr' , h ( 'td' , { colspan : LOCK_TABLE_HEADER_KEYS . length } , h ( 'hr' ) ) ) ;
178+
179+ /**
180+ * Helper function to get the state of the detector (Active, Inactive, Unknown) based on the activeDetectorsRemote data
181+ * @param {RemoteData } activeDetectorsRemote - remote data with the list of active detectors
182+ * @param {String } detectorName - name of the detector to get the state for
183+ * @return {String } state of the detector (Active, Inactive, Unknown)
184+ */
185+ const _getDetectorState = ( activeDetectorsRemote , detectorName ) => {
186+ return activeDetectorsRemote . match ( {
187+ NotAsked : ( ) => DetectorState . UNDEFINED ,
188+ Loading : ( ) => DetectorState . UNDEFINED ,
189+ Failure : ( ) => DetectorState . ERROR ,
190+ Success : ( activeDetectors ) =>
191+ activeDetectors . includes ( detectorName ) ? DetectorState . ACTIVE : DetectorState . UNDEFINED
192+ } )
193+ }
0 commit comments