mirror of
				https://github.com/MindWorkAI/AI-Studio.git
				synced 2025-11-04 01:20:21 +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 bool IsChat { get; init; }
 | 
			
		||||
    public TreeItemType Type { get; init; }
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
                
 | 
			
		||||
            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>
 | 
			
		||||
                            <div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
 | 
			
		||||
                                <MudText Style="justify-self: start;">@treeItem.Text</MudText>
 | 
			
		||||
@ -28,9 +28,28 @@
 | 
			
		||||
                        </BodyContent>
 | 
			
		||||
                    </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
 | 
			
		||||
                {
 | 
			
		||||
                    <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>
 | 
			
		||||
                            <div style="display: grid; grid-template-columns: 1fr auto; align-items: center; width: 100%">
 | 
			
		||||
                                <MudText Style="justify-self: start;">@treeItem.Text</MudText>
 | 
			
		||||
 | 
			
		||||
@ -108,7 +108,7 @@ public partial class Workspaces : ComponentBase
 | 
			
		||||
                            
 | 
			
		||||
            tempChildren.Add(new TreeItemData
 | 
			
		||||
            {
 | 
			
		||||
                IsChat = true,
 | 
			
		||||
                Type = TreeItemType.CHAT,
 | 
			
		||||
                Depth = 1,
 | 
			
		||||
                Branch = WorkspaceBranch.TEMPORARY_CHATS,
 | 
			
		||||
                Text = chatName,
 | 
			
		||||
@ -154,7 +154,7 @@ public partial class Workspaces : ComponentBase
 | 
			
		||||
                                
 | 
			
		||||
            workspaces.Add(new TreeItemData
 | 
			
		||||
            {
 | 
			
		||||
                IsChat = false,
 | 
			
		||||
                Type = TreeItemType.WORKSPACE,
 | 
			
		||||
                Depth = 1,
 | 
			
		||||
                Branch = WorkspaceBranch.WORKSPACES,
 | 
			
		||||
                Text = workspaceName,
 | 
			
		||||
@ -182,7 +182,7 @@ public partial class Workspaces : ComponentBase
 | 
			
		||||
                                
 | 
			
		||||
            workspaceChats.Add(new TreeItemData
 | 
			
		||||
            {
 | 
			
		||||
                IsChat = true,
 | 
			
		||||
                Type = TreeItemType.CHAT,
 | 
			
		||||
                Depth = 2,
 | 
			
		||||
                Branch = WorkspaceBranch.WORKSPACES,
 | 
			
		||||
                Text = chatName,
 | 
			
		||||
@ -309,6 +309,31 @@ public partial class Workspaces : ComponentBase
 | 
			
		||||
        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()
 | 
			
		||||
    {
 | 
			
		||||
        var dialogParameters = new DialogParameters
 | 
			
		||||
@ -333,6 +358,31 @@ public partial class Workspaces : ComponentBase
 | 
			
		||||
        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)
 | 
			
		||||
    {
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user