@@ -30,8 +30,6 @@ import {
3030} from '../Components/TreeContext' ;
3131import { useHighlightHostInstance } from '../hooks' ;
3232import { StoreContext } from '../context' ;
33- import ButtonIcon from '../ButtonIcon' ;
34- import Button from '../Button' ;
3533
3634export function useChangeActivitySliceAction ( ) : (
3735 id : Element [ 'id' ] | null ,
@@ -118,6 +116,8 @@ export default function ActivityList({
118116 useTransition ( ) ;
119117 const changeActivitySliceAction = useChangeActivitySliceAction ( ) ;
120118
119+ const includeAllOption = activityID !== null ;
120+
121121 function handleKeyDown ( event : SyntheticKeyboardEvent ) {
122122 switch ( event . key ) {
123123 case 'Escape' :
@@ -128,15 +128,16 @@ export default function ActivityList({
128128 break ;
129129 case 'Enter' :
130130 case ' ' :
131- if ( inspectedElementID !== null ) {
132- startActivitySliceSelection ( ( ) => {
133- changeActivitySliceAction ( inspectedElementID ) ;
134- } ) ;
135- }
131+ startActivitySliceSelection ( ( ) => {
132+ changeActivitySliceAction ( inspectedElementID ) ;
133+ } ) ;
136134 event . preventDefault ( ) ;
137135 break ;
138136 case 'Home' :
139- treeDispatch ( { type : 'SELECT_ELEMENT_BY_ID' , payload : activities [ 0 ] . id } ) ;
137+ treeDispatch ( {
138+ type : 'SELECT_ELEMENT_BY_ID' ,
139+ payload : includeAllOption ? null : activities [ 0 ] . id ,
140+ } ) ;
140141 event . preventDefault ( ) ;
141142 break ;
142143 case 'End' :
@@ -150,30 +151,39 @@ export default function ActivityList({
150151 const currentIndex = activities . findIndex (
151152 activity => activity . id === selectedActivityID ,
152153 ) ;
153- if ( currentIndex !== undefined ) {
154- const nextIndex =
155- ( currentIndex + activities . length - 1 ) % activities . length ;
156-
157- treeDispatch ( {
158- type : 'SELECT_ELEMENT_BY_ID' ,
159- payload : activities [ nextIndex ] . id ,
160- } ) ;
154+ let nextIndex : number ;
155+ if ( currentIndex === - 1 ) {
156+ // Currently selecting "All", wrap around to last Activity.
157+ nextIndex = activities . length - 1 ;
158+ } else {
159+ nextIndex = currentIndex - 1 ;
160+ if ( ! includeAllOption ) {
161+ nextIndex = ( nextIndex + activities . length ) % activities . length ;
162+ }
161163 }
164+
165+ treeDispatch ( {
166+ type : 'SELECT_ELEMENT_BY_ID' ,
167+ payload : nextIndex === - 1 ? null : activities [ nextIndex ] . id ,
168+ } ) ;
162169 event . preventDefault ( ) ;
163170 break ;
164171 }
165172 case 'ArrowDown' : {
166173 const currentIndex = activities . findIndex (
167174 activity => activity . id === selectedActivityID ,
168175 ) ;
169- if ( currentIndex !== undefined ) {
170- const nextIndex = ( currentIndex + 1 ) % activities . length ;
171-
172- treeDispatch ( {
173- type : 'SELECT_ELEMENT_BY_ID' ,
174- payload : activities [ nextIndex ] . id ,
175- } ) ;
176+ let nextIndex : number ;
177+ if ( includeAllOption && currentIndex === activities . length - 1 ) {
178+ // Currently selecting last Activity, wrap around to "All".
179+ nextIndex = - 1 ;
180+ } else {
181+ nextIndex = ( currentIndex + 1 ) % activities . length ;
176182 }
183+ treeDispatch ( {
184+ type : 'SELECT_ELEMENT_BY_ID' ,
185+ payload : nextIndex === - 1 ? null : activities [ nextIndex ] . id ,
186+ } ) ;
177187 event . preventDefault ( ) ;
178188 break ;
179189 }
@@ -182,7 +192,7 @@ export default function ActivityList({
182192 }
183193 }
184194
185- function handleClick ( id : Element [ 'id' ] , event : SyntheticMouseEvent ) {
195+ function handleClick ( id : Element [ 'id' ] | null , event : SyntheticMouseEvent ) {
186196 event . preventDefault ( ) ;
187197 treeDispatch ( { type : 'SELECT_ELEMENT_BY_ID' , payload : id } ) ;
188198 }
@@ -195,25 +205,24 @@ export default function ActivityList({
195205
196206 return (
197207 < div className = { styles . ActivityListContaier } >
198- < div className = { styles . ActivityListHeader } >
199- { activityID !== null && (
200- // TODO: Obsolete once filtered Activities are included in this list.
201- < Button
202- onClick = { startActivitySliceSelection . bind (
203- null ,
204- changeActivitySliceAction . bind ( null , null ) ,
205- ) }
206- title = "Back to full tree view" >
207- < ButtonIcon type = "previous" />
208- </ Button >
209- ) }
210- </ div >
208+ < div className = { styles . ActivityListHeader } />
211209 < ol
212210 role = "listbox"
213211 className = { styles . ActivityListList }
214212 data-pending-activity-slice-selection = { isPendingActivitySliceSelection }
215213 tabIndex = { 0 }
216214 onKeyDown = { handleKeyDown } >
215+ { includeAllOption && (
216+ // TODO: Obsolete once filtered Activities are included in this list.
217+ < li
218+ role = "option"
219+ aria-selected = { null === selectedActivityID ? 'true' : 'false' }
220+ className = { styles . ActivityListItem }
221+ onClick = { handleClick . bind ( null , null ) }
222+ onDoubleClick = { handleDoubleClick } >
223+ All
224+ </ li >
225+ ) }
217226 { activities . map ( ( { id, depth} ) => {
218227 const activity = store . getElementByID ( id ) ;
219228 if ( activity === null ) {
@@ -244,7 +253,7 @@ export default function ActivityList({
244253 false ,
245254 ) }
246255 onPointerLeave = { clearHighlightHostInstance } >
247- { '\u00A0' . repeat ( depth ) + name }
256+ { '\u00A0' . repeat ( depth + ( includeAllOption ? 1 : 0 ) ) + name }
248257 </ li >
249258 ) ;
250259 } ) }
0 commit comments