import { PropertyProxy , ProxifiedMapProperty } from '@fluid-experimental/property-proxy' ; import { SetProperty , ContainerProperty } from '@fluid-experimental/property-properties' ; import * as React from 'react' ; import { IEditableValueCellProps } from './EditableValueCell' ; import { BooleanView } from './PropertyViews/Boolean' ; import { EnumView } from './PropertyViews/Enum' ; import { NumberView } from './PropertyViews/Number' ; import { StringView } from './PropertyViews/String' ; import { Utils } from './typeUtils' ; function onInlineEditEnd ( val , props ) { const { rowData } = props ; if ( rowData . typeid !== 'Uint64' && rowData . typeid !== 'Int64' && rowData . typeid !== 'String' ) { val = ! isNaN ( + val ) ? + val : val ; } const proxiedParent = PropertyProxy . proxify ( rowData . parent ! ) ; const parentContext = rowData . parent ! . getContext ( ) ; try { if ( parentContext === 'single' || parentContext === 'array' ) { if ( Utils . isEnumArrayProperty ( rowData . parent ! ) ) { ( rowData . parent ! as any ) . set ( parseInt ( rowData . name , 10 ) , val ) ; } else { proxiedParent [ rowData . name ] = val ; } } else if ( parentContext === 'map' ) { ( proxiedParent as unknown as ProxifiedMapProperty ) . set ( rowData . name , val ) ; } else if ( parentContext === 'set' ) { ( rowData . parent ! as SetProperty ) . get ( rowData . name ) ! . value = val ; } rowData . parent ! . getRoot ( ) . getWorkspace ( ) ! . commit ( ) ; } catch ( error ) { console . error ( error ) ; } } export const Field = ( { rowData , ... restProps } ) => { const parent = rowData . parent ! ; let typeid = rowData . typeid ; let property ; try { property = ( rowData . parent ! as ContainerProperty ) . get ( rowData . name ) ; } catch { typeid = 'Reference' ; } if ( Utils . isEnumProperty ( property ) || Utils . isEnumArrayProperty ( parent ! ) ) { typeid = 'enum' ; } const ViewComponent = typeToViewMap . hasOwnProperty ( typeid ) ? typeToViewMap [ typeid ] : StringView ; return ( < ViewComponent onSubmit = { onInlineEditEnd } rowData = { rowData } { ... restProps } />); } ; const typeToViewMap = { Bool : BooleanView , String : StringView , enum : EnumView , Float32 : NumberView , Float64 : NumberView , Int16 : NumberView , Int32 : NumberView , Int64 : NumberView , Int8 : NumberView , Uint16 : NumberView , Uint32 : NumberView , Uint64 : NumberView , Uint8 : NumberView } ;