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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: adjust database custom prompt ui (#7989)
Richard Shiue29f8f0d3171c
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dartindex de777b3c10..3a3724f6d8 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart@@ -12,6 +12,7 @@ import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';import 'package:appflowy_ui/appflowy_ui.dart';import 'package:collection/collection.dart';import 'package:easy_localization/easy_localization.dart';+import 'package:equatable/equatable.dart';import 'package:expandable/expandable.dart';import 'package:flowy_infra_ui/widget/spacing.dart';import 'package:flutter/material.dart';@@ -215,81 +216,102 @@ class _HeaderState extends State<_Header> {return SizedBox.shrink();}- return Center(- child: ViewSelector(- viewSelectorCubit: BlocProvider(- create: (context) => ViewSelectorCubit(- getIgnoreViewType: getIgnoreViewType,- ),- ),- child: BlocSelector<SpaceBloc, SpaceState, (List<ViewPB>, ViewPB?)>(- selector: (state) => (state.spaces, state.currentSpace),- builder: (context, state) {- return Padding(- padding: EdgeInsets.symmetric(- vertical: theme.spacing.xl,+ return Padding(+ padding: EdgeInsets.symmetric(+ horizontal: theme.spacing.m,+ vertical: theme.spacing.xl,+ ),+ child: Row(+ spacing: theme.spacing.s,+ children: [+ Expanded(+ child: Text(+ LocaleKeys.ai_customPrompt_selectDatabase.tr(),+ style: theme.textStyle.body.standard(+ color: theme.textColorScheme.secondary,),- child: AFPopover(- controller: popoverController,- decoration: BoxDecoration(- color: theme.surfaceColorScheme.primary,- borderRadius: BorderRadius.circular(theme.borderRadius.l),- border: Border.all(- color: theme.borderColorScheme.primary,+ ),+ ),+ Expanded(+ child: Center(+ child: ViewSelector(+ viewSelectorCubit: BlocProvider(+ create: (context) => ViewSelectorCubit(+ getIgnoreViewType: getIgnoreViewType,),- boxShadow: theme.shadow.medium,- ),- padding: EdgeInsets.zero,- anchor: AFAnchor(- childAlignment: Alignment.topCenter,- overlayAlignment: Alignment.bottomCenter,- offset: Offset(0, theme.spacing.xs),),- popover: (context) {- return _PopoverContent(- onSelectViewItem: (item) {- context- .read<AiPromptDatabaseSelectorCubit>()- .selectDatabaseView(item.view.id);- popoverController.hide();- },- );- },- child: AFOutlinedButton.normal(- onTap: () {- context- .read<ViewSelectorCubit>()- .refreshSources(state.$1, state.$2);- popoverController.toggle();- },- builder: (context, isHovering, disabled) {- return Row(- mainAxisSize: MainAxisSize.min,- spacing: theme.spacing.s,- children: [- Flexible(- child: Text(- viewName == null- ? LocaleKeys.ai_customPrompt_selectDatabase- .tr()- : viewName!,- style: theme.textStyle.body.enhanced(- color: theme.textColorScheme.primary,- ),- ),+ child: BlocSelector<SpaceBloc, SpaceState,+ (List<ViewPB>, ViewPB?)>(+ selector: (state) => (state.spaces, state.currentSpace),+ builder: (context, state) {+ return AFPopover(+ controller: popoverController,+ decoration: BoxDecoration(+ color: theme.surfaceColorScheme.primary,+ borderRadius:+ BorderRadius.circular(theme.borderRadius.l),+ border: Border.all(+ color: theme.borderColorScheme.primary,),- FlowySvg(- FlowySvgs.toolbar_arrow_down_m,- size: Size(12, 20),- ),- ],+ boxShadow: theme.shadow.medium,+ ),+ padding: EdgeInsets.zero,+ anchor: AFAnchor(+ childAlignment: Alignment.topCenter,+ overlayAlignment: Alignment.bottomCenter,+ offset: Offset(0, theme.spacing.xs),+ ),+ popover: (context) {+ return _PopoverContent(+ onSelectViewItem: (item) {+ context+ .read<AiPromptDatabaseSelectorCubit>()+ .selectDatabaseView(item.view.id);+ popoverController.hide();+ },+ );+ },+ child: AFOutlinedButton.normal(+ onTap: () {+ context+ .read<ViewSelectorCubit>()+ .refreshSources(state.$1, state.$2);+ popoverController.toggle();+ },+ builder: (context, isHovering, disabled) {+ return Row(+ mainAxisSize: MainAxisSize.min,+ spacing: theme.spacing.s,+ children: [+ Flexible(+ child: Text(+ viewName ??+ LocaleKeys+ .ai_customPrompt_selectDatabase+ .tr(),+ style: theme.textStyle.body.enhanced(+ color: theme.textColorScheme.primary,+ ),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ ),+ ),+ FlowySvg(+ FlowySvgs.toolbar_arrow_down_m,+ color: theme.iconColorScheme.primary,+ size: Size(12, 20),+ ),+ ],+ );+ },+ ),);},),),- );- },- ),+ ),+ ),+ ],),);},@@ -341,13 +363,8 @@ class _Expanded extends StatelessWidget {return state.maybeMap(orElse: () => SizedBox.shrink(),selected: (selectedState) {- return Container(- decoration: BoxDecoration(- borderRadius: BorderRadius.circular(theme.borderRadius.l),- ),- padding: EdgeInsets.all(- theme.spacing.m,- ),+ return Padding(+ padding: EdgeInsets.all(theme.spacing.m),child: Column(mainAxisSize: MainAxisSize.min,crossAxisAlignment: CrossAxisAlignment.start,@@ -517,7 +534,19 @@ class _PopoverContentState extends State<_PopoverContent> {}}-class FieldSelector extends StatefulWidget {+class _FieldPBWrapper extends Equatable with AFDropDownMenuMixin {+ const _FieldPBWrapper(this.field);++ final FieldPB field;++ @override+ String get label => field.name;++ @override+ List<Object?> get props => [field.id];+}++class FieldSelector extends StatelessWidget {const FieldSelector({super.key,required this.title,@@ -535,25 +564,12 @@ class FieldSelector extends StatefulWidget {final List<FieldPB> fields;final void Function(String? id)? onSelect;- @override- State<FieldSelector> createState() => _FieldSelectorState();-}--class _FieldSelectorState extends State<FieldSelector> {- final popoverController = AFPopoverController();-- @override- void dispose() {- popoverController.dispose();- super.dispose();- }-@overrideWidget build(BuildContext context) {final theme = AppFlowyTheme.of(context);- final selectedField = widget.fields.firstWhereOrNull(- (field) => field.id == widget.currentFieldId,+ final selectedField = fields.firstWhereOrNull(+ (field) => field.id == currentFieldId,);return Row(@@ -561,104 +577,49 @@ class _FieldSelectorState extends State<FieldSelector> {children: [Expanded(child: Text(- widget.title,+ title,style: theme.textStyle.body.standard(color: theme.textColorScheme.secondary,),),),- AFPopover(- controller: popoverController,- decoration: BoxDecoration(- color: theme.surfaceColorScheme.primary,- borderRadius: BorderRadius.circular(theme.borderRadius.l),- border: Border.all(- color: theme.borderColorScheme.primary,- ),- boxShadow: theme.shadow.medium,- ),- padding: EdgeInsets.zero,- anchor: AFAnchor(- childAlignment: Alignment.topCenter,- overlayAlignment: Alignment.bottomCenter,- offset: Offset(0, theme.spacing.xs),- ),- popover: (context) {- return ConstrainedBox(- constraints: const BoxConstraints(maxWidth: 200),- child: ListView.builder(- itemCount: widget.fields.length,- shrinkWrap: true,- padding: EdgeInsets.all(theme.spacing.m),- itemBuilder: (context, index) {- final field = widget.fields[index];- return AFTextMenuItem(- title: field.name,- trailing: field.id == selectedField?.id- ? FlowySvg(- FlowySvgs.check_s,- size: const Size.square(20),- color: theme.fillColorScheme.themeThick,- )- : null,- onTap: () {- widget.onSelect?.call(field.id);- popoverController.hide();- },- );- },- ),- );- },- child: AFOutlinedButton.normal(- disabled: widget.isDisabled,- builder: (context, isHovering, disabled) {- return Row(- children: [- Text(- selectedField?.name ??- LocaleKeys.ai_customPrompt_selectField.tr(),- style: theme.textStyle.body.enhanced(- color: disabled- ? theme.textColorScheme.tertiary- : selectedField == null- ? theme.textColorScheme.secondary- : theme.textColorScheme.primary,+ Expanded(+ child: AFDropDownMenu<_FieldPBWrapper>(+ isDisabled: isDisabled,+ items: fields.map((field) => _FieldPBWrapper(field)).toList(),+ selectedItems: [+ if (selectedField != null) _FieldPBWrapper(selectedField),+ ],+ clearIcon: selectedField == null ||+ !fields.contains(selectedField) ||+ !isOptional+ ? null+ : MouseRegion(+ cursor: SystemMouseCursors.click,+ child: GestureDetector(+ onTap: () {+ onSelect?.call(null);+ },+ child: FlowySvg(+ FlowySvgs.search_clear_m,+ size: Size.square(16),+ color: theme.iconColorScheme.tertiary,+ ),),),- HSpace(- theme.spacing.s,- ),- FlowySvg(- FlowySvgs.toolbar_arrow_down_m,- size: Size(12, 20),- ),- ],- );+ onSelected: (value) {+ if (value == null) {+ return;+ }+ onSelect?.call(value.field.id);},- onTap: () => popoverController.toggle(),+ dropdownIcon: FlowySvg(+ FlowySvgs.toolbar_arrow_down_m,+ color: theme.iconColorScheme.primary,+ size: Size(12, 20),+ ),),),- if (widget.isOptional)- AFGhostButton.normal(- onTap: () {- widget.onSelect?.call(null);- },- padding: EdgeInsets.all(theme.spacing.xs),- disabled: widget.currentFieldId == null ||- !widget.fields.map((f) => f.id).contains(widget.currentFieldId),- builder: (context, isHovering, disabled) {- return FlowySvg(- FlowySvgs.eraser_m,- size: const Size.square(20),- color: disabled- ? theme.iconColorScheme.tertiary- : theme.iconColorScheme.primary,- );- },- )- else- const SizedBox.square(dimension: 28),],);}diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dartindex 7a31b4257b..33c1cfae3a 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart@@ -46,6 +46,7 @@ class AiPromptModal extends StatelessWidget {final theme = AppFlowyTheme.of(context);return AFModal(+ backgroundColor: theme.backgroundColorScheme.primary,constraints: const BoxConstraints(maxWidth: 1200,maxHeight: 800,diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dartindex 84f3674a73..687d1597ea 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_visible_list.dart@@ -60,13 +60,6 @@ class _AiPromptVisibleListState extends State<AiPromptVisibleList> {return Column(children: [- Padding(- padding: EdgeInsets.symmetric(horizontal: theme.spacing.l),- child: buildSearchField(context),- ),- VSpace(- theme.spacing.s,- ),BlocConsumer<AiPromptSelectorCubit, AiPromptSelectorState>(listener: (context, state) {state.maybeMap(@@ -95,21 +88,39 @@ class _AiPromptVisibleListState extends State<AiPromptVisibleList> {if (!readyState.isCustomPromptSectionSelected) {return const SizedBox.shrink();}- return Padding(- padding: EdgeInsets.only(+ return Container(+ margin: EdgeInsets.only(left: theme.spacing.l,- top: theme.spacing.s,right: theme.spacing.l,+ bottom: theme.spacing.l,+ ),+ decoration: BoxDecoration(+ borderRadius: BorderRadius.circular(theme.borderRadius.m),+ color: theme.surfaceContainerColorScheme.layer01,),+ padding: EdgeInsets.all(theme.spacing.m),child: Row(children: [Expanded(- child: Text(- "${LocaleKeys.ai_customPrompt_promptDatabase.tr()}: ${readyState.databaseConfig?.view.nameOrDefault ?? ""}",- maxLines: 1,+ child: Text.rich(+ TextSpan(+ children: [+ TextSpan(+ text:+ "${LocaleKeys.ai_customPrompt_promptDatabase.tr()}: ",+ style: TextStyle(fontWeight: FontWeight.w500),+ ),+ TextSpan(+ text: readyState+ .databaseConfig?.view.nameOrDefault ??+ "",+ ),+ ],+ ),style: theme.textStyle.body.standard(color: theme.textColorScheme.primary,),+ maxLines: 1,overflow: TextOverflow.ellipsis,),),@@ -165,6 +176,10 @@ class _AiPromptVisibleListState extends State<AiPromptVisibleList> {);},),+ Padding(+ padding: EdgeInsets.symmetric(horizontal: theme.spacing.l),+ child: buildSearchField(context),+ ),Expanded(child: TextFieldTapRegion(groupId: "ai_prompt_category_list",diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/modal/modal.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/modal/modal.dartindex 4b40aebcbd..3b37fe2e64 100644--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/modal/modal.dart+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/modal/modal.dart@@ -7,10 +7,12 @@ class AFModal extends StatelessWidget {const AFModal({super.key,this.constraints = const BoxConstraints(),+ this.backgroundColor,required this.child,});final BoxConstraints constraints;+ final Color? backgroundColor;final Widget child;@override@@ -26,7 +28,7 @@ class AFModal extends StatelessWidget {decoration: BoxDecoration(boxShadow: theme.shadow.medium,borderRadius: BorderRadius.circular(theme.borderRadius.xl),- color: theme.surfaceColorScheme.primary,+ color: backgroundColor ?? theme.surfaceColorScheme.primary,),child: Material(color: Colors.transparent,