import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import 'run_detail_content.dart'; /// Opens a pipeline at a version; 0 means its latest. typedef OpenPipeline = void Function(int pipelineId, int version); const runPipelineLinkKey = ValueKey('run-pipeline-link'); /// The run's pipeline id, or null when the server recorded none. int? runPipelineId(JsonMap run) { final id = run['pipeline_id']; return id is num && id > 0 && id == id.truncate() ? id.toInt() : null; } /// The run's pipeline name, a link to that pipeline at the run's pinned /// version when the run names one and the host can navigate. class RunPipelineLink extends StatelessWidget { const RunPipelineLink({ super.key, required this.run, required this.cupertino, this.onOpenPipeline, }); final JsonMap run; final bool cupertino; final OpenPipeline? onOpenPipeline; @override Widget build(BuildContext context) { final name = detailPipeline(run); final id = runPipelineId(run); final open = onOpenPipeline; if (id == null || open == null) return Text(name); final version = run['version']; void go() => open(id, version is num ? version.toInt() : 0); final label = Text( name, style: const TextStyle(decoration: TextDecoration.underline), ); return Semantics( link: true, label: 'Open pipeline $name', excludeSemantics: true, child: cupertino ? CupertinoButton( key: runPipelineLinkKey, padding: EdgeInsets.zero, minimumSize: Size.zero, onPressed: go, child: label, ) : InkWell( key: runPipelineLinkKey, onTap: go, child: DefaultTextStyle.merge( style: TextStyle(color: Theme.of(context).colorScheme.primary), child: label, ), ), ); } }