Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| adcc9afe05 | |||
| 24d1e472a2 | |||
| da1b210865 | |||
| eadf630c61 | |||
| 4fb073a1ff |
@@ -9,9 +9,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
|
|
||||||
"moku-backend/internal/database"
|
"moku-backend/internal/database"
|
||||||
@@ -38,6 +40,9 @@ const (
|
|||||||
bootstrapWorkspaceKindDept = "department"
|
bootstrapWorkspaceKindDept = "department"
|
||||||
bootstrapWorkspaceKindTeam = "team"
|
bootstrapWorkspaceKindTeam = "team"
|
||||||
bootstrapWorkspaceKindProject = "project"
|
bootstrapWorkspaceKindProject = "project"
|
||||||
|
projectFolderOrderRootKey = "__root__"
|
||||||
|
projectFolderOrderHierarchy = "hierarchy"
|
||||||
|
projectFolderOrderTree = "tree"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -183,6 +188,7 @@ type namedRecord struct {
|
|||||||
|
|
||||||
type ProjectHierarchyFolderRecord struct {
|
type ProjectHierarchyFolderRecord struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
Path string `json:"path"`
|
||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Children []ProjectHierarchyFolderRecord `json:"children"`
|
Children []ProjectHierarchyFolderRecord `json:"children"`
|
||||||
}
|
}
|
||||||
@@ -207,7 +213,10 @@ type RenameProjectFolderInput struct {
|
|||||||
type MoveProjectFolderInput struct {
|
type MoveProjectFolderInput struct {
|
||||||
ProjectID string
|
ProjectID string
|
||||||
FolderID string
|
FolderID string
|
||||||
|
FolderNodeID string
|
||||||
ParentFolderID string
|
ParentFolderID string
|
||||||
|
ParentNodeID string
|
||||||
|
TargetIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateProjectFolderResult struct {
|
type CreateProjectFolderResult struct {
|
||||||
@@ -217,26 +226,30 @@ type CreateProjectFolderResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DeleteProjectFolderResult struct {
|
type DeleteProjectFolderResult struct {
|
||||||
ProjectID string `json:"projectId"`
|
ProjectID string `json:"projectId"`
|
||||||
DeletedFolderID string `json:"deletedFolderId"`
|
DeletedFolderID string `json:"deletedFolderId"`
|
||||||
Folders []ProjectHierarchyFolderRecord `json:"folders"`
|
DeletedFolderPath string `json:"deletedFolderPath"`
|
||||||
|
Folders []ProjectHierarchyFolderRecord `json:"folders"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RenameProjectFolderResult struct {
|
type RenameProjectFolderResult struct {
|
||||||
ProjectID string `json:"projectId"`
|
ProjectID string `json:"projectId"`
|
||||||
PreviousFolderID string `json:"previousFolderId"`
|
PreviousFolderID string `json:"previousFolderId"`
|
||||||
RenamedFolder ProjectHierarchyFolderRecord `json:"renamedFolder"`
|
PreviousFolderPath string `json:"previousFolderPath"`
|
||||||
Folders []ProjectHierarchyFolderRecord `json:"folders"`
|
RenamedFolder ProjectHierarchyFolderRecord `json:"renamedFolder"`
|
||||||
|
Folders []ProjectHierarchyFolderRecord `json:"folders"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MoveProjectFolderResult struct {
|
type MoveProjectFolderResult struct {
|
||||||
ProjectID string `json:"projectId"`
|
ProjectID string `json:"projectId"`
|
||||||
PreviousFolderID string `json:"previousFolderId"`
|
PreviousFolderID string `json:"previousFolderId"`
|
||||||
MovedFolder ProjectHierarchyFolderRecord `json:"movedFolder"`
|
PreviousFolderPath string `json:"previousFolderPath"`
|
||||||
Folders []ProjectHierarchyFolderRecord `json:"folders"`
|
MovedFolder ProjectHierarchyFolderRecord `json:"movedFolder"`
|
||||||
|
Folders []ProjectHierarchyFolderRecord `json:"folders"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type projectHierarchyFolderRow struct {
|
type projectHierarchyFolderRow struct {
|
||||||
|
ID string
|
||||||
Path string
|
Path string
|
||||||
ParentPath string
|
ParentPath string
|
||||||
Label string
|
Label string
|
||||||
@@ -900,6 +913,7 @@ func (service *Service) getProjectHierarchyFoldersByRootPath(
|
|||||||
|
|
||||||
rows, err := service.db.Pool.Query(ctx, `
|
rows, err := service.db.Pool.Query(ctx, `
|
||||||
SELECT
|
SELECT
|
||||||
|
COALESCE(folder_meta.resource_id, ''),
|
||||||
directories.path,
|
directories.path,
|
||||||
COALESCE(directories.parent_path, ''),
|
COALESCE(directories.parent_path, ''),
|
||||||
COALESCE(folder_meta.resource_name, directories.resource_name, '')
|
COALESCE(folder_meta.resource_name, directories.resource_name, '')
|
||||||
@@ -921,7 +935,7 @@ func (service *Service) getProjectHierarchyFoldersByRootPath(
|
|||||||
var folderRows []projectHierarchyFolderRow
|
var folderRows []projectHierarchyFolderRow
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var row projectHierarchyFolderRow
|
var row projectHierarchyFolderRow
|
||||||
if err := rows.Scan(&row.Path, &row.ParentPath, &row.Label); err != nil {
|
if err := rows.Scan(&row.ID, &row.Path, &row.ParentPath, &row.Label); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
folderRows = append(folderRows, row)
|
folderRows = append(folderRows, row)
|
||||||
@@ -931,7 +945,10 @@ func (service *Service) getProjectHierarchyFoldersByRootPath(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildProjectHierarchyFolderTree(folderRows, rootParentPath), nil
|
folders := buildProjectHierarchyFolderTree(folderRows, rootParentPath)
|
||||||
|
folderOrder := service.readProjectFolderOrder(project.Slug, rootParentPath)
|
||||||
|
|
||||||
|
return applyProjectHierarchyFolderOrdering(folders, folderOrder), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (service *Service) CreateProjectFolder(ctx context.Context, input CreateProjectFolderInput) (CreateProjectFolderResult, error) {
|
func (service *Service) CreateProjectFolder(ctx context.Context, input CreateProjectFolderInput) (CreateProjectFolderResult, error) {
|
||||||
@@ -977,6 +994,21 @@ func (service *Service) createProjectHierarchyFolder(
|
|||||||
return CreateProjectFolderResult{}, err
|
return CreateProjectFolderResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentFolders, err := service.getProjectHierarchyFoldersByRootPath(ctx, project.ID, rootPath)
|
||||||
|
if err != nil {
|
||||||
|
return CreateProjectFolderResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
parentOrderID := ""
|
||||||
|
trimmedParentFolderID := strings.TrimSpace(input.ParentFolderID)
|
||||||
|
if trimmedParentFolderID != "" {
|
||||||
|
parentFolder, found := findProjectHierarchyFolderByPath(currentFolders, trimmedParentFolderID)
|
||||||
|
if !found {
|
||||||
|
return CreateProjectFolderResult{}, ErrProjectFolderNotFound
|
||||||
|
}
|
||||||
|
parentOrderID = parentFolder.ID
|
||||||
|
}
|
||||||
|
|
||||||
createdPath, _, err := createOnDisk(project.Slug, strings.TrimSpace(input.ParentFolderID), input.Name)
|
createdPath, _, err := createOnDisk(project.Slug, strings.TrimSpace(input.ParentFolderID), input.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CreateProjectFolderResult{}, err
|
return CreateProjectFolderResult{}, err
|
||||||
@@ -991,11 +1023,28 @@ func (service *Service) createProjectHierarchyFolder(
|
|||||||
return CreateProjectFolderResult{}, err
|
return CreateProjectFolderResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
createdFolder, ok := findProjectHierarchyFolder(folders, createdPath)
|
createdFolder, ok := findProjectHierarchyFolderByPath(folders, createdPath)
|
||||||
if !ok {
|
if !ok {
|
||||||
return CreateProjectFolderResult{}, fmt.Errorf("created project folder missing from projection")
|
return CreateProjectFolderResult{}, fmt.Errorf("created project folder missing from projection")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
folderOrder := service.readProjectFolderOrder(project.Slug, rootPath(project.Slug))
|
||||||
|
seedFolderOrderParent(folderOrder, currentFolders, parentOrderID)
|
||||||
|
insertFolderOrder(folderOrder, parentOrderID, createdFolder.ID, len(folderOrderChildren(folderOrder, parentOrderID)))
|
||||||
|
if err := service.writeProjectFolderOrder(project.Slug, rootPath(project.Slug), folderOrder); err != nil {
|
||||||
|
return CreateProjectFolderResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
folders, err = service.getProjectHierarchyFoldersByRootPath(ctx, project.ID, rootPath)
|
||||||
|
if err != nil {
|
||||||
|
return CreateProjectFolderResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
createdFolder, ok = findProjectHierarchyFolderByPath(folders, createdPath)
|
||||||
|
if !ok {
|
||||||
|
return CreateProjectFolderResult{}, fmt.Errorf("created project folder missing from ordered projection")
|
||||||
|
}
|
||||||
|
|
||||||
return CreateProjectFolderResult{
|
return CreateProjectFolderResult{
|
||||||
ProjectID: project.ID,
|
ProjectID: project.ID,
|
||||||
CreatedFolder: createdFolder,
|
CreatedFolder: createdFolder,
|
||||||
@@ -1014,6 +1063,16 @@ func (service *Service) deleteProjectHierarchyFolder(
|
|||||||
return DeleteProjectFolderResult{}, err
|
return DeleteProjectFolderResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentFolders, err := service.getProjectHierarchyFoldersByRootPath(ctx, project.ID, rootPath)
|
||||||
|
if err != nil {
|
||||||
|
return DeleteProjectFolderResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
deletedFolder, found := findProjectHierarchyFolderByPath(currentFolders, strings.TrimSpace(input.FolderID))
|
||||||
|
if !found {
|
||||||
|
return DeleteProjectFolderResult{}, ErrProjectFolderNotFound
|
||||||
|
}
|
||||||
|
|
||||||
deletedFolderID, err := deleteOnDisk(project.Slug, input.FolderID)
|
deletedFolderID, err := deleteOnDisk(project.Slug, input.FolderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DeleteProjectFolderResult{}, err
|
return DeleteProjectFolderResult{}, err
|
||||||
@@ -1028,14 +1087,26 @@ func (service *Service) deleteProjectHierarchyFolder(
|
|||||||
return DeleteProjectFolderResult{}, err
|
return DeleteProjectFolderResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, found := findProjectHierarchyFolder(folders, deletedFolderID); found {
|
if _, found := findProjectHierarchyFolderByPath(folders, deletedFolderID); found {
|
||||||
return DeleteProjectFolderResult{}, fmt.Errorf("deleted project folder still present in projection")
|
return DeleteProjectFolderResult{}, fmt.Errorf("deleted project folder still present in projection")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
folderOrder := service.readProjectFolderOrder(project.Slug, rootPath(project.Slug))
|
||||||
|
removeFolderOrder(folderOrder, deletedFolder.ID)
|
||||||
|
if err := service.writeProjectFolderOrder(project.Slug, rootPath(project.Slug), folderOrder); err != nil {
|
||||||
|
return DeleteProjectFolderResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
folders, err = service.getProjectHierarchyFoldersByRootPath(ctx, project.ID, rootPath)
|
||||||
|
if err != nil {
|
||||||
|
return DeleteProjectFolderResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
return DeleteProjectFolderResult{
|
return DeleteProjectFolderResult{
|
||||||
ProjectID: project.ID,
|
ProjectID: project.ID,
|
||||||
DeletedFolderID: deletedFolderID,
|
DeletedFolderID: deletedFolder.ID,
|
||||||
Folders: folders,
|
DeletedFolderPath: deletedFolderID,
|
||||||
|
Folders: folders,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1064,20 +1135,21 @@ func (service *Service) renameProjectHierarchyFolder(
|
|||||||
return RenameProjectFolderResult{}, err
|
return RenameProjectFolderResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
renamedFolder, found := findProjectHierarchyFolder(folders, renamedFolderID)
|
renamedFolder, found := findProjectHierarchyFolderByPath(folders, renamedFolderID)
|
||||||
if !found {
|
if !found {
|
||||||
return RenameProjectFolderResult{}, fmt.Errorf("renamed project folder missing from projection")
|
return RenameProjectFolderResult{}, fmt.Errorf("renamed project folder missing from projection")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, found := findProjectHierarchyFolder(folders, previousFolderID); found {
|
if _, found := findProjectHierarchyFolderByPath(folders, previousFolderID); found {
|
||||||
return RenameProjectFolderResult{}, fmt.Errorf("previous project folder path still present in projection")
|
return RenameProjectFolderResult{}, fmt.Errorf("previous project folder path still present in projection")
|
||||||
}
|
}
|
||||||
|
|
||||||
return RenameProjectFolderResult{
|
return RenameProjectFolderResult{
|
||||||
ProjectID: project.ID,
|
ProjectID: project.ID,
|
||||||
PreviousFolderID: previousFolderID,
|
PreviousFolderID: renamedFolder.ID,
|
||||||
RenamedFolder: renamedFolder,
|
PreviousFolderPath: previousFolderID,
|
||||||
Folders: folders,
|
RenamedFolder: renamedFolder,
|
||||||
|
Folders: folders,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1092,6 +1164,38 @@ func (service *Service) moveProjectHierarchyFolder(
|
|||||||
return MoveProjectFolderResult{}, err
|
return MoveProjectFolderResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentFolders, err := service.getProjectHierarchyFoldersByRootPath(ctx, project.ID, rootPath)
|
||||||
|
if err != nil {
|
||||||
|
return MoveProjectFolderResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFolder, found := findProjectHierarchyFolderByPath(currentFolders, strings.TrimSpace(input.FolderID))
|
||||||
|
if !found {
|
||||||
|
return MoveProjectFolderResult{}, ErrProjectFolderNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
movedFolderOrderID := currentFolder.ID
|
||||||
|
providedFolderNodeID := strings.TrimSpace(input.FolderNodeID)
|
||||||
|
if providedFolderNodeID != "" && providedFolderNodeID != movedFolderOrderID {
|
||||||
|
return MoveProjectFolderResult{}, ErrInvalidProjectFolderMove
|
||||||
|
}
|
||||||
|
|
||||||
|
parentOrderID := ""
|
||||||
|
trimmedParentFolderID := strings.TrimSpace(input.ParentFolderID)
|
||||||
|
providedParentNodeID := strings.TrimSpace(input.ParentNodeID)
|
||||||
|
if trimmedParentFolderID != "" {
|
||||||
|
parentFolder, found := findProjectHierarchyFolderByPath(currentFolders, trimmedParentFolderID)
|
||||||
|
if !found {
|
||||||
|
return MoveProjectFolderResult{}, ErrProjectFolderNotFound
|
||||||
|
}
|
||||||
|
parentOrderID = parentFolder.ID
|
||||||
|
if providedParentNodeID != "" && providedParentNodeID != parentOrderID {
|
||||||
|
return MoveProjectFolderResult{}, ErrInvalidProjectFolderMove
|
||||||
|
}
|
||||||
|
} else if providedParentNodeID != "" {
|
||||||
|
return MoveProjectFolderResult{}, ErrInvalidProjectFolderMove
|
||||||
|
}
|
||||||
|
|
||||||
previousFolderID, movedFolderID, err := moveOnDisk(project.Slug, input.FolderID, input.ParentFolderID)
|
previousFolderID, movedFolderID, err := moveOnDisk(project.Slug, input.FolderID, input.ParentFolderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MoveProjectFolderResult{}, err
|
return MoveProjectFolderResult{}, err
|
||||||
@@ -1106,22 +1210,42 @@ func (service *Service) moveProjectHierarchyFolder(
|
|||||||
return MoveProjectFolderResult{}, err
|
return MoveProjectFolderResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
movedFolder, found := findProjectHierarchyFolder(folders, movedFolderID)
|
movedFolder, found := findProjectHierarchyFolderByPath(folders, movedFolderID)
|
||||||
if !found {
|
if !found {
|
||||||
return MoveProjectFolderResult{}, fmt.Errorf("moved project folder missing from projection")
|
return MoveProjectFolderResult{}, fmt.Errorf("moved project folder missing from projection")
|
||||||
}
|
}
|
||||||
|
|
||||||
if previousFolderID != movedFolderID {
|
if previousFolderID != movedFolderID {
|
||||||
if _, found := findProjectHierarchyFolder(folders, previousFolderID); found {
|
if _, found := findProjectHierarchyFolderByPath(folders, previousFolderID); found {
|
||||||
return MoveProjectFolderResult{}, fmt.Errorf("previous project folder path still present in projection")
|
return MoveProjectFolderResult{}, fmt.Errorf("previous project folder path still present in projection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
folderOrder := service.readProjectFolderOrder(project.Slug, rootPath(project.Slug))
|
||||||
|
seedFolderOrderParent(folderOrder, currentFolders, parentOrderID)
|
||||||
|
removeFolderOrderReference(folderOrder, movedFolderOrderID)
|
||||||
|
removeFolderOrderReference(folderOrder, movedFolder.ID)
|
||||||
|
insertFolderOrder(folderOrder, parentOrderID, movedFolder.ID, input.TargetIndex)
|
||||||
|
if err := service.writeProjectFolderOrder(project.Slug, rootPath(project.Slug), folderOrder); err != nil {
|
||||||
|
return MoveProjectFolderResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
folders, err = service.getProjectHierarchyFoldersByRootPath(ctx, project.ID, rootPath)
|
||||||
|
if err != nil {
|
||||||
|
return MoveProjectFolderResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
movedFolder, found = findProjectHierarchyFolderByPath(folders, movedFolderID)
|
||||||
|
if !found {
|
||||||
|
return MoveProjectFolderResult{}, fmt.Errorf("moved project folder missing from ordered projection")
|
||||||
|
}
|
||||||
|
|
||||||
return MoveProjectFolderResult{
|
return MoveProjectFolderResult{
|
||||||
ProjectID: project.ID,
|
ProjectID: project.ID,
|
||||||
PreviousFolderID: previousFolderID,
|
PreviousFolderID: movedFolder.ID,
|
||||||
MovedFolder: movedFolder,
|
PreviousFolderPath: previousFolderID,
|
||||||
Folders: folders,
|
MovedFolder: movedFolder,
|
||||||
|
Folders: folders,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1304,6 +1428,12 @@ func (service *Service) ensureBootstrapPOSIXSkeleton(
|
|||||||
teamPath := filepath.Join(departmentPath, "teams", slugDir("team", team.Slug))
|
teamPath := filepath.Join(departmentPath, "teams", slugDir("team", team.Slug))
|
||||||
projectPath := filepath.Join(rootPath, "projects", slugDir("project", project.Slug))
|
projectPath := filepath.Join(rootPath, "projects", slugDir("project", project.Slug))
|
||||||
usersPath := filepath.Join(rootPath, "users")
|
usersPath := filepath.Join(rootPath, "users")
|
||||||
|
personalName := strings.TrimSpace(admin.DisplayName)
|
||||||
|
if personalName == "" {
|
||||||
|
personalName = defaultPersonalDisplayName
|
||||||
|
}
|
||||||
|
personalSlug := normalizePOSIXSlug(personalName)
|
||||||
|
personalHomePath := filepath.Join(usersPath, "personals", slugDir("personal", personalSlug))
|
||||||
|
|
||||||
for _, dirPath := range []string{
|
for _, dirPath := range []string{
|
||||||
departmentPath,
|
departmentPath,
|
||||||
@@ -1312,6 +1442,8 @@ func (service *Service) ensureBootstrapPOSIXSkeleton(
|
|||||||
filepath.Join(projectPath, "children"),
|
filepath.Join(projectPath, "children"),
|
||||||
filepath.Join(projectPath, "tree"),
|
filepath.Join(projectPath, "tree"),
|
||||||
filepath.Join(usersPath, "personals"),
|
filepath.Join(usersPath, "personals"),
|
||||||
|
personalHomePath,
|
||||||
|
filepath.Join(personalHomePath, "tree"),
|
||||||
} {
|
} {
|
||||||
if err := os.MkdirAll(dirPath, 0o755); err != nil {
|
if err := os.MkdirAll(dirPath, 0o755); err != nil {
|
||||||
return fmt.Errorf("create POSIX directory %s: %w", dirPath, err)
|
return fmt.Errorf("create POSIX directory %s: %w", dirPath, err)
|
||||||
@@ -1397,6 +1529,37 @@ func (service *Service) ensureBootstrapPOSIXSkeleton(
|
|||||||
return fmt.Errorf("write users data.json: %w", err)
|
return fmt.Errorf("write users data.json: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := writeJSONFile(filepath.Join(personalHomePath, "settings.json"), map[string]any{
|
||||||
|
"id": admin.ID,
|
||||||
|
"name": personalName,
|
||||||
|
"slug": personalSlug,
|
||||||
|
"type": "personal",
|
||||||
|
"ownerUserId": admin.ID,
|
||||||
|
"email": admin.Email,
|
||||||
|
}); err != nil {
|
||||||
|
return fmt.Errorf("write personal settings.json: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := writeJSONFile(filepath.Join(personalHomePath, "layout.json"), map[string]any{
|
||||||
|
"version": 1,
|
||||||
|
"type": "personal-layout",
|
||||||
|
}); err != nil {
|
||||||
|
return fmt.Errorf("write personal layout.json: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := writeJSONFile(filepath.Join(personalHomePath, "home.json"), map[string]any{
|
||||||
|
"type": "personal-home",
|
||||||
|
"title": personalHomeTitle(personalName),
|
||||||
|
"owner": map[string]any{
|
||||||
|
"id": admin.ID,
|
||||||
|
"email": admin.Email,
|
||||||
|
"displayName": personalName,
|
||||||
|
},
|
||||||
|
"widgets": []any{},
|
||||||
|
}); err != nil {
|
||||||
|
return fmt.Errorf("write personal home.json: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1489,7 +1652,10 @@ func (service *Service) createProjectFolderOnDisk(
|
|||||||
return "", "", fmt.Errorf("create project hierarchy folder: %w", err)
|
return "", "", fmt.Errorf("create project hierarchy folder: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
folderID := uuid.NewString()
|
||||||
|
|
||||||
if err := writeJSONFile(filepath.Join(folderDir, "folder.json"), map[string]any{
|
if err := writeJSONFile(filepath.Join(folderDir, "folder.json"), map[string]any{
|
||||||
|
"id": folderID,
|
||||||
"name": trimmedName,
|
"name": trimmedName,
|
||||||
"slug": folderSlug,
|
"slug": folderSlug,
|
||||||
"type": "folder",
|
"type": "folder",
|
||||||
@@ -1613,7 +1779,14 @@ func (service *Service) renameProjectFolderOnDisk(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
folderPayload := readJSONFileMap(filepath.Join(destinationDir, "folder.json"))
|
||||||
|
folderMetadataID, _ := folderPayload["id"].(string)
|
||||||
|
if strings.TrimSpace(folderMetadataID) == "" {
|
||||||
|
folderMetadataID = uuid.NewString()
|
||||||
|
}
|
||||||
|
|
||||||
if err := writeJSONFile(filepath.Join(destinationDir, "folder.json"), map[string]any{
|
if err := writeJSONFile(filepath.Join(destinationDir, "folder.json"), map[string]any{
|
||||||
|
"id": folderMetadataID,
|
||||||
"name": trimmedName,
|
"name": trimmedName,
|
||||||
"slug": folderSlug,
|
"slug": folderSlug,
|
||||||
"type": "folder",
|
"type": "folder",
|
||||||
@@ -1685,6 +1858,10 @@ func (service *Service) moveProjectFolderOnDisk(
|
|||||||
}
|
}
|
||||||
|
|
||||||
folderPayload := readJSONFileMap(filepath.Join(folderDir, "folder.json"))
|
folderPayload := readJSONFileMap(filepath.Join(folderDir, "folder.json"))
|
||||||
|
folderMetadataID, _ := folderPayload["id"].(string)
|
||||||
|
if strings.TrimSpace(folderMetadataID) == "" {
|
||||||
|
folderMetadataID = uuid.NewString()
|
||||||
|
}
|
||||||
folderName, _ := folderPayload["name"].(string)
|
folderName, _ := folderPayload["name"].(string)
|
||||||
if strings.TrimSpace(folderName) == "" {
|
if strings.TrimSpace(folderName) == "" {
|
||||||
folderName = fallbackFolderLabel(folderProjectionPath)
|
folderName = fallbackFolderLabel(folderProjectionPath)
|
||||||
@@ -1715,6 +1892,7 @@ func (service *Service) moveProjectFolderOnDisk(
|
|||||||
return "", "", fmt.Errorf("move project folder: %w", err)
|
return "", "", fmt.Errorf("move project folder: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
folderPayload["id"] = folderMetadataID
|
||||||
folderPayload["name"] = folderName
|
folderPayload["name"] = folderName
|
||||||
folderPayload["slug"] = folderSlug
|
folderPayload["slug"] = folderSlug
|
||||||
folderPayload["type"] = "folder"
|
folderPayload["type"] = "folder"
|
||||||
@@ -1740,6 +1918,271 @@ func samePath(left, right string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (service *Service) readProjectFolderOrder(projectSlug, rootProjectionPath string) map[string][]string {
|
||||||
|
settingsPath := service.projectSettingsPath(projectSlug)
|
||||||
|
settingsPayload := readJSONFileMap(settingsPath)
|
||||||
|
folderOrderPayload, _ := settingsPayload["folderOrder"].(map[string]any)
|
||||||
|
if folderOrderPayload == nil {
|
||||||
|
return map[string][]string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
scopePayload, _ := folderOrderPayload[projectFolderOrderScope(rootProjectionPath)].(map[string]any)
|
||||||
|
if scopePayload == nil {
|
||||||
|
return map[string][]string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
byParentPayload, _ := scopePayload["byParent"].(map[string]any)
|
||||||
|
if byParentPayload == nil {
|
||||||
|
return map[string][]string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
order := make(map[string][]string, len(byParentPayload))
|
||||||
|
for key, raw := range byParentPayload {
|
||||||
|
for _, id := range stringSliceValue(raw) {
|
||||||
|
trimmedID := strings.TrimSpace(id)
|
||||||
|
if trimmedID == "" || slicesContains(order[key], trimmedID) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
order[key] = append(order[key], trimmedID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return order
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *Service) writeProjectFolderOrder(projectSlug, rootProjectionPath string, folderOrder map[string][]string) error {
|
||||||
|
settingsPath := service.projectSettingsPath(projectSlug)
|
||||||
|
settingsPayload := readJSONFileMap(settingsPath)
|
||||||
|
if settingsPayload == nil {
|
||||||
|
settingsPayload = map[string]any{}
|
||||||
|
}
|
||||||
|
|
||||||
|
folderOrderPayload, _ := settingsPayload["folderOrder"].(map[string]any)
|
||||||
|
if folderOrderPayload == nil {
|
||||||
|
folderOrderPayload = map[string]any{}
|
||||||
|
}
|
||||||
|
|
||||||
|
scopeKey := projectFolderOrderScope(rootProjectionPath)
|
||||||
|
scopePayload, _ := folderOrderPayload[scopeKey].(map[string]any)
|
||||||
|
if scopePayload == nil {
|
||||||
|
scopePayload = map[string]any{}
|
||||||
|
}
|
||||||
|
|
||||||
|
byParentPayload := map[string]any{}
|
||||||
|
for key, ids := range folderOrder {
|
||||||
|
if len(ids) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
copied := make([]string, 0, len(ids))
|
||||||
|
for _, id := range ids {
|
||||||
|
trimmedID := strings.TrimSpace(id)
|
||||||
|
if trimmedID == "" || slicesContains(copied, trimmedID) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
copied = append(copied, trimmedID)
|
||||||
|
}
|
||||||
|
if len(copied) > 0 {
|
||||||
|
byParentPayload[key] = copied
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scopePayload["byParent"] = byParentPayload
|
||||||
|
folderOrderPayload[scopeKey] = scopePayload
|
||||||
|
settingsPayload["folderOrder"] = folderOrderPayload
|
||||||
|
|
||||||
|
if err := writeJSONFile(settingsPath, settingsPayload); err != nil {
|
||||||
|
return fmt.Errorf("write project settings.json: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (service *Service) projectSettingsPath(projectSlug string) string {
|
||||||
|
return filepath.Join(strings.TrimSpace(service.posixRoot), "projects", slugDir("project", projectSlug), "settings.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
func projectFolderOrderScope(rootProjectionPath string) string {
|
||||||
|
if strings.HasSuffix(rootProjectionPath, "/tree") {
|
||||||
|
return projectFolderOrderTree
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectFolderOrderHierarchy
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyProjectHierarchyFolderOrdering(folders []ProjectHierarchyFolderRecord, folderOrder map[string][]string) []ProjectHierarchyFolderRecord {
|
||||||
|
return applyProjectHierarchyFolderOrderingForParent(folders, "", folderOrder)
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyProjectHierarchyFolderOrderingForParent(folders []ProjectHierarchyFolderRecord, parentID string, folderOrder map[string][]string) []ProjectHierarchyFolderRecord {
|
||||||
|
if len(folders) == 0 {
|
||||||
|
return folders
|
||||||
|
}
|
||||||
|
|
||||||
|
nextFolders := make([]ProjectHierarchyFolderRecord, len(folders))
|
||||||
|
copy(nextFolders, folders)
|
||||||
|
for index := range nextFolders {
|
||||||
|
nextFolders[index].Children = applyProjectHierarchyFolderOrderingForParent(nextFolders[index].Children, nextFolders[index].ID, folderOrder)
|
||||||
|
}
|
||||||
|
|
||||||
|
orderIDs := folderOrder[projectFolderOrderParentKey(parentID)]
|
||||||
|
if len(orderIDs) == 0 {
|
||||||
|
return nextFolders
|
||||||
|
}
|
||||||
|
|
||||||
|
rankByID := make(map[string]int, len(orderIDs))
|
||||||
|
for index, id := range orderIDs {
|
||||||
|
if _, exists := rankByID[id]; !exists {
|
||||||
|
rankByID[id] = index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.SliceStable(nextFolders, func(left, right int) bool {
|
||||||
|
leftRank, leftOrdered := rankByID[nextFolders[left].ID]
|
||||||
|
rightRank, rightOrdered := rankByID[nextFolders[right].ID]
|
||||||
|
if leftOrdered && rightOrdered {
|
||||||
|
return leftRank < rightRank
|
||||||
|
}
|
||||||
|
if leftOrdered != rightOrdered {
|
||||||
|
return leftOrdered
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
return nextFolders
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeFolderOrder(folderOrder map[string][]string, folderID string) {
|
||||||
|
removeFolderOrderReference(folderOrder, folderID)
|
||||||
|
|
||||||
|
trimmedFolderID := strings.TrimSpace(folderID)
|
||||||
|
if trimmedFolderID == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(folderOrder, projectFolderOrderParentKey(trimmedFolderID))
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeFolderOrderReference(folderOrder map[string][]string, folderID string) {
|
||||||
|
trimmedFolderID := strings.TrimSpace(folderID)
|
||||||
|
if trimmedFolderID == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, ids := range folderOrder {
|
||||||
|
nextIDs := ids[:0]
|
||||||
|
for _, id := range ids {
|
||||||
|
if strings.TrimSpace(id) == trimmedFolderID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
nextIDs = append(nextIDs, id)
|
||||||
|
}
|
||||||
|
if len(nextIDs) == 0 {
|
||||||
|
delete(folderOrder, key)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
folderOrder[key] = append([]string(nil), nextIDs...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func insertFolderOrder(folderOrder map[string][]string, parentID, folderID string, index int) {
|
||||||
|
trimmedFolderID := strings.TrimSpace(folderID)
|
||||||
|
if trimmedFolderID == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
removeFolderOrderReference(folderOrder, trimmedFolderID)
|
||||||
|
|
||||||
|
parentKey := projectFolderOrderParentKey(parentID)
|
||||||
|
children := append([]string(nil), folderOrder[parentKey]...)
|
||||||
|
if index < 0 {
|
||||||
|
index = 0
|
||||||
|
}
|
||||||
|
if index > len(children) {
|
||||||
|
index = len(children)
|
||||||
|
}
|
||||||
|
children = slicesInsert(children, index, trimmedFolderID)
|
||||||
|
folderOrder[parentKey] = children
|
||||||
|
}
|
||||||
|
|
||||||
|
func seedFolderOrderParent(folderOrder map[string][]string, folders []ProjectHierarchyFolderRecord, parentID string) {
|
||||||
|
children := folders
|
||||||
|
trimmedParentID := strings.TrimSpace(parentID)
|
||||||
|
if trimmedParentID != "" {
|
||||||
|
parent, found := findProjectHierarchyFolder(folders, trimmedParentID)
|
||||||
|
if !found {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
children = parent.Children
|
||||||
|
}
|
||||||
|
|
||||||
|
parentKey := projectFolderOrderParentKey(trimmedParentID)
|
||||||
|
seeded := make([]string, 0, len(children))
|
||||||
|
for _, child := range children {
|
||||||
|
childID := strings.TrimSpace(child.ID)
|
||||||
|
if childID == "" || slicesContains(seeded, childID) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seeded = append(seeded, childID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(seeded) == 0 {
|
||||||
|
delete(folderOrder, parentKey)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
folderOrder[parentKey] = seeded
|
||||||
|
}
|
||||||
|
|
||||||
|
func folderOrderChildren(folderOrder map[string][]string, parentID string) []string {
|
||||||
|
return append([]string(nil), folderOrder[projectFolderOrderParentKey(parentID)]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func projectFolderOrderParentKey(parentID string) string {
|
||||||
|
trimmedParentID := strings.TrimSpace(parentID)
|
||||||
|
if trimmedParentID == "" {
|
||||||
|
return projectFolderOrderRootKey
|
||||||
|
}
|
||||||
|
|
||||||
|
return trimmedParentID
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringSliceValue(value any) []string {
|
||||||
|
items, ok := value.([]any)
|
||||||
|
if !ok {
|
||||||
|
if typed, ok := value.([]string); ok {
|
||||||
|
return typed
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]string, 0, len(items))
|
||||||
|
for _, item := range items {
|
||||||
|
text, ok := item.(string)
|
||||||
|
if ok {
|
||||||
|
result = append(result, text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func slicesContains(values []string, value string) bool {
|
||||||
|
for _, existing := range values {
|
||||||
|
if existing == value {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func slicesInsert(values []string, index int, value string) []string {
|
||||||
|
values = append(values, "")
|
||||||
|
copy(values[index+1:], values[index:])
|
||||||
|
values[index] = value
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
||||||
func readJSONFileMap(path string) map[string]any {
|
func readJSONFileMap(path string) map[string]any {
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1763,12 +2206,17 @@ func buildProjectHierarchyFolderTree(rows []projectHierarchyFolderRow, rootParen
|
|||||||
childrenByParent := make(map[string][]string)
|
childrenByParent := make(map[string][]string)
|
||||||
|
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
|
folderID := strings.TrimSpace(row.ID)
|
||||||
|
if folderID == "" {
|
||||||
|
folderID = row.Path
|
||||||
|
}
|
||||||
label := strings.TrimSpace(row.Label)
|
label := strings.TrimSpace(row.Label)
|
||||||
if label == "" {
|
if label == "" {
|
||||||
label = fallbackFolderLabel(row.Path)
|
label = fallbackFolderLabel(row.Path)
|
||||||
}
|
}
|
||||||
nodesByPath[row.Path] = &ProjectHierarchyFolderRecord{
|
nodesByPath[row.Path] = &ProjectHierarchyFolderRecord{
|
||||||
ID: row.Path,
|
ID: folderID,
|
||||||
|
Path: row.Path,
|
||||||
Label: label,
|
Label: label,
|
||||||
Children: []ProjectHierarchyFolderRecord{},
|
Children: []ProjectHierarchyFolderRecord{},
|
||||||
}
|
}
|
||||||
@@ -1791,6 +2239,7 @@ func buildProjectHierarchyFolderTree(rows []projectHierarchyFolderRow, rootParen
|
|||||||
|
|
||||||
folder := ProjectHierarchyFolderRecord{
|
folder := ProjectHierarchyFolderRecord{
|
||||||
ID: node.ID,
|
ID: node.ID,
|
||||||
|
Path: node.Path,
|
||||||
Label: node.Label,
|
Label: node.Label,
|
||||||
Children: build(filepath.ToSlash(filepath.Join(childPath, "children"))),
|
Children: build(filepath.ToSlash(filepath.Join(childPath, "children"))),
|
||||||
}
|
}
|
||||||
@@ -1817,6 +2266,20 @@ func findProjectHierarchyFolder(folders []ProjectHierarchyFolderRecord, folderID
|
|||||||
return ProjectHierarchyFolderRecord{}, false
|
return ProjectHierarchyFolderRecord{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findProjectHierarchyFolderByPath(folders []ProjectHierarchyFolderRecord, folderPath string) (ProjectHierarchyFolderRecord, bool) {
|
||||||
|
for _, folder := range folders {
|
||||||
|
if folder.Path == folderPath {
|
||||||
|
return folder, true
|
||||||
|
}
|
||||||
|
|
||||||
|
if child, ok := findProjectHierarchyFolderByPath(folder.Children, folderPath); ok {
|
||||||
|
return child, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ProjectHierarchyFolderRecord{}, false
|
||||||
|
}
|
||||||
|
|
||||||
func projectHierarchyRootPath(projectSlug string) string {
|
func projectHierarchyRootPath(projectSlug string) string {
|
||||||
return filepath.ToSlash(filepath.Join("projects", slugDir("project", projectSlug), "children"))
|
return filepath.ToSlash(filepath.Join("projects", slugDir("project", projectSlug), "children"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -59,6 +60,10 @@ func TestEnsureBootstrapPOSIXSkeletonInitializesEmptyRoot(t *testing.T) {
|
|||||||
filepath.Join(rootPath, "users", "settings.json"),
|
filepath.Join(rootPath, "users", "settings.json"),
|
||||||
filepath.Join(rootPath, "users", "data.json"),
|
filepath.Join(rootPath, "users", "data.json"),
|
||||||
filepath.Join(rootPath, "users", "personals"),
|
filepath.Join(rootPath, "users", "personals"),
|
||||||
|
filepath.Join(rootPath, "users", "personals", "personal-ronald", "settings.json"),
|
||||||
|
filepath.Join(rootPath, "users", "personals", "personal-ronald", "layout.json"),
|
||||||
|
filepath.Join(rootPath, "users", "personals", "personal-ronald", "home.json"),
|
||||||
|
filepath.Join(rootPath, "users", "personals", "personal-ronald", "tree"),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range requiredPaths {
|
for _, path := range requiredPaths {
|
||||||
@@ -102,6 +107,25 @@ func TestEnsureBootstrapPOSIXSkeletonInitializesEmptyRoot(t *testing.T) {
|
|||||||
if usersSettings["primaryAdminId"] != "admin-1" {
|
if usersSettings["primaryAdminId"] != "admin-1" {
|
||||||
t.Fatalf("expected primary admin id admin-1, got %#v", usersSettings["primaryAdminId"])
|
t.Fatalf("expected primary admin id admin-1, got %#v", usersSettings["primaryAdminId"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
personalSettings := readJSONFileForTest[map[string]any](t, filepath.Join(rootPath, "users", "personals", "personal-ronald", "settings.json"))
|
||||||
|
if personalSettings["type"] != "personal" {
|
||||||
|
t.Fatalf("expected personal settings type personal, got %#v", personalSettings["type"])
|
||||||
|
}
|
||||||
|
if personalSettings["name"] != "Ronald" {
|
||||||
|
t.Fatalf("expected personal name Ronald, got %#v", personalSettings["name"])
|
||||||
|
}
|
||||||
|
if personalSettings["slug"] != "ronald" {
|
||||||
|
t.Fatalf("expected personal slug ronald, got %#v", personalSettings["slug"])
|
||||||
|
}
|
||||||
|
|
||||||
|
personalHome := readJSONFileForTest[map[string]any](t, filepath.Join(rootPath, "users", "personals", "personal-ronald", "home.json"))
|
||||||
|
if personalHome["type"] != "personal-home" {
|
||||||
|
t.Fatalf("expected personal home type personal-home, got %#v", personalHome["type"])
|
||||||
|
}
|
||||||
|
if personalHome["title"] != "Ronald's Home" {
|
||||||
|
t.Fatalf("expected personal home title Ronald's Home, got %#v", personalHome["title"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateProjectHierarchyFolderOnDiskCreatesExpectedFolderShape(t *testing.T) {
|
func TestCreateProjectHierarchyFolderOnDiskCreatesExpectedFolderShape(t *testing.T) {
|
||||||
@@ -143,6 +167,9 @@ func TestCreateProjectHierarchyFolderOnDiskCreatesExpectedFolderShape(t *testing
|
|||||||
}
|
}
|
||||||
|
|
||||||
folderPayload := readJSONFileForTest[map[string]any](t, filepath.Join(createdFolderPath, "folder.json"))
|
folderPayload := readJSONFileForTest[map[string]any](t, filepath.Join(createdFolderPath, "folder.json"))
|
||||||
|
if strings.TrimSpace(asStringForTest(folderPayload["id"])) == "" {
|
||||||
|
t.Fatalf("expected created folder to have stable id, got %#v", folderPayload["id"])
|
||||||
|
}
|
||||||
if folderPayload["name"] != "Design System" {
|
if folderPayload["name"] != "Design System" {
|
||||||
t.Fatalf("expected folder name Design System, got %#v", folderPayload["name"])
|
t.Fatalf("expected folder name Design System, got %#v", folderPayload["name"])
|
||||||
}
|
}
|
||||||
@@ -259,6 +286,9 @@ func TestRenameProjectHierarchyFolderOnDiskRenamesFolderShape(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
folderPayload := readJSONFileForTest[map[string]any](t, filepath.Join(renamedFolderPath, "folder.json"))
|
folderPayload := readJSONFileForTest[map[string]any](t, filepath.Join(renamedFolderPath, "folder.json"))
|
||||||
|
if strings.TrimSpace(asStringForTest(folderPayload["id"])) == "" {
|
||||||
|
t.Fatalf("expected renamed folder to preserve stable id, got %#v", folderPayload["id"])
|
||||||
|
}
|
||||||
if folderPayload["name"] != "Platform Design" {
|
if folderPayload["name"] != "Platform Design" {
|
||||||
t.Fatalf("expected renamed folder name Platform Design, got %#v", folderPayload["name"])
|
t.Fatalf("expected renamed folder name Platform Design, got %#v", folderPayload["name"])
|
||||||
}
|
}
|
||||||
@@ -365,6 +395,9 @@ func TestMoveProjectHierarchyFolderOnDiskMovesFolderToNewParent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
folderPayload := readJSONFileForTest[map[string]any](t, filepath.Join(movedFolderPath, "folder.json"))
|
folderPayload := readJSONFileForTest[map[string]any](t, filepath.Join(movedFolderPath, "folder.json"))
|
||||||
|
if strings.TrimSpace(asStringForTest(folderPayload["id"])) == "" {
|
||||||
|
t.Fatalf("expected moved folder to preserve stable id, got %#v", folderPayload["id"])
|
||||||
|
}
|
||||||
if folderPayload["name"] != "Research" {
|
if folderPayload["name"] != "Research" {
|
||||||
t.Fatalf("expected moved folder name Research, got %#v", folderPayload["name"])
|
t.Fatalf("expected moved folder name Research, got %#v", folderPayload["name"])
|
||||||
}
|
}
|
||||||
@@ -454,9 +487,9 @@ func TestMoveProjectHierarchyFolderOnDiskRejectsDescendantTarget(t *testing.T) {
|
|||||||
|
|
||||||
func TestBuildProjectHierarchyFolderTreeBuildsNestedStructure(t *testing.T) {
|
func TestBuildProjectHierarchyFolderTreeBuildsNestedStructure(t *testing.T) {
|
||||||
rows := []projectHierarchyFolderRow{
|
rows := []projectHierarchyFolderRow{
|
||||||
{Path: "projects/project-primary-project/children/folder-design", ParentPath: projectHierarchyRootPath("primary-project"), Label: "Design"},
|
{ID: "folder-design-id", Path: "projects/project-primary-project/children/folder-design", ParentPath: projectHierarchyRootPath("primary-project"), Label: "Design"},
|
||||||
{Path: "projects/project-primary-project/children/folder-design/children/folder-research", ParentPath: "projects/project-primary-project/children/folder-design/children", Label: "Research"},
|
{ID: "folder-research-id", Path: "projects/project-primary-project/children/folder-design/children/folder-research", ParentPath: "projects/project-primary-project/children/folder-design/children", Label: "Research"},
|
||||||
{Path: "projects/project-primary-project/children/folder-ops", ParentPath: projectHierarchyRootPath("primary-project"), Label: "Ops"},
|
{ID: "folder-ops-id", Path: "projects/project-primary-project/children/folder-ops", ParentPath: projectHierarchyRootPath("primary-project"), Label: "Ops"},
|
||||||
}
|
}
|
||||||
|
|
||||||
folders := buildProjectHierarchyFolderTree(rows, projectHierarchyRootPath("primary-project"))
|
folders := buildProjectHierarchyFolderTree(rows, projectHierarchyRootPath("primary-project"))
|
||||||
@@ -469,6 +502,64 @@ func TestBuildProjectHierarchyFolderTreeBuildsNestedStructure(t *testing.T) {
|
|||||||
if len(folders[0].Children) != 1 || folders[0].Children[0].Label != "Research" {
|
if len(folders[0].Children) != 1 || folders[0].Children[0].Label != "Research" {
|
||||||
t.Fatalf("unexpected nested folder structure: %#v", folders[0].Children)
|
t.Fatalf("unexpected nested folder structure: %#v", folders[0].Children)
|
||||||
}
|
}
|
||||||
|
if folders[0].ID != "folder-design-id" || folders[0].Path != "projects/project-primary-project/children/folder-design" {
|
||||||
|
t.Fatalf("expected design folder to retain stable id/path, got %#v", folders[0])
|
||||||
|
}
|
||||||
|
if folders[0].Children[0].ID != "folder-research-id" || folders[1].ID != "folder-ops-id" {
|
||||||
|
t.Fatalf("expected nested/top-level folder ids to be preserved, got %#v / %#v", folders[0].Children[0], folders[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyProjectHierarchyFolderOrderingOrdersRootAndChildrenByStableID(t *testing.T) {
|
||||||
|
folders := []ProjectHierarchyFolderRecord{
|
||||||
|
{
|
||||||
|
ID: "folder-design-id",
|
||||||
|
Path: "projects/project-primary-project/children/folder-design",
|
||||||
|
Label: "Design",
|
||||||
|
Children: []ProjectHierarchyFolderRecord{
|
||||||
|
{ID: "folder-research-id", Path: "projects/project-primary-project/children/folder-design/children/folder-research", Label: "Research"},
|
||||||
|
{ID: "folder-assets-id", Path: "projects/project-primary-project/children/folder-design/children/folder-assets", Label: "Assets"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ID: "folder-ops-id", Path: "projects/project-primary-project/children/folder-ops", Label: "Ops"},
|
||||||
|
{ID: "folder-qa-id", Path: "projects/project-primary-project/children/folder-qa", Label: "QA"},
|
||||||
|
}
|
||||||
|
|
||||||
|
ordered := applyProjectHierarchyFolderOrdering(folders, map[string][]string{
|
||||||
|
projectFolderOrderRootKey: {"folder-qa-id", "folder-design-id"},
|
||||||
|
"folder-design-id": {"folder-assets-id", "folder-research-id"},
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(ordered) != 3 {
|
||||||
|
t.Fatalf("expected 3 ordered root folders, got %d", len(ordered))
|
||||||
|
}
|
||||||
|
if ordered[0].ID != "folder-qa-id" || ordered[1].ID != "folder-design-id" || ordered[2].ID != "folder-ops-id" {
|
||||||
|
t.Fatalf("unexpected ordered root ids: %#v", ordered)
|
||||||
|
}
|
||||||
|
if len(ordered[1].Children) != 2 {
|
||||||
|
t.Fatalf("expected design folder children to be preserved, got %#v", ordered[1].Children)
|
||||||
|
}
|
||||||
|
if ordered[1].Children[0].ID != "folder-assets-id" || ordered[1].Children[1].ID != "folder-research-id" {
|
||||||
|
t.Fatalf("unexpected ordered child ids: %#v", ordered[1].Children)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInsertFolderOrderReordersWithinSameParent(t *testing.T) {
|
||||||
|
folderOrder := map[string][]string{
|
||||||
|
projectFolderOrderRootKey: {"folder-a", "folder-b", "folder-c"},
|
||||||
|
}
|
||||||
|
|
||||||
|
insertFolderOrder(folderOrder, "", "folder-c", 0)
|
||||||
|
|
||||||
|
got := folderOrder[projectFolderOrderRootKey]
|
||||||
|
if len(got) != 3 || got[0] != "folder-c" || got[1] != "folder-a" || got[2] != "folder-b" {
|
||||||
|
t.Fatalf("unexpected reordered root children: %#v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func asStringForTest(value any) string {
|
||||||
|
text, _ := value.(string)
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func readJSONFileForTest[T any](t *testing.T, path string) T {
|
func readJSONFileForTest[T any](t *testing.T, path string) T {
|
||||||
|
|||||||
@@ -28,7 +28,10 @@ type deleteProjectFolderRequest struct {
|
|||||||
|
|
||||||
type moveProjectFolderRequest struct {
|
type moveProjectFolderRequest struct {
|
||||||
FolderID string `json:"folderId"`
|
FolderID string `json:"folderId"`
|
||||||
|
FolderNodeID string `json:"folderNodeId"`
|
||||||
ParentFolderID string `json:"parentFolderId"`
|
ParentFolderID string `json:"parentFolderId"`
|
||||||
|
ParentNodeID string `json:"parentNodeId"`
|
||||||
|
TargetIndex int `json:"targetIndex"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (routes apiRoutes) handleProjectFolders(w http.ResponseWriter, r *http.Request) {
|
func (routes apiRoutes) handleProjectFolders(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -179,7 +182,9 @@ func (routes apiRoutes) handleMoveProjectFolder(w http.ResponseWriter, r *http.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload.FolderID = strings.TrimSpace(payload.FolderID)
|
payload.FolderID = strings.TrimSpace(payload.FolderID)
|
||||||
|
payload.FolderNodeID = strings.TrimSpace(payload.FolderNodeID)
|
||||||
payload.ParentFolderID = strings.TrimSpace(payload.ParentFolderID)
|
payload.ParentFolderID = strings.TrimSpace(payload.ParentFolderID)
|
||||||
|
payload.ParentNodeID = strings.TrimSpace(payload.ParentNodeID)
|
||||||
if payload.FolderID == "" {
|
if payload.FolderID == "" {
|
||||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Folder ID is required.")
|
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Folder ID is required.")
|
||||||
return
|
return
|
||||||
@@ -188,7 +193,10 @@ func (routes apiRoutes) handleMoveProjectFolder(w http.ResponseWriter, r *http.R
|
|||||||
result, err := routes.bootstrapService().MoveProjectFolder(r.Context(), bootstrapservice.MoveProjectFolderInput{
|
result, err := routes.bootstrapService().MoveProjectFolder(r.Context(), bootstrapservice.MoveProjectFolderInput{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
FolderID: payload.FolderID,
|
FolderID: payload.FolderID,
|
||||||
|
FolderNodeID: payload.FolderNodeID,
|
||||||
ParentFolderID: payload.ParentFolderID,
|
ParentFolderID: payload.ParentFolderID,
|
||||||
|
ParentNodeID: payload.ParentNodeID,
|
||||||
|
TargetIndex: payload.TargetIndex,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
routes.writeProjectFolderError(w, r, err, "move")
|
routes.writeProjectFolderError(w, r, err, "move")
|
||||||
@@ -352,7 +360,9 @@ func (routes apiRoutes) handleMoveProjectTreeFolder(w http.ResponseWriter, r *ht
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload.FolderID = strings.TrimSpace(payload.FolderID)
|
payload.FolderID = strings.TrimSpace(payload.FolderID)
|
||||||
|
payload.FolderNodeID = strings.TrimSpace(payload.FolderNodeID)
|
||||||
payload.ParentFolderID = strings.TrimSpace(payload.ParentFolderID)
|
payload.ParentFolderID = strings.TrimSpace(payload.ParentFolderID)
|
||||||
|
payload.ParentNodeID = strings.TrimSpace(payload.ParentNodeID)
|
||||||
if payload.FolderID == "" {
|
if payload.FolderID == "" {
|
||||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Folder ID is required.")
|
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Folder ID is required.")
|
||||||
return
|
return
|
||||||
@@ -361,7 +371,10 @@ func (routes apiRoutes) handleMoveProjectTreeFolder(w http.ResponseWriter, r *ht
|
|||||||
result, err := routes.bootstrapService().MoveProjectTreeFolder(r.Context(), bootstrapservice.MoveProjectFolderInput{
|
result, err := routes.bootstrapService().MoveProjectTreeFolder(r.Context(), bootstrapservice.MoveProjectFolderInput{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
FolderID: payload.FolderID,
|
FolderID: payload.FolderID,
|
||||||
|
FolderNodeID: payload.FolderNodeID,
|
||||||
ParentFolderID: payload.ParentFolderID,
|
ParentFolderID: payload.ParentFolderID,
|
||||||
|
ParentNodeID: payload.ParentNodeID,
|
||||||
|
TargetIndex: payload.TargetIndex,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
routes.writeProjectFolderError(w, r, err, "move")
|
routes.writeProjectFolderError(w, r, err, "move")
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ type ProjectSelectorProps = {
|
|||||||
type ProjectFolderNode = {
|
type ProjectFolderNode = {
|
||||||
kind: "folder";
|
kind: "folder";
|
||||||
id: string;
|
id: string;
|
||||||
|
path: string;
|
||||||
label: string;
|
label: string;
|
||||||
meta?: string;
|
meta?: string;
|
||||||
children: ProjectTreeNode[];
|
children: ProjectTreeNode[];
|
||||||
@@ -50,6 +51,7 @@ type ProjectTreeNode = ProjectFolderNode | ProjectLeafNode;
|
|||||||
|
|
||||||
type PersistedProjectFolderRecord = {
|
type PersistedProjectFolderRecord = {
|
||||||
id: string;
|
id: string;
|
||||||
|
path: string;
|
||||||
label: string;
|
label: string;
|
||||||
children: PersistedProjectFolderRecord[];
|
children: PersistedProjectFolderRecord[];
|
||||||
};
|
};
|
||||||
@@ -60,6 +62,7 @@ type ProjectFoldersResponse = {
|
|||||||
renamedFolder?: PersistedProjectFolderRecord;
|
renamedFolder?: PersistedProjectFolderRecord;
|
||||||
movedFolder?: PersistedProjectFolderRecord;
|
movedFolder?: PersistedProjectFolderRecord;
|
||||||
previousFolderId?: string;
|
previousFolderId?: string;
|
||||||
|
previousFolderPath?: string;
|
||||||
};
|
};
|
||||||
error?: string;
|
error?: string;
|
||||||
message?: string;
|
message?: string;
|
||||||
@@ -91,6 +94,7 @@ const buildPersistedFolderNodes = (folders: readonly PersistedProjectFolderRecor
|
|||||||
folders.map((folder) => ({
|
folders.map((folder) => ({
|
||||||
kind: "folder",
|
kind: "folder",
|
||||||
id: folder.id,
|
id: folder.id,
|
||||||
|
path: folder.path,
|
||||||
label: folder.label,
|
label: folder.label,
|
||||||
children: buildPersistedFolderNodes(folder.children ?? []),
|
children: buildPersistedFolderNodes(folder.children ?? []),
|
||||||
}));
|
}));
|
||||||
@@ -578,18 +582,39 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
|
|
||||||
const currentNodes = projectTreeNodes();
|
const currentNodes = projectTreeNodes();
|
||||||
const draggedLocation = findTreeNodeLocation(currentNodes, nextDragState.draggedNodeId, projectTreeAdapter);
|
const draggedLocation = findTreeNodeLocation(currentNodes, nextDragState.draggedNodeId, projectTreeAdapter);
|
||||||
const persistedParentId = nextDragState.dropTarget.parentId;
|
|
||||||
const canPersistMove = isUuidString(selectedProject().id);
|
const canPersistMove = isUuidString(selectedProject().id);
|
||||||
const persistedParentLocation = persistedParentId
|
const draggedFolderPath = draggedLocation?.node.kind === "folder" ? draggedLocation.node.path : null;
|
||||||
? findTreeNodeLocation(currentNodes, persistedParentId, projectTreeAdapter)
|
const previewNodes = moveTreeNode(currentNodes, nextDragState.draggedNodeId, nextDragState.dropTarget as ProjectDragTarget, projectTreeAdapter);
|
||||||
|
const previewLocation = findTreeNodeLocation(previewNodes, nextDragState.draggedNodeId, projectTreeAdapter);
|
||||||
|
const persistedParentLocation = previewLocation?.parentId
|
||||||
|
? findTreeNodeLocation(previewNodes, previewLocation.parentId, projectTreeAdapter)
|
||||||
: null;
|
: null;
|
||||||
|
const persistedParentFolderPath =
|
||||||
|
persistedParentLocation?.node.kind === "folder" ? persistedParentLocation.node.path : null;
|
||||||
|
const previewSiblings = previewLocation?.parentId
|
||||||
|
? persistedParentLocation?.node.kind === "folder"
|
||||||
|
? persistedParentLocation.node.children
|
||||||
|
: []
|
||||||
|
: previewNodes;
|
||||||
|
const targetIndex = previewLocation
|
||||||
|
? previewSiblings
|
||||||
|
.slice(0, previewLocation.index)
|
||||||
|
.filter((node) => node.kind === "folder").length
|
||||||
|
: 0;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
canPersistMove &&
|
canPersistMove &&
|
||||||
draggedLocation?.node.kind === "folder" &&
|
draggedLocation?.node.kind === "folder" &&
|
||||||
(persistedParentId === null || persistedParentLocation?.node.kind === "folder")
|
draggedFolderPath &&
|
||||||
|
(!previewLocation?.parentId || persistedParentLocation?.node.kind === "folder")
|
||||||
) {
|
) {
|
||||||
void movePersistedFolder(draggedLocation.node.id, persistedParentId);
|
void movePersistedFolder(
|
||||||
|
draggedFolderPath,
|
||||||
|
persistedParentFolderPath,
|
||||||
|
draggedLocation.node.id,
|
||||||
|
persistedParentLocation?.node.kind === "folder" ? persistedParentLocation.node.id : null,
|
||||||
|
targetIndex,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
setProjectTreeNodes((current) =>
|
setProjectTreeNodes((current) =>
|
||||||
moveTreeNode(current, nextDragState.draggedNodeId, nextDragState.dropTarget as ProjectDragTarget, projectTreeAdapter),
|
moveTreeNode(current, nextDragState.draggedNodeId, nextDragState.dropTarget as ProjectDragTarget, projectTreeAdapter),
|
||||||
@@ -674,6 +699,11 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
setPendingFolderRenameName(label);
|
setPendingFolderRenameName(label);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resolveFolderPath = (folderId: string): string | null => {
|
||||||
|
const location = findTreeNodeLocation(projectTreeNodes(), folderId, projectTreeAdapter);
|
||||||
|
return location && location.node.kind === "folder" ? location.node.path : null;
|
||||||
|
};
|
||||||
|
|
||||||
const submitPendingFolder = async (): Promise<void> => {
|
const submitPendingFolder = async (): Promise<void> => {
|
||||||
const name = pendingFolderName().trim();
|
const name = pendingFolderName().trim();
|
||||||
const draft = pendingFolderDraft();
|
const draft = pendingFolderDraft();
|
||||||
@@ -694,6 +724,12 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parentFolderPath = draft.parentId ? resolveFolderPath(draft.parentId) : null;
|
||||||
|
if (draft.parentId && !parentFolderPath) {
|
||||||
|
cancelPendingFolder();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${resolveAPIBase()}/projects/${projectId}/folders`, {
|
const response = await fetch(`${resolveAPIBase()}/projects/${projectId}/folders`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -703,7 +739,7 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name,
|
name,
|
||||||
parentFolderId: draft.parentId,
|
parentFolderId: parentFolderPath,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -727,9 +763,14 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const folderPath = resolveFolderPath(folderId);
|
||||||
|
if (!folderPath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${resolveAPIBase()}/projects/${projectId}/folders?folderId=${encodeURIComponent(folderId)}`,
|
`${resolveAPIBase()}/projects/${projectId}/folders?folderId=${encodeURIComponent(folderPath)}`,
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -751,9 +792,15 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const movePersistedFolder = async (folderId: string, parentFolderId: string | null): Promise<void> => {
|
const movePersistedFolder = async (
|
||||||
|
folderPath: string,
|
||||||
|
parentFolderPath: string | null,
|
||||||
|
folderNodeId: string,
|
||||||
|
parentNodeId: string | null,
|
||||||
|
targetIndex: number,
|
||||||
|
): Promise<void> => {
|
||||||
const projectId = selectedProject().id;
|
const projectId = selectedProject().id;
|
||||||
if (!folderId || !isUuidString(projectId)) {
|
if (!folderPath || !folderNodeId || !isUuidString(projectId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,8 +812,11 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
folderId,
|
folderId: folderPath,
|
||||||
parentFolderId,
|
folderNodeId,
|
||||||
|
parentFolderId: parentFolderPath,
|
||||||
|
parentNodeId,
|
||||||
|
targetIndex,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -777,14 +827,6 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPersistedFolders(readPersistedFolders(body));
|
setPersistedFolders(readPersistedFolders(body));
|
||||||
|
|
||||||
const previousFolderId = body.data?.previousFolderId;
|
|
||||||
const movedFolderId = body.data?.movedFolder?.id;
|
|
||||||
if (previousFolderId && movedFolderId && previousFolderId !== movedFolderId) {
|
|
||||||
setCollapsedFolderIds((current) =>
|
|
||||||
current.map((id) => (id === previousFolderId ? movedFolderId : id)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
@@ -810,6 +852,12 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const folderPath = resolveFolderPath(draft.folderId);
|
||||||
|
if (!folderPath) {
|
||||||
|
cancelPendingFolderRename();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${resolveAPIBase()}/projects/${projectId}/folders`, {
|
const response = await fetch(`${resolveAPIBase()}/projects/${projectId}/folders`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
@@ -818,7 +866,7 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
folderId: draft.folderId,
|
folderId: folderPath,
|
||||||
name,
|
name,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -832,14 +880,6 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
|||||||
setPersistedFolders(readPersistedFolders(body));
|
setPersistedFolders(readPersistedFolders(body));
|
||||||
setPendingFolderRename(null);
|
setPendingFolderRename(null);
|
||||||
setPendingFolderRenameName("");
|
setPendingFolderRenameName("");
|
||||||
|
|
||||||
const previousFolderId = body.data?.previousFolderId;
|
|
||||||
const renamedFolderId = body.data?.renamedFolder?.id;
|
|
||||||
if (previousFolderId && renamedFolderId && previousFolderId !== renamedFolderId) {
|
|
||||||
setCollapsedFolderIds((current) =>
|
|
||||||
current.map((id) => (id === previousFolderId ? renamedFolderId : id)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ type WorkspaceDragState = {
|
|||||||
|
|
||||||
type PersistedWorkspaceFolderRecord = {
|
type PersistedWorkspaceFolderRecord = {
|
||||||
id: string;
|
id: string;
|
||||||
|
path: string;
|
||||||
label: string;
|
label: string;
|
||||||
children?: PersistedWorkspaceFolderRecord[];
|
children?: PersistedWorkspaceFolderRecord[];
|
||||||
};
|
};
|
||||||
@@ -62,6 +63,7 @@ type WorkspaceFoldersResponse = {
|
|||||||
renamedFolder?: PersistedWorkspaceFolderRecord;
|
renamedFolder?: PersistedWorkspaceFolderRecord;
|
||||||
movedFolder?: PersistedWorkspaceFolderRecord;
|
movedFolder?: PersistedWorkspaceFolderRecord;
|
||||||
previousFolderId?: string;
|
previousFolderId?: string;
|
||||||
|
previousFolderPath?: string;
|
||||||
};
|
};
|
||||||
error?: string;
|
error?: string;
|
||||||
message?: string;
|
message?: string;
|
||||||
@@ -81,6 +83,7 @@ const buildPersistedWorkspaceFolderNodes = (
|
|||||||
): WorkspaceTreeNode[] =>
|
): WorkspaceTreeNode[] =>
|
||||||
folders.map((folder) => ({
|
folders.map((folder) => ({
|
||||||
id: folder.id,
|
id: folder.id,
|
||||||
|
path: folder.path,
|
||||||
label: folder.label,
|
label: folder.label,
|
||||||
kind: "folder",
|
kind: "folder",
|
||||||
icon: Folder,
|
icon: Folder,
|
||||||
@@ -532,18 +535,38 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
|
|
||||||
const currentNodes = workspaceTreeNodes();
|
const currentNodes = workspaceTreeNodes();
|
||||||
const draggedLocation = findTreeNodeLocation(currentNodes, nextDragState.draggedNodeId, workspaceTreeAdapter);
|
const draggedLocation = findTreeNodeLocation(currentNodes, nextDragState.draggedNodeId, workspaceTreeAdapter);
|
||||||
const persistedParentId = nextDragState.dropTarget.parentId;
|
|
||||||
const canPersistMove = isUuidString(activeProject()?.id ?? "");
|
const canPersistMove = isUuidString(activeProject()?.id ?? "");
|
||||||
const persistedParentLocation = persistedParentId
|
const draggedFolderPath = draggedLocation?.node.kind === "folder" ? draggedLocation.node.path ?? null : null;
|
||||||
? findTreeNodeLocation(currentNodes, persistedParentId, workspaceTreeAdapter)
|
const previewNodes = moveTreeNode(currentNodes, nextDragState.draggedNodeId, nextDragState.dropTarget as WorkspaceDragTarget, workspaceTreeAdapter);
|
||||||
|
const previewLocation = findTreeNodeLocation(previewNodes, nextDragState.draggedNodeId, workspaceTreeAdapter);
|
||||||
|
const persistedParentLocation = previewLocation?.parentId
|
||||||
|
? findTreeNodeLocation(previewNodes, previewLocation.parentId, workspaceTreeAdapter)
|
||||||
: null;
|
: null;
|
||||||
|
const persistedParentFolderPath = persistedParentLocation?.node.kind === "folder" ? persistedParentLocation.node.path ?? null : null;
|
||||||
|
const previewSiblings = previewLocation?.parentId
|
||||||
|
? persistedParentLocation?.node.kind === "folder"
|
||||||
|
? persistedParentLocation.node.children ?? []
|
||||||
|
: []
|
||||||
|
: previewNodes;
|
||||||
|
const targetIndex = previewLocation
|
||||||
|
? previewSiblings
|
||||||
|
.slice(0, previewLocation.index)
|
||||||
|
.filter((node) => node.kind === "folder").length
|
||||||
|
: 0;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
canPersistMove &&
|
canPersistMove &&
|
||||||
draggedLocation?.node.kind === "folder" &&
|
draggedLocation?.node.kind === "folder" &&
|
||||||
(persistedParentId === null || persistedParentLocation?.node.kind === "folder")
|
draggedFolderPath &&
|
||||||
|
(!previewLocation?.parentId || persistedParentLocation?.node.kind === "folder")
|
||||||
) {
|
) {
|
||||||
void movePersistedFolder(draggedLocation.node.id, persistedParentId);
|
void movePersistedFolder(
|
||||||
|
draggedFolderPath,
|
||||||
|
persistedParentFolderPath,
|
||||||
|
draggedLocation.node.id,
|
||||||
|
persistedParentLocation?.node.kind === "folder" ? persistedParentLocation.node.id : null,
|
||||||
|
targetIndex,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
setWorkspaceTreeNodes((current) =>
|
setWorkspaceTreeNodes((current) =>
|
||||||
moveTreeNode(current, nextDragState.draggedNodeId, nextDragState.dropTarget as WorkspaceDragTarget, workspaceTreeAdapter),
|
moveTreeNode(current, nextDragState.draggedNodeId, nextDragState.dropTarget as WorkspaceDragTarget, workspaceTreeAdapter),
|
||||||
@@ -598,6 +621,11 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
setPendingFolderRenameName(label);
|
setPendingFolderRenameName(label);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resolveFolderPath = (folderId: string): string | null => {
|
||||||
|
const location = findTreeNodeLocation(workspaceTreeNodes(), folderId, workspaceTreeAdapter);
|
||||||
|
return location?.node.kind === "folder" ? location.node.path ?? null : null;
|
||||||
|
};
|
||||||
|
|
||||||
const submitPendingFolder = async (): Promise<void> => {
|
const submitPendingFolder = async (): Promise<void> => {
|
||||||
const name = pendingFolderName().trim();
|
const name = pendingFolderName().trim();
|
||||||
const draft = pendingFolderDraft();
|
const draft = pendingFolderDraft();
|
||||||
@@ -618,6 +646,12 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parentFolderPath = draft.parentId ? resolveFolderPath(draft.parentId) : null;
|
||||||
|
if (draft.parentId && !parentFolderPath) {
|
||||||
|
cancelPendingFolder();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${resolveAPIBase()}/projects/${projectId}/tree/folders`, {
|
const response = await fetch(`${resolveAPIBase()}/projects/${projectId}/tree/folders`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -627,7 +661,7 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name,
|
name,
|
||||||
parentFolderId: draft.parentId,
|
parentFolderId: parentFolderPath,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -647,13 +681,17 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
|
|
||||||
const deletePersistedFolder = async (folderId: string): Promise<void> => {
|
const deletePersistedFolder = async (folderId: string): Promise<void> => {
|
||||||
const projectId = activeProject()?.id ?? "";
|
const projectId = activeProject()?.id ?? "";
|
||||||
|
const folderPath = resolveFolderPath(folderId);
|
||||||
if (!folderId || !projectId || !isUuidString(projectId)) {
|
if (!folderId || !projectId || !isUuidString(projectId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!folderPath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${resolveAPIBase()}/projects/${projectId}/tree/folders?folderId=${encodeURIComponent(folderId)}`,
|
`${resolveAPIBase()}/projects/${projectId}/tree/folders?folderId=${encodeURIComponent(folderPath)}`,
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -675,9 +713,15 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const movePersistedFolder = async (folderId: string, parentFolderId: string | null): Promise<void> => {
|
const movePersistedFolder = async (
|
||||||
|
folderPath: string,
|
||||||
|
parentFolderPath: string | null,
|
||||||
|
folderNodeId: string,
|
||||||
|
parentNodeId: string | null,
|
||||||
|
targetIndex: number,
|
||||||
|
): Promise<void> => {
|
||||||
const projectId = activeProject()?.id ?? "";
|
const projectId = activeProject()?.id ?? "";
|
||||||
if (!folderId || !projectId || !isUuidString(projectId)) {
|
if (!folderPath || !folderNodeId || !projectId || !isUuidString(projectId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,8 +733,11 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
folderId,
|
folderId: folderPath,
|
||||||
parentFolderId,
|
folderNodeId,
|
||||||
|
parentFolderId: parentFolderPath,
|
||||||
|
parentNodeId,
|
||||||
|
targetIndex,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -701,14 +748,6 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPersistedFolders(readPersistedWorkspaceFolders(body));
|
setPersistedFolders(readPersistedWorkspaceFolders(body));
|
||||||
|
|
||||||
const previousFolderId = body.data?.previousFolderId;
|
|
||||||
const movedFolderId = body.data?.movedFolder?.id;
|
|
||||||
if (previousFolderId && movedFolderId && previousFolderId !== movedFolderId) {
|
|
||||||
setCollapsedFolderIds((current) =>
|
|
||||||
current.map((id) => (id === previousFolderId ? movedFolderId : id)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
@@ -734,6 +773,12 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const folderPath = resolveFolderPath(draft.folderId);
|
||||||
|
if (!folderPath) {
|
||||||
|
cancelPendingFolderRename();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${resolveAPIBase()}/projects/${projectId}/tree/folders`, {
|
const response = await fetch(`${resolveAPIBase()}/projects/${projectId}/tree/folders`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
@@ -742,7 +787,7 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
folderId: draft.folderId,
|
folderId: folderPath,
|
||||||
name,
|
name,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -756,14 +801,6 @@ export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
|||||||
setPersistedFolders(readPersistedWorkspaceFolders(body));
|
setPersistedFolders(readPersistedWorkspaceFolders(body));
|
||||||
setPendingFolderRename(null);
|
setPendingFolderRename(null);
|
||||||
setPendingFolderRenameName("");
|
setPendingFolderRenameName("");
|
||||||
|
|
||||||
const previousFolderId = body.data?.previousFolderId;
|
|
||||||
const renamedFolderId = body.data?.renamedFolder?.id;
|
|
||||||
if (previousFolderId && renamedFolderId && previousFolderId !== renamedFolderId) {
|
|
||||||
setCollapsedFolderIds((current) =>
|
|
||||||
current.map((id) => (id === previousFolderId ? renamedFolderId : id)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ export type WorkspaceStaticItem = SidebarItem & {
|
|||||||
|
|
||||||
export type WorkspaceFolderNode = {
|
export type WorkspaceFolderNode = {
|
||||||
id: string;
|
id: string;
|
||||||
|
path?: string;
|
||||||
label: string;
|
label: string;
|
||||||
kind: "folder";
|
kind: "folder";
|
||||||
icon: ShellIcon;
|
icon: ShellIcon;
|
||||||
|
|||||||
@@ -21,6 +21,29 @@ type BootstrapSubmissionState = {
|
|||||||
error: string;
|
error: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type InstanceForm = {
|
||||||
|
protocol: "http" | "https";
|
||||||
|
access: "local" | "remote";
|
||||||
|
host: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ModeForm = {
|
||||||
|
mode: "personal" | "organizational";
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type AdminForm = {
|
||||||
|
displayName: string;
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type StructureForm = {
|
||||||
|
departmentName: string;
|
||||||
|
teamName: string;
|
||||||
|
projectName: string;
|
||||||
|
};
|
||||||
|
|
||||||
const bootstrapStepDefinitions: readonly BootstrapStepDefinition[] = [
|
const bootstrapStepDefinitions: readonly BootstrapStepDefinition[] = [
|
||||||
{
|
{
|
||||||
id: "instance",
|
id: "instance",
|
||||||
@@ -44,37 +67,37 @@ const bootstrapStepDefinitions: readonly BootstrapStepDefinition[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const defaultInstanceForm = {
|
const defaultInstanceForm: InstanceForm = {
|
||||||
protocol: "http",
|
protocol: "http",
|
||||||
access: "local",
|
access: "local",
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
} as const;
|
};
|
||||||
|
|
||||||
const defaultModeForm = {
|
const defaultModeForm: ModeForm = {
|
||||||
mode: "personal",
|
mode: "personal",
|
||||||
name: "",
|
name: "",
|
||||||
} as const;
|
};
|
||||||
|
|
||||||
const defaultAdminForm = {
|
const defaultAdminForm: AdminForm = {
|
||||||
displayName: "Admin",
|
displayName: "Admin",
|
||||||
email: "admin@example.com",
|
email: "admin@example.com",
|
||||||
password: "",
|
password: "",
|
||||||
} as const;
|
};
|
||||||
|
|
||||||
const personalStructureDefaults = {
|
const personalStructureDefaults = {
|
||||||
departmentName: "Default",
|
departmentName: "Default",
|
||||||
teamName: "Personal",
|
teamName: "Personal",
|
||||||
} as const;
|
};
|
||||||
|
|
||||||
const organizationalStructureDefaults = {
|
const organizationalStructureDefaults = {
|
||||||
departmentName: "Department",
|
departmentName: "Department",
|
||||||
teamName: "Team",
|
teamName: "Team",
|
||||||
} as const;
|
};
|
||||||
|
|
||||||
const defaultStructureForm = {
|
const defaultStructureForm: StructureForm = {
|
||||||
...personalStructureDefaults,
|
...personalStructureDefaults,
|
||||||
projectName: "Project",
|
projectName: "Project",
|
||||||
} as const;
|
};
|
||||||
|
|
||||||
const initialSubmissionState = (): BootstrapSubmissionState => ({
|
const initialSubmissionState = (): BootstrapSubmissionState => ({
|
||||||
status: "idle",
|
status: "idle",
|
||||||
@@ -148,10 +171,10 @@ type WorkspaceHomeProps = {
|
|||||||
|
|
||||||
export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
||||||
const appShellData = useAppShellData();
|
const appShellData = useAppShellData();
|
||||||
const [instanceForm, setInstanceForm] = createStore({ ...defaultInstanceForm });
|
const [instanceForm, setInstanceForm] = createStore<InstanceForm>({ ...defaultInstanceForm });
|
||||||
const [modeForm, setModeForm] = createStore({ ...defaultModeForm });
|
const [modeForm, setModeForm] = createStore<ModeForm>({ ...defaultModeForm });
|
||||||
const [adminForm, setAdminForm] = createStore({ ...defaultAdminForm });
|
const [adminForm, setAdminForm] = createStore<AdminForm>({ ...defaultAdminForm });
|
||||||
const [structureForm, setStructureForm] = createStore({ ...defaultStructureForm });
|
const [structureForm, setStructureForm] = createStore<StructureForm>({ ...defaultStructureForm });
|
||||||
const [stepState, setStepState] = createStore<Record<BootstrapStepKey, BootstrapSubmissionState>>({
|
const [stepState, setStepState] = createStore<Record<BootstrapStepKey, BootstrapSubmissionState>>({
|
||||||
instance: initialSubmissionState(),
|
instance: initialSubmissionState(),
|
||||||
mode: initialSubmissionState(),
|
mode: initialSubmissionState(),
|
||||||
@@ -363,7 +386,13 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
<h1 class={styles.title}>{isBootstrapComplete() ? appShellData.activeServer().name : bootstrapTargetLabel()}</h1>
|
<h1 class={styles.title}>{isBootstrapComplete() ? appShellData.activeServer().name : bootstrapTargetLabel()}</h1>
|
||||||
<Show when={isBootstrapStateResolved() && !isBootstrapComplete()}>
|
<Show when={isBootstrapStateResolved() && !isBootstrapComplete()}>
|
||||||
<div class={styles.heroActions}>
|
<div class={styles.heroActions}>
|
||||||
<button type="button" class={styles.primaryButton} onClick={(): void => setIsWizardOpen(true)}>
|
<button
|
||||||
|
type="button"
|
||||||
|
class={styles.primaryButton}
|
||||||
|
onClick={(): void => {
|
||||||
|
setIsWizardOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
Open bootstrap wizard
|
Open bootstrap wizard
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -384,7 +413,13 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<Show when={canDismissWizard()}>
|
<Show when={canDismissWizard()}>
|
||||||
<button type="button" class={styles.wizardCloseButton} onClick={(): void => setIsWizardOpen(false)}>
|
<button
|
||||||
|
type="button"
|
||||||
|
class={styles.wizardCloseButton}
|
||||||
|
onClick={(): void => {
|
||||||
|
setIsWizardOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
Close
|
Close
|
||||||
</button>
|
</button>
|
||||||
</Show>
|
</Show>
|
||||||
@@ -433,14 +468,24 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
<>
|
<>
|
||||||
<label class={styles.field}>
|
<label class={styles.field}>
|
||||||
<span class={styles.fieldLabel}>Protocol</span>
|
<span class={styles.fieldLabel}>Protocol</span>
|
||||||
<select value={instanceForm.protocol} onInput={(event): void => setInstanceForm("protocol", event.currentTarget.value)}>
|
<select
|
||||||
|
value={instanceForm.protocol}
|
||||||
|
onInput={(event): void =>
|
||||||
|
setInstanceForm("protocol", event.currentTarget.value as InstanceForm["protocol"])
|
||||||
|
}
|
||||||
|
>
|
||||||
<option value="http">http</option>
|
<option value="http">http</option>
|
||||||
<option value="https">https</option>
|
<option value="https">https</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label class={styles.field}>
|
<label class={styles.field}>
|
||||||
<span class={styles.fieldLabel}>Access</span>
|
<span class={styles.fieldLabel}>Access</span>
|
||||||
<select value={instanceForm.access} onInput={(event): void => setInstanceForm("access", event.currentTarget.value)}>
|
<select
|
||||||
|
value={instanceForm.access}
|
||||||
|
onInput={(event): void =>
|
||||||
|
setInstanceForm("access", event.currentTarget.value as InstanceForm["access"])
|
||||||
|
}
|
||||||
|
>
|
||||||
<option value="local">local</option>
|
<option value="local">local</option>
|
||||||
<option value="remote">remote</option>
|
<option value="remote">remote</option>
|
||||||
</select>
|
</select>
|
||||||
@@ -461,7 +506,10 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
<>
|
<>
|
||||||
<label class={styles.field}>
|
<label class={styles.field}>
|
||||||
<span class={styles.fieldLabel}>Mode</span>
|
<span class={styles.fieldLabel}>Mode</span>
|
||||||
<select value={modeForm.mode} onInput={(event): void => setModeForm("mode", event.currentTarget.value)}>
|
<select
|
||||||
|
value={modeForm.mode}
|
||||||
|
onInput={(event): void => setModeForm("mode", event.currentTarget.value as ModeForm["mode"])}
|
||||||
|
>
|
||||||
<option value="personal">personal</option>
|
<option value="personal">personal</option>
|
||||||
<option value="organizational">organizational</option>
|
<option value="organizational">organizational</option>
|
||||||
</select>
|
</select>
|
||||||
@@ -553,7 +601,9 @@ export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
|||||||
type="button"
|
type="button"
|
||||||
class={styles.secondaryButton}
|
class={styles.secondaryButton}
|
||||||
disabled={isFirstStep()}
|
disabled={isFirstStep()}
|
||||||
onClick={(): void => setCurrentStepIndex((index) => Math.max(index - 1, 0))}
|
onClick={(): void => {
|
||||||
|
setCurrentStepIndex((index) => Math.max(index - 1, 0));
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Back
|
Back
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user