Skip to content

Commit

Permalink
fix: settings site issues (AppFlowy-IO#6701)
Browse files Browse the repository at this point in the history
* fix: pages overflow when selecting homepage

* fix: settings site issues

* chore: try to fix windows ci

* test: add tests

* fix: shareblock state update

* fix: pages overflow when selecting homepage

* fix: view name doesn't update after publishing

* chore: add translations

* feat: close popup menu after unpublishing page

* feat: align the published page name with header
  • Loading branch information
LucasXu0 authored Nov 5, 2024
1 parent 39eee12 commit 54096b3
Show file tree
Hide file tree
Showing 17 changed files with 501 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ void main() {
// expect to see unpublish, visit site and manage all sites button
expect(unpublishButton, findsOneWidget);
expect(find.text(LocaleKeys.shareAction_visitSite.tr()), findsOneWidget);
expect(
find.text(LocaleKeys.shareAction_manageAllSites.tr()),
findsOneWidget,
);

// unpublish the document
await tester.tapButton(unpublishButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';

import 'package:appflowy/env/cloud_env.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/widgets/loading.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/plugins/shared/share/publish_tab.dart';
Expand All @@ -21,6 +22,8 @@ import 'package:appflowy/workspace/presentation/settings/pages/sites/domain/doma
import 'package:appflowy/workspace/presentation/settings/pages/sites/domain/domain_settings_dialog.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/domain/home_page_menu.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/published_page/published_view_item.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/published_page/published_view_more_action.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/published_page/published_view_settings_dialog.dart';
import 'package:appflowy/workspace/presentation/settings/shared/setting_list_tile.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart';
import 'package:appflowy/workspace/presentation/widgets/user_avatar.dart';
Expand Down Expand Up @@ -233,5 +236,133 @@ void main() {
// await tester.pumpUntilFound(successToast);
// expect(successToast, findsOneWidget);
});

testWidgets('''
More actions for published page:
1. visit site
2. copy link
3. settings
4. unpublish
5. custom url
''', (tester) async {
await tester.initializeAppFlowy(
cloudType: AuthenticatorType.appflowyCloudSelfHost,
);
await tester.tapGoogleLoginInButton();
await tester.expectToSeeHomePageWithGetStartedPage();

const pageName = 'Document';

await tester.createNewPageInSpace(
spaceName: Constants.generalSpaceName,
layout: ViewLayoutPB.Document,
pageName: pageName,
);

// open the publish menu
await tester.openPublishMenu();

// publish the document
await tester.tapButton(find.byType(PublishButton));

// click empty area to close the publish menu
await tester.tapAt(Offset.zero);
await tester.pumpAndSettle();
// check if the page is published in sites page
await tester.openSettings();
await tester.openSettingsPage(SettingsPage.sites);
// wait the backend return the sites data
await tester.wait(1000);

// check if the page is published in sites page
final pageItem = find.byWidgetPredicate(
(widget) =>
widget is PublishedViewItem &&
widget.publishInfoView.view.name == pageName,
);
expect(pageItem, findsOneWidget);

final copyLinkItem = find.text(LocaleKeys.shareAction_copyLink.tr());
final customUrlItem = find.text(LocaleKeys.settings_sites_customUrl.tr());
final unpublishItem = find.text(LocaleKeys.shareAction_unPublish.tr());

// custom url
final publishMoreAction = find.byType(PublishedViewMoreAction);

// click the copy link button
{
await tester.tapButton(publishMoreAction);
await tester.pumpAndSettle();
await tester.pumpUntilFound(copyLinkItem);
await tester.tapButton(copyLinkItem);
await tester.pumpAndSettle();
await tester.pumpUntilNotFound(copyLinkItem);

final clipboardContent = await getIt<ClipboardService>().getData();
final plainText = clipboardContent.plainText;
expect(
plainText,
contains(pageName),
);
}

// custom url
{
await tester.tapButton(publishMoreAction);
await tester.pumpAndSettle();
await tester.pumpUntilFound(customUrlItem);
await tester.tapButton(customUrlItem);
await tester.pumpAndSettle();
await tester.pumpUntilNotFound(customUrlItem);

// see the custom url dialog
final customUrlDialog = find.byType(PublishedViewSettingsDialog);
expect(customUrlDialog, findsOneWidget);

// rename the custom url
final textField = find.descendant(
of: customUrlDialog,
matching: find.byType(TextField),
);
await tester.enterText(textField, 'hello-world');
await tester.pumpAndSettle();

// click the save button
final saveButton = find.descendant(
of: customUrlDialog,
matching: find.text(LocaleKeys.button_save.tr()),
);
await tester.tapButton(saveButton);
await tester.pumpAndSettle();

// expect to see the toast with success message
final successToast = find.text(
LocaleKeys.settings_sites_success_updatePathNameSuccess.tr(),
);
await tester.pumpUntilFound(successToast);
expect(successToast, findsOneWidget);
}

// unpublish
{
await tester.tapButton(publishMoreAction);
await tester.pumpAndSettle();
await tester.pumpUntilFound(unpublishItem);
await tester.tapButton(unpublishItem);
await tester.pumpAndSettle();
await tester.pumpUntilNotFound(unpublishItem);

// expect to see the toast with success message
final successToast = find.text(
LocaleKeys.publish_unpublishSuccessfully.tr(),
);
await tester.pumpUntilFound(successToast);
expect(successToast, findsOneWidget);
await tester.pumpUntilNotFound(successToast);

// check if the page is unpublished in sites page
expect(pageItem, findsNothing);
}
});
});
}
69 changes: 38 additions & 31 deletions frontend/appflowy_flutter/lib/plugins/shared/share/_shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,46 @@ class ShareMenuButton extends StatelessWidget {
final shareBloc = context.read<ShareBloc>();
final databaseBloc = context.read<DatabaseTabBarBloc?>();
final userWorkspaceBloc = context.read<UserWorkspaceBloc>();
return SizedBox(
height: 32.0,
child: IntrinsicWidth(
child: AppFlowyPopover(
direction: PopoverDirection.bottomWithRightAligned,
constraints: const BoxConstraints(
maxWidth: 500,
),
offset: const Offset(0, 8),
onOpen: () {
context
.read<ShareBloc>()
.add(const ShareEvent.updatePublishStatus());
},
popupBuilder: (context) => MultiBlocProvider(
providers: [
if (databaseBloc != null)
BlocProvider.value(
value: databaseBloc,
),
BlocProvider.value(value: shareBloc),
BlocProvider.value(value: userWorkspaceBloc),
],
child: ShareMenu(
tabs: tabs,
return BlocBuilder<ShareBloc, ShareState>(
builder: (context, state) {
return SizedBox(
height: 32.0,
child: IntrinsicWidth(
child: AppFlowyPopover(
direction: PopoverDirection.bottomWithRightAligned,
constraints: const BoxConstraints(
maxWidth: 500,
),
offset: const Offset(0, 8),
onOpen: () {
context
.read<ShareBloc>()
.add(const ShareEvent.updatePublishStatus());
},
popupBuilder: (_) {
return MultiBlocProvider(
providers: [
if (databaseBloc != null)
BlocProvider.value(
value: databaseBloc,
),
BlocProvider.value(value: shareBloc),
BlocProvider.value(value: userWorkspaceBloc),
],
child: ShareMenu(
tabs: tabs,
viewName: state.viewName,
),
);
},
child: PrimaryRoundedButton(
text: LocaleKeys.shareAction_buttonText.tr(),
figmaLineHeight: 16,
),
),
),
child: PrimaryRoundedButton(
text: LocaleKeys.shareAction_buttonText.tr(),
figmaLineHeight: 16,
),
),
),
);
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import 'package:appflowy/plugins/shared/share/publish_name_generator.dart';
import 'package:appflowy/plugins/shared/share/share_bloc.dart';
import 'package:appflowy/shared/error_code/error_code_map.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/settings/prelude.dart';
import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/sidebar_setting.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
Expand All @@ -25,7 +22,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class PublishTab extends StatelessWidget {
const PublishTab({super.key});
const PublishTab({
super.key,
required this.viewName,
});

final String viewName;

@override
Widget build(BuildContext context) {
Expand All @@ -50,7 +52,7 @@ class PublishTab extends StatelessWidget {
final id = context.read<ShareBloc>().view.id;
final publishName = await generatePublishName(
id,
state.viewName,
viewName,
);

if (selectedViews.isNotEmpty) {
Expand Down Expand Up @@ -188,7 +190,6 @@ class _PublishedWidgetState extends State<_PublishedWidget> {
Row(
mainAxisSize: MainAxisSize.min,
children: [
_buildManageSiteButton(),
const Spacer(),
UnPublishButton(
onUnPublish: widget.onUnPublish,
Expand All @@ -201,33 +202,6 @@ class _PublishedWidgetState extends State<_PublishedWidget> {
);
}

Widget _buildManageSiteButton() {
return SizedBox(
width: 128,
height: 36,
child: FlowyButton(
radius: BorderRadius.circular(10),
text: FlowyText.regular(
lineHeight: 1.0,
LocaleKeys.shareAction_manageAllSites.tr(),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
onTap: () {
PopoverContainer.of(context).close();

// open settings sites page
showSettingsDialog(
context,
context.read<UserWorkspaceBloc>().userProfile,
context.read<UserWorkspaceBloc>(),
SettingsPage.sites,
);
},
),
);
}

Widget _buildVisitSiteButton() {
return RoundedTextButton(
width: 108,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ class ShareBloc extends Bloc<ShareEvent, ShareState> {
unPublish: () async => _unpublish(emit),
updatePublishStatus: () async => _updatePublishStatus(emit),
updateViewName: (viewName, viewId) async {
emit(state.copyWith(viewName: viewName, viewId: viewId));
emit(
state.copyWith(
viewName: viewName,
viewId: viewId,
updatePathNameResult: null,
publishResult: null,
unpublishResult: null,
),
);
},
setPublishStatus: (isPublished) {
emit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class ShareMenu extends StatefulWidget {
const ShareMenu({
super.key,
required this.tabs,
required this.viewName,
});

final List<ShareMenuTab> tabs;
final String viewName;

@override
State<ShareMenu> createState() => _ShareMenuState();
Expand Down Expand Up @@ -119,7 +121,9 @@ class _ShareMenuState extends State<ShareMenu>
Widget _buildTab(BuildContext context) {
switch (selectedTab) {
case ShareMenuTab.publish:
return const PublishTab();
return PublishTab(
viewName: widget.viewName,
);
case ShareMenuTab.exportAs:
return const ExportTab();
case ShareMenuTab.share:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter/material.dart';

class SettingsPageSitesConstants {
static const threeDotsButtonWidth = 26.0;
static const alignPadding = 6.0;

static final dateFormat = DateFormat('MMM d, yyyy');

Expand Down
Loading

0 comments on commit 54096b3

Please sign in to comment.