Skip to content

Commit

Permalink
fix(#432): fallback to id sorting if predicates provide equal result
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesvedder committed Aug 15, 2023
1 parent 3ad137a commit e52bcac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion core/lib/src/models/tables/study.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ enum ResultSharing {
}

@JsonSerializable()
class Study extends SupabaseObjectFunctions<Study> {
class Study extends SupabaseObjectFunctions<Study> implements Comparable<Study> {
static const String tableName = 'study';

@override
Expand Down Expand Up @@ -246,4 +246,9 @@ class Study extends SupabaseObjectFunctions<Study> {
String toString() {
return 'Study{id: $id, title: $title, description: $description, userId: $userId, participation: $participation, resultSharing: $resultSharing, contact: $contact, iconName: $iconName, published: $published, questionnaire: $questionnaire, eligibilityCriteria: $eligibilityCriteria, consent: $consent, interventions: $interventions, observations: $observations, schedule: $schedule, reportSpecification: $reportSpecification, results: $results, collaboratorEmails: $collaboratorEmails, registryPublished: $registryPublished, participantCount: $participantCount, endedCount: $endedCount, activeSubjectCount: $activeSubjectCount, missedDays: $missedDays, repo: $repo, invites: $invites, participants: $participants, participantsProgress: $participantsProgress, createdAt: $createdAt}';
}

@override
int compareTo(Study other) {
return id.compareTo(other.id);
}
}
18 changes: 15 additions & 3 deletions designer_v2/lib/common_views/standard_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,22 @@ class _StandardTableState<T> extends State<StandardTable<T>> {
}
}

int _sortLogic(T a, T b, {required int columnIndex, required bool? sortAscending}) {
int _sortLogic(T a, T b, {required int columnIndex, required bool? sortAscending, bool? useSortPredicate}) {
final sortPredicate = widget.sortColumnPredicates;
if (sortPredicate != null && sortPredicate[columnIndex] != null) {
return sortAscending ?? true ? sortPredicate[columnIndex]!(a, b) : sortPredicate[columnIndex]!(b, a);
if (useSortPredicate != null && useSortPredicate &&
sortPredicate != null && sortPredicate[columnIndex] != null
) {
final int res;
if (sortAscending ?? true) {
res = sortPredicate[columnIndex]!(a, b);
} else {
res = sortPredicate[columnIndex]!(b, a);
}
if (res == 0) {
// Fallback to default sorting algorithm
return _sortLogic(a, b, columnIndex: columnIndex, sortAscending: sortAscending, useSortPredicate: false);
}
return res;
} else if (a is Comparable && b is Comparable) {
// If sortPredicate is not provided, use default comparison logic
return sortAscending ?? true ? Comparable.compare(a, b) : Comparable.compare(b, a);
Expand Down

0 comments on commit e52bcac

Please sign in to comment.