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 3 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
6 changes: 2 additions & 4 deletions src/Cell.tsx
Expand Up @@ -16,6 +16,7 @@ function Cell<R, SR>({
row,
rowIdx,
eventBus,
dragHandle,
onRowClick,
onClick,
onDoubleClick,
Expand Down Expand Up @@ -86,10 +87,7 @@ function Cell<R, SR>({
isRowSelected={isRowSelected}
onRowSelectionChange={onRowSelectionChange}
/>
{isSelected && (
// if (!enableCellDragAndDrop || !isCellEditable(selectedPosition) || selectedPosition.mode === 'EDIT') return null;
<div className="rdg-cell-drag-handle" />
)}
{dragHandle}
</div>
);
}
Expand Down
24 changes: 13 additions & 11 deletions src/DataGrid.tsx
Expand Up @@ -469,11 +469,7 @@ function DataGrid<R, K extends keyof R, SR>({
}
}

function handleMouseDown(event: React.MouseEvent<HTMLDivElement>) {
if (!enableCellDragAndDrop) return;
const { target } = event;
if (!(target instanceof HTMLDivElement && target.className === 'rdg-cell-drag-handle')) return;

function handleMouseDown() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should check that we initiate dragging with the primary mouse button, so we can at least avoid a re-render.

setDragging(true);
window.addEventListener('mouseover', onMouseover);
window.addEventListener('mouseup', onMouseup);
Expand All @@ -493,10 +489,6 @@ function DataGrid<R, K extends keyof R, SR>({
}

function handleDoubleClick(event: React.MouseEvent<HTMLDivElement>) {
if (!enableCellDragAndDrop) return;
const { target } = event;
if (!(target instanceof HTMLDivElement && target.className === 'rdg-cell-drag-handle')) return;

event.stopPropagation();

const column = columns[selectedPosition.idx];
Expand Down Expand Up @@ -639,6 +631,17 @@ function DataGrid<R, K extends keyof R, SR>({
);
}

function getDragHandle() {
if (!enableCellDragAndDrop || !isCellEditable(selectedPosition) || selectedPosition.mode === 'EDIT') return null;
return (
<div
className="rdg-cell-drag-handle"
onMouseDown={handleMouseDown}
onDoubleClick={handleDoubleClick}
/>
);
}

function getViewportRows() {
const rowElements = [];

Expand Down Expand Up @@ -670,6 +673,7 @@ function DataGrid<R, K extends keyof R, SR>({
rowClass={rowClass}
top={rowIdx * rowHeight + totalHeaderHeight}
setDraggedOverRowIdx={isDragging ? setDraggedOverRowIdx : undefined}
dragHandle={selectedPosition.rowIdx === rowIdx ? getDragHandle() : undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks weird combining this condition with the checks inside the getDragHandle function at ln#635. I think it will be better for maintenance to either add a checking outside like this

dragHandle={displayDragHandle() ? getDragHandle() : undefined} // remove the checks from getDragHandle

or completely move all conditions inside getDragHandle like this

function getDragHandle() {
    if (selectedPosition.rowIdx !== rowIdx || !enableCellDragAndDrop || !isCellEditable(selectedPosition) || selectedPosition.mode === 'EDIT') return null;
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is fine. We need to add dragHandle only on the row that has the selected position. I will have to change the signature otherwise getDragHandle(rowIdx). I am happy to revisit after code cleanup

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Qi. We can also do return instead of return null in getDragHandle.

/>
);
}
Expand Down Expand Up @@ -724,8 +728,6 @@ function DataGrid<R, K extends keyof R, SR>({
<div
className={clsx({ 'rdg-viewport-dragging': isDragging })}
onKeyDown={handleKeyDown}
onMouseDown={handleMouseDown}
onDoubleClick={handleDoubleClick}
>
{viewportWidth > 0 && getViewportRows()}
{getEditorContainer()}
amanmahajan7 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 2 additions & 0 deletions src/Row.tsx
Expand Up @@ -17,6 +17,7 @@ function Row<R, SR = unknown>({
draggedOverCellIdx,
row,
viewportColumns,
dragHandle,
onRowClick,
rowClass,
setDraggedOverRowIdx,
Expand Down Expand Up @@ -55,6 +56,7 @@ function Row<R, SR = unknown>({
isDraggedOver={draggedOverCellIdx === column.idx}
isRowSelected={isRowSelected}
eventBus={eventBus}
dragHandle={selectedCellIdx === column.idx ? dragHandle : undefined}
onRowClick={onRowClick}
/>
))}
Expand Down
10 changes: 2 additions & 8 deletions src/common/types.ts
Expand Up @@ -56,14 +56,6 @@ export interface Position {
rowIdx: number;
}

export interface Dimension {
width: number;
height: number;
top: number;
left: number;
zIndex: number;
}

export interface Editor<TValue = never> {
getInputNode: () => Element | Text | undefined | null;
getValue: () => TValue;
Expand Down Expand Up @@ -113,6 +105,7 @@ export interface CellRendererProps<TRow, TSummaryRow = unknown> extends Omit<Rea
isCopied: boolean;
isDraggedOver: boolean;
eventBus: EventBus;
dragHandle: React.ReactNode;
onRowClick?: (rowIdx: number, row: TRow, column: CalculatedColumn<TRow, TSummaryRow>) => void;
}

Expand All @@ -128,6 +121,7 @@ export interface RowRendererProps<TRow, TSummaryRow = unknown> extends Omit<Reac
isRowSelected: boolean;
eventBus: EventBus;
top: number;
dragHandle: React.ReactNode;
onRowClick?: (rowIdx: number, row: TRow, column: CalculatedColumn<TRow, TSummaryRow>) => void;
rowClass?: (row: TRow) => string | undefined;
setDraggedOverRowIdx?: (overRowIdx: number) => void;
Expand Down
26 changes: 1 addition & 25 deletions src/utils/selectedCellUtils.ts
@@ -1,30 +1,6 @@
import { CellNavigationMode } from '../common/enums';
import { canEdit } from './columnUtils';
import { CalculatedColumn, Position, Dimension } from '../common/types';

// above unfrozen cells, below frozen cells
const zCellMask = 1;
// above frozen cells, below header/filter/summary rows
const zFrozenCellMask = 2;

interface GetSelectedDimensionsOpts<R, SR> {
selectedPosition: Position;
columns: readonly CalculatedColumn<R, SR>[];
rowHeight: number;
scrollLeft: number;
}

export function getSelectedDimensions<R, SR>({ selectedPosition: { idx, rowIdx }, columns, rowHeight, scrollLeft }: GetSelectedDimensionsOpts<R, SR>): Dimension {
if (idx < 0) {
return { width: 0, left: 0, top: 0, height: rowHeight, zIndex: 1 };
}
const column = columns[idx];
const { width } = column;
const left = column.frozen ? column.left + scrollLeft : column.left;
const top = rowIdx * rowHeight;
const zIndex = column.frozen ? zFrozenCellMask : zCellMask;
return { width, left, top, height: rowHeight, zIndex };
}
import { CalculatedColumn, Position } from '../common/types';

interface IsSelectedCellEditableOpts<R, SR> {
selectedPosition: Position;
Expand Down
4 changes: 2 additions & 2 deletions stories/demos/AllFeatures.less
@@ -1,8 +1,8 @@
.highlight {
.highlight .rdg-cell {
background-color: #9370DB;
color: white;
}

.rdg-row.highlight:hover {
.highlight:hover .rdg-cell {
background-color: #800080;
}