Skip to content

Commit

Permalink
Extract common filters across families
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed Jan 17, 2025
1 parent f58cb07 commit 17791b4
Showing 1 changed file with 68 additions and 112 deletions.
180 changes: 68 additions & 112 deletions frontend/lib/models/filters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,133 +98,39 @@ Filters<Artefact> createEmptyArtefactFilters(FamilyName family) {

final emptyCharmFilters = Filters<Artefact>(
filters: [
Filter<Artefact>(
name: 'Assignee',
extractOption: (artefact) => artefact.assignee.name,
),
Filter<Artefact>(
name: 'Status',
extractOption: (artefact) => artefact.status.name,
),
Filter<Artefact>(
name: 'Due date',
extractOption: (artefact) {
final now = DateTime.now();
final dueDate = artefact.dueDate;

if (dueDate == null) return 'No due date';
if (dueDate.isBefore(now)) return 'Overdue';

final daysDueIn = now.difference(dueDate).inDays;
if (daysDueIn >= 7) return 'More than a week';
return 'Within a week';
},
),
Filter<Artefact>(
name: 'Risk',
extractOption: (artefact) => artefact.stage.name,
),
_artefactAssigneeFilter,
_artefactStatusFilter,
_artefactDueDateFilter,
_artefactRiskFilter,
],
);

final emptyDebFilters = Filters<Artefact>(
filters: [
Filter<Artefact>(
name: 'Assignee',
extractOption: (artefact) => artefact.assignee.name,
),
Filter<Artefact>(
name: 'Status',
extractOption: (artefact) => artefact.status.name,
),
Filter<Artefact>(
name: 'Due date',
extractOption: (artefact) {
final now = DateTime.now();
final dueDate = artefact.dueDate;

if (dueDate == null) return 'No due date';
if (dueDate.isBefore(now)) return 'Overdue';

final daysDueIn = now.difference(dueDate).inDays;
if (daysDueIn >= 7) return 'More than a week';
return 'Within a week';
},
),
Filter<Artefact>(
name: 'Series',
extractOption: (artefact) => artefact.series,
),
_artefactAssigneeFilter,
_artefactStatusFilter,
_artefactDueDateFilter,
_artefactSeriesFilter,
],
);

final emptySnapFilters = Filters<Artefact>(
filters: [
Filter<Artefact>(
name: 'Assignee',
extractOption: (artefact) => artefact.assignee.name,
),
Filter<Artefact>(
name: 'Status',
extractOption: (artefact) => artefact.status.name,
),
Filter<Artefact>(
name: 'Due date',
extractOption: (artefact) {
final now = DateTime.now();
final dueDate = artefact.dueDate;

if (dueDate == null) return 'No due date';
if (dueDate.isBefore(now)) return 'Overdue';

final daysDueIn = now.difference(dueDate).inDays;
if (daysDueIn >= 7) return 'More than a week';
return 'Within a week';
},
),
Filter<Artefact>(
name: 'Risk',
extractOption: (artefact) => artefact.stage.name,
),
_artefactAssigneeFilter,
_artefactStatusFilter,
_artefactDueDateFilter,
_artefactRiskFilter,
],
);

final emptyImageFilters = Filters<Artefact>(
filters: [
Filter<Artefact>(
name: 'OS type',
extractOption: (artefact) => artefact.os,
),
Filter<Artefact>(
name: 'Release',
extractOption: (artefact) => artefact.release,
),
Filter<Artefact>(
name: 'Owner',
extractOption: (artefact) => artefact.owner,
),
Filter<Artefact>(
name: 'Assignee',
extractOption: (artefact) => artefact.assignee.name,
),
Filter<Artefact>(
name: 'Status',
extractOption: (artefact) => artefact.status.name,
),
Filter<Artefact>(
name: 'Due date',
extractOption: (artefact) {
final now = DateTime.now();
final dueDate = artefact.dueDate;

if (dueDate == null) return 'No due date';
if (dueDate.isBefore(now)) return 'Overdue';

final daysDueIn = now.difference(dueDate).inDays;
if (daysDueIn >= 7) return 'More than a week';
return 'Within a week';
},
),
_artefactOSFilter,
_artefactReleaseFilter,
_artefactOwnerFilter,
_artefactAssigneeFilter,
_artefactStatusFilter,
_artefactDueDateFilter,
],
);

Expand All @@ -246,3 +152,53 @@ final emptyArtefactEnvironmentsFilters = Filters<ArtefactEnvironment>(
),
],
);

Filter<Artefact> _artefactAssigneeFilter = Filter<Artefact>(
name: 'Assignee',
extractOption: (artefact) => artefact.assignee.name,
);

Filter<Artefact> _artefactStatusFilter = Filter<Artefact>(
name: 'Status',
extractOption: (artefact) => artefact.status.name,
);

Filter<Artefact> _artefactDueDateFilter = Filter<Artefact>(
name: 'Due date',
extractOption: (artefact) {
final now = DateTime.now();
final dueDate = artefact.dueDate;

if (dueDate == null) return 'No due date';
if (dueDate.isBefore(now)) return 'Overdue';

final daysDueIn = now.difference(dueDate).inDays;
if (daysDueIn >= 7) return 'More than a week';
return 'Within a week';
},
);

Filter<Artefact> _artefactRiskFilter = Filter<Artefact>(
name: 'Risk',
extractOption: (artefact) => artefact.stage.name,
);

Filter<Artefact> _artefactSeriesFilter = Filter<Artefact>(
name: 'Series',
extractOption: (artefact) => artefact.series,
);

Filter<Artefact> _artefactOSFilter = Filter<Artefact>(
name: 'OS type',
extractOption: (artefact) => artefact.os,
);

Filter<Artefact> _artefactReleaseFilter = Filter<Artefact>(
name: 'Release',
extractOption: (artefact) => artefact.release,
);

Filter<Artefact> _artefactOwnerFilter = Filter<Artefact>(
name: 'Owner',
extractOption: (artefact) => artefact.owner,
);

0 comments on commit 17791b4

Please sign in to comment.