Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove InteractionMask #2061

Merged
merged 43 commits into from Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1b998a3
Initial commit
amanmahajan7 Jun 23, 2020
2eaa5a0
Copy Tab logic
amanmahajan7 Jun 23, 2020
b085271
Initial cell drag implementation
Jun 24, 2020
1bc4eca
Initial cell editing implementation
Jun 26, 2020
54de1df
Move editorContainer to the DataGrid component
Jun 26, 2020
85d95a2
Update src/utils/selectedCellUtils.ts
amanmahajan7 Jun 26, 2020
66b0dfc
Cleanup
Jun 26, 2020
526fa66
Remove masks components
Jun 26, 2020
0600a9f
Cancel copying
Jun 26, 2020
a596653
Remove edit check
Jun 26, 2020
888dd59
Cleanup
Jun 29, 2020
362414e
Address comments
Jun 29, 2020
36d0ce9
Move DragHandle to the parent DataGrid component
Jun 29, 2020
ff7d61e
Do not paste on the copied cell
Jun 29, 2020
34f11c1
Remove unnecessary class
Jun 29, 2020
c024ae7
Fix copy/dragged cell styles
Jun 30, 2020
f9b9151
Address dragging issues
nstepien Jun 30, 2020
5e355ed
Pass down dragHandle component
Jun 30, 2020
c4b6ad7
Fix styles
Jun 30, 2020
787ab44
Remove unused function
Jun 30, 2020
9404987
Move getNextPosition to selectedCellUtils
Jul 1, 2020
1b8c3a5
Use ref to get the latest draggedOverRowIdx
Jul 1, 2020
a9a2613
Revert EventBus changes
Jul 1, 2020
336c793
Fix type errors
Jul 1, 2020
ac2c630
Specify return type
Jul 2, 2020
57ec91d
Update changelog
Jul 2, 2020
0504d29
Add selectedCellProps props
Jul 6, 2020
3cc29bd
Remove isMouted check
Jul 6, 2020
de4248a
Add the row containing the selected cell if not included in the verti…
Jul 6, 2020
3acd681
Update src/DataGrid.tsx
amanmahajan7 Jul 6, 2020
1c53773
Merge branch 'canary' into am-remove-masks
Jul 7, 2020
689c727
Address comments
Jul 7, 2020
a4beb50
Set focus in useLayoutEffect and set tabIndex to -1
Jul 8, 2020
86ca94b
setFocus -> shouldFocus
Jul 8, 2020
ba7d7e3
Address comments
Jul 8, 2020
5a5b9fe
Cleanup
Jul 8, 2020
a4ecddf
use event.buttons
Jul 8, 2020
eda56d0
Better focus handling
Jul 13, 2020
9011686
Remove comments
Jul 13, 2020
421d265
Check valid selection
Jul 14, 2020
6ffb06a
Even better focus implementation
Jul 14, 2020
4eb1100
Cleanup handleKeyDown usage
Jul 15, 2020
c8cb194
Remove drag cell borders
Jul 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Cell.test.tsx
Expand Up @@ -22,7 +22,9 @@ const testProps: CellRendererProps<Row> = {
lastFrozenColumnIndex: -1,
row: { id: 1, description: 'Wicklow' },
isRowSelected: false,
eventBus: new EventBus()
eventBus: new EventBus(),
isCopied: false,
isDraggedOver: false
};

