00a3c8ca2b
* Change to using arrow functions Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Add lint rule --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { useContext } from 'react';
|
|
import { useSetRecoilState } from 'recoil';
|
|
|
|
import { contextMenuIsOpenState } from '@/ui/context-menu/states/contextMenuIsOpenState';
|
|
import { contextMenuPositionState } from '@/ui/context-menu/states/contextMenuPositionState';
|
|
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
|
|
|
import { ColumnContext } from '../contexts/ColumnContext';
|
|
import { ColumnIndexContext } from '../contexts/ColumnIndexContext';
|
|
import { GenericEditableCell } from '../editable-cell/components/GenericEditableCell';
|
|
import { useCurrentRowSelected } from '../hooks/useCurrentRowSelected';
|
|
|
|
export const EntityTableCell = ({ cellIndex }: { cellIndex: number }) => {
|
|
const setContextMenuPosition = useSetRecoilState(contextMenuPositionState);
|
|
const setContextMenuOpenState = useSetRecoilState(contextMenuIsOpenState);
|
|
|
|
const { setCurrentRowSelected } = useCurrentRowSelected();
|
|
|
|
const handleContextMenu = (event: React.MouseEvent) => {
|
|
event.preventDefault();
|
|
setCurrentRowSelected(true);
|
|
setContextMenuPosition({
|
|
x: event.clientX,
|
|
y: event.clientY,
|
|
});
|
|
setContextMenuOpenState(true);
|
|
};
|
|
|
|
const columnDefinition = useContext(ColumnContext);
|
|
|
|
if (!columnDefinition) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<RecoilScope>
|
|
<ColumnIndexContext.Provider value={cellIndex}>
|
|
<td onContextMenu={(event) => handleContextMenu(event)}>
|
|
<GenericEditableCell columnDefinition={columnDefinition} />
|
|
</td>
|
|
</ColumnIndexContext.Provider>
|
|
</RecoilScope>
|
|
);
|
|
};
|