Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

3.1 props fixes #112

Merged
merged 5 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,8 @@ Derived properties allow the component to expose complex state that can be usefu
* (CLASS) dash-freeze-top
* (CLASS) dash-spreadsheet
* (CLASS) dash-spreadsheet-container
* (CLASS) dash-spreadsheet-inner
* (CLASS) dash-spreadsheet-inner

## RC3 - Miscellaneous fixes for pagination, virtual df and viewport df

Issue: https://github.com/plotly/dash-table/pull/112
4 changes: 2 additions & 2 deletions dash_table/bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dash_table/demo.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_table/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-table",
"version": "3.1.0rc2",
"version": "3.1.0rc3",
"description": "Dash table",
"main": "build/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-table",
"version": "3.1.0rc2",
"version": "3.1.0rc3",
"description": "Dash table",
"main": "build/index.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions src/dash-table/components/FilterFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface IFilterOptions {

export default class FilterFactory {
private readonly handlers = new Map();
private readonly ops = new Map<ColumnId, string>();
private readonly ops = new Map<string, string>();

private get props() {
return this.propsFn();
Expand All @@ -40,9 +40,9 @@ export default class FilterFactory {
const value = ev.target.value.trim();

if (value && value.length) {
ops.set(columnId, value);
ops.set(columnId.toString(), value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

turns out a map behaves just like a normal object.. using a number as a key causes a bunch of weird behaviors.. coerce into a string first!

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm interesting! What kind of behaviours did you run into? Maybe a silly question, but if you're using a string here, could you not use a regular Object instead of a Map?

} else {
ops.delete(columnId);
ops.delete(columnId.toString());
}

setFilter(R.map(
Expand Down Expand Up @@ -142,13 +142,13 @@ export default class FilterFactory {
}

private isFragmentValidOrNull(columnId: ColumnId) {
const op = this.ops.get(columnId);
const op = this.ops.get(columnId.toString());

return !op || !op.trim().length || this.isFragmentValid(columnId);
}

private isFragmentValid(columnId: ColumnId) {
const op = this.ops.get(columnId);
const op = this.ops.get(columnId.toString());

const lexerResult = lexer(`${columnId} ${op}`);
const syntaxerResult = syntaxer(lexerResult);
Expand Down Expand Up @@ -182,7 +182,7 @@ export default class FilterFactory {
isValid={this.isFragmentValidOrNull(column.id)}
property={column.id}
setFilter={this.getEventHandler(this.onChange, column.id, this.ops, setFilter)}
value={this.ops.get(column.id)}
value={this.ops.get(column.id.toString())}
/>);
}, columns) :
[(<AdvancedFilter
Expand Down
3 changes: 2 additions & 1 deletion src/dash-table/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class Table extends Component<PropsWithDefaultsAndDerived> {
super(props);

this.controlled = this.getControlledProps(this.props);
this.updateDerivedProps();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sure the derived props are calculated prior to first render

}

componentWillReceiveProps(nextProps: PropsWithDefaultsAndDerived) {
Expand Down Expand Up @@ -84,7 +85,7 @@ export default class Table extends Component<PropsWithDefaultsAndDerived> {
pagination_mode,
pagination_settings,
setProps,
viewport.dataframe
virtual.dataframe
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The paginator should have been using the virtual_df all along

);

const visibleColumns = this.visibleColumns(columns);
Expand Down
23 changes: 9 additions & 14 deletions src/dash-table/components/Table/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export enum FilteringType {
Basic = 'basic'
}

export interface IDerivedDataframe {
dataframe: Dataframe;
indices: Indices;
}

export type ActiveCell = CellCoordinates | [];
export type CellCoordinates = [number, number];
export type ColumnId = string | number;
Expand Down Expand Up @@ -142,15 +147,9 @@ export type ControlledTableProps = PropsWithDefaults & {
setProps: SetProps;

columns: VisibleColumns;
paginator: IPaginator
viewport: {
dataframe: Dataframe,
indices: Indices
},
virtual: {
dataframe: Dataframe,
indices: Indices
}
paginator: IPaginator;
viewport: IDerivedDataframe;
virtual: IDerivedDataframe;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Iterative typing improvements

};

export interface ICellFactoryOptions {
Expand All @@ -173,9 +172,5 @@ export interface ICellFactoryOptions {
selected_cell: SelectedCells;
selected_rows: number[];
setProps: SetProps;

viewport: {
dataframe: Dataframe,
indices: Indices
};
viewport: IDerivedDataframe;
}
20 changes: 14 additions & 6 deletions src/dash-table/derived/paginator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as R from 'ramda';

import { memoizeOneFactory } from 'core/memoizer';

import {
Expand Down Expand Up @@ -35,25 +37,31 @@ function getBackEndPagination(
function getFrontEndPagination(
pagination_settings: IPaginationSettings,
setProps: SetProps,
virtual_dataframe: Dataframe
dataframe: Dataframe
) {
return {
loadNext: () => {
let maxPageIndex = Math.floor(virtual_dataframe.length / pagination_settings.page_size);
let maxPageIndex = Math.floor(dataframe.length / pagination_settings.page_size);

if (pagination_settings.current_page >= maxPageIndex) {
return;
}

pagination_settings.current_page++;
pagination_settings = R.merge(pagination_settings, {
current_page: pagination_settings.current_page + 1
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pagination_settings is immutable, create a new one and setprops! -- otherwise render is not triggered on table


setProps({ pagination_settings });
},
loadPrevious: () => {
if (pagination_settings.current_page <= 0) {
return;
}

pagination_settings.current_page--;
pagination_settings = R.merge(pagination_settings, {
current_page: pagination_settings.current_page - 1
});

setProps({ pagination_settings });
}
};
Expand All @@ -70,14 +78,14 @@ const getter = (
pagination_mode: PaginationMode,
pagination_settings: IPaginationSettings,
setProps: SetProps,
virtual_dataframe: Dataframe
dataframe: Dataframe
): IPaginator => {
switch (pagination_mode) {
case false:
return getNoPagination();
case true:
case 'fe':
return getFrontEndPagination(pagination_settings, setProps, virtual_dataframe);
return getFrontEndPagination(pagination_settings, setProps, dataframe);
case 'be':
return getBackEndPagination(pagination_settings, setProps);
default:
Expand Down
16 changes: 6 additions & 10 deletions src/dash-table/derived/viewportDataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ import {
Dataframe,
Indices,
IPaginationSettings,
PaginationMode
PaginationMode,
IDerivedDataframe
} from 'dash-table/components/Table/props';

interface IResult {
dataframe: Dataframe;
indices: Indices;
}

function getNoPagination(dataframe: Dataframe, indices: Indices): IResult {
function getNoPagination(dataframe: Dataframe, indices: Indices): IDerivedDataframe {
return { dataframe, indices };
}

function getFrontEndPagination(settings: IPaginationSettings, dataframe: Dataframe, indices: Indices): IResult {
function getFrontEndPagination(settings: IPaginationSettings, dataframe: Dataframe, indices: Indices): IDerivedDataframe {
let currentPage = Math.min(
settings.current_page,
Math.floor(dataframe.length / settings.page_size)
Expand All @@ -34,7 +30,7 @@ function getFrontEndPagination(settings: IPaginationSettings, dataframe: Datafra
};
}

function getBackEndPagination(dataframe: Dataframe, indices: Indices): IResult {
function getBackEndPagination(dataframe: Dataframe, indices: Indices): IDerivedDataframe {
return { dataframe, indices };
}

Expand All @@ -43,7 +39,7 @@ const getter = (
pagination_settings: IPaginationSettings,
dataframe: Dataframe,
indices: Indices
): IResult => {
): IDerivedDataframe => {
switch (pagination_mode) {
case false:
return getNoPagination(dataframe, indices);
Expand Down
9 changes: 2 additions & 7 deletions src/dash-table/derived/virtualDataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,19 @@ import SyntaxTree from 'core/syntax-tree';
import {
Dataframe,
Datum,
Indices,
Filtering,
IDerivedDataframe,
Sorting
} from 'dash-table/components/Table/props';

interface IResult {
dataframe: Dataframe;
indices: Indices;
}

const getter = (
dataframe: Dataframe,
filtering: Filtering,
filtering_settings: string,
sorting: Sorting,
sorting_settings: SortSettings = [],
sorting_treat_empty_string_as_none: boolean
): IResult => {
): IDerivedDataframe => {
const map = new Map<Datum, number>();
R.addIndex(R.forEach)((datum, index) => {
map.set(datum, index);
Expand Down
51 changes: 51 additions & 0 deletions tests/e2e/cypress/integration/unit/derivedViewport_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as R from 'ramda';

import derivedViewportDataframe from 'dash-table/derived/viewportDataframe';

describe.only('derived viewport', () => {
const viewportDataframe = derivedViewportDataframe();

describe('virtual dataframe <= page size', () => {
describe('with no pagination', () => {
it('returns entire dataframe', () => {
const result = viewportDataframe(
false,
{ displayed_pages: 1, current_page: 0, page_size: 250 },
R.map(() => { }, R.range(0, 5)),
R.range(0, 5)
);

expect(result.dataframe.length).to.equal(5);
expect(result.indices.length).to.equal(5);
});
});

describe('with fe pagination', () => {
it('returns entire dataframe', () => {
const result = viewportDataframe(
'fe',
{ displayed_pages: 1, current_page: 0, page_size: 250 },
R.map(() => { }, R.range(0, 5)),
R.range(0, 5)
);

expect(result.dataframe.length).to.equal(5);
expect(result.indices.length).to.equal(5);
});
});

describe('with be pagination', () => {
it('returns entire dataframe', () => {
const result = viewportDataframe(
'be',
{ displayed_pages: 1, current_page: 0, page_size: 250 },
R.map(() => { }, R.range(0, 5)),
R.range(0, 5)
);

expect(result.dataframe.length).to.equal(5);
expect(result.indices.length).to.equal(5);
});
});
});
});