@@ -54,95 +54,108 @@ export const NotebookCard = ({
5454 onRename,
5555 onDelete,
5656 t,
57- } : NotebookCardProps ) => (
58- < Card
59- className = { classes . notebookCard }
60- isSelectable
61- isClickable
62- onClick = { ( ) => onClick ( notebook ) }
63- >
64- < CardHeader
65- className = { classes . notebookCardHeader }
66- actions = { {
67- actions : (
68- < Dropdown
69- className = { classes . notebookDropdownMenu }
70- isOpen = { openNotebookMenuId === notebook . session_id }
71- popperProps = { {
72- position : 'end' ,
73- preventOverflow : true ,
74- } }
75- onOpenChange = { isOpen =>
76- setOpenNotebookMenuId ( isOpen ? notebook . session_id : null )
77- }
78- toggle = { toggleRef => (
79- < MenuToggle
80- ref = { toggleRef }
81- variant = "plain"
82- className = { classes . notebookMenuButton }
83- aria-label = { t ( 'aria.options.label' ) }
84- isExpanded = { openNotebookMenuId === notebook . session_id }
85- onClick = { event => {
86- event . stopPropagation ( ) ;
87- setOpenNotebookMenuId ( current =>
88- current === notebook . session_id
89- ? null
90- : notebook . session_id ,
91- ) ;
92- } }
93- >
94- < EllipsisVIcon />
95- </ MenuToggle >
96- ) }
97- >
98- < DropdownList className = { classes . notebookDropdownList } >
99- < DropdownItem
100- className = { classes . notebookDropdownItem }
101- onClick = { event => {
102- event . stopPropagation ( ) ;
103- onRename ( notebook . session_id ) ;
104- setOpenNotebookMenuId ( null ) ;
105- } }
106- >
107- { t ( 'notebooks.actions.rename' ) }
108- </ DropdownItem >
109- < DropdownItem
110- className = { classes . notebookDropdownItem }
111- onClick = { event => {
112- event . stopPropagation ( ) ;
113- onDelete ( notebook . session_id ) ;
114- setOpenNotebookMenuId ( null ) ;
115- } }
116- >
117- { t ( 'notebooks.actions.delete' ) }
118- </ DropdownItem >
119- </ DropdownList >
120- </ Dropdown >
121- ) ,
122- className : classes . notebookCardHeaderActions ,
123- } }
57+ } : NotebookCardProps ) => {
58+ const isMenuOpen = openNotebookMenuId === notebook . session_id ;
59+
60+ const handleCardKeyDown = ( e : React . KeyboardEvent ) => {
61+ if ( e . key === 'Enter' || e . key === ' ' ) {
62+ e . preventDefault ( ) ;
63+ onClick ( notebook ) ;
64+ }
65+ } ;
66+
67+ return (
68+ < Card
69+ className = { classes . notebookCard }
70+ component = "div"
71+ tabIndex = { 0 }
72+ aria-label = { t ( 'notebooks.card.openAria' as any , { name : notebook . name } ) }
73+ onClick = { ( ) => onClick ( notebook ) }
74+ onKeyDown = { handleCardKeyDown }
12475 >
125- < CardTitle className = { classes . notebookTitle } >
126- < CatalogIcon />
127- < Typography component = "span" className = { classes . notebookTitleText } >
128- { notebook . name }
129- </ Typography >
130- </ CardTitle >
131- </ CardHeader >
132- < div className = { classes . notebookCardDivider } />
133- < CardBody className = { classes . notebookCardBody } >
134- < div >
135- < div className = { classes . notebookDocuments } >
136- < Typography variant = "body2" >
137- { notebook . document_count ?? 0 } { t ( 'notebooks.documents' ) }
76+ < CardHeader
77+ className = { classes . notebookCardHeader }
78+ actions = { {
79+ actions : (
80+ < Dropdown
81+ className = { classes . notebookDropdownMenu }
82+ isOpen = { isMenuOpen }
83+ popperProps = { {
84+ position : 'end' ,
85+ preventOverflow : true ,
86+ } }
87+ onOpenChange = { isOpen =>
88+ setOpenNotebookMenuId ( isOpen ? notebook . session_id : null )
89+ }
90+ toggle = { toggleRef => (
91+ < MenuToggle
92+ ref = { toggleRef }
93+ variant = "plain"
94+ className = { classes . notebookMenuButton }
95+ aria-label = { t ( 'aria.options.label' ) }
96+ isExpanded = { isMenuOpen }
97+ onClick = { event => {
98+ event . stopPropagation ( ) ;
99+ setOpenNotebookMenuId ( current =>
100+ current === notebook . session_id
101+ ? null
102+ : notebook . session_id ,
103+ ) ;
104+ } }
105+ >
106+ < EllipsisVIcon />
107+ </ MenuToggle >
108+ ) }
109+ >
110+ < DropdownList className = { classes . notebookDropdownList } >
111+ < DropdownItem
112+ className = { classes . notebookDropdownItem }
113+ onClick = { event => {
114+ event . stopPropagation ( ) ;
115+ onRename ( notebook . session_id ) ;
116+ setOpenNotebookMenuId ( null ) ;
117+ } }
118+ >
119+ { t ( 'notebooks.actions.rename' ) }
120+ </ DropdownItem >
121+ < DropdownItem
122+ className = { classes . notebookDropdownItem }
123+ onClick = { event => {
124+ event . stopPropagation ( ) ;
125+ onDelete ( notebook . session_id ) ;
126+ setOpenNotebookMenuId ( null ) ;
127+ } }
128+ >
129+ { t ( 'notebooks.actions.delete' ) }
130+ </ DropdownItem >
131+ </ DropdownList >
132+ </ Dropdown >
133+ ) ,
134+ className : classes . notebookCardHeaderActions ,
135+ } }
136+ >
137+ < CardTitle className = { classes . notebookTitle } >
138+ < CatalogIcon />
139+ < Typography component = "span" className = { classes . notebookTitleText } >
140+ { notebook . name }
138141 </ Typography >
142+ </ CardTitle >
143+ </ CardHeader >
144+ < div className = { classes . notebookCardDivider } />
145+ < CardBody className = { classes . notebookCardBody } >
146+ < div >
147+ < div className = { classes . notebookDocuments } >
148+ < Typography variant = "body2" >
149+ { notebook . document_count ?? 0 } { t ( 'notebooks.documents' ) }
150+ </ Typography >
151+ </ div >
152+ < div className = { classes . notebookUpdated } >
153+ < Typography variant = "caption" >
154+ { formatUpdatedLabel ( notebook . updated_at , t ) }
155+ </ Typography >
156+ </ div >
139157 </ div >
140- < div className = { classes . notebookUpdated } >
141- < Typography variant = "caption" >
142- { formatUpdatedLabel ( notebook . updated_at , t ) }
143- </ Typography >
144- </ div >
145- </ div >
146- </ CardBody >
147- </ Card >
148- ) ;
158+ </ CardBody >
159+ </ Card >
160+ ) ;
161+ } ;
0 commit comments