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

numeric sort for component edits #1639

Merged
merged 2 commits into from
May 1, 2017
Merged

numeric sort for component edits #1639

merged 2 commits into from
May 1, 2017

Conversation

alexcjohnson
Copy link
Collaborator

Not the first time I've been bitten by the default sort being alphabetical even if the items are numbers... This made a bug where if you tried to add annotations 9 and 10 in a single relayout, it would try to add 10 first but it couldn't do that because 9 didn't exist yet (or if it did, 10 would get inserted in the array in the wrong places) and similar problems on deletion.

@etpinard OK?

@@ -101,7 +101,7 @@ exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np,
return true;
}

var componentNums = Object.keys(edits).map(Number).sort(),
var componentNums = Object.keys(edits).map(Number).sort(function(a, b) { return a - b; }),
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to use Lib.sorterAsc to DRY it up 🌴

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah thanks - should've guessed we'd have that already exposed somewhere!

@@ -223,6 +223,33 @@ describe('annotations relayout', function() {
.then(done);
});

it('should sort correctly when index>10', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice test!

@etpinard
Copy link
Contributor

etpinard commented May 1, 2017

💃 after that little bit of 🌴

@etpinard
Copy link
Contributor

etpinard commented May 1, 2017

💃

@alexcjohnson alexcjohnson merged commit 2bac6ef into master May 1, 2017
@alexcjohnson alexcjohnson deleted the component-sort branch May 1, 2017 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants