Skip to content

Commit

Permalink
feat(app): use annotation table on gene page
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Jan 23, 2025
1 parent 3fd7058 commit 70fcdf5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 65 deletions.
64 changes: 43 additions & 21 deletions app/lib/common/widgets/annotation_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableRowDefinition> rowDefinitions,
{
TextStyle? style,
bool boldHeader = true,
bool boldKey = true,
bool italicValue = false,
}
) {
return Column(
Expand All @@ -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,
),
],
),
Expand All @@ -40,42 +51,53 @@ 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(
padding: EdgeInsets.only(
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<WidgetSpan> _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)),
]
: [];
}
2 changes: 1 addition & 1 deletion app/lib/common/widgets/page_indicator_explanation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/common/widgets/phenoconversion_explanation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class PhenoconversionExplanation extends StatelessWidget {
displayConfig.userGenitive,
).capitalize(),
)],
boldHeader: false,
boldKey: false,
),
titlePadding: EdgeInsets.zero,
childrenPadding: EdgeInsets.all(PharMeTheme.mediumSpace),
Expand Down
55 changes: 13 additions & 42 deletions app/lib/report/pages/gene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
),
]);
}

0 comments on commit 70fcdf5

Please sign in to comment.