const renderComponent = (extraProps?: PropsWithChildren<Partial<CellRendererProps<Row>>>) => {
Expand Down Expand Up @@ -60,7 +62,9 @@ describe('Cell', () => {
lastFrozenColumnIndex: -1,
row: helpers.rows[11],
isRowSelected: false,
eventBus: new EventBus()
eventBus: new EventBus(),
isCopied: false,
isDraggedOver: false
};

it('passes classname property', () => {
Expand Down
105 changes: 77 additions & 28 deletions src/Cell.tsx
@@ -1,77 +1,126 @@
import React, { forwardRef, memo } from 'react';
import React, { forwardRef, memo, useLayoutEffect, useRef } from 'react';
import clsx from 'clsx';

import { EditorContainer, EditorPortal } from './editors';
import { CellRendererProps } from './common/types';
import { preventDefault, wrapEvent } from './utils';
import { wrapEvent } from './utils';
import { useCombinedRefs } from './hooks';

function Cell<R, SR>({
className,
column,
isCopied,
isDraggedOver,
isRowSelected,
lastFrozenColumnIndex,
row,
rowIdx,
eventBus,
selectedCellProps,
onRowClick,
onKeyDown,
onClick,
onDoubleClick,
onContextMenu,
onDragOver,
...props
}: CellRendererProps<R, SR>, ref: React.Ref<HTMLDivElement>) {
const cellRef = useRef<HTMLDivElement>(null);
const isSelected = selectedCellProps !== undefined;
const isEditing = selectedCellProps?.mode === 'EDIT';
const shouldFocus = isSelected && !isEditing;

const { cellClass } = column;
className = clsx(
'rdg-cell',
{
'rdg-cell-frozen': column.frozen,
'rdg-cell-frozen-last': column.idx === lastFrozenColumnIndex,
'rdg-cell-selected': isSelected,
'rdg-cell-copied': isCopied,
'rdg-cell-dragged-over': isDraggedOver
},
typeof cellClass === 'function' ? cellClass(row) : cellClass,
className
);

useLayoutEffect(() => {
if (shouldFocus) {
cellRef.current?.focus();
amanmahajan7 marked this conversation as resolved.
Show resolved Hide resolved
}
}, [shouldFocus]);

function selectCell(openEditor?: boolean) {
eventBus.dispatch('SELECT_CELL', { idx: column.idx, rowIdx }, openEditor);
}

function handleCellClick() {
qili26 marked this conversation as resolved.
Show resolved Hide resolved
function handleClick() {
selectCell();
onRowClick?.(rowIdx, row, column);
}

function handleCellContextMenu() {
function handleContextMenu() {
selectCell();
}

function handleCellDoubleClick() {
function handleDoubleClick() {
selectCell(true);
}

function onRowSelectionChange(checked: boolean, isShiftClick: boolean) {
eventBus.dispatch('SELECT_ROW', { rowIdx, checked, isShiftClick });
}

const { cellClass } = column;
className = clsx(
'rdg-cell',
{
'rdg-cell-frozen': column.frozen,
'rdg-cell-frozen-last': column.idx === lastFrozenColumnIndex
},
typeof cellClass === 'function' ? cellClass(row) : cellClass,
className
);
function getCellContent() {
if (selectedCellProps && selectedCellProps.mode === 'EDIT') {
const { editorPortalTarget, ...editorProps } = selectedCellProps.editorContainerProps;
const { left, top } = cellRef.current!.getBoundingClientRect();

return (
<EditorPortal target={editorPortalTarget}>
<EditorContainer<R, SR>
{...editorProps}
rowIdx={rowIdx}
row={row}
column={column}
left={left}
top={top}
/>
</EditorPortal>
);
}

return (
<>
<column.formatter
column={column}
rowIdx={rowIdx}
row={row}
isRowSelected={isRowSelected}
onRowSelectionChange={onRowSelectionChange}
/>
{selectedCellProps?.dragHandleProps && (
<div className="rdg-cell-drag-handle" {...selectedCellProps.dragHandleProps} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I don't know if is a good UI. The drag handle looks weird to me when it is expending inside.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is difficult to style it from what I can tell, @nstepien is there a way to make it look like the old drag handle?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't make it overflow without degrading performance, we could use a portal but then it wouldn't be in perfect sync when scrolling.

)}
</>
);
}

return (
<div
ref={ref}
ref={useCombinedRefs(cellRef, ref)}
className={className}
tabIndex={isSelected ? -1 : undefined}
style={{
width: column.width,
left: column.left
}}
onClick={wrapEvent(handleCellClick, onClick)}
onDoubleClick={wrapEvent(handleCellDoubleClick, onDoubleClick)}
onContextMenu={wrapEvent(handleCellContextMenu, onContextMenu)}
onDragOver={wrapEvent(preventDefault, onDragOver)}
onKeyDown={selectedCellProps?.onKeyDown ? wrapEvent(selectedCellProps.onKeyDown, onKeyDown) : onKeyDown}
onClick={isEditing ? onClick : wrapEvent(handleClick, onClick)}
onDoubleClick={isEditing ? onDoubleClick : wrapEvent(handleDoubleClick, onDoubleClick)}
onContextMenu={isEditing ? onContextMenu : wrapEvent(handleContextMenu, onContextMenu)}
{...props}
>
<column.formatter
column={column}
rowIdx={rowIdx}
row={row}
isRowSelected={isRowSelected}
onRowSelectionChange={onRowSelectionChange}
/>
{getCellContent()}
</div>
);
}
Expand Down