import { updateCellValue , updatePopupPosition } from '../actionCreators' ; import { ActionType , EditingMode } from '../enums' ; import { Column , EditableCell } from '../models' ; import { PopupPosition } from '../Models/PopupPosition' ; import { DispatchFunc } from '../types' ; import { getCopyOfArrayAndAddItem } from './ArrayUtils' ; export const isEditableCell = ( editingMode , column , rowEditableCells ) : boolean => { if ( column . isEditable !== undefined ) { return column . isEditable ; } return ! ! rowEditableCells . find ( ( c ) => c . columnKey === column . key ) ; } ; export const getEditableCell = ( column , rowEditableCells ) : EditableCell | undefined => { if ( column . isEditable === false ) { return undefined ; } return rowEditableCells . find ( ( c ) => c . columnKey === column . key ) ; } ; export const addItemToEditableCells = ( item , editableCells ) : EditableCell [ ] => { return getCopyOfArrayAndAddItem ( item , editableCells ) ; } ; export const getCellEditorDispatchHandler = ( dispatch ) => { return ( action ) => { if ( action . type === ActionType . UpdateEditorValue ) { dispatch ( updateCellValue ( action . rowKeyValue , action . columnKey , action . value ) ) ; } else { dispatch ( action ) ; } } ; } ; export const removeItemFromEditableCells = ( item , editableCells ) : EditableCell [ ] => { return editableCells . filter ( ( c ) => c . columnKey !== item . columnKey || c . rowKeyValue !== item . rowKeyValue ) ; } ; export const checkPopupPosition = ( column , refToElement , dispatch ) => { if ( refToElement . current && column . isHeaderFilterPopupShown ) { const newPopupPosition = { x : refToElement . current . offsetLeft + ( refToElement . current . offsetParent as HTMLElement ) ?. offsetLeft , y : refToElement . current . offsetTop + ( refToElement . current . offsetParent as HTMLElement ) ?. offsetTop + refToElement . current . offsetHeight } ; if ( newPopupPosition . x !== column . headerFilterPopupPosition ?. x || newPopupPosition . y !== column . headerFilterPopupPosition ?. y ) { dispatch ( updatePopupPosition ( newPopupPosition ) ) ; } } } ;