Skip to content

Commit

Permalink
fix: use reactive multiselect widget for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesvedder committed Jul 3, 2023
1 parent 3183a27 commit 6356e4e
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 324 deletions.
6 changes: 4 additions & 2 deletions core/lib/src/models/tables/study.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ class Study extends SupabaseObjectFunctions<Study> {
final study = _$StudyFromJson(json);
final List? studyTags = json['study_tags'] as List?;
if (studyTags != null) {
study.studyTags = studyTags.map(
study.studyTags = studyTags
.map(
(json) => StudyTag.fromTag(
studyId: study.id,
tag: Tag.fromJson(json as Map<String, dynamic>),
),
).toList();
)
.toList();
}

final List? repo = json['repo'] as List?;
Expand Down
154 changes: 0 additions & 154 deletions designer_v2/lib/common_views/multi_select.dart

This file was deleted.

4 changes: 1 addition & 3 deletions designer_v2/lib/common_views/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ class SearchState extends State<Search> {
backgroundColor: MaterialStateProperty.resolveWith((states) {
return ThemeConfig.sidesheetBackgroundColor(theme).withOpacity(0.5);
}),
)
);
));
}

@override
Expand All @@ -72,5 +71,4 @@ class SearchState extends State<Search> {

class SearchController {
late void Function(String text) setText;

}
6 changes: 2 additions & 4 deletions designer_v2/lib/features/dashboard/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
Search(
searchController: controller.searchController,
hintText: tr.search,
onQueryChanged: (query) => controller.filterStudies(query)
),
onQueryChanged: (query) => controller.filterStudies(query)),
],
),
const SizedBox(height: 24.0), // spacing between body elements
Expand Down Expand Up @@ -106,8 +105,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
),
)
: const SizedBox.shrink(),
)
);
));
}
return const SizedBox.shrink();
}),
Expand Down
3 changes: 1 addition & 2 deletions designer_v2/lib/features/dashboard/dashboard_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class DashboardState extends Equatable {
AsyncValue<List<Study>> visibleStudies(Set<String> pinnedStudies, String query) {
return studies.when(
data: (studies) {
List<Study> updatedStudies =
studiesFilter.apply(studies: studies, user: currentUser).toList();
List<Study> updatedStudies = studiesFilter.apply(studies: studies, user: currentUser).toList();
updatedStudies = filter(studiesToFilter: updatedStudies);
updatedStudies = sort(pinnedStudies: pinnedStudies, studiesToSort: updatedStudies);
return AsyncValue.data(updatedStudies);
Expand Down
42 changes: 14 additions & 28 deletions designer_v2/lib/features/dashboard/studies_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class StudiesTable extends StatelessWidget {
tr.studies_list_header_participants_active,
tr.studies_list_header_participants_completed,
];
final int maxLength = headers.fold(
0, (max, element) => max > element.length ? max : element.length);
final int maxLength = headers.fold(0, (max, element) => max > element.length ? max : element.length);
final double statsCellWidth = maxLength * 11;

return StandardTable<Study>(
Expand All @@ -50,20 +49,17 @@ class StudiesTable extends StatelessWidget {
),
StandardTableColumn(
label: tr.studies_list_header_title,
columnWidth:
const MaxColumnWidth(FixedColumnWidth(200), FlexColumnWidth(2.4)),
columnWidth: const MaxColumnWidth(FixedColumnWidth(200), FlexColumnWidth(2.4)),
sortable: true,
),
StandardTableColumn(
label: tr.studies_list_header_status,
columnWidth: const MaxColumnWidth(
FixedColumnWidth(90), IntrinsicColumnWidth()),
columnWidth: const MaxColumnWidth(FixedColumnWidth(90), IntrinsicColumnWidth()),
sortable: true,
),
StandardTableColumn(
label: tr.studies_list_header_participation,
columnWidth: const MaxColumnWidth(
FixedColumnWidth(130), IntrinsicColumnWidth()),
columnWidth: const MaxColumnWidth(FixedColumnWidth(130), IntrinsicColumnWidth()),
sortable: true,
),
StandardTableColumn(
Expand All @@ -73,20 +69,17 @@ class StudiesTable extends StatelessWidget {
),
StandardTableColumn(
label: tr.studies_list_header_participants_enrolled,
columnWidth: MaxColumnWidth(
FixedColumnWidth(statsCellWidth), const IntrinsicColumnWidth()),
columnWidth: MaxColumnWidth(FixedColumnWidth(statsCellWidth), const IntrinsicColumnWidth()),
sortable: true,
),
StandardTableColumn(
label: tr.studies_list_header_participants_active,
columnWidth: MaxColumnWidth(
FixedColumnWidth(statsCellWidth), const IntrinsicColumnWidth()),
columnWidth: MaxColumnWidth(FixedColumnWidth(statsCellWidth), const IntrinsicColumnWidth()),
sortable: true,
),
StandardTableColumn(
label: tr.studies_list_header_participants_completed,
columnWidth: MaxColumnWidth(
FixedColumnWidth(statsCellWidth), const IntrinsicColumnWidth()),
columnWidth: MaxColumnWidth(FixedColumnWidth(statsCellWidth), const IntrinsicColumnWidth()),
sortable: true,
),
],
Expand Down Expand Up @@ -115,19 +108,16 @@ class StudiesTable extends StatelessWidget {
(Study a, Study b) => 0, // do not sort pin icon
(Study a, Study b) => a.title!.compareTo(b.title!),
(Study a, Study b) => a.status.index.compareTo(b.status.index),
(Study a, Study b) =>
a.participation.index.compareTo(b.participation.index),
(Study a, Study b) => a.participation.index.compareTo(b.participation.index),
(Study a, Study b) => a.createdAt!.compareTo(b.createdAt!),
(Study a, Study b) => a.participantCount.compareTo(b.participantCount),
(Study a, Study b) =>
a.activeSubjectCount.compareTo(b.activeSubjectCount),
(Study a, Study b) => a.activeSubjectCount.compareTo(b.activeSubjectCount),
(Study a, Study b) => a.endedCount.compareTo(b.endedCount),
];
return predicates;
}

List<Widget> _buildRow(
BuildContext context, Study item, int rowIdx, Set<MaterialState> states) {
List<Widget> _buildRow(BuildContext context, Study item, int rowIdx, Set<MaterialState> states) {
final theme = Theme.of(context);

TextStyle? mutedTextStyleIfZero(int value) {
Expand Down Expand Up @@ -191,8 +181,7 @@ class StudiesTable extends StatelessWidget {
type: studybadge.BadgeType.outlineFill,
icon: null,
color: item.studyTags.elementAt(index).color != null
? Color(int.parse(
item.studyTags.elementAt(index).color!))
? Color(int.parse(item.studyTags.elementAt(index).color!))
: Colors.grey,
);
},
Expand All @@ -209,12 +198,9 @@ class StudiesTable extends StatelessWidget {
participation: item.participation,
),
Text(item.createdAt?.toTimeAgoString() ?? ''),
Text(item.participantCount.toString(),
style: mutedTextStyleIfZero(item.participantCount)),
Text(item.activeSubjectCount.toString(),
style: mutedTextStyleIfZero(item.activeSubjectCount)),
Text(item.endedCount.toString(),
style: mutedTextStyleIfZero(item.endedCount)),
Text(item.participantCount.toString(), style: mutedTextStyleIfZero(item.participantCount)),
Text(item.activeSubjectCount.toString(), style: mutedTextStyleIfZero(item.activeSubjectCount)),
Text(item.endedCount.toString(), style: mutedTextStyleIfZero(item.endedCount)),
];
}
}
Loading

0 comments on commit 6356e4e

Please sign in to comment.