Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Issue 491#498

Merged
alinastarkov merged 30 commits into
masterfrom
491Bugs
Jul 16, 2019
Merged

Issue 491#498
alinastarkov merged 30 commits into
masterfrom
491Bugs

Conversation

@alinastarkov

Copy link
Copy Markdown
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
Comment thread src/dash-table/utils/actions.js Outdated
@@ -1,12 +1,20 @@
import * as R from 'ramda';
import merge from 'ramda/es/merge';

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 :)

Comment thread src/dash-table/utils/actions.js Outdated
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
Copy Markdown
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.

Comment thread src/dash-table/utils/actions.js Outdated
cloneColumn = Object.assign({}, column, {name: newColumnNames});
}
const transformedColumns = columns.map(col => {
if (((typeof column.name === 'string') || (column.name instanceof String)) && col.id === column.id) {

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

Copy link
Copy Markdown
Contributor

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.

Comment thread src/dash-table/utils/actions.js Outdated
maxLength = row.length;
}}, array);
return maxLength;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread src/dash-table/utils/actions.js Outdated

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

Copy link
Copy Markdown
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 { }.

Comment thread src/dash-table/utils/actions.js Outdated
} else {
return col;
}
});

Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread src/dash-table/utils/actions.js Outdated
/* 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
Copy Markdown
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.

Comment thread src/dash-table/utils/actions.js Outdated

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

Copy link
Copy Markdown
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.

Comment thread src/dash-table/utils/actions.js Outdated
}
const transformedColumns = columns.slice(0);
const columnIndex = columns.findIndex(col => col.id === column.id);
transformedColumns[columnIndex] = cloneColumn;

Copy link
Copy Markdown
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

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

Copy link
Copy Markdown
Contributor

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