From 70fcdf5293fb3058d1cb6281f10a90068d62a281 Mon Sep 17 00:00:00 2001 From: tamslo Date: Thu, 23 Jan 2025 20:43:38 +0100 Subject: [PATCH] feat(app): use annotation table on gene page --- app/lib/common/widgets/annotation_table.dart | 64 +++++++++++++------ .../widgets/page_indicator_explanation.dart | 2 +- .../widgets/phenoconversion_explanation.dart | 2 +- app/lib/report/pages/gene.dart | 55 ++++------------ 4 files changed, 58 insertions(+), 65 deletions(-) diff --git a/app/lib/common/widgets/annotation_table.dart b/app/lib/common/widgets/annotation_table.dart index ac344cf9..c2baa9a9 100644 --- a/app/lib/common/widgets/annotation_table.dart +++ b/app/lib/common/widgets/annotation_table.dart @@ -2,17 +2,27 @@ import '../../drug/widgets/tooltip_icon.dart'; import '../module.dart'; class TableRowDefinition { - const TableRowDefinition(this.key, this.value, { this.tooltip }); + const TableRowDefinition( + this.key, + this.value, + { + this.keyTooltip, + this.valueTooltip, + } + ); + final String key; final String value; - final String? tooltip; + final String? keyTooltip; + final String? valueTooltip; } Widget buildTable( List rowDefinitions, { TextStyle? style, - bool boldHeader = true, + bool boldKey = true, + bool italicValue = false, } ) { return Column( @@ -25,9 +35,10 @@ Widget buildTable( rowDefinition.key, rowDefinition.value, style ?? PharMeTheme.textTheme.bodyMedium!, - boldHeader: boldHeader, + boldKey: boldKey, isLast: index == rowDefinitions.length - 1, - tooltip: rowDefinition.tooltip, + keyTooltip: rowDefinition.keyTooltip, + valueTooltip: rowDefinition.valueTooltip, ), ], ), @@ -40,13 +51,12 @@ TableRow _buildRow( String value, TextStyle textStyle, { - required bool boldHeader, + required bool boldKey, required bool isLast, - String? tooltip, + String? keyTooltip, + String? valueTooltip, } ) { - const tooltipSize = 16.0; - return TableRow( children: [ Padding( @@ -54,28 +64,40 @@ TableRow _buildRow( right: PharMeTheme.smallSpace, bottom: isLast ? 0 : PharMeTheme.smallSpace, ), - child: Text( - key, - style: boldHeader - ? textStyle.copyWith(fontWeight: FontWeight.bold) - : textStyle, + child: Text.rich( + TextSpan( + children: [ + TextSpan(text: key), + ..._maybeBuildTooltip(keyTooltip), + ], + style: boldKey + ? textStyle.copyWith(fontWeight: FontWeight.bold) + : textStyle, + ), ), ), Text.rich( TextSpan( children: [ TextSpan(text: value), - if (tooltip.isNotNullOrBlank) ...[ - WidgetSpan(child: SizedBox(width: PharMeTheme.smallSpace)), - WidgetSpan( - child: TooltipIcon(tooltip!, size: tooltipSize), - ), - WidgetSpan(child: SizedBox(height: tooltipSize)), - ], + ..._maybeBuildTooltip(valueTooltip), ], style: textStyle, ), ), ], ); +} + +List _maybeBuildTooltip(String? tooltip) { + const tooltipSize = 16.0; + return tooltip.isNotNullOrBlank + ? [ + WidgetSpan(child: SizedBox(width: PharMeTheme.smallSpace)), + WidgetSpan( + child: TooltipIcon(tooltip!, size: tooltipSize), + ), + WidgetSpan(child: SizedBox(height: tooltipSize)), + ] + : []; } \ No newline at end of file diff --git a/app/lib/common/widgets/page_indicator_explanation.dart b/app/lib/common/widgets/page_indicator_explanation.dart index bf944bbf..1decc082 100644 --- a/app/lib/common/widgets/page_indicator_explanation.dart +++ b/app/lib/common/widgets/page_indicator_explanation.dart @@ -16,7 +16,7 @@ class PageIndicatorExplanation extends StatelessWidget { child: indicator.isNotNullOrBlank ? buildTable( [TableRowDefinition(indicator!, text)], - boldHeader: false, + boldKey: false, style: textStyle, ) : Text(text, style: textStyle), diff --git a/app/lib/common/widgets/phenoconversion_explanation.dart b/app/lib/common/widgets/phenoconversion_explanation.dart index f3f3f4c8..1cd6cd22 100644 --- a/app/lib/common/widgets/phenoconversion_explanation.dart +++ b/app/lib/common/widgets/phenoconversion_explanation.dart @@ -133,7 +133,7 @@ class PhenoconversionExplanation extends StatelessWidget { displayConfig.userGenitive, ).capitalize(), )], - boldHeader: false, + boldKey: false, ), titlePadding: EdgeInsets.zero, childrenPadding: EdgeInsets.all(PharMeTheme.mediumSpace), diff --git a/app/lib/report/pages/gene.dart b/app/lib/report/pages/gene.dart index 9db489ad..38e1d139 100644 --- a/app/lib/report/pages/gene.dart +++ b/app/lib/report/pages/gene.dart @@ -62,20 +62,7 @@ class GenePage extends HookWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Table( - columnWidths: Map.from({ - 0: IntrinsicColumnWidth(), - 1: IntrinsicColumnWidth(flex: 1), - }), - children: [ - _buildRow( - context.l10n.gene_page_genotype, - genotypeResult.variantDisplayString(context), - tooltip: context.l10n.gene_page_genotype_tooltip - ), - _buildPhenotypeRow(context), - ], - ), + _buildGeneResults(context), if (isInhibited(genotypeResult, drug: null)) ...[ SizedBox(height: PharMeTheme.smallSpace), PhenoconversionExplanation( @@ -105,35 +92,19 @@ class GenePage extends HookWidget { ), ) ); - } - TableRow _buildPhenotypeRow(BuildContext context) { - return _buildRow( + } + + Widget _buildGeneResults(BuildContext context) => buildTable([ + TableRowDefinition( + context.l10n.gene_page_genotype, + genotypeResult.variantDisplayString(context), + keyTooltip: context.l10n.gene_page_genotype_tooltip, + ), + TableRowDefinition( context.l10n.gene_page_phenotype, possiblyAdaptedPhenotype(context, genotypeResult, drug: null), - tooltip: - context.l10n.gene_page_phenotype_tooltip, - ); - } - - TableRow _buildRow(String key, String value, {String? tooltip}) => - TableRow(children: [ - Padding( - padding: EdgeInsets.fromLTRB(0, 4, 12, 4), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text(key, - style: PharMeTheme.textTheme.bodyMedium! - .copyWith(fontWeight: FontWeight.bold)), - if (tooltip.isNotNullOrEmpty) ...[ - SizedBox(width: PharMeTheme.smallSpace), - TooltipIcon(tooltip!), - ], - ], - ), - ), - Padding(padding: EdgeInsets.fromLTRB(0, 4, 0, 4), child: Text(value)), - ]); + keyTooltip: context.l10n.gene_page_phenotype_tooltip, + ), + ]); }