Skip to content

Commit

Permalink
feat(app): filter reacts to visible drugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Nov 29, 2024
1 parent 8ac08d9 commit 1cda6ef
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app/lib/common/widgets/drug_list/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DrugList extends HookWidget {
List<Widget>? children,
Widget? indicator,
Widget? noDrugsMessage,
bool? showInactiveDrugs
}) buildContainer;

Widget _buildDrugList(
Expand Down Expand Up @@ -142,6 +143,7 @@ class DrugList extends HookWidget {
return buildContainer(
children: drugLists,
indicator: indicator,
showInactiveDrugs: !currentlyEnabled || currentlyExpanded,
);
}

Expand Down
23 changes: 19 additions & 4 deletions app/lib/common/widgets/drug_search/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,28 @@ class DrugSearch extends HookWidget {
: ''
),
searchForDrugClass: searchForDrugClass,
buildContainer:
({children, indicator, noDrugsMessage}) => Column(
buildContainer: ({
children,
indicator,
noDrugsMessage,
showInactiveDrugs,
}) => Column(
children: [
Padding(
padding: EdgeInsets.all(PharMeTheme.smallSpace),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: _buildSearchBarItems(context, searchController),
children: _buildSearchBarItems(
context,
searchController,
showInactiveDrugs: showInactiveDrugs ?? true,
),
),
),
if (children != null) scrollList(keepPosition: keepPosition, children),
if (children != null) scrollList(
keepPosition: keepPosition,
children,
),
if (noDrugsMessage != null) noDrugsMessage,
if (indicator != null) indicator,
],
Expand All @@ -65,6 +76,9 @@ class DrugSearch extends HookWidget {
List<Widget> _buildSearchBarItems(
BuildContext context,
TextEditingController searchController,
{
required bool showInactiveDrugs,
}
) {
return [
Expanded(
Expand All @@ -89,6 +103,7 @@ class DrugSearch extends HookWidget {
state: state,
activeDrugs: activeDrugs,
searchForDrugClass: searchForDrugClass,
showInactiveDrugs: showInactiveDrugs,
),
],
];
Expand Down
18 changes: 16 additions & 2 deletions app/lib/common/widgets/drug_search/drug_filters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class WarningLevelFilterChip extends HookWidget {
required this.drugs,
required this.activeDrugs,
required this.searchForDrugClass,
required this.showInactiveDrugs,
});

final WarningLevel warningLevel;
Expand All @@ -18,12 +19,17 @@ class WarningLevelFilterChip extends HookWidget {
final List<Drug> drugs;
final ActiveDrugs activeDrugs;
final bool searchForDrugClass;
final bool showInactiveDrugs;

int _getFilteredNumber({
required FilterState itemFilter,
required List<Drug> drugs,
}) {
return itemFilter
final currentFilter = FilterState.from(
itemFilter,
showInactive: showInactiveDrugs,
);
return currentFilter
.filter(drugs, activeDrugs, searchForDrugClass: searchForDrugClass)
.length;
}
Expand Down Expand Up @@ -135,25 +141,32 @@ class DrugFilters extends StatelessWidget {
required this.state,
required this.activeDrugs,
required this.searchForDrugClass,
required this.showInactiveDrugs,
});

final DrugListCubit cubit;
final DrugListState state;
final ActiveDrugs activeDrugs;
final bool searchForDrugClass;
final bool showInactiveDrugs;

bool _showActiveIndicator() => state.whenOrNull(
loaded: (allDrugs, filter) {
final relevantDrugsFilter = FilterState.from(
FilterState.initial(),
query: filter.query,
showInactive: showInactiveDrugs,
);
final totalNumberOfDrugs = relevantDrugsFilter.filter(
allDrugs,
activeDrugs,
searchForDrugClass: searchForDrugClass,
).length;
final currentNumberOfDrugs = filter.filter(
final currentFilter = FilterState.from(
filter,
showInactive: showInactiveDrugs,
);
final currentNumberOfDrugs = currentFilter.filter(
allDrugs,
activeDrugs,
searchForDrugClass: searchForDrugClass,
Expand Down Expand Up @@ -196,6 +209,7 @@ class DrugFilters extends StatelessWidget {
filter: filter,
activeDrugs: activeDrugs,
searchForDrugClass: searchForDrugClass,
showInactiveDrugs: showInactiveDrugs,
),
);
return [
Expand Down
7 changes: 6 additions & 1 deletion app/lib/report/pages/gene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class GenePage extends HookWidget {
state: state,
activeDrugs: activeDrugs,
noDrugsMessage: context.l10n.gene_page_no_relevant_drugs,
buildContainer: ({children, indicator, noDrugsMessage}) =>
buildContainer: ({
children,
indicator,
noDrugsMessage,
showInactiveDrugs,
}) =>
Column(
children: [
Padding(
Expand Down

0 comments on commit 1cda6ef

Please sign in to comment.