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

Promote editor2 #2149

Merged
merged 37 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a5174a7
editor -> _old_editor
nstepien Sep 4, 2020
ae59dd1
fix types
nstepien Sep 4, 2020
bf3efe3
editor2 -> editor
nstepien Sep 4, 2020
dceddc6
rename file
nstepien Sep 4, 2020
0414273
Add wrapOldEditor
nstepien Sep 4, 2020
6e9728a
mark onRowsUpdate as deprecated
nstepien Sep 4, 2020
fa1d9f6
working edits
nstepien Sep 4, 2020
e2ffd7d
simplify
nstepien Sep 4, 2020
5d044e5
changelog
nstepien Sep 9, 2020
756247e
Merge branch 'canary' into promote-editor
nstepien Oct 27, 2020
e4872d8
_old_editor -> oldEditor
nstepien Oct 27, 2020
ecceae8
fix lint
nstepien Oct 27, 2020
bdf76e8
Merge branch 'canary' into promote-editor
nstepien Oct 27, 2020
69fe5f7
start nuking the old editor code
nstepien Oct 27, 2020
499d3ff
progress
nstepien Oct 27, 2020
7ffa81d
accidentally removed this line
nstepien Oct 27, 2020
bfcc7cf
Use SimpleTextEditor
nstepien Oct 27, 2020
b4c55ae
Merge branch 'canary' into promote-editor
nstepien Oct 27, 2020
e20008e
autofocus SimpleTextEditor
nstepien Oct 28, 2020
4f461cd
rename class, remove css prefixes
nstepien Oct 28, 2020
a059c5f
tweak editor styles
nstepien Oct 28, 2020
caa952c
rm TextEditor
nstepien Oct 28, 2020
b05f9cc
-Simple
nstepien Oct 28, 2020
f44415d
Update AllFeatures/DropDownEditor
nstepien Oct 28, 2020
ca26f22
rm EditorPortal
nstepien Oct 28, 2020
abfdfa2
rm src/editors/index.ts
nstepien Oct 28, 2020
2cad2ee
rm SimpleCellFormatter
nstepien Oct 28, 2020
4a94906
update useClickOutside, rm a couple extraneous exports
nstepien Oct 28, 2020
af555a6
fix type issue
nstepien Oct 28, 2020
4676d85
inline wrapRefs
nstepien Oct 28, 2020
26d7079
tweaks
nstepien Oct 28, 2020
9717ec4
remove `deprecated` for onRowsUpdate
nstepien Oct 28, 2020
3eba88c
TextEditor: autofocus+select
nstepien Oct 28, 2020
a03625f
rm 1 type assertion
nstepien Oct 29, 2020
b3977ae
Merge branch 'canary' into promote-editor
nstepien Oct 29, 2020
dcd8181
update canEdit
nstepien Oct 29, 2020
16d229e
update onRowsUpdate doc
nstepien Oct 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
- `column.minWidth`
- `column.maxWidth`
- `column.headerCellClass`
- `column.editor2`
- `column.editor`
- New API
- `column.editorOptions`
- More info in [#2102](https://github.com/adazzle/react-data-grid/pull/2102)
- `column.groupFormatter`
Expand Down
10 changes: 2 additions & 8 deletions src/Cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mount } from 'enzyme';

import Cell from './Cell';
import helpers, { Row } from './test/GridPropHelpers';
import { SimpleCellFormatter } from './formatters';
import { ValueFormatter } from './formatters';
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

import { CalculatedColumn, CellRendererProps, FormatterProps } from './types';
import EventBus from './EventBus';

Expand All @@ -15,7 +15,7 @@ const defaultColumn: CalculatedColumn<Row> = {
left: 0,
resizable: false,
sortable: false,
formatter: SimpleCellFormatter
formatter: ValueFormatter
};

