Skip to content

Commit

Permalink
Preserve pagination after actions which trigger an update of the grid (
Browse files Browse the repository at this point in the history
…#5411)

* Adapt the GridState interface to separate sorting and pagination.

This adds `getRowsBefore` methods, counterpart to the existing pagination
methods, so that we can do efficient and correct pagination, solving #33 and #570

* Revert "(I #2638) Feature to Goto a page directly (#2639)"

Go back to simply displaying a range of row numbers, because
that will enable a solution for #33, #570 and #572.
This reverts commit d7aaac2.

* Do not move back to the first page when applying an action which refreshes the grid.

Instead, the current page is refreshed.
This closes #33, closes #570, closes #572.

* Specify which actions preserve row and record ids

This lets us preserve pagination only when it is guaranteed to show the same
part of the data after the operation.

* Make paging user-editable like before

* Adapt cypress tests
  • Loading branch information
wetneb committed Apr 24, 2024
1 parent 23cf4e8 commit 12589c5
Show file tree
Hide file tree
Showing 30 changed files with 700 additions and 202 deletions.
Expand Up @@ -309,7 +309,7 @@ Refine.DatabaseImportController.prototype._getPreviewData = function(callback, n
result.rowModel = data;
callback(result);
},
"jsonp"
"json"
);
},
"json"
Expand Down
Expand Up @@ -60,7 +60,7 @@ PerformEditsDialog.launch = function(logged_in_username, max_severity) {
tag: WikibaseManager.getSelectedWikibaseTagTemplate(),
maxEditsPerMinute: WikibaseManager.getSelectedWikibaseMaxEditsPerMinute()
},
{ includeEngine: true, cellsChanged: true, columnStatsChanged: true },
{ includeEngine: true, cellsChanged: true, columnStatsChanged: true, rowIdsPreserved: true, recordIdsPreserved: true },
{ onDone: function() { dismiss(); } }
);
};
Expand Down
6 changes: 4 additions & 2 deletions main/src/com/google/refine/browsing/Engine.java
Expand Up @@ -46,6 +46,7 @@ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
import com.google.refine.browsing.util.ConjunctiveFilteredRows;
import com.google.refine.browsing.util.FilteredRecordsAsFilteredRows;
import com.google.refine.model.Project;
import com.google.refine.model.Record;
import com.google.refine.model.Row;

/**
Expand Down Expand Up @@ -105,7 +106,7 @@ public void accept(Project project, RowVisitor visitor) {
int c = project.rows.size();
for (int rowIndex = 0; rowIndex < c; rowIndex++) {
Row row = project.rows.get(rowIndex);
if (visitor.visit(project, rowIndex, row)) {
if (visitor.visit(project, rowIndex, rowIndex, row)) {
break;
}
}
Expand Down Expand Up @@ -150,7 +151,8 @@ public void accept(Project project, RecordVisitor visitor) {

int c = project.recordModel.getRecordCount();
for (int r = 0; r < c; r++) {
visitor.visit(project, project.recordModel.getRecord(r));
Record record = project.recordModel.getRecord(r);
visitor.visit(project, record.fromRowIndex, record);
}
} finally {
visitor.end(project);
Expand Down
20 changes: 20 additions & 0 deletions main/src/com/google/refine/browsing/RecordVisitor.java
Expand Up @@ -44,9 +44,29 @@ public interface RecordVisitor {

public void start(Project project); // called before any visit() call

/**
* @deprecated use {@link #visit(Project, int, Record)}
*/
@Deprecated
public boolean visit(
Project project,
Record record);

/**
* @param project
* project the record is part of
* @param sortedStartRowIndex
* zero-based sorted index of the first row in the record
* @param record
* the record to visit
* @return true to abort visitation early - no further visit calls will be made
*/
public default boolean visit(
Project project,
int sortedStartRowIndex,
Record record) {
return visit(project, record);
}

public void end(Project project); // called after all visit() calls
}
25 changes: 23 additions & 2 deletions main/src/com/google/refine/browsing/RowVisitor.java
Expand Up @@ -51,18 +51,39 @@ public interface RowVisitor {

/**
* @param project
* project
* project the row is part of
* @param rowIndex
* zero-based row index
* zero-based row index (unaffected by a temporary sort)
* @param row
* row
* @return true to abort visitation early - no further visit calls will be made
* @deprecated use {@link #visit(Project, int, int, Row)}
*/
@Deprecated
public boolean visit(
Project project,
int rowIndex,
Row row);

/**
* @param project
* project the row is part of
* @param rowIndex
* zero-based row index (unaffected by a temporary sort)
* @param sortedRowIndex
* zero-based row index in the sorted view (or equal to rowIndex if no temporary sorting is in place)
* @param row
* row
* @return true to abort visitation early - no further visit calls will be made
*/
public default boolean visit(
Project project,
int rowIndex,
int sortedRowIndex,
Row row) {
return visit(project, rowIndex, row);
}

/**
* Called after all visit() calls.
*
Expand Down
Expand Up @@ -150,7 +150,7 @@ public boolean visit(Project project, int rowIndex, Row row) {
@Override
public boolean visit(Project project, Record record) {
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
visit(project, r, project.rows.get(r));
visit(project, r, r, project.rows.get(r));
}
return false;
}
Expand Down
Expand Up @@ -62,7 +62,7 @@ public void accept(Project project, RecordVisitor visitor) {
for (int r = 0; r < c; r++) {
Record record = project.recordModel.getRecord(r);
if (matchRecord(project, record)) {
if (visitor.visit(project, record)) {
if (visitor.visit(project, record.fromRowIndex, record)) {
return;
}
}
Expand Down
Expand Up @@ -74,7 +74,7 @@ public void accept(Project project, RowVisitor visitor) {
}

protected boolean visitRow(Project project, RowVisitor visitor, int rowIndex, Row row) {
return visitor.visit(project, rowIndex, row);
return visitor.visit(project, rowIndex, rowIndex, row);
}

protected boolean matchRow(Project project, int rowIndex, Row row) {
Expand Down
Expand Up @@ -59,7 +59,7 @@ public void end(Project project) {
@Override
public boolean visit(Project project, Record record) {
for (int r = record.fromRowIndex; r < record.toRowIndex; r++) {
if (_rowVisitor.visit(project, r, project.rows.get(r))) {
if (_rowVisitor.visit(project, r, r, project.rows.get(r))) {
return true;
}
}
Expand Down

0 comments on commit 12589c5

Please sign in to comment.