Skip to content

Commit

Permalink
feat(#664): adapt filter wording
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Oct 18, 2023
1 parent 1bc95ea commit eec57ad
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 38 deletions.
84 changes: 58 additions & 26 deletions app/lib/common/widgets/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import '../module.dart';
class ContextMenu extends StatelessWidget {
const ContextMenu({
super.key,
this.headerItem,
required this.items,
required this.child,
});

final Widget? headerItem;
final List<ContextMenuCheckmark> items;
final Widget child;

Expand All @@ -19,7 +21,9 @@ class ContextMenu extends StatelessWidget {
showPopover(
context: context,
bodyBuilder: (context) => Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
padding: EdgeInsets.symmetric(
horizontal: PharMeTheme.smallToMediumSpace
),
child: Container(
decoration: BoxDecoration(
color: PharMeTheme.onSurfaceColor,
Expand All @@ -29,19 +33,7 @@ class ContextMenu extends StatelessWidget {
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: items
.mapIndexed(
(index, item) => (index == items.count() - 1)
? item
: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
width: 0.5,
color: PharMeTheme.borderColor),
)),
child: item))
.toList(),
children: _buildContent(context),
),
),
),
Expand All @@ -57,6 +49,49 @@ class ContextMenu extends StatelessWidget {
},
child: child);
}

Widget _itemContainer(
Widget item,
{
bool showBorder = true,
double padding = PharMeTheme.smallToMediumSpace,
}
) {
return Container(
decoration: showBorder ? BoxDecoration(
border: Border(
bottom: BorderSide(
width: 0.5,
color: PharMeTheme.borderColor
),
),
) : null,
child: Padding(
padding: EdgeInsets.all(padding),
child: item,
)
);
}

List<Widget> _buildContent(BuildContext context) {
final body = items.mapIndexed(
(index, item) => (index == items.count() - 1)
? _itemContainer(item, showBorder: false)
: _itemContainer(item)
).toList();
return headerItem != null
? [
_itemContainer(
Row(
children: [headerItem!]
),
padding: PharMeTheme.mediumSpace,
showBorder: false,
),
...body,
]
: body;
}
}

class ContextMenuCheckmark extends StatelessWidget {
Expand All @@ -81,18 +116,15 @@ class ContextMenuCheckmark extends StatelessWidget {
setState(state);
});
},
child: Padding(
padding: EdgeInsets.all(12),
child: Row(
children: [
if (state)
Icon(Icons.check_rounded, size: 16)
else
SizedBox(width: 16, height: 16),
SizedBox(width: 8),
Expanded(child: Text(label)),
],
),
child: Row(
children: [
if (state)
Icon(Icons.check_box, size: PharMeTheme.mediumSpace)
else
Icon(Icons.check_box_outline_blank, size: PharMeTheme.mediumSpace),
SizedBox(width: PharMeTheme.smallSpace),
Expanded(child: Text(label)),
],
),
),
);
Expand Down
9 changes: 8 additions & 1 deletion app/lib/common/widgets/drug_list/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,16 @@ class FilterState {
[];
final warningLevel =
userGuideline?.annotations.warningLevel ?? WarningLevel.none;
var warningLevelMatches = showWarningLevel[warningLevel] ?? true;
// WarningLevel.none is also shown in green in app; therefore, it should
// also be filtered with green option
if (warningLevel == WarningLevel.none) {
warningLevelMatches = warningLevelMatches &&
showWarningLevel[WarningLevel.green]!;
}
final isDrugAccepted = drug.matches(query: query) &&
(drug.isActive() || showInactive) &&
(showWarningLevel[warningLevel] ?? true) &&
warningLevelMatches &&
(gene.isBlank || (guidelineGenes.contains(gene)));
return isDrugAccepted;
}
Expand Down
25 changes: 19 additions & 6 deletions app/lib/common/widgets/drug_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,31 @@ class DrugSearch extends HookWidget {
return ContextMenu(
items: [
ContextMenuCheckmark(
label: context.l10n.search_page_filter_inactive,
setState: (state) => cubit.search(showInactive: state),
initialState: filter?.showInactive ?? false),
...WarningLevel.values.map((level) => ContextMenuCheckmark(
label: context.l10n.search_page_filter_only_active,
// Invert state as filter has opposite meaning ('only show active' vs.
// 'show inactive')
setState: (state) => cubit.search(showInactive: !state),
initialState: filter != null && !filter.showInactive),
...WarningLevel.values.filter((level) => level != WarningLevel.none)
.map((level) => ContextMenuCheckmark(
label: {
WarningLevel.green: context.l10n.search_page_filter_green,
WarningLevel.yellow: context.l10n.search_page_filter_yellow,
WarningLevel.red: context.l10n.search_page_filter_red,
WarningLevel.none: context.l10n.search_page_filter_gray,
}[level]!,
setState: (state) => cubit.search(showWarningLevel: {level: state}),
initialState: filter?.showWarningLevel[level] ?? false))
initialState: filter?.showWarningLevel[level] ?? false
)
),
ContextMenuCheckmark(
label: context.l10n.search_page_filter_only_with_guidelines,
// Invert state as filter has opposite meaning ('show only with
// guidelines' vs. 'show with unknown warning level')
setState: (state) => cubit.search(
showWarningLevel: {WarningLevel.none: !state}
),
initialState: filter != null &&
!filter.showWarningLevel[WarningLevel.none]!,)
],
child: Padding(
padding: EdgeInsets.all(8), child: Icon(Icons.filter_list_rounded)),
Expand Down
10 changes: 5 additions & 5 deletions app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"general_not_tested": "Not tested",

"search_page_tooltip_search": "Search for drugs by their name, brand name or class.",
"search_page_filter_inactive": "Show currently not taken drugs",
"search_page_filter_green": "Show green warning level",
"search_page_filter_yellow": "Show yellow warning level",
"search_page_filter_red": "Show red warning level",
"search_page_filter_gray": "Show drugs without guidelines",
"search_page_filter_only_active": "Only active drugs",
"search_page_filter_green": "Green warning level",
"search_page_filter_yellow": "Yellow warning level",
"search_page_filter_red": "Red warning level",
"search_page_filter_only_with_guidelines": "Only drugs with guidelines",
"search_page_indicator_explanation": "Taking drugs with an {indicatorName} ({indicator}) can influence your results for other drugs",
"@search_page_indicator_explanation": {
"description": "Explanation of drug-drug interaction indicators",
Expand Down

0 comments on commit eec57ad

Please sign in to comment.