mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 15:59:48 +00:00
Implemented rename and delete operations for workspaces
This commit is contained in:
parent
50da92ee29
commit
7b5d2df873
@ -10,7 +10,7 @@ public class TreeItemData : ITreeItem
|
|||||||
|
|
||||||
public string Icon { get; init; } = string.Empty;
|
public string Icon { get; init; } = string.Empty;
|
||||||
|
|
||||||
public bool IsChat { get; init; }
|
public TreeItemType Type { get; init; }
|
||||||
|
|
||||||
public string Path { get; init; } = string.Empty;
|
public string Path { get; init; } = string.Empty;
|
||||||
|
|
||||||
|
9
app/MindWork AI Studio/Components/Blocks/TreeItemType.cs
Normal file
9
app/MindWork AI Studio/Components/Blocks/TreeItemType.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace AIStudio.Components.Blocks;
|
||||||
|
|
||||||
|
public enum TreeItemType
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
|
||||||
|
CHAT,
|
||||||
|
WORKSPACE,
|
||||||
|
}
|
@ -9,9 +9,9 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TreeItemData treeItem:
|
case TreeItemData treeItem:
|
||||||
@if (treeItem.IsChat)
|
@if (treeItem.Type is TreeItemType.CHAT)
|
||||||
{
|
{
|
||||||
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item" LoadingIconColor="@Color.Info" CanExpand="@treeItem.Expandable" Items="@treeItem.Children" OnClick="() => this.LoadChat(treeItem.Path, true)">
|
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item" CanExpand="@treeItem.Expandable" Items="@treeItem.Children" OnClick="() => this.LoadChat(treeItem.Path, true)">
|
||||||
<BodyContent>
|
<BodyContent>
|
||||||
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
|
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
|
||||||
<MudText Style="justify-self: start;">@treeItem.Text</MudText>
|
<MudText Style="justify-self: start;">@treeItem.Text</MudText>
|
||||||
@ -28,9 +28,28 @@
|
|||||||
</BodyContent>
|
</BodyContent>
|
||||||
</MudTreeViewItem>
|
</MudTreeViewItem>
|
||||||
}
|
}
|
||||||
|
else if (treeItem.Type is TreeItemType.WORKSPACE)
|
||||||
|
{
|
||||||
|
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item" 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>
|
||||||
|
<div style="justify-self: end;">
|
||||||
|
<MudTooltip Text="Rename" Placement="Placement.Right">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Medium" Color="Color.Inherit" OnClick="() => this.RenameWorkspace(treeItem.Path)"/>
|
||||||
|
</MudTooltip>
|
||||||
|
|
||||||
|
<MudTooltip Text="Delete" Placement="Placement.Right">
|
||||||
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Medium" Color="Color.Inherit" OnClick="() => this.DeleteWorkspace(treeItem.Path)"/>
|
||||||
|
</MudTooltip>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</BodyContent>
|
||||||
|
</MudTreeViewItem>
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item" LoadingIconColor="@Color.Info" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
|
<MudTreeViewItem T="ITreeItem" Icon="@treeItem.Icon" Value="@item" CanExpand="@treeItem.Expandable" Items="@treeItem.Children">
|
||||||
<BodyContent>
|
<BodyContent>
|
||||||
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
|
<div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
|
||||||
<MudText Style="justify-self: start;">@treeItem.Text</MudText>
|
<MudText Style="justify-self: start;">@treeItem.Text</MudText>
|
||||||
|
@ -108,7 +108,7 @@ public partial class Workspaces : ComponentBase
|
|||||||
|
|
||||||
tempChildren.Add(new TreeItemData
|
tempChildren.Add(new TreeItemData
|
||||||
{
|
{
|
||||||
IsChat = true,
|
Type = TreeItemType.CHAT,
|
||||||
Depth = 1,
|
Depth = 1,
|
||||||
Branch = WorkspaceBranch.TEMPORARY_CHATS,
|
Branch = WorkspaceBranch.TEMPORARY_CHATS,
|
||||||
Text = chatName,
|
Text = chatName,
|
||||||
@ -154,7 +154,7 @@ public partial class Workspaces : ComponentBase
|
|||||||
|
|
||||||
workspaces.Add(new TreeItemData
|
workspaces.Add(new TreeItemData
|
||||||
{
|
{
|
||||||
IsChat = false,
|
Type = TreeItemType.WORKSPACE,
|
||||||
Depth = 1,
|
Depth = 1,
|
||||||
Branch = WorkspaceBranch.WORKSPACES,
|
Branch = WorkspaceBranch.WORKSPACES,
|
||||||
Text = workspaceName,
|
Text = workspaceName,
|
||||||
@ -182,7 +182,7 @@ public partial class Workspaces : ComponentBase
|
|||||||
|
|
||||||
workspaceChats.Add(new TreeItemData
|
workspaceChats.Add(new TreeItemData
|
||||||
{
|
{
|
||||||
IsChat = true,
|
Type = TreeItemType.CHAT,
|
||||||
Depth = 2,
|
Depth = 2,
|
||||||
Branch = WorkspaceBranch.WORKSPACES,
|
Branch = WorkspaceBranch.WORKSPACES,
|
||||||
Text = chatName,
|
Text = chatName,
|
||||||
@ -309,6 +309,31 @@ public partial class Workspaces : ComponentBase
|
|||||||
await this.LoadTreeItems();
|
await this.LoadTreeItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task RenameWorkspace(string? workspacePath)
|
||||||
|
{
|
||||||
|
if(workspacePath is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var workspaceId = Guid.Parse(Path.GetFileName(workspacePath));
|
||||||
|
var workspaceName = await this.LoadWorkspaceName(workspaceId);
|
||||||
|
var dialogParameters = new DialogParameters
|
||||||
|
{
|
||||||
|
{ "Message", $"Please enter a new or edit the name for your workspace '{workspaceName}':" },
|
||||||
|
{ "UserInput", workspaceName },
|
||||||
|
{ "ConfirmText", "Rename" },
|
||||||
|
};
|
||||||
|
|
||||||
|
var dialogReference = await this.DialogService.ShowAsync<SingleInputDialog>("Rename Workspace", dialogParameters, DialogOptions.FULLSCREEN);
|
||||||
|
var dialogResult = await dialogReference.Result;
|
||||||
|
if (dialogResult.Canceled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var alteredWorkspaceName = (dialogResult.Data as string)!;
|
||||||
|
var workspaceNamePath = Path.Join(workspacePath, "name");
|
||||||
|
await File.WriteAllTextAsync(workspaceNamePath, alteredWorkspaceName, Encoding.UTF8);
|
||||||
|
await this.LoadTreeItems();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task AddWorkspace()
|
private async Task AddWorkspace()
|
||||||
{
|
{
|
||||||
var dialogParameters = new DialogParameters
|
var dialogParameters = new DialogParameters
|
||||||
@ -333,6 +358,31 @@ public partial class Workspaces : ComponentBase
|
|||||||
await this.LoadTreeItems();
|
await this.LoadTreeItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task DeleteWorkspace(string? workspacePath)
|
||||||
|
{
|
||||||
|
if(workspacePath is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var workspaceId = Guid.Parse(Path.GetFileName(workspacePath));
|
||||||
|
var workspaceName = await this.LoadWorkspaceName(workspaceId);
|
||||||
|
|
||||||
|
// Determine how many chats are in the workspace:
|
||||||
|
var chatCount = Directory.EnumerateDirectories(workspacePath).Count();
|
||||||
|
|
||||||
|
var dialogParameters = new DialogParameters
|
||||||
|
{
|
||||||
|
{ "Message", $"Are you sure you want to delete the workspace '{workspaceName}'? This will also delete {chatCount} chat(s) in this workspace." },
|
||||||
|
};
|
||||||
|
|
||||||
|
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>("Delete Workspace", dialogParameters, DialogOptions.FULLSCREEN);
|
||||||
|
var dialogResult = await dialogReference.Result;
|
||||||
|
if (dialogResult.Canceled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Directory.Delete(workspacePath, true);
|
||||||
|
await this.LoadTreeItems();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task AddChat(string workspacePath)
|
private async Task AddChat(string workspacePath)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user