Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: include parent view id in initial chat settings (#7030)

Richard Shiueed052c67923f
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_menu.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_menu.dart
index f136dac7cf..c92d561e78 100644
--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_input/select_sources_menu.dart
@@ -9,6 +9,7 @@ import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
@@ -314,11 +315,18 @@ class _ChatSourceTreeItemState extends State<ChatSourceTreeItem> {
final disabledEnabledChild =
widget.chatSource.ignoreStatus == IgnoreViewType.disable
- ? Opacity(
- opacity: 0.5,
- child: MouseRegion(
- cursor: SystemMouseCursors.forbidden,
- child: IgnorePointer(child: child),
+ ? FlowyTooltip(
+ message: switch (widget.chatSource.view.layout) {
+ ViewLayoutPB.Document =>
+ "You can only select up to 3 top-level documents and its children",
+ _ => "We don't support chatting with databases at this time",
+ },
+ child: Opacity(
+ opacity: 0.5,
+ child: MouseRegion(
+ cursor: SystemMouseCursors.forbidden,
+ child: IgnorePointer(child: child),
+ ),
),
)
: child;
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/chat_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/chat_deps.rs
index 5696987485..85b9693f05 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/chat_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/chat_deps.rs
@@ -53,7 +53,7 @@ impl AIExternalService for ChatQueryServiceImpl {
) -> Result<Vec<String>, FlowyError> {
let mut ids = self
.folder_service
- .get_sibling_ids_with_view_layout(parent_view_id, ViewLayout::Document)
+ .get_surrounding_view_ids_with_view_layout(parent_view_id, ViewLayout::Document)
.await;
if !ids.is_empty() {
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
index b643631be9..c9c5f8b6b6 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps.rs
@@ -686,35 +686,41 @@ impl FolderViewEdit for FolderServiceImpl {
#[async_trait]
impl FolderQueryService for FolderServiceImpl {
- async fn get_sibling_ids_with_view_layout(
+ async fn get_surrounding_view_ids_with_view_layout(
&self,
parent_view_id: &str,
view_layout: ViewLayout,
) -> Vec<String> {
- match self.folder_manager.upgrade() {
- None => vec![],
- Some(folder_manager) => {
- if let Ok(parent_view) = folder_manager.get_view(parent_view_id).await {
- if parent_view.space_info().is_none() {
- if let Ok(views) = folder_manager
- .get_untrashed_views_belong_to(parent_view_id)
- .await
- {
- return views
- .into_iter()
- .filter_map(|child| {
- if child.layout == view_layout {
- Some(child.id.clone())
- } else {
- None
- }
- })
- .collect::<Vec<String>>();
+ let folder_manager = match self.folder_manager.upgrade() {
+ Some(folder_manager) => folder_manager,
+ None => return vec![],
+ };
+
+ if let Ok(view) = folder_manager.get_view(parent_view_id).await {
+ if view.space_info().is_some() {
+ return vec![];
+ }
+ }
+
+ match folder_manager
+ .get_untrashed_views_belong_to(parent_view_id)
+ .await
+ {
+ Ok(views) => {
+ let mut children = views
+ .into_iter()
+ .filter_map(|child| {
+ if child.layout == view_layout {
+ Some(child.id.clone())
+ } else {
+ None
}
- }
- }
- vec![]
+ })
+ .collect::<Vec<_>>();
+ children.push(parent_view_id.to_string());
+ children
},
+ _ => vec![],
}
}
diff --git a/frontend/rust-lib/flowy-folder-pub/src/query.rs b/frontend/rust-lib/flowy-folder-pub/src/query.rs
index ed4c62e696..7b4682885d 100644
--- a/frontend/rust-lib/flowy-folder-pub/src/query.rs
+++ b/frontend/rust-lib/flowy-folder-pub/src/query.rs
@@ -13,7 +13,9 @@ pub trait FolderService: FolderQueryService + FolderViewEdit {}
#[async_trait]
pub trait FolderQueryService: Send + Sync + 'static {
- async fn get_sibling_ids_with_view_layout(
+ /// gets the parent view and all of the ids of its children views matching
+ /// the provided view layout, given that the parent view is not a space
+ async fn get_surrounding_view_ids_with_view_layout(
&self,
parent_view_id: &str,
view_layout: ViewLayout,