Skip to content

When user press ctrl+a combination selection will be correct #78

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YaroslavOvdii
Copy link
Contributor

@YaroslavOvdii YaroslavOvdii commented Apr 9, 2020

@sofiiakvasnevska

Issue

https://github.com/Fliplet/fliplet-studio/issues/6108

Description

When user press ctrl+a combination selection will be correct

Screenshots/screencasts

https://share.getcloudapp.com/OAub0Y6m
https://share.getcloudapp.com/Z4uLbO18 - large data selection 60k rows ~100 cols

Backward compatibility

This change is fully backward compatible.

Reviewers

@upplabs-alex-levchenko @MaksymShokin

var cellsWithData = {
right: tableData[selectedCell.row][selectedCell.col + 1] !== null,
left: tableData[selectedCell.row][selectedCell.col - 1] !== null,
top: tableData[selectedCell.row - 1][selectedCell.col] !== null,
Copy link
Contributor

Choose a reason for hiding this comment

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

How are you making sure the row index for top and column index for left doesn't become -1? If it's -1, you'll end up comparing undefined with null. Will this cause any problem?

image


// If there is no true value in cellsWithData object we should select all table
if (countCellsWithData === 0) {
return {selectAll: true};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return {selectAll: true};
return { selectAll: true };


return dataAt;
if (tableData[selectedCell.row][selectedCell.col] !== null) {
return {cellWithData: true};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return {cellWithData: true};
return { cellWithData: true };

bottom: false,
all: false,
hasData: false
function nearestCellsWithData(selectedCell, tableData) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
function nearestCellsWithData(selectedCell, tableData) {
function getAdjacentCellsWithData(selectedCell, tableData) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the explanation, I'd call this adjacentCellHasData().

right: tableData[selectedCell.row][selectedCell.col + 1] !== null,
left: tableData[selectedCell.row][selectedCell.col - 1] !== null,
top: tableData[selectedCell.row - 1][selectedCell.col] !== null,
bottom: tableData[selectedCell.row + 1][selectedCell.col] !== null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a current: tableData[selectedCell.row][selectedCell.col] !== null, then just return the cellsWithData object. In fact, it doesn't really a var declared.

The reason for this is that the function will do exactly what the name suggests, and does not add logic on top to dictate what other functions should do with the information. The caller of this function can then decide under what scenario it should select all etc.

}
}
// Return false in the case when we need to select all table data
if (nearestDataAt.selectAll) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the for (var key in ...) logic from inside the getAdjacentCellsWithData() function to here.

* @returns {Array} - coordinats that needs to be selected. Example of the returned data: [[startRow, startCol, endRow, endCol]]
* @param {array} tableData - an array of data from the Handsontable library
* @param {int} startSearchFrom - index of the row/col from what we should start a search
* @param {int} colIndex - a not necessary option that tells us what we need to look, a row index or column index
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I right in suggesting this?

Suggested change
* @param {int} colIndex - a not necessary option that tells us what we need to look, a row index or column index
* @param {int} colIndex - (optional) when provided, the search is performed along the rows for the column specified


firstCol = firstCol || 0;
// If column index is not 0 it means that data what we need to select is in the next column
firstCol = firstCol === 0 ? firstCol : firstCol + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm reading this right, if firstCol is 1, you'd end up adding 1 to it and make it 2? What's the reason behind doing this?

Copy link
Contributor Author

@YaroslavOvdii YaroslavOvdii Apr 14, 2020

Choose a reason for hiding this comment

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

@tonytlwu it would be easier to explain on an example:
How selection will behave without this line.
https://share.getcloudapp.com/yAu2Pode

And with this line.
https://share.getcloudapp.com/WnuG1woX

This behavior occurs because of how we searching for the coordinates.
Our functions getStartIndex and getEndIndex are looking for the null in value of the cell to determine that there is no data in that cell. That is why they are returning an index of the cell with null, but we are interested to select only cells with data, that is why we adding to the row or cell 1 here.

This behavior occurs only in the situation I showed in the example when there is more that 1 data selection available in the data source.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could getStartIndex() and getEndIndex() change its output so that it returns the first/last cell with data instead of without data? It would match the function names better.

}
}
// If row index is not 0 it means that data what we need to select is in the next row
firstRow = firstRow === 0 ? firstRow : firstRow + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. Why are we turning 1 to 2 while 0 remains the same as 0?

}
}
lastCol = getEndIndex(tableData[firstRow], firstCol);
lastCol = lastCol < selectedCellPosition.col ? selectedCellPosition.col : lastCol;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
lastCol = lastCol < selectedCellPosition.col ? selectedCellPosition.col : lastCol;
lastCol = Math.min(lastCol, selectedCellPosition.col);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tonytlwu, in this case, we should use Math.max as well. Because Math.min will cause this issue https://share.getcloudapp.com/wbu0AeAb

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, indeed. It should be Math.max().

@tonytlwu
Copy link
Contributor

@YaroslavOvdii @sofiiakvasnevska What's happening with this? Looks like it's been put on pause. Can we continue with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants