Skip to content

Commit 16cb63b

Browse files
authored
issue24170 google colab link added (#24820)
* issue24170 added google colab link * fixed github icon svg * issue24170 fixed code * issue24170 colab new line * issue24170 colors fixed * issue24170 github and colab buttons at embedded playground * issue24170 pr fix * issue23924 dataset button (#415) * issue23924 dataset button * issue23924 fix pr * issue23924 embedded shorten buttons * minor fixes * issue 23924 show buttons text arg fixed
1 parent 4e6a3e4 commit 16cb63b

16 files changed

Lines changed: 346 additions & 45 deletions

File tree

Lines changed: 26 additions & 0 deletions
Loading

playground/frontend/assets/github.svg

Lines changed: 2 additions & 2 deletions
Loading

playground/frontend/assets/translations/en.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ intents:
1919
playground:
2020
clearOutput: 'Clear Output'
2121
newExample: 'New Example'
22+
openGoogleColab: 'Open in Google Colab'
23+
showDatasets: 'Dataset: {fileName}'
24+
viewOnGithub: 'View on GitHub'
2225
usesEmulatedData: 'This examples uses emulated data'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import 'package:easy_localization/easy_localization.dart';
20+
import 'package:flutter/material.dart';
21+
import 'package:flutter/widgets.dart';
22+
23+
import '../../src/assets/assets.gen.dart';
24+
import 'link_button.dart';
25+
26+
class ColabButton extends StatelessWidget {
27+
final bool showText;
28+
final String url;
29+
30+
const ColabButton({
31+
required this.url,
32+
required this.showText,
33+
});
34+
35+
@override
36+
Widget build(BuildContext context) {
37+
return LinkButton(
38+
iconPath: Assets.colab,
39+
text: 'intents.playground.openGoogleColab'.tr(),
40+
url: url,
41+
showText: showText,
42+
);
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import 'package:easy_localization/easy_localization.dart';
20+
import 'package:flutter/material.dart';
21+
import 'package:playground_components/playground_components.dart';
22+
23+
import '../../src/assets/assets.gen.dart';
24+
import 'link_button.dart';
25+
26+
const _datasetsFolderPath =
27+
'https://github.com/apache/beam/blob/master/playground/backend/datasets/';
28+
29+
class DatasetButton extends StatelessWidget {
30+
final String fileName;
31+
const DatasetButton({required this.fileName});
32+
33+
@override
34+
Widget build(BuildContext context) {
35+
return LinkButton(
36+
color: Theme.of(context).extension<BeamThemeExtension>()?.iconColor,
37+
iconPath: Assets.streaming,
38+
text: 'intents.playground.showDatasets'.tr(
39+
namedArgs: {'fileName': fileName},
40+
),
41+
url: '$_datasetsFolderPath$fileName',
42+
);
43+
}
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import 'package:easy_localization/easy_localization.dart';
20+
import 'package:flutter/material.dart';
21+
22+
import '../../src/assets/assets.gen.dart';
23+
import 'link_button.dart';
24+
25+
class GithubButton extends StatelessWidget {
26+
final bool showText;
27+
final String url;
28+
29+
const GithubButton({
30+
required this.url,
31+
required this.showText,
32+
});
33+
34+
@override
35+
Widget build(BuildContext context) {
36+
return LinkButton(
37+
iconPath: Assets.github,
38+
text: 'intents.playground.viewOnGithub'.tr(),
39+
url: url,
40+
showText: showText,
41+
);
42+
}
43+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import 'package:flutter/material.dart';
20+
import 'package:flutter_svg/svg.dart';
21+
import 'package:url_launcher/url_launcher.dart';
22+
23+
class LinkButton extends StatelessWidget {
24+
final Color? color;
25+
final String iconPath;
26+
final bool showText;
27+
final String text;
28+
final String url;
29+
30+
const LinkButton({
31+
required this.iconPath,
32+
required this.text,
33+
required this.url,
34+
this.color,
35+
this.showText = true,
36+
});
37+
38+
@override
39+
Widget build(BuildContext context) {
40+
final icon = SvgPicture.asset(
41+
iconPath,
42+
color: color,
43+
);
44+
void onTap() => launchUrl(Uri.parse(url));
45+
46+
if (showText) {
47+
return TextButton.icon(
48+
icon: icon,
49+
onPressed: onTap,
50+
label: Text(text),
51+
);
52+
} else {
53+
return InkWell(
54+
onTap: onTap,
55+
borderRadius: const BorderRadius.all(Radius.circular(8)),
56+
child: Padding(
57+
padding: const EdgeInsets.all(2.0),
58+
child: icon,
59+
),
60+
);
61+
}
62+
}
63+
}

playground/frontend/lib/l10n/app_en.arb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@
183183
"@pipelineOptionsError": {
184184
"description": "Pipeline options parse error"
185185
},
186-
"viewOnGithub": "View on GitHub",
187-
"@viewOnGithub": {
188-
"description": "View on Github button"
189-
},
190186
"addExample": "Add your own example",
191187
"@addExample": {
192188
"description": "Add example link text"

playground/frontend/lib/modules/examples/components/description_popover/description_popover.dart

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@
1717
*/
1818

1919
import 'package:flutter/material.dart';
20-
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
21-
import 'package:flutter_svg/flutter_svg.dart';
20+
import 'package:playground/constants/font_weight.dart';
21+
import 'package:playground/constants/sizes.dart';
2222
import 'package:playground_components/playground_components.dart';
23-
import 'package:url_launcher/url_launcher.dart';
2423

25-
import '../../../../constants/font_weight.dart';
26-
import '../../../../constants/sizes.dart';
27-
import '../../../../src/assets/assets.gen.dart';
24+
import '../example_actions.dart';
2825

2926
const kDescriptionWidth = 300.0;
3027

@@ -35,18 +32,20 @@ class DescriptionPopover extends StatelessWidget {
3532

3633
@override
3734
Widget build(BuildContext context) {
38-
final hasLink = example.link?.isNotEmpty ?? false;
3935
return SizedBox(
4036
width: kDescriptionWidth,
4137
child: Card(
4238
child: Padding(
4339
padding: const EdgeInsets.all(kLgSpacing),
44-
child: Wrap(
45-
runSpacing: kMdSpacing,
40+
child: Column(
41+
mainAxisSize: MainAxisSize.min,
42+
crossAxisAlignment: CrossAxisAlignment.start,
4643
children: [
4744
title,
45+
const SizedBox(height: kMdSpacing),
4846
description,
49-
if (hasLink) getViewOnGithub(context),
47+
const SizedBox(height: kMdSpacing),
48+
...buildExampleActions(example, showButtonsText: true),
5049
],
5150
),
5251
),
@@ -63,15 +62,4 @@ class DescriptionPopover extends StatelessWidget {
6362
);
6463

6564
Widget get description => Text(example.description);
66-
67-
Widget getViewOnGithub(BuildContext context) {
68-
AppLocalizations appLocale = AppLocalizations.of(context)!;
69-
return TextButton.icon(
70-
icon: SvgPicture.asset(Assets.github),
71-
onPressed: () {
72-
launchUrl(Uri.parse(example.link ?? ''));
73-
},
74-
label: Text(appLocale.viewOnGithub),
75-
);
76-
}
7765
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import 'package:flutter/widgets.dart';
20+
import 'package:playground_components/playground_components.dart';
21+
22+
import '../../../components/link_button/colab_button.dart';
23+
import '../../../components/link_button/dataset_button.dart';
24+
import '../../../components/link_button/github_button.dart';
25+
26+
List<Widget> buildExampleActions(
27+
ExampleBase? example, {
28+
required bool showButtonsText,
29+
}) {
30+
if (example == null) {
31+
return [];
32+
}
33+
34+
final hasColabLink = example.urlNotebook?.isNotEmpty ?? false;
35+
final hasDatasets = example.datasets.isNotEmpty;
36+
final hasGithubLink = example.urlVcs?.isNotEmpty ?? false;
37+
38+
return [
39+
if (hasGithubLink)
40+
GithubButton(
41+
url: example.urlVcs ?? '',
42+
showText: showButtonsText,
43+
),
44+
if (hasColabLink)
45+
ColabButton(
46+
url: example.urlNotebook ?? '',
47+
showText: showButtonsText,
48+
),
49+
if (hasDatasets)
50+
DatasetButton(fileName: example.datasets.first.datasetPath),
51+
];
52+
}

0 commit comments

Comments
 (0)