Allow expanding all root nodes (default by now)

This commit is contained in:
Thorsten Sommer 2024-11-02 22:46:16 +01:00
parent 71634ea566
commit b5cac31d08
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 21 additions and 14 deletions

View File

@ -1,4 +1,4 @@
<MudTreeView T="ITreeItem" Items="@this.treeItems" SelectionMode="SelectionMode.SingleSelection" Hover="@true" ExpandOnClick="@true">
<MudTreeView T="ITreeItem" Items="@this.treeItems" SelectionMode="SelectionMode.SingleSelection" Hover="@true" ExpandOnClick="@true" Class="ma-3">
<ItemTemplate Context="item">
@switch (item.Value)
{
@ -11,7 +11,7 @@
case TreeItemData treeItem:
@if (treeItem.Type is TreeItemType.CHAT)
{
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" CanExpand="@treeItem.Expandable" Items="@treeItem.Children" OnClick="() => this.LoadChat(treeItem.Path, true)">
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@treeItem.Expandable" Items="@treeItem.Children" OnClick="() => this.LoadChat(treeItem.Path, true)">
<BodyContent>
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;">
@ -44,7 +44,7 @@
}
else if (treeItem.Type is TreeItemType.WORKSPACE)
{
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
<BodyContent>
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;">@treeItem.Text</MudText>
@ -63,7 +63,7 @@
}
else
{
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item.Value" Expanded="@item.Expanded" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
<BodyContent>
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
<MudText Style="justify-self: start;">@treeItem.Text</MudText>

View File

@ -35,6 +35,9 @@ public partial class Workspaces : ComponentBase
[Parameter]
public Func<Task> LoadedChatWasChanged { get; set; } = () => Task.CompletedTask;
[Parameter]
public bool ExpandRootNodes { get; set; } = true;
private const Placement WORKSPACE_ITEM_TOOLTIP_PLACEMENT = Placement.Bottom;
public static readonly Guid WORKSPACE_ID_BIAS = Guid.Parse("82050a4e-ee92-43d7-8ee5-ab512f847e02");
@ -73,9 +76,9 @@ public partial class Workspaces : ComponentBase
private async Task LoadTreeItems()
{
this.treeItems.Clear();
this.treeItems.Add(new TreeItemData<ITreeItem>
var workspacesNode = new TreeItemData<ITreeItem>
{
Expanded = this.ExpandRootNodes,
Expandable = true,
Value = new TreeItemData
{
@ -87,16 +90,11 @@ public partial class Workspaces : ComponentBase
Path = "root",
Children = await this.LoadWorkspaces(),
},
});
};
this.treeItems.Add(new TreeItemData<ITreeItem>
{
Expandable = false,
Value = new TreeDivider(),
});
this.treeItems.Add(new TreeItemData<ITreeItem>
var tempChatNode = new TreeItemData<ITreeItem>
{
Expanded = this.ExpandRootNodes,
Expandable = true,
Value = new TreeItemData
{
@ -108,7 +106,16 @@ public partial class Workspaces : ComponentBase
Path = "temp",
Children = await this.LoadTemporaryChats(),
},
};
this.treeItems.Clear();
this.treeItems.Add(workspacesNode);
this.treeItems.Add(new TreeItemData<ITreeItem>
{
Expandable = false,
Value = new TreeDivider(),
});
this.treeItems.Add(tempChatNode);
}
private async Task<IReadOnlyCollection<TreeItemData<ITreeItem>>> LoadTemporaryChats()