Files
Auto-GPT/frontend/lib/views/main_layout.dart
hunteraraujo 314cce75b5 Integrate TaskQueueView and Enhance SkillTree Functionality (#5206)
* Add TestQueueView to Main Layout

This commit integrates the TestQueueView into the main layout. The layout now conditionally displays the TestQueueView based on whether a node in the SkillTree is selected.

- TestQueueView appears when a SkillTree node is selected.
- Main layout adjusts to accommodate TestQueueView alongside SkillTreeView and ChatView.
- Implemented responsive layout logic to manage the widths of the different views based on the screen width and the state of the SkillTree.

* Extend SkillTreeViewModel to Track Selected Node Hierarchy

This commit enhances the SkillTreeViewModel to maintain a list of nodes that form a hierarchy from the currently selected node to the root. This allows for more interactive and informative views that can leverage this hierarchical data.

- Added a new property `selectedNodeHierarchy` to keep track of the node hierarchy.
- Modified the `toggleNodeSelection` method to populate or clear `selectedNodeHierarchy` based on node selection.
- Introduced a new method `populateSelectedNodeHierarchy` to build the hierarchy from the selected node to the root.

* Extract skill tree view model reset state to method

* Implement UI enhancements for TaskQueueView

This commit introduces several UI improvements to the TaskQueueView:
- Tiles are padded 20 units from both the leading and trailing edges.
- Tiles now have a white background.
- Added a thin black border to the tiles.
- Incorporated a slight corner radius for the tiles.
- Centered the title and subtitle horizontally within the tiles.
- Added a checkmark button with a tooltip at the bottom-right corner for running a suite of tests.

These changes aim to improve the user experience and visual appeal of the TaskQueueView.

* Make MainLayout a consumer of SkillTreeViewModel
2023-09-12 14:01:32 -07:00

144 lines
5.3 KiB
Dart

import 'package:auto_gpt_flutter_client/viewmodels/skill_tree_viewmodel.dart';
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart';
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';
import 'package:auto_gpt_flutter_client/views/side_bar/side_bar_view.dart';
import 'package:auto_gpt_flutter_client/views/skill_tree/skill_tree_view.dart';
import 'package:auto_gpt_flutter_client/views/task/task_view.dart';
import 'package:auto_gpt_flutter_client/views/chat/chat_view.dart';
import 'package:auto_gpt_flutter_client/views/task_queue/task_queue_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
class MainLayout extends StatelessWidget {
final ValueNotifier<String> selectedViewNotifier = ValueNotifier('TaskView');
MainLayout({super.key});
@override
Widget build(BuildContext context) {
// Get the screen width
double width = MediaQuery.of(context).size.width;
// Access the various ViewModels from the context
final taskViewModel = Provider.of<TaskViewModel>(context);
final chatViewModel = Provider.of<ChatViewModel>(context);
// Initialize the width for the SideBarView
double sideBarWidth = 60.0;
// Initialize the width for the TaskView
double taskViewWidth = 280.0;
// Calculate remaining width after subtracting the width of the SideBarView
double remainingWidth = width - sideBarWidth;
// Declare variables to hold the widths of SkillTreeView, TestQueueView, and ChatView
double skillTreeViewWidth = 0;
double testQueueViewWidth = 0;
double chatViewWidth = 0;
if (width > 800) {
return Row(
children: [
SizedBox(
width: sideBarWidth,
child: SideBarView(selectedViewNotifier: selectedViewNotifier)),
ValueListenableBuilder(
valueListenable: selectedViewNotifier,
builder: (context, String value, _) {
return Consumer<SkillTreeViewModel>(
builder: (context, skillTreeViewModel, _) {
if (value == 'TaskView') {
skillTreeViewModel.resetState();
chatViewWidth = remainingWidth - taskViewWidth;
return Row(
children: [
SizedBox(
width: taskViewWidth,
child: TaskView(viewModel: taskViewModel)),
SizedBox(
width: chatViewWidth,
child: ChatView(viewModel: chatViewModel))
],
);
} else {
if (skillTreeViewModel.selectedNode != null) {
// If TaskQueueView should be displayed
testQueueViewWidth = remainingWidth * 0.25;
skillTreeViewWidth = remainingWidth * 0.25;
chatViewWidth = remainingWidth * 0.5;
} else {
// If only SkillTreeView and ChatView should be displayed
skillTreeViewWidth = remainingWidth * 0.5;
chatViewWidth = remainingWidth * 0.5;
}
return Row(
children: [
SizedBox(
width: skillTreeViewWidth,
child:
SkillTreeView(viewModel: skillTreeViewModel)),
if (skillTreeViewModel.selectedNode != null)
SizedBox(
width: testQueueViewWidth,
child: TaskQueueView()),
SizedBox(
width: chatViewWidth,
child: ChatView(viewModel: chatViewModel)),
],
);
}
},
);
},
),
],
);
} else {
// For smaller screens, return a tabbed layout
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.person),
label: 'Tasks',
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.chat_bubble),
label: 'Chat',
),
],
),
tabBuilder: (BuildContext context, int index) {
CupertinoTabView? returnValue;
switch (index) {
case 0:
returnValue = CupertinoTabView(builder: (context) {
return CupertinoPageScaffold(
child: SafeArea(child: TaskView(viewModel: taskViewModel)),
);
});
break;
case 1:
returnValue = CupertinoTabView(builder: (context) {
return CupertinoPageScaffold(
child: SafeArea(child: ChatView(viewModel: chatViewModel)),
);
});
break;
}
return returnValue ??
CupertinoTabView(builder: (context) {
return CupertinoPageScaffold(
child: Container(), // Default empty container
);
});
},
);
}
}
}