const testProps: CellRendererProps<Row> = {
Expand All @@ -34,12 +34,6 @@ const renderComponent = (extraProps?: PropsWithChildren<Partial<CellRendererProp
};

describe('Cell', () => {
it('should render a SimpleCellFormatter with value', () => {
const wrapper = renderComponent();
const formatter = wrapper.find(SimpleCellFormatter);
expect(formatter.props().row[defaultColumn.key]).toStrictEqual('Wicklow');
});

it('should render a custom formatter when specified on column', () => {
const CustomFormatter = (props: FormatterProps) => <div>{props.row[props.column.key]}</div>;

Expand Down
23 changes: 10 additions & 13 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ export interface DataGridProps<R, SR = unknown> extends SharedDivProps {
/**
* Callback called whenever row data is updated
* When editing is enabled, this callback will be called for the following scenarios
* 1. Using the supplied editor of the column. The default editor is the SimpleTextEditor.
* 2. Copy/pasting the value from one cell to another <kbd>CTRL</kbd>+<kbd>C</kbd>, <kbd>CTRL</kbd>+<kbd>V</kbd>
* 3. Update multiple cells by dragging the fill handle of a cell up or down to a destination cell.
* 4. Update all cells under a given cell by double clicking the cell's fill handle.
* 1. Copy/pasting the value from one cell to another <kbd>CTRL</kbd>+<kbd>C</kbd>, <kbd>CTRL</kbd>+<kbd>V</kbd>
* 2. Update multiple cells by dragging the fill handle of a cell up or down to a destination cell.
* 3. Update all cells under a given cell by double clicking the cell's fill handle.
*/
onRowsUpdate?: <E extends RowsUpdateEvent>(event: E) => void;
onRowsChange?: (rows: R[]) => void;
Expand Down Expand Up @@ -481,9 +480,9 @@ function DataGrid<R, SR>({
closeEditor();
}

function commitEditor2Changes() {
function commitEditorChanges() {
if (
columns[selectedPosition.idx]?.editor2 === undefined
columns[selectedPosition.idx]?.editor === undefined
|| selectedPosition.mode === 'SELECT'
|| selectedPosition.row === selectedPosition.originalRow) {
return;
Expand Down Expand Up @@ -535,7 +534,7 @@ function DataGrid<R, SR>({
if (selectedPosition.mode === 'EDIT') {
if (key === 'Enter') {
// Custom editors can listen for the event and stop propagation to prevent commit
commitEditor2Changes();
commitEditorChanges();
closeEditor();
}
return;
Expand Down Expand Up @@ -626,7 +625,7 @@ function DataGrid<R, SR>({

function handleOnClose(commitChanges?: boolean) {
if (commitChanges) {
commitEditor2Changes();
commitEditorChanges();
}
closeEditor();
}
Expand All @@ -645,7 +644,7 @@ function DataGrid<R, SR>({

function selectCell(position: Position, enableEditor = false): void {
if (!isCellWithinBounds(position)) return;
commitEditor2Changes();
commitEditorChanges();

if (enableEditor && isCellEditable(position)) {
const row = rows[position.rowIdx] as R;
Expand Down Expand Up @@ -802,7 +801,7 @@ function DataGrid<R, SR>({
onCommit: handleCommit,
onCommitCancel: closeEditor
},
editor2Props: {
editorProps: {
rowHeight,
row: selectedPosition.row,
onRowChange: handleRowChange,
Expand Down Expand Up @@ -963,6 +962,4 @@ function DataGrid<R, SR>({
);
}

export default forwardRef(
DataGrid as React.ForwardRefRenderFunction<DataGridHandle>
) as <R, SR = unknown>(props: DataGridProps<R, SR> & React.RefAttributes<DataGridHandle>) => JSX.Element;
export default forwardRef(DataGrid) as <R, SR = unknown>(props: DataGridProps<R, SR> & React.RefAttributes<DataGridHandle>) => JSX.Element;
56 changes: 15 additions & 41 deletions src/EditCell.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import React, { forwardRef, useState, useCallback } from 'react';
import React, { useState, useCallback } from 'react';
import clsx from 'clsx';

import { EditorContainer, EditorContainer2, EditorPortal } from './editors';
import { CellRendererProps, SharedEditorContainerProps, SharedEditor2Props } from './types';
import { useCombinedRefs } from './hooks';
import EditorContainer from './editors/EditorContainer';
import { CellRendererProps, SharedEditorContainerProps, SharedEditorProps } from './types';

type SharedCellRendererProps<R, SR> = Pick<CellRendererProps<R, SR>,
| 'rowIdx'
| 'row'
| 'column'
| 'rowIdx'
| 'row'
| 'column'
>;

interface EditCellRendererProps<R, SR> extends SharedCellRendererProps<R, SR>, Omit<React.HTMLAttributes<HTMLDivElement>, 'style' | 'children'> {
editorPortalTarget: Element;
editorContainerProps: SharedEditorContainerProps;
editor2Props: SharedEditor2Props<R>;
editorProps: SharedEditorProps<R>;
}

function EditCell<R, SR>({
export default function EditCell<R, SR>({
className,
column,
row,
rowIdx,
editorPortalTarget,
editorContainerProps,
editor2Props,
editorProps,
onKeyDown,
...props
}: EditCellRendererProps<R, SR>, ref: React.Ref<HTMLDivElement>) {
}: EditCellRendererProps<R, SR>) {
const [dimensions, setDimensions] = useState<{ left: number; top: number } | null>(null);

const cellRef = useCallback(node => {
Expand Down Expand Up @@ -57,47 +56,24 @@ function EditCell<R, SR>({
const gridLeft = left + docLeft;
const gridTop = top + docTop;

if (column.editor2 !== undefined) {
return (
<EditorContainer2
{...editor2Props}
editorPortalTarget={editorPortalTarget}
rowIdx={rowIdx}
column={column}
left={gridLeft}
top={gridTop}
/>
);
}

const editor = (
<EditorContainer<R, SR>
{...editorContainerProps}
return (
<EditorContainer
{...editorProps}
editorPortalTarget={editorPortalTarget}
rowIdx={rowIdx}
row={row}
column={column}
left={gridLeft}
top={gridTop}
/>
);

if (column.editorOptions?.createPortal !== false) {
return (
<EditorPortal target={editorPortalTarget}>
{editor}
</EditorPortal>
);
}

return editor;
}

return (
<div
role="gridcell"
aria-colindex={column.idx + 1} // aria-colindex is 1-based
aria-selected
ref={useCombinedRefs(cellRef, ref)}
ref={cellRef}
className={className}
style={{
width: column.width,
Expand All @@ -110,5 +86,3 @@ function EditCell<R, SR>({
</div>
);
}

export default forwardRef(EditCell) as <R, SR = unknown>(props: EditCellRendererProps<R, SR> & React.RefAttributes<HTMLDivElement>) => JSX.Element;
2 changes: 1 addition & 1 deletion src/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Row<R, SR = unknown>({
onKeyDown={selectedCellProps.onKeyDown}
editorPortalTarget={selectedCellProps.editorPortalTarget}
editorContainerProps={selectedCellProps.editorContainerProps}
editor2Props={selectedCellProps.editor2Props}
editorProps={selectedCellProps.editorProps}
/>
);
}
Expand Down
34 changes: 0 additions & 34 deletions src/editors/Editor2Container.tsx

This file was deleted.

Loading