@@ -141,9 +141,10 @@ class TableState {
141141 private virtualButton : ButtonState ;
142142
143143 /**
144- * Underlying DOM Table Caption Element .
144+ * Instance of ButtonState for the 'show/hide virtual rows' button .
145145 */
146- private caption : Nullable < HTMLTableCaptionElement > = null ;
146+ // @ts -expect-error null handling is performed in the constructor
147+ private disconnectedButton : ButtonState ;
147148
148149 /**
149150 * All table rows in table
@@ -166,9 +167,10 @@ class TableState {
166167 this . table ,
167168 'button.toggle-virtual' ,
168169 ) ;
169-
170- const caption = this . table . querySelector ( 'caption' ) ;
171- this . caption = caption ;
170+ const toggleDisconnectedButton = findFirstAdjacent < HTMLButtonElement > (
171+ this . table ,
172+ 'button.toggle-disconnected' ,
173+ ) ;
172174
173175 if ( toggleEnabledButton === null ) {
174176 throw new TableStateError ( "Table is missing a 'toggle-enabled' button." , table ) ;
@@ -182,10 +184,15 @@ class TableState {
182184 throw new TableStateError ( "Table is missing a 'toggle-virtual' button." , table ) ;
183185 }
184186
187+ if ( toggleDisconnectedButton === null ) {
188+ throw new TableStateError ( "Table is missing a 'toggle-disconnected' button." , table ) ;
189+ }
190+
185191 // Attach event listeners to the buttons elements.
186192 toggleEnabledButton . addEventListener ( 'click' , event => this . handleClick ( event , this ) ) ;
187193 toggleDisabledButton . addEventListener ( 'click' , event => this . handleClick ( event , this ) ) ;
188194 toggleVirtualButton . addEventListener ( 'click' , event => this . handleClick ( event , this ) ) ;
195+ toggleDisconnectedButton . addEventListener ( 'click' , event => this . handleClick ( event , this ) ) ;
189196
190197 // Instantiate ButtonState for each button for state management.
191198 this . enabledButton = new ButtonState (
@@ -200,6 +207,10 @@ class TableState {
200207 toggleVirtualButton ,
201208 table . querySelectorAll < HTMLTableRowElement > ( 'tr[data-type="virtual"]' ) ,
202209 ) ;
210+ this . disconnectedButton = new ButtonState (
211+ toggleDisconnectedButton ,
212+ table . querySelectorAll < HTMLTableRowElement > ( 'tr[data-connected="disconnected"]' ) ,
213+ ) ;
203214 } catch ( err ) {
204215 if ( err instanceof TableStateError ) {
205216 // This class is useless for tables that don't have toggle buttons.
@@ -211,52 +222,6 @@ class TableState {
211222 }
212223 }
213224
214- /**
215- * Get the table caption's text.
216- */
217- private get captionText ( ) : string {
218- if ( this . caption !== null ) {
219- return this . caption . innerText ;
220- }
221- return '' ;
222- }
223-
224- /**
225- * Set the table caption's text.
226- */
227- private set captionText ( value : string ) {
228- if ( this . caption !== null ) {
229- this . caption . innerText = value ;
230- }
231- }
232-
233- /**
234- * Update the table caption's text based on the state of each toggle button.
235- */
236- private toggleCaption ( ) : void {
237- const showEnabled = this . enabledButton . buttonState === 'show' ;
238- const showDisabled = this . disabledButton . buttonState === 'show' ;
239- const showVirtual = this . virtualButton . buttonState === 'show' ;
240-
241- if ( showEnabled && ! showDisabled && ! showVirtual ) {
242- this . captionText = 'Showing Enabled Interfaces' ;
243- } else if ( showEnabled && showDisabled && ! showVirtual ) {
244- this . captionText = 'Showing Enabled & Disabled Interfaces' ;
245- } else if ( ! showEnabled && showDisabled && ! showVirtual ) {
246- this . captionText = 'Showing Disabled Interfaces' ;
247- } else if ( ! showEnabled && ! showDisabled && ! showVirtual ) {
248- this . captionText = 'Hiding Enabled, Disabled & Virtual Interfaces' ;
249- } else if ( ! showEnabled && ! showDisabled && showVirtual ) {
250- this . captionText = 'Showing Virtual Interfaces' ;
251- } else if ( showEnabled && ! showDisabled && showVirtual ) {
252- this . captionText = 'Showing Enabled & Virtual Interfaces' ;
253- } else if ( showEnabled && showDisabled && showVirtual ) {
254- this . captionText = 'Showing Enabled, Disabled & Virtual Interfaces' ;
255- } else {
256- this . captionText = '' ;
257- }
258- }
259-
260225 /**
261226 * When toggle buttons are clicked, reapply visability all rows and
262227 * pass the event to all button handlers
@@ -272,7 +237,7 @@ class TableState {
272237 instance . enabledButton . handleClick ( event ) ;
273238 instance . disabledButton . handleClick ( event ) ;
274239 instance . virtualButton . handleClick ( event ) ;
275- instance . toggleCaption ( ) ;
240+ instance . disconnectedButton . handleClick ( event ) ;
276241 }
277242}
278243
0 commit comments