Skip to content

Commit 1ebf451

Browse files
authored
Display health and maintenance issues separately. (#1644)
* Refactor suggestion rendering * Display health and maintenance issues separately.
1 parent 4a54463 commit 1ebf451

15 files changed

+103
-34
lines changed

app/lib/frontend/templates.dart

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,6 @@ class TemplateService {
238238
break;
239239
}
240240

241-
final List suggestions = analysis.suggestions?.map((suggestion) {
242-
return {
243-
'icon_class': _suggestionIconClass(suggestion.level),
244-
'title_html':
245-
_renderSuggestionTitle(suggestion.title, suggestion.score),
246-
'description_html': markdownToHtml(suggestion.description, null),
247-
'suggestion_help_html': getSuggestionHelpMessage(suggestion.code),
248-
};
249-
})?.toList();
250-
final hasIssues =
251-
analysis.suggestions?.any((s) => s.isError || s.isWarning) ?? false;
252-
253241
List<Map> prepareDependencies(List<PkgDependency> list) {
254242
if (list == null || list.isEmpty) return const [];
255243
return list.map((pd) => {'row_html': _renderAnalysisDepRow(pd)}).toList();
@@ -285,9 +273,12 @@ class TemplateService {
285273
?.join(', ') ??
286274
'<i>unsure</i>',
287275
'platforms_reason_html': markdownToHtml(analysis.platformsReason, null),
288-
'hasSuggestions': suggestions != null && suggestions.isNotEmpty,
289-
'suggestions_label': hasIssues ? 'Issues and suggestions' : 'Suggestions',
290-
'suggestions': suggestions,
276+
'analysis_suggestions_html':
277+
_renderSuggestionBlockHtml('Analysis', analysis.panaSuggestions),
278+
'health_suggestions_html':
279+
_renderSuggestionBlockHtml('Health', analysis.healthSuggestions),
280+
'maintenance_suggestions_html': _renderSuggestionBlockHtml(
281+
'Maintenance', analysis.maintenanceSuggestions),
291282
'has_dependency': hasDependency,
292283
'dependencies': {
293284
'has_sdk': hasSdkConstraint,
@@ -305,6 +296,33 @@ class TemplateService {
305296
return _renderTemplate('pkg/analysis_tab', data);
306297
}
307298

299+
String _renderSuggestionBlockHtml(
300+
String header, List<Suggestion> suggestions) {
301+
if (suggestions == null || suggestions.isEmpty) {
302+
return null;
303+
}
304+
305+
final hasIssues = suggestions.any((s) => s.isError || s.isWarning);
306+
final label =
307+
hasIssues ? '$header issues and suggestions' : '$header suggestions';
308+
309+
final mappedValues = suggestions.map((suggestion) {
310+
return {
311+
'icon_class': _suggestionIconClass(suggestion.level),
312+
'title_html':
313+
_renderSuggestionTitle(suggestion.title, suggestion.score),
314+
'description_html': markdownToHtml(suggestion.description, null),
315+
'suggestion_help_html': getSuggestionHelpMessage(suggestion.code),
316+
};
317+
}).toList();
318+
319+
final data = <String, dynamic>{
320+
'label': label,
321+
'suggestions': mappedValues,
322+
};
323+
return _renderTemplate('pkg/analysis_suggestion_block', data);
324+
}
325+
308326
Map<String, Object> _pkgShowPageValues(
309327
Package package,
310328
List<PackageVersion> versions,

app/lib/shared/analyzer_client.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ class AnalysisView {
245245

246246
List<Suggestion> get suggestions => getAllSuggestions(_summary);
247247

248+
List<Suggestion> get panaSuggestions => _summary?.suggestions;
249+
List<Suggestion> get healthSuggestions => _summary?.health?.suggestions;
250+
List<Suggestion> get maintenanceSuggestions =>
251+
_summary?.maintenance?.suggestions;
252+
248253
double get maintenanceScore => _data?.maintenanceScore ?? 0.0;
249254
}
250255

app/test/frontend/golden/analysis_tab_aborted.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@ <h4>Platforms</h4>
112112
<blockquote></blockquote>
113113

114114

115+
116+
117+

app/test/frontend/golden/analysis_tab_http.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ <h4>Platforms</h4>
112112
<blockquote><p>No platform restriction found in primary library <code>package:http/http.dart</code>.</p>
113113
</blockquote>
114114

115-
<h4>Suggestions</h4>
115+
116+
117+
<h4>Maintenance suggestions</h4>
116118
<div class="suggestion-row">
117119
<div class="suggestion-title">
118120
<span class="suggestion-icon-info"></span>
@@ -138,6 +140,7 @@ <h4>Suggestions</h4>
138140
</div>
139141
</div>
140142

143+
141144
<h4>Dependencies</h4>
142145
<div class="overflow-x">
143146
<table class="dependency-table">

app/test/frontend/golden/analysis_tab_mock.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ <h4>Platforms</h4>
112112
<blockquote><p>All libraries agree.</p>
113113
</blockquote>
114114

115-
<h4>Issues and suggestions</h4>
115+
116+
<h4>Health issues and suggestions</h4>
116117
<div class="suggestion-row">
117118
<div class="suggestion-title">
118119
<span class="suggestion-icon-danger"></span>
@@ -126,6 +127,8 @@ <h4>Issues and suggestions</h4>
126127
</div>
127128
</div>
128129

130+
131+
129132
<h4>Dependencies</h4>
130133
<div class="overflow-x">
131134
<table class="dependency-table">

app/test/frontend/golden/analysis_tab_outdated.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,6 @@
101101
</p>
102102

103103

104+
105+
106+

app/test/frontend/golden/pkg_show_page.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ <h4>Platforms</h4>
292292
<blockquote></blockquote>
293293

294294

295+
296+
297+
295298
<h4>Dependencies</h4>
296299
<div class="overflow-x">
297300
<table class="dependency-table">

app/test/frontend/golden/pkg_show_page_discontinued.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ <h3>3. Import it</h3>
276276

277277

278278

279+
280+
281+
279282
</section>
280283
</div>
281284

app/test/frontend/golden/pkg_show_page_flutter_plugin.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ <h4>Platforms</h4>
280280

281281

282282

283+
284+
285+
283286
</section>
284287
</div>
285288

app/test/frontend/golden/pkg_show_page_legacy.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ <h3>3. Import it</h3>
278278
Until this is resolved, the package will receive a health and maintenance score of 0.
279279
</p>
280280

281-
<h4>Issues and suggestions</h4>
281+
<h4>Analysis issues and suggestions</h4>
282282
<div class="suggestion-row">
283283
<div class="suggestion-title">
284284
<span class="suggestion-icon-danger"></span>
@@ -293,6 +293,9 @@ <h4>Issues and suggestions</h4>
293293
</div>
294294

295295

296+
297+
298+
296299
</section>
297300
</div>
298301

app/test/frontend/golden/pkg_show_page_outdated.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ <h3>3. Import it</h3>
280280

281281

282282

283+
284+
285+
283286
</section>
284287
</div>
285288

app/test/frontend/golden/pkg_show_version_page.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ <h4>Platforms</h4>
294294
<blockquote></blockquote>
295295

296296

297+
298+
299+
297300
<h4>Dependencies</h4>
298301
<div class="overflow-x">
299302
<table class="dependency-table">

app/test/frontend/templates_test.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ void main() {
299299
platforms: ['web'],
300300
platformsReason: 'All libraries agree.',
301301
health: 0.95,
302-
suggestions: [
302+
healthSuggestions: [
303303
new Suggestion.error(SuggestionCode.dartfmtAborted,
304304
'Fix `dartfmt`.', 'Running `dartfmt -n .` failed.'),
305305
],
@@ -650,6 +650,15 @@ class MockAnalysisView implements AnalysisView {
650650
@override
651651
List<Suggestion> suggestions;
652652

653+
@override
654+
List<Suggestion> panaSuggestions;
655+
656+
@override
657+
List<Suggestion> healthSuggestions;
658+
659+
@override
660+
List<Suggestion> maintenanceSuggestions;
661+
653662
@override
654663
double maintenanceScore;
655664

@@ -663,5 +672,8 @@ class MockAnalysisView implements AnalysisView {
663672
this.devDependencies,
664673
this.health,
665674
this.suggestions,
675+
this.panaSuggestions,
676+
this.healthSuggestions,
677+
this.maintenanceSuggestions,
666678
});
667679
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{! Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
for details. All rights reserved. Use of this source code is governed by a
3+
BSD-style license that can be found in the LICENSE file. }}
4+
<h4>{{label}}</h4>
5+
{{#suggestions}}
6+
<div class="suggestion-row">
7+
<div class="suggestion-title">
8+
<span class="{{icon_class}}"></span>
9+
{{& title_html}}
10+
</div>
11+
<div class="suggestion-description">
12+
{{& description_html}}
13+
{{& suggestion_help_html}}
14+
</div>
15+
</div>
16+
{{/suggestions}}

app/views/pkg/analysis_tab.mustache

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,9 @@
9191
<blockquote>{{& platforms_reason_html}}</blockquote>
9292
{{/show_analysis}}
9393

94-
{{#hasSuggestions}}
95-
<h4>{{suggestions_label}}</h4>
96-
{{#suggestions}}
97-
<div class="suggestion-row">
98-
<div class="suggestion-title">
99-
<span class="{{icon_class}}"></span>
100-
{{& title_html}}
101-
</div>
102-
<div class="suggestion-description">
103-
{{& description_html}}
104-
{{& suggestion_help_html}}
105-
</div>
106-
</div>
107-
{{/suggestions}}
108-
{{/hasSuggestions}}
94+
{{& analysis_suggestions_html}}
95+
{{& health_suggestions_html}}
96+
{{& maintenance_suggestions_html}}
10997

11098
{{#has_dependency}}
11199
<h4>Dependencies</h4>

0 commit comments

Comments
 (0)