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

Issue 491 #498

Merged
merged 30 commits into from
Jul 16, 2019
Merged

Issue 491 #498

merged 30 commits into from
Jul 16, 2019

Conversation

alinastarkov
Copy link
Contributor

Fixes #491

@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 11, 2019 20:46 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 11, 2019 20:47 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 11, 2019 21:01 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 11, 2019 21:07 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 12, 2019 01:54 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 12, 2019 01:56 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 12, 2019 01:56 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 12, 2019 15:01 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 15, 2019 14:31 Inactive
@@ -1,12 +1,20 @@
import * as R from 'ramda';
import merge from 'ramda/es/merge';
Copy link
Contributor

Choose a reason for hiding this comment

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

Use R.merge instead

Copy link
Collaborator

Choose a reason for hiding this comment

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

R.merge is deprecated - mergeRight is its more explicit replacement.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, that makes for a lot of R.merge usage to be updated in the table repo later :)

const columnHeaders = columns.map(col => col.name);
const maxLength = findMaxLength(columnHeaders);
const newColumnNames = Array(maxLength).fill(column.name);
cloneColumn = Object.assign({}, column, {name: newColumnNames});
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to transform into an array if there is only one header row.

cloneColumn = Object.assign({}, column, {name: newColumnNames});
}
const transformedColumns = columns.map(col => {
if (((typeof column.name === 'string') || (column.name instanceof String)) && col.id === column.id) {
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet Jul 15, 2019

Choose a reason for hiding this comment

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

instanceof String is only useful if we use the new String(...), which we do not (enforced
through tslint no-construct rule), typeof should be enough.

maxLength = row.length;
}}, array);
return maxLength;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -53,23 +61,36 @@ export const clearSelection = {
selected_cells: []
};

export function editColumnName(column, columns, headerRowIndex) {
export function changeColumnHeader(column, columns, headerRowIndex, mergeDuplicateHeaders, newColumnName) {
let cloneColumn = Object.assign({}, column);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use R.merge or R.mergeAll for consistency. The nice advantage is that it treats all arguments as immutables -- so you do not have to add a target { }.

} else {
return col;
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of a map you can:

newColumns = columns.slice(0) // shallow clone of array
newColumns[newColumns.indexOf(column)] = newColumn // replace the modified entry

});
});

describe.only(`edit headers, mode=${AppMode.Typed}`, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a file for header tests is warranted.
Don't forget to remove the .only :)

@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 15, 2019 18:04 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 15, 2019 18:07 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 15, 2019 18:10 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 15, 2019 18:16 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 15, 2019 19:28 Inactive
/* eslint no-alert: 0 */
const newColumnName = window.prompt('Enter a new column name');
let newColumns = R.clone(columns);
let newColumns = R.clone(transformedColumns);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the deep clone (https://ramdajs.com/docs/#clone) is necessary here. It will actually make multiple memoizeOne functions fail their test on their column argument, forcing a significant portion of the table to re-evaluate itself.

@@ -53,23 +53,31 @@ export const clearSelection = {
selected_cells: []
};

export function editColumnName(column, columns, headerRowIndex) {
export function changeColumnHeader(column, columns, headerRowIndex, mergeDuplicateHeaders, newColumnName) {
let cloneColumn = R.mergeRight({}, column);
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no need to clone the column if it's not modified in the if below. R.set below (https://github.com/plotly/dash-table/pull/498/files#diff-4102a065e79334d16000051ec35189f7R75) will treat the entire data structure as immutable in any case.

}
const transformedColumns = columns.slice(0);
const columnIndex = columns.findIndex(col => col.id === column.id);
transformedColumns[columnIndex] = cloneColumn;
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, because of how R.set works, it's unnecessary to clone columns if the affected column above is not modified.

@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 16, 2019 15:11 Inactive
@chriddyp chriddyp temporarily deployed to dash-table-review-pr-498 July 16, 2019 15:21 Inactive
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet left a comment

Choose a reason for hiding this comment

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

💃

@alinastarkov alinastarkov merged commit af71ecd into master Jul 16, 2019
@alinastarkov alinastarkov deleted the 491Bugs branch July 16, 2019 17:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing one header cell changes all the header cells on the left
4 participants