Skip to content

Commit 531a97a

Browse files
authored
Improve /experimental (#8313)
1 parent 8bbe836 commit 531a97a

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

app/lib/frontend/handlers/experimental.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ import 'package:meta/meta.dart';
66

77
import '../../shared/cookie_utils.dart';
88

9-
const _publicFlags = <String>{
10-
'dark',
11-
'download-counts',
12-
'search-completion',
13-
'search-topics',
9+
typedef PublicFlag = ({String name, String description});
10+
11+
const _publicFlags = <PublicFlag>{
12+
(name: 'dark', description: 'Dark mode'),
13+
(name: 'download-counts', description: 'Download count metrics'),
14+
(name: 'search-completion', description: 'Completions for the search bar'),
15+
(name: 'search-topics', description: 'Show matching topics when searching'),
1416
};
1517

16-
const _allFlags = <String>{
18+
final _allFlags = <String>{
1719
'dark-as-default',
18-
..._publicFlags,
20+
..._publicFlags.map((x) => x.name),
1921
};
2022

2123
/// The name of the experimental cookie.
@@ -33,7 +35,8 @@ class ExperimentalFlags {
3335
ExperimentalFlags(Set<String> enabled)
3436
: _enabled = enabled.intersection(_allFlags);
3537

36-
static final List<String> publicFlags = _publicFlags.toList()..sort();
38+
static final List<PublicFlag> publicFlags = _publicFlags.toList()
39+
..sort((a, b) => a.name.compareTo(b.name));
3740
static final ExperimentalFlags empty = ExperimentalFlags(const {});
3841

3942
factory ExperimentalFlags.parseFromCookie(String? value) {

app/lib/frontend/handlers/misc.dart

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,29 +204,48 @@ Future<shelf.Response> experimentalHandler(shelf.Request request) async {
204204

205205
final clearUri = Uri(
206206
path: '/experimental', queryParameters: flags.urlParametersForToggle());
207-
final clearLink = flags.isEmpty ? '' : '(<a href="$clearUri">clear</a>).';
208-
final publicBlock = ExperimentalFlags.publicFlags.map((f) {
209-
final change = flags.isEnabled(f) ? '0' : '1';
210-
final uri = Uri(path: '/experimental', queryParameters: {f: change});
211-
return '<a href="$uri">toggle: <b>$f</b></a><br />';
212-
}).join();
207+
final clearLink = flags.isEmpty ? '' : '(<a href="$clearUri">clear all</a>).';
208+
final publicBlock = '''
209+
<ul>
210+
${ExperimentalFlags.publicFlags.map((f) {
211+
final change = flags.isEnabled(f.name) ? '0' : '1';
212+
final uri = Uri(path: '/experimental', queryParameters: {f.name: change});
213+
return '<li><b>${f.description}</b> <a href="$uri">(toggle)</a>';
214+
}).join()}
215+
</ul>
216+
''';
213217
return htmlResponse('''
214218
<!doctype html>
215219
<html>
216220
<head>
217-
<meta http-equiv="refresh" content="15; url=/">
218221
<meta name="robots" content="noindex" />
219222
</head>
220223
<body>
221-
<center>
224+
<h1>Experiments</h1>
225+
<p>
226+
Experiments are not an official part of the pub.dev site.
227+
<p>
228+
They showcase features we are working on, that are not yet ready for
229+
deployment, and might still not:
230+
<ul>
231+
<li> work fully or as expected,
232+
<li> be well documented,
233+
<li> have good accesibility,
234+
<li> have the final polished styling.
235+
</ul>
236+
<p>
237+
Enable experiments at your own discresion.
238+
<p>
239+
An experiment is no promise of an actual later launch of that given feature.
240+
<p>
241+
Still, feel free to provide feedback on the
242+
<a href="https://github.com/dart-lang/pub-dev/issues">issue tracker</a>.
243+
Be sure to mention what experiments were enabled.
222244
<p>
223245
Experiments enabled: <b>$flags</b><br>$clearLink
224-
</p>
225-
<p>$publicBlock</p>
246+
<p>$publicBlock
226247
<p>
227-
(redirecting to <a href="/">pub.dev</a> in 15 seconds).
228-
</p>
229-
</center>
248+
After enabling experiments go back to <a href="/">pub.dev</a>.
230249
</body>
231250
</html>''', headers: {
232251
HttpHeaders.setCookieHeader: buildSetCookieValue(

0 commit comments

Comments
 (0)