22// SPDX-License-Identifier: Apache-2.0
33import React , { ForwardedRef , forwardRef , useContext , useEffect , useRef , useState } from 'react' ;
44
5- import { Box , Button , Checkbox , Link , Modal , SpaceBetween } from '~components' ;
5+ import { Box , Button , Checkbox , Modal , SpaceBetween } from '~components' ;
66import Alert from '~components/alert' ;
77import Autosuggest , { AutosuggestProps } from '~components/autosuggest' ;
88import Header from '~components/header' ;
@@ -20,6 +20,7 @@ type PageContext = React.Context<
2020 AppContextType < {
2121 resizableColumns : boolean ;
2222 enableKeyboardNavigation : boolean ;
23+ expandableRows : boolean ;
2324 } >
2425> ;
2526
@@ -62,7 +63,27 @@ const columns: TableProps.ColumnDefinition<DistributionInfo>[] = [
6263 header : 'Distribution ID' ,
6364 sortingField : 'Id' ,
6465 width : 180 ,
65- cell : ( item : DistributionInfo ) => < Link href = { `/#/distributions/${ item . Id } ` } > { item . Id } </ Link > ,
66+ cell : ( item : DistributionInfo ) => item . Id ,
67+ editConfig : {
68+ ariaLabel : 'Distribution ID' ,
69+ editIconAriaLabel : 'editable' ,
70+ errorIconAriaLabel : 'Distribution ID Error' ,
71+ editingCell ( item , { currentValue, setValue } : TableProps . CellContext < string > ) {
72+ return (
73+ < Input
74+ autoFocus = { true }
75+ value = { currentValue ?? item . Id }
76+ onChange = { withDirtyState ( event => setValue ( event . detail . value ) ) }
77+ />
78+ ) ;
79+ } ,
80+ disabledReason ( item ) {
81+ if ( item . Id . includes ( 'E2' ) ) {
82+ return "You don't have the necessary permissions to edit this item." ;
83+ }
84+ return undefined ;
85+ } ,
86+ } ,
6687 } ,
6788 {
6889 id : 'DomainName' ,
@@ -222,7 +243,7 @@ const Demo = forwardRef(
222243 ) => {
223244 const [ items , setItems ] = useState ( initialItems ) ;
224245 const {
225- urlParams : { resizableColumns = true , enableKeyboardNavigation = false } ,
246+ urlParams : { resizableColumns = true , enableKeyboardNavigation = false , expandableRows = false } ,
226247 } = useContext ( AppContext as PageContext ) ;
227248
228249 const handleSubmit : TableProps . SubmitEditFunction < DistributionInfo > = async ( currentItem , column , newValue ) => {
@@ -273,14 +294,24 @@ const Demo = forwardRef(
273294 stickyHeader = { true }
274295 resizableColumns = { resizableColumns }
275296 enableKeyboardNavigation = { enableKeyboardNavigation }
297+ expandableRows = {
298+ expandableRows
299+ ? {
300+ getItemChildren : ( ) => [ ] ,
301+ isItemExpandable : ( ) => true ,
302+ expandedItems : [ ] ,
303+ onExpandableItemToggle : ( ) => { } ,
304+ }
305+ : undefined
306+ }
276307 />
277308 ) ;
278309 }
279310) ;
280311
281312export default function ( ) {
282313 const {
283- urlParams : { resizableColumns = true , enableKeyboardNavigation = false } ,
314+ urlParams : { resizableColumns = true , enableKeyboardNavigation = false , expandableRows = false } ,
284315 setUrlParams,
285316 } = useContext ( AppContext as PageContext ) ;
286317 const [ modalVisible , setModalVisible ] = useState ( false ) ;
@@ -321,6 +352,10 @@ export default function () {
321352 >
322353 Keyboard navigation
323354 </ Checkbox >
355+
356+ < Checkbox checked = { expandableRows } onChange = { event => setUrlParams ( { expandableRows : event . detail . checked } ) } >
357+ Expandable rows
358+ </ Checkbox >
324359 </ SpaceBetween >
325360
326361 < input data-testid = "focus" aria-label = "focus input" />
0 commit comments