Compare commits
16 Commits
Features/F
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07590f1c4f | ||
|
|
3c7a73853d | ||
|
|
9b4f1ce197 | ||
|
|
5735e3008d | ||
|
|
626ae02df0 | ||
|
|
7f47ca84fa | ||
|
|
eac4fb423e | ||
|
|
14ac0f46de | ||
|
|
5a565f8165 | ||
|
|
12cbc68db6 | ||
|
|
699574e345 | ||
|
|
35c1a861f5 | ||
|
|
27101bbdd6 | ||
|
|
6ba04effcf | ||
|
|
913825f596 | ||
|
|
93ce3e07f0 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -27,3 +27,5 @@ tmp/
|
||||
bin/
|
||||
|
||||
.cgcignore
|
||||
|
||||
POSIX/
|
||||
52
Backend/cmd/posix/main.go
Normal file
52
Backend/cmd/posix/main.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"moku-backend/internal/config"
|
||||
"moku-backend/internal/database"
|
||||
"moku-backend/internal/posixproj"
|
||||
)
|
||||
|
||||
func main() {
|
||||
command := "rebuild"
|
||||
if len(os.Args) > 1 {
|
||||
command = os.Args[1]
|
||||
}
|
||||
|
||||
switch command {
|
||||
case "rebuild":
|
||||
if err := rebuildProjection(context.Background()); err != nil {
|
||||
log.Fatalf("rebuild POSIX projection: %v", err)
|
||||
}
|
||||
default:
|
||||
log.Fatalf("unsupported posix command %q (supported: rebuild)", command)
|
||||
}
|
||||
}
|
||||
|
||||
func rebuildProjection(ctx context.Context) error {
|
||||
cfg := config.Load()
|
||||
|
||||
db, err := database.NewPostgres(cfg.PostgresURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("connect database: %w", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
summary, err := posixproj.NewProjector(db, cfg.POSIXRoot).RebuildWithSummary(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf(
|
||||
"POSIX projection rebuilt from %s\n total nodes: %d\n directories: %d\n files: %d\n",
|
||||
cfg.POSIXRoot,
|
||||
summary.TotalNodes,
|
||||
summary.DirectoryCount,
|
||||
summary.FileCount,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
180
Backend/db/migrations/000002_bootstrap_foundation.sql
Normal file
180
Backend/db/migrations/000002_bootstrap_foundation.sql
Normal file
@@ -0,0 +1,180 @@
|
||||
-- +goose Up
|
||||
|
||||
CREATE TYPE instance_mode AS ENUM ('personal', 'organizational');
|
||||
CREATE TYPE instance_access AS ENUM ('local', 'remote');
|
||||
CREATE TYPE instance_protocol AS ENUM ('http', 'https');
|
||||
CREATE TYPE workspace_kind AS ENUM ('organization', 'department', 'team', 'project');
|
||||
CREATE TYPE membership_role AS ENUM ('owner', 'admin', 'member');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS installations (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
singleton BOOLEAN NOT NULL DEFAULT TRUE UNIQUE,
|
||||
mode instance_mode NOT NULL,
|
||||
access instance_access NOT NULL,
|
||||
protocol instance_protocol NOT NULL DEFAULT 'http',
|
||||
host TEXT NOT NULL,
|
||||
is_bootstrapped BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
bootstrapped_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
email TEXT NOT NULL,
|
||||
display_name TEXT NOT NULL,
|
||||
password_hash TEXT NOT NULL,
|
||||
is_instance_admin BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_users_email_unique ON users (LOWER(email));
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_homes (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID NOT NULL UNIQUE REFERENCES users(id) ON DELETE CASCADE,
|
||||
title TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
ALTER TABLE organizations
|
||||
ADD COLUMN IF NOT EXISTS created_by_user_id UUID REFERENCES users(id) ON DELETE SET NULL;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS organization_memberships (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
role membership_role NOT NULL DEFAULT 'member',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (organization_id, user_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_organization_memberships_user_id ON organization_memberships (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS departments (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
name TEXT NOT NULL,
|
||||
slug TEXT NOT NULL,
|
||||
created_by_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (organization_id, slug)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_departments_organization_id ON departments (organization_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS teams (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
department_id UUID REFERENCES departments(id) ON DELETE SET NULL,
|
||||
name TEXT NOT NULL,
|
||||
slug TEXT NOT NULL,
|
||||
created_by_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (organization_id, slug)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_teams_organization_id ON teams (organization_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_teams_department_id ON teams (department_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS team_memberships (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
team_id UUID NOT NULL REFERENCES teams(id) ON DELETE CASCADE,
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
role membership_role NOT NULL DEFAULT 'member',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (team_id, user_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_team_memberships_user_id ON team_memberships (user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS projects (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
department_id UUID REFERENCES departments(id) ON DELETE SET NULL,
|
||||
team_id UUID REFERENCES teams(id) ON DELETE SET NULL,
|
||||
name TEXT NOT NULL,
|
||||
slug TEXT NOT NULL,
|
||||
created_by_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (organization_id, slug)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_projects_organization_id ON projects (organization_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_projects_department_id ON projects (department_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_projects_team_id ON projects (team_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS project_memberships (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
role membership_role NOT NULL DEFAULT 'member',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (project_id, user_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_project_memberships_user_id ON project_memberships (user_id);
|
||||
|
||||
ALTER TABLE workspaces
|
||||
ADD COLUMN IF NOT EXISTS kind workspace_kind NOT NULL DEFAULT 'organization',
|
||||
ADD COLUMN IF NOT EXISTS created_by_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
ADD COLUMN IF NOT EXISTS department_id UUID REFERENCES departments(id) ON DELETE SET NULL,
|
||||
ADD COLUMN IF NOT EXISTS team_id UUID REFERENCES teams(id) ON DELETE SET NULL,
|
||||
ADD COLUMN IF NOT EXISTS project_id UUID REFERENCES projects(id) ON DELETE SET NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_workspaces_department_id ON workspaces (department_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_workspaces_team_id ON workspaces (team_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_workspaces_project_id ON workspaces (project_id);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
DROP INDEX IF EXISTS idx_workspaces_project_id;
|
||||
DROP INDEX IF EXISTS idx_workspaces_team_id;
|
||||
DROP INDEX IF EXISTS idx_workspaces_department_id;
|
||||
|
||||
ALTER TABLE workspaces
|
||||
DROP COLUMN IF EXISTS project_id,
|
||||
DROP COLUMN IF EXISTS team_id,
|
||||
DROP COLUMN IF EXISTS department_id,
|
||||
DROP COLUMN IF EXISTS created_by_user_id,
|
||||
DROP COLUMN IF EXISTS kind;
|
||||
|
||||
DROP INDEX IF EXISTS idx_project_memberships_user_id;
|
||||
DROP TABLE IF EXISTS project_memberships;
|
||||
|
||||
DROP INDEX IF EXISTS idx_projects_team_id;
|
||||
DROP INDEX IF EXISTS idx_projects_department_id;
|
||||
DROP INDEX IF EXISTS idx_projects_organization_id;
|
||||
DROP TABLE IF EXISTS projects;
|
||||
|
||||
DROP INDEX IF EXISTS idx_team_memberships_user_id;
|
||||
DROP TABLE IF EXISTS team_memberships;
|
||||
|
||||
DROP INDEX IF EXISTS idx_teams_department_id;
|
||||
DROP INDEX IF EXISTS idx_teams_organization_id;
|
||||
DROP TABLE IF EXISTS teams;
|
||||
|
||||
DROP INDEX IF EXISTS idx_departments_organization_id;
|
||||
DROP TABLE IF EXISTS departments;
|
||||
|
||||
DROP INDEX IF EXISTS idx_organization_memberships_user_id;
|
||||
DROP TABLE IF EXISTS organization_memberships;
|
||||
|
||||
ALTER TABLE organizations
|
||||
DROP COLUMN IF EXISTS created_by_user_id;
|
||||
|
||||
DROP TABLE IF EXISTS user_homes;
|
||||
DROP INDEX IF EXISTS idx_users_email_unique;
|
||||
DROP TABLE IF EXISTS users;
|
||||
DROP TABLE IF EXISTS installations;
|
||||
|
||||
DROP TYPE IF EXISTS membership_role;
|
||||
DROP TYPE IF EXISTS workspace_kind;
|
||||
DROP TYPE IF EXISTS instance_protocol;
|
||||
DROP TYPE IF EXISTS instance_access;
|
||||
DROP TYPE IF EXISTS instance_mode;
|
||||
9
Backend/db/migrations/000003_installation_name.sql
Normal file
9
Backend/db/migrations/000003_installation_name.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- +goose Up
|
||||
|
||||
ALTER TABLE installations
|
||||
ADD COLUMN IF NOT EXISTS name TEXT NOT NULL DEFAULT '';
|
||||
|
||||
-- +goose Down
|
||||
|
||||
ALTER TABLE installations
|
||||
DROP COLUMN IF EXISTS name;
|
||||
45
Backend/db/migrations/000004_posix_nodes.sql
Normal file
45
Backend/db/migrations/000004_posix_nodes.sql
Normal file
@@ -0,0 +1,45 @@
|
||||
-- +goose Up
|
||||
|
||||
CREATE TYPE posix_node_kind AS ENUM ('directory', 'file');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS posix_nodes (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
path TEXT NOT NULL UNIQUE,
|
||||
parent_path TEXT,
|
||||
name TEXT NOT NULL,
|
||||
depth INTEGER NOT NULL,
|
||||
node_kind posix_node_kind NOT NULL,
|
||||
logical_type TEXT NOT NULL DEFAULT 'generic',
|
||||
file_role TEXT,
|
||||
resource_id TEXT,
|
||||
resource_name TEXT,
|
||||
resource_slug TEXT,
|
||||
installation_id TEXT,
|
||||
organization_id TEXT,
|
||||
organization_slug TEXT,
|
||||
department_slug TEXT,
|
||||
team_slug TEXT,
|
||||
project_slug TEXT,
|
||||
personal_slug TEXT,
|
||||
content_json JSONB,
|
||||
size_bytes BIGINT NOT NULL DEFAULT 0,
|
||||
checksum TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_posix_nodes_parent_path ON posix_nodes (parent_path);
|
||||
CREATE INDEX IF NOT EXISTS idx_posix_nodes_logical_type ON posix_nodes (logical_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_posix_nodes_project_slug ON posix_nodes (project_slug);
|
||||
CREATE INDEX IF NOT EXISTS idx_posix_nodes_department_slug ON posix_nodes (department_slug);
|
||||
CREATE INDEX IF NOT EXISTS idx_posix_nodes_team_slug ON posix_nodes (team_slug);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
DROP INDEX IF EXISTS idx_posix_nodes_team_slug;
|
||||
DROP INDEX IF EXISTS idx_posix_nodes_department_slug;
|
||||
DROP INDEX IF EXISTS idx_posix_nodes_project_slug;
|
||||
DROP INDEX IF EXISTS idx_posix_nodes_logical_type;
|
||||
DROP INDEX IF EXISTS idx_posix_nodes_parent_path;
|
||||
DROP TABLE IF EXISTS posix_nodes;
|
||||
DROP TYPE IF EXISTS posix_node_kind;
|
||||
@@ -23,14 +23,50 @@ target "dev-image" {
|
||||
tags = ["${REGISTRY}/moku/work-backend:dev-${TAG}"]
|
||||
}
|
||||
|
||||
target "prod-api" {
|
||||
inherits = ["_app"]
|
||||
target = "runtime"
|
||||
args = {
|
||||
SERVICE_NAME = "api"
|
||||
}
|
||||
tags = ["moku/work-backend:local-prod-api"]
|
||||
}
|
||||
|
||||
target "prod-worker" {
|
||||
inherits = ["_app"]
|
||||
target = "runtime"
|
||||
args = {
|
||||
SERVICE_NAME = "worker"
|
||||
}
|
||||
tags = ["moku/work-backend:local-prod-worker"]
|
||||
}
|
||||
|
||||
target "prod-api-image" {
|
||||
inherits = ["_app"]
|
||||
target = "runtime"
|
||||
args = {
|
||||
SERVICE_NAME = "api"
|
||||
}
|
||||
tags = ["${REGISTRY}/moku/work-backend:prod-api-${TAG}"]
|
||||
}
|
||||
|
||||
target "prod-worker-image" {
|
||||
inherits = ["_app"]
|
||||
target = "runtime"
|
||||
args = {
|
||||
SERVICE_NAME = "worker"
|
||||
}
|
||||
tags = ["${REGISTRY}/moku/work-backend:prod-worker-${TAG}"]
|
||||
}
|
||||
|
||||
group "local" {
|
||||
targets = ["dev"]
|
||||
targets = ["dev", "prod-api", "prod-worker"]
|
||||
}
|
||||
|
||||
group "registry" {
|
||||
targets = ["dev-image"]
|
||||
targets = ["dev-image", "prod-api-image", "prod-worker-image"]
|
||||
}
|
||||
|
||||
group "default" {
|
||||
targets = ["dev"]
|
||||
targets = ["dev", "prod-api", "prod-worker"]
|
||||
}
|
||||
|
||||
1086
Backend/internal/bootstrap/service.go
Normal file
1086
Backend/internal/bootstrap/service.go
Normal file
File diff suppressed because it is too large
Load Diff
113
Backend/internal/bootstrap/service_test.go
Normal file
113
Backend/internal/bootstrap/service_test.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEnsureBootstrapPOSIXSkeletonInitializesEmptyRoot(t *testing.T) {
|
||||
rootPath := filepath.Join(t.TempDir(), "POSIX")
|
||||
t.Setenv("POSIX_ROOT", rootPath)
|
||||
|
||||
if _, err := os.Stat(rootPath); !os.IsNotExist(err) {
|
||||
t.Fatalf("expected isolated POSIX root to start absent, got err=%v", err)
|
||||
}
|
||||
|
||||
service := NewService(nil, os.Getenv("POSIX_ROOT"))
|
||||
|
||||
err := service.ensureBootstrapPOSIXSkeleton(
|
||||
InstallationRecord{
|
||||
ID: "installation-1",
|
||||
Name: "MangoPig",
|
||||
Mode: "personal",
|
||||
Access: "local",
|
||||
Protocol: "http",
|
||||
Host: "localhost",
|
||||
IsBootstrapped: true,
|
||||
},
|
||||
AdminSummary{
|
||||
ID: "admin-1",
|
||||
Email: "ronald@example.com",
|
||||
DisplayName: "Ronald",
|
||||
},
|
||||
namedRecord{ID: "org-1", Name: "Primary Organization", Slug: "primary-organization"},
|
||||
namedRecord{ID: "dept-1", Name: "Primary Department", Slug: "primary-department"},
|
||||
namedRecord{ID: "team-1", Name: "Primary Team", Slug: "primary-team"},
|
||||
namedRecord{ID: "project-1", Name: "Primary Project", Slug: "primary-project"},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("ensure bootstrap POSIX skeleton: %v", err)
|
||||
}
|
||||
|
||||
requiredPaths := []string{
|
||||
filepath.Join(rootPath, "settings.json"),
|
||||
filepath.Join(rootPath, "layout.json"),
|
||||
filepath.Join(rootPath, "catalog", "packs"),
|
||||
filepath.Join(rootPath, "catalog", "standalone"),
|
||||
filepath.Join(rootPath, "departments", "department-primary-department", "settings.json"),
|
||||
filepath.Join(rootPath, "departments", "department-primary-department", "users.json"),
|
||||
filepath.Join(rootPath, "departments", "department-primary-department", "teams", "team-primary-team", "settings.json"),
|
||||
filepath.Join(rootPath, "departments", "department-primary-department", "teams", "team-primary-team", "users.json"),
|
||||
filepath.Join(rootPath, "projects", "project-primary-project", "settings.json"),
|
||||
filepath.Join(rootPath, "projects", "project-primary-project", "home.json"),
|
||||
filepath.Join(rootPath, "projects", "project-primary-project", "tree"),
|
||||
filepath.Join(rootPath, "users", "settings.json"),
|
||||
filepath.Join(rootPath, "users", "data.json"),
|
||||
filepath.Join(rootPath, "users", "personals"),
|
||||
}
|
||||
|
||||
for _, path := range requiredPaths {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
t.Fatalf("expected path to exist %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
settingsPayload := readJSONFileForTest[map[string]any](t, filepath.Join(rootPath, "settings.json"))
|
||||
installationPayload, ok := settingsPayload["installation"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("settings.json missing installation object: %#v", settingsPayload)
|
||||
}
|
||||
if installationPayload["name"] != "MangoPig" {
|
||||
t.Fatalf("expected installation name MangoPig, got %#v", installationPayload["name"])
|
||||
}
|
||||
if installationPayload["isBootstrapped"] != true {
|
||||
t.Fatalf("expected installation to be bootstrapped, got %#v", installationPayload["isBootstrapped"])
|
||||
}
|
||||
|
||||
layoutPayload := readJSONFileForTest[map[string]any](t, filepath.Join(rootPath, "layout.json"))
|
||||
homePayload, ok := layoutPayload["home"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("layout.json missing home object: %#v", layoutPayload)
|
||||
}
|
||||
if homePayload["defaultProjectSlug"] != "primary-project" {
|
||||
t.Fatalf("expected default project slug primary-project, got %#v", homePayload["defaultProjectSlug"])
|
||||
}
|
||||
|
||||
projectSettings := readJSONFileForTest[map[string]any](t, filepath.Join(rootPath, "projects", "project-primary-project", "settings.json"))
|
||||
if projectSettings["type"] != "project" {
|
||||
t.Fatalf("expected project settings type project, got %#v", projectSettings["type"])
|
||||
}
|
||||
|
||||
usersSettings := readJSONFileForTest[map[string]any](t, filepath.Join(rootPath, "users", "settings.json"))
|
||||
if usersSettings["primaryAdminId"] != "admin-1" {
|
||||
t.Fatalf("expected primary admin id admin-1, got %#v", usersSettings["primaryAdminId"])
|
||||
}
|
||||
}
|
||||
|
||||
func readJSONFileForTest[T any](t *testing.T, path string) T {
|
||||
t.Helper()
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", path, err)
|
||||
}
|
||||
|
||||
var payload T
|
||||
if err := json.Unmarshal(data, &payload); err != nil {
|
||||
t.Fatalf("unmarshal %s: %v", path, err)
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
@@ -17,6 +17,7 @@ type Config struct {
|
||||
APIPort string
|
||||
PostgresURL string
|
||||
ValkeyURL string
|
||||
POSIXRoot string
|
||||
ShutdownTimeout time.Duration
|
||||
}
|
||||
|
||||
@@ -29,6 +30,7 @@ func Load() *Config {
|
||||
APIPort: getEnv("BACKEND_API_PORT", "8081"),
|
||||
PostgresURL: getEnv("DATABASE_URL", "postgres://moku:moku_dev_password@localhost:5432/moku?sslmode=disable"),
|
||||
ValkeyURL: getEnv("VALKEY_URL", "redis://localhost:6379/0"),
|
||||
POSIXRoot: getEnv("POSIX_ROOT", "../POSIX"),
|
||||
ShutdownTimeout: getDurationEnv("BACKEND_SHUTDOWN_TIMEOUT", 10*time.Second),
|
||||
}
|
||||
}
|
||||
|
||||
396
Backend/internal/httpx/api_bootstrap_routes.go
Normal file
396
Backend/internal/httpx/api_bootstrap_routes.go
Normal file
@@ -0,0 +1,396 @@
|
||||
// Path: Backend/internal/httpx/api_bootstrap_routes.go
|
||||
|
||||
package httpx
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
bootstrapservice "moku-backend/internal/bootstrap"
|
||||
)
|
||||
|
||||
type bootstrapInstanceStepRequest struct {
|
||||
Protocol string `json:"protocol"`
|
||||
Access string `json:"access"`
|
||||
Host string `json:"host"`
|
||||
}
|
||||
|
||||
type bootstrapModeStepRequest struct {
|
||||
Mode string `json:"mode"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type bootstrapAdminStepRequest struct {
|
||||
DisplayName string `json:"displayName"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type bootstrapStructureStepRequest struct {
|
||||
OrganizationName string `json:"organizationName"`
|
||||
DepartmentName string `json:"departmentName"`
|
||||
TeamName string `json:"teamName"`
|
||||
ProjectName string `json:"projectName"`
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleBootstrapOverview(w http.ResponseWriter, _ *http.Request) {
|
||||
WriteJSON(w, http.StatusOK, map[string]any{
|
||||
"data": map[string]any{
|
||||
"resource": "bootstrap",
|
||||
"status": "persisted",
|
||||
"steps": []map[string]string{
|
||||
{
|
||||
"id": "instance",
|
||||
"method": http.MethodPost,
|
||||
"path": "/v1/bootstrap/steps/instance",
|
||||
},
|
||||
{
|
||||
"id": "mode",
|
||||
"method": http.MethodPost,
|
||||
"path": "/v1/bootstrap/steps/mode",
|
||||
},
|
||||
{
|
||||
"id": "admin",
|
||||
"method": http.MethodPost,
|
||||
"path": "/v1/bootstrap/steps/admin",
|
||||
},
|
||||
{
|
||||
"id": "structure",
|
||||
"method": http.MethodPost,
|
||||
"path": "/v1/bootstrap/steps/structure",
|
||||
},
|
||||
{
|
||||
"id": "installation",
|
||||
"method": http.MethodGet,
|
||||
"path": "/v1/bootstrap/installation",
|
||||
},
|
||||
{
|
||||
"id": "admin-state",
|
||||
"method": http.MethodGet,
|
||||
"path": "/v1/bootstrap/admin",
|
||||
},
|
||||
{
|
||||
"id": "structure-state",
|
||||
"method": http.MethodGet,
|
||||
"path": "/v1/bootstrap/structure",
|
||||
},
|
||||
{
|
||||
"id": "bootstrap-state",
|
||||
"method": http.MethodGet,
|
||||
"path": "/v1/bootstrap/state",
|
||||
},
|
||||
{
|
||||
"id": "app-shell",
|
||||
"method": http.MethodGet,
|
||||
"path": "/v1/app-shell",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleBootstrapInstallation(w http.ResponseWriter, r *http.Request) {
|
||||
record, err := routes.bootstrapService().GetInstallation(r.Context())
|
||||
if err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
WriteJSON(w, http.StatusOK, map[string]any{
|
||||
"data": record,
|
||||
"meta": map[string]any{
|
||||
"resource": "bootstrap-installation",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleBootstrapAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
record, err := routes.bootstrapService().GetAdmin(r.Context())
|
||||
if err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
WriteJSON(w, http.StatusOK, map[string]any{
|
||||
"data": record,
|
||||
"meta": map[string]any{
|
||||
"resource": "bootstrap-admin",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleBootstrapStructure(w http.ResponseWriter, r *http.Request) {
|
||||
record, err := routes.bootstrapService().GetStructure(r.Context())
|
||||
if err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
WriteJSON(w, http.StatusOK, map[string]any{
|
||||
"data": record,
|
||||
"meta": map[string]any{
|
||||
"resource": "bootstrap-structure",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleBootstrapState(w http.ResponseWriter, r *http.Request) {
|
||||
record, err := routes.bootstrapService().GetState(r.Context())
|
||||
if err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
WriteJSON(w, http.StatusOK, map[string]any{
|
||||
"data": record,
|
||||
"meta": map[string]any{
|
||||
"resource": "bootstrap-state",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleAppShellState(w http.ResponseWriter, r *http.Request) {
|
||||
record, err := routes.bootstrapService().GetAppShellState(r.Context())
|
||||
if err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
WriteJSON(w, http.StatusOK, map[string]any{
|
||||
"data": record,
|
||||
"meta": map[string]any{
|
||||
"resource": "app-shell",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleDevelopmentBootstrapReset(w http.ResponseWriter, r *http.Request) {
|
||||
if !routes.cfg.Config.IsDevelopment() {
|
||||
WriteError(w, http.StatusNotFound, RequestIDFromContext(r.Context()), "not_found", "The requested endpoint does not exist.")
|
||||
return
|
||||
}
|
||||
|
||||
if err := routes.bootstrapService().ResetDevelopmentState(r.Context()); err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
WriteJSON(w, http.StatusOK, map[string]any{
|
||||
"data": map[string]any{
|
||||
"reset": true,
|
||||
},
|
||||
"meta": map[string]any{
|
||||
"resource": "development-bootstrap-reset",
|
||||
"developmentOnly": true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleBootstrapInstanceStep(w http.ResponseWriter, r *http.Request) {
|
||||
payload, ok := decodeBootstrapRequest[bootstrapInstanceStepRequest](w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
payload.Protocol = strings.ToLower(strings.TrimSpace(payload.Protocol))
|
||||
payload.Access = strings.ToLower(strings.TrimSpace(payload.Access))
|
||||
payload.Host = strings.TrimSpace(payload.Host)
|
||||
|
||||
if payload.Protocol != "http" && payload.Protocol != "https" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Protocol must be either 'http' or 'https'.")
|
||||
return
|
||||
}
|
||||
|
||||
if payload.Access != "local" && payload.Access != "remote" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Access must be either 'local' or 'remote'.")
|
||||
return
|
||||
}
|
||||
|
||||
if payload.Host == "" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Host is required.")
|
||||
return
|
||||
}
|
||||
|
||||
record, err := routes.bootstrapService().SaveInstance(r.Context(), bootstrapservice.SaveInstanceInput{
|
||||
Protocol: payload.Protocol,
|
||||
Access: payload.Access,
|
||||
Host: payload.Host,
|
||||
})
|
||||
if err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
routes.writeBootstrapStepResponse(w, http.StatusOK, "instance", map[string]any{
|
||||
"request": payload,
|
||||
"installation": record,
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleBootstrapModeStep(w http.ResponseWriter, r *http.Request) {
|
||||
payload, ok := decodeBootstrapRequest[bootstrapModeStepRequest](w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
payload.Mode = strings.ToLower(strings.TrimSpace(payload.Mode))
|
||||
payload.Name = strings.TrimSpace(payload.Name)
|
||||
|
||||
if payload.Mode != "personal" && payload.Mode != "organizational" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Mode must be either 'personal' or 'organizational'.")
|
||||
return
|
||||
}
|
||||
|
||||
if payload.Name == "" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Name is required.")
|
||||
return
|
||||
}
|
||||
|
||||
record, err := routes.bootstrapService().SaveMode(r.Context(), bootstrapservice.SaveModeInput{Mode: payload.Mode, Name: payload.Name})
|
||||
if err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
routes.writeBootstrapStepResponse(w, http.StatusOK, "mode", map[string]any{
|
||||
"request": payload,
|
||||
"installation": record,
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleBootstrapAdminStep(w http.ResponseWriter, r *http.Request) {
|
||||
payload, ok := decodeBootstrapRequest[bootstrapAdminStepRequest](w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
payload.DisplayName = strings.TrimSpace(payload.DisplayName)
|
||||
payload.Email = strings.ToLower(strings.TrimSpace(payload.Email))
|
||||
|
||||
if payload.DisplayName == "" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Display name is required.")
|
||||
return
|
||||
}
|
||||
|
||||
if payload.Email == "" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Email is required.")
|
||||
return
|
||||
}
|
||||
|
||||
if strings.TrimSpace(payload.Password) == "" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Password is required.")
|
||||
return
|
||||
}
|
||||
|
||||
record, err := routes.bootstrapService().SaveAdmin(r.Context(), bootstrapservice.SaveAdminInput{
|
||||
DisplayName: payload.DisplayName,
|
||||
Email: payload.Email,
|
||||
Password: payload.Password,
|
||||
})
|
||||
if err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
routes.writeBootstrapStepResponse(w, http.StatusOK, "admin", map[string]any{
|
||||
"request": payload,
|
||||
"admin": record,
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) handleBootstrapStructureStep(w http.ResponseWriter, r *http.Request) {
|
||||
payload, ok := decodeBootstrapRequest[bootstrapStructureStepRequest](w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
payload.OrganizationName = strings.TrimSpace(payload.OrganizationName)
|
||||
payload.DepartmentName = strings.TrimSpace(payload.DepartmentName)
|
||||
payload.TeamName = strings.TrimSpace(payload.TeamName)
|
||||
payload.ProjectName = strings.TrimSpace(payload.ProjectName)
|
||||
|
||||
if payload.DepartmentName == "" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Department name is required.")
|
||||
return
|
||||
}
|
||||
|
||||
if payload.TeamName == "" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Team name is required.")
|
||||
return
|
||||
}
|
||||
|
||||
if payload.ProjectName == "" {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_request", "Project name is required.")
|
||||
return
|
||||
}
|
||||
|
||||
record, err := routes.bootstrapService().SaveStructure(r.Context(), bootstrapservice.SaveStructureInput{
|
||||
OrganizationName: payload.OrganizationName,
|
||||
DepartmentName: payload.DepartmentName,
|
||||
TeamName: payload.TeamName,
|
||||
ProjectName: payload.ProjectName,
|
||||
})
|
||||
if err != nil {
|
||||
routes.writeBootstrapPersistenceError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
routes.writeBootstrapStepResponse(w, http.StatusOK, "structure", map[string]any{
|
||||
"request": payload,
|
||||
"structure": record,
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) bootstrapService() *bootstrapservice.Service {
|
||||
return bootstrapservice.NewService(routes.cfg.Database, routes.cfg.Config.POSIXRoot)
|
||||
}
|
||||
|
||||
func (routes apiRoutes) writeBootstrapStepResponse(w http.ResponseWriter, status int, step string, payload any) {
|
||||
WriteJSON(w, status, map[string]any{
|
||||
"data": map[string]any{
|
||||
"step": step,
|
||||
"result": payload,
|
||||
},
|
||||
"meta": map[string]any{
|
||||
"resource": "bootstrap-step",
|
||||
"persisted": true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (routes apiRoutes) writeBootstrapPersistenceError(w http.ResponseWriter, r *http.Request, err error) {
|
||||
switch {
|
||||
case errors.Is(err, bootstrapservice.ErrInstallationNotConfigured), errors.Is(err, bootstrapservice.ErrAdminNotConfigured):
|
||||
WriteError(w, http.StatusConflict, RequestIDFromContext(r.Context()), "bootstrap_prerequisite_missing", err.Error())
|
||||
default:
|
||||
routes.cfg.Logger.Error("persist bootstrap step", "error", err, "path", r.URL.Path)
|
||||
message := "Failed to persist bootstrap data."
|
||||
if routes.cfg.Config.IsDevelopment() {
|
||||
message = message + " " + err.Error()
|
||||
}
|
||||
WriteError(w, http.StatusInternalServerError, RequestIDFromContext(r.Context()), "bootstrap_persist_failed", message)
|
||||
}
|
||||
}
|
||||
|
||||
func decodeBootstrapRequest[T any](w http.ResponseWriter, r *http.Request) (T, bool) {
|
||||
var payload T
|
||||
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
decoder.DisallowUnknownFields()
|
||||
|
||||
if err := decoder.Decode(&payload); err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_json", "The request body is required and must be valid JSON for this bootstrap step.")
|
||||
return payload, false
|
||||
}
|
||||
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_json", "The request body must be valid JSON for this bootstrap step.")
|
||||
return payload, false
|
||||
}
|
||||
|
||||
if err := decoder.Decode(&struct{}{}); !errors.Is(err, io.EOF) {
|
||||
WriteError(w, http.StatusBadRequest, RequestIDFromContext(r.Context()), "invalid_json", "The request body must contain a single JSON object.")
|
||||
return payload, false
|
||||
}
|
||||
|
||||
return payload, true
|
||||
}
|
||||
@@ -19,8 +19,24 @@ func newAPIRoutes(cfg RouterConfig) routeRegistrar {
|
||||
func (routes apiRoutes) Register(router chi.Router) {
|
||||
router.Route("/v1", func(apiRouter chi.Router) {
|
||||
apiRouter.Get("/", routes.handleIndex)
|
||||
apiRouter.Get("/bootstrap", routes.handleBootstrapOverview)
|
||||
apiRouter.Get("/bootstrap/installation", routes.handleBootstrapInstallation)
|
||||
apiRouter.Get("/bootstrap/admin", routes.handleBootstrapAdmin)
|
||||
apiRouter.Get("/bootstrap/structure", routes.handleBootstrapStructure)
|
||||
apiRouter.Get("/bootstrap/state", routes.handleBootstrapState)
|
||||
apiRouter.Route("/bootstrap/steps", func(bootstrapRouter chi.Router) {
|
||||
bootstrapRouter.Post("/instance", routes.handleBootstrapInstanceStep)
|
||||
bootstrapRouter.Post("/mode", routes.handleBootstrapModeStep)
|
||||
bootstrapRouter.Post("/admin", routes.handleBootstrapAdminStep)
|
||||
bootstrapRouter.Post("/structure", routes.handleBootstrapStructureStep)
|
||||
})
|
||||
apiRouter.Get("/app-shell", routes.handleAppShellState)
|
||||
apiRouter.Get("/organizations", routes.handleOrganizations)
|
||||
apiRouter.Get("/workspaces", routes.handleWorkspaces)
|
||||
|
||||
if routes.cfg.Config.IsDevelopment() {
|
||||
apiRouter.Post("/dev/bootstrap/reset", routes.handleDevelopmentBootstrapReset)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
531
Backend/internal/posixproj/projector.go
Normal file
531
Backend/internal/posixproj/projector.go
Normal file
@@ -0,0 +1,531 @@
|
||||
package posixproj
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"moku-backend/internal/database"
|
||||
)
|
||||
|
||||
const rootProjectionPath = "/"
|
||||
|
||||
type Projector struct {
|
||||
db *database.DB
|
||||
root string
|
||||
}
|
||||
|
||||
type RebuildSummary struct {
|
||||
TotalNodes int
|
||||
DirectoryCount int
|
||||
FileCount int
|
||||
}
|
||||
|
||||
type NodeKind string
|
||||
|
||||
const (
|
||||
NodeKindDirectory NodeKind = "directory"
|
||||
NodeKindFile NodeKind = "file"
|
||||
)
|
||||
|
||||
type Scope struct {
|
||||
InstallationID string
|
||||
OrganizationID string
|
||||
OrganizationSlug string
|
||||
DepartmentSlug string
|
||||
TeamSlug string
|
||||
ProjectSlug string
|
||||
PersonalSlug string
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
Path string
|
||||
ParentPath *string
|
||||
Name string
|
||||
Depth int
|
||||
NodeKind NodeKind
|
||||
LogicalType string
|
||||
FileRole string
|
||||
ResourceID string
|
||||
ResourceName string
|
||||
ResourceSlug string
|
||||
InstallationID string
|
||||
OrganizationID string
|
||||
OrganizationSlug string
|
||||
DepartmentSlug string
|
||||
TeamSlug string
|
||||
ProjectSlug string
|
||||
PersonalSlug string
|
||||
ContentJSON []byte
|
||||
SizeBytes int64
|
||||
Checksum string
|
||||
}
|
||||
|
||||
func NewProjector(db *database.DB, root string) *Projector {
|
||||
return &Projector{db: db, root: strings.TrimSpace(root)}
|
||||
}
|
||||
|
||||
func (projector *Projector) Rebuild(ctx context.Context) error {
|
||||
_, err := projector.RebuildWithSummary(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
func (projector *Projector) RebuildWithSummary(ctx context.Context) (RebuildSummary, error) {
|
||||
if projector == nil || projector.db == nil || projector.db.Pool == nil {
|
||||
return RebuildSummary{}, nil
|
||||
}
|
||||
|
||||
nodes, err := ScanRoot(projector.root)
|
||||
if err != nil {
|
||||
return RebuildSummary{}, err
|
||||
}
|
||||
|
||||
summary := summarizeNodes(nodes)
|
||||
|
||||
tx, err := projector.db.Pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return RebuildSummary{}, err
|
||||
}
|
||||
defer func() {
|
||||
_ = tx.Rollback(ctx)
|
||||
}()
|
||||
|
||||
if _, err := tx.Exec(ctx, `DELETE FROM posix_nodes;`); err != nil {
|
||||
return RebuildSummary{}, fmt.Errorf("clear posix_nodes: %w", err)
|
||||
}
|
||||
|
||||
for _, node := range nodes {
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO posix_nodes (
|
||||
path,
|
||||
parent_path,
|
||||
name,
|
||||
depth,
|
||||
node_kind,
|
||||
logical_type,
|
||||
file_role,
|
||||
resource_id,
|
||||
resource_name,
|
||||
resource_slug,
|
||||
installation_id,
|
||||
organization_id,
|
||||
organization_slug,
|
||||
department_slug,
|
||||
team_slug,
|
||||
project_slug,
|
||||
personal_slug,
|
||||
content_json,
|
||||
size_bytes,
|
||||
checksum
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5::posix_node_kind, $6, $7, $8, $9, $10,
|
||||
$11, $12, $13, $14, $15, $16, $17, $18::jsonb, $19, $20
|
||||
);
|
||||
`,
|
||||
node.Path,
|
||||
node.ParentPath,
|
||||
node.Name,
|
||||
node.Depth,
|
||||
string(node.NodeKind),
|
||||
node.LogicalType,
|
||||
node.FileRole,
|
||||
node.ResourceID,
|
||||
node.ResourceName,
|
||||
node.ResourceSlug,
|
||||
node.InstallationID,
|
||||
node.OrganizationID,
|
||||
node.OrganizationSlug,
|
||||
node.DepartmentSlug,
|
||||
node.TeamSlug,
|
||||
node.ProjectSlug,
|
||||
node.PersonalSlug,
|
||||
node.ContentJSON,
|
||||
node.SizeBytes,
|
||||
node.Checksum,
|
||||
); err != nil {
|
||||
return RebuildSummary{}, fmt.Errorf("insert posix node %s: %w", node.Path, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
return RebuildSummary{}, err
|
||||
}
|
||||
|
||||
return summary, nil
|
||||
}
|
||||
|
||||
func ScanRoot(root string) ([]Node, error) {
|
||||
rootPath := strings.TrimSpace(root)
|
||||
if rootPath == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
info, err := os.Stat(rootPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("stat POSIX root: %w", err)
|
||||
}
|
||||
if !info.IsDir() {
|
||||
return nil, fmt.Errorf("POSIX root is not a directory: %s", rootPath)
|
||||
}
|
||||
|
||||
rootScope, err := loadRootScope(rootPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nodes := []Node{{
|
||||
Path: rootProjectionPath,
|
||||
ParentPath: nil,
|
||||
Name: filepath.Base(rootPath),
|
||||
Depth: 0,
|
||||
NodeKind: NodeKindDirectory,
|
||||
LogicalType: "tenant_root",
|
||||
InstallationID: rootScope.InstallationID,
|
||||
OrganizationID: rootScope.OrganizationID,
|
||||
OrganizationSlug: rootScope.OrganizationSlug,
|
||||
}}
|
||||
|
||||
err = filepath.WalkDir(rootPath, func(path string, entry fs.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if path == rootPath {
|
||||
return nil
|
||||
}
|
||||
|
||||
relPath, err := filepath.Rel(rootPath, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
relPath = filepath.ToSlash(relPath)
|
||||
if relPath == "." {
|
||||
return nil
|
||||
}
|
||||
|
||||
node, err := buildNode(rootPath, relPath, entry, rootScope)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nodes = append(nodes, node)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("scan POSIX root: %w", err)
|
||||
}
|
||||
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func loadRootScope(rootPath string) (Scope, error) {
|
||||
settingsPath := filepath.Join(rootPath, "settings.json")
|
||||
content, err := os.ReadFile(settingsPath)
|
||||
if err != nil {
|
||||
if errorsIsNotExist(err) {
|
||||
return Scope{}, nil
|
||||
}
|
||||
return Scope{}, fmt.Errorf("read root settings.json: %w", err)
|
||||
}
|
||||
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(content, &payload); err != nil {
|
||||
return Scope{}, fmt.Errorf("decode root settings.json: %w", err)
|
||||
}
|
||||
|
||||
installation, _ := payload["installation"].(map[string]any)
|
||||
organization, _ := payload["organization"].(map[string]any)
|
||||
|
||||
return Scope{
|
||||
InstallationID: stringValue(installation["id"]),
|
||||
OrganizationID: stringValue(organization["id"]),
|
||||
OrganizationSlug: stringValue(organization["slug"]),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func buildNode(rootPath, relPath string, entry fs.DirEntry, rootScope Scope) (Node, error) {
|
||||
scope := deriveScope(relPath, rootScope)
|
||||
parentPath := projectionParentPath(relPath)
|
||||
logicalType, fileRole := classifyPath(relPath, entry.IsDir())
|
||||
|
||||
node := Node{
|
||||
Path: relPath,
|
||||
ParentPath: parentPath,
|
||||
Name: entry.Name(),
|
||||
Depth: strings.Count(relPath, "/") + 1,
|
||||
NodeKind: NodeKindDirectory,
|
||||
LogicalType: logicalType,
|
||||
FileRole: fileRole,
|
||||
InstallationID: scope.InstallationID,
|
||||
OrganizationID: scope.OrganizationID,
|
||||
OrganizationSlug: scope.OrganizationSlug,
|
||||
DepartmentSlug: scope.DepartmentSlug,
|
||||
TeamSlug: scope.TeamSlug,
|
||||
ProjectSlug: scope.ProjectSlug,
|
||||
PersonalSlug: scope.PersonalSlug,
|
||||
}
|
||||
|
||||
if entry.IsDir() {
|
||||
return node, nil
|
||||
}
|
||||
|
||||
absPath := filepath.Join(rootPath, filepath.FromSlash(relPath))
|
||||
content, err := os.ReadFile(absPath)
|
||||
if err != nil {
|
||||
return Node{}, fmt.Errorf("read POSIX file %s: %w", relPath, err)
|
||||
}
|
||||
|
||||
hash := sha256.Sum256(content)
|
||||
node.NodeKind = NodeKindFile
|
||||
node.SizeBytes = int64(len(content))
|
||||
node.Checksum = hex.EncodeToString(hash[:])
|
||||
|
||||
if strings.EqualFold(filepath.Ext(entry.Name()), ".json") {
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(content, &payload); err == nil {
|
||||
jsonContent, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return Node{}, fmt.Errorf("remarshal POSIX file %s: %w", relPath, err)
|
||||
}
|
||||
node.ContentJSON = jsonContent
|
||||
node.ResourceID = stringValue(payload["id"])
|
||||
node.ResourceName = stringValue(payload["name"])
|
||||
node.ResourceSlug = stringValue(payload["slug"])
|
||||
if node.ResourceID == "" && fileRole == "settings" && logicalType == "tenant" {
|
||||
installation, _ := payload["installation"].(map[string]any)
|
||||
organization, _ := payload["organization"].(map[string]any)
|
||||
node.ResourceID = stringValue(installation["id"])
|
||||
node.ResourceName = stringValue(installation["name"])
|
||||
node.InstallationID = stringValue(installation["id"])
|
||||
node.OrganizationID = stringValue(organization["id"])
|
||||
node.OrganizationSlug = firstNonEmpty(node.OrganizationSlug, stringValue(organization["slug"]))
|
||||
}
|
||||
if node.ResourceID == "" && fileRole == "users" {
|
||||
node.ResourceName = firstNonEmpty(node.ResourceName, parentEntityName(logicalType, scope))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if node.ResourceSlug == "" {
|
||||
node.ResourceSlug = inferredResourceSlug(logicalType, scope)
|
||||
}
|
||||
|
||||
return node, nil
|
||||
}
|
||||
|
||||
func deriveScope(relPath string, rootScope Scope) Scope {
|
||||
scope := rootScope
|
||||
parts := strings.Split(relPath, "/")
|
||||
if len(parts) >= 2 && parts[0] == "departments" && strings.HasPrefix(parts[1], "department-") {
|
||||
scope.DepartmentSlug = strings.TrimPrefix(parts[1], "department-")
|
||||
}
|
||||
if len(parts) >= 4 && parts[0] == "departments" && parts[2] == "teams" && strings.HasPrefix(parts[3], "team-") {
|
||||
scope.DepartmentSlug = strings.TrimPrefix(parts[1], "department-")
|
||||
scope.TeamSlug = strings.TrimPrefix(parts[3], "team-")
|
||||
}
|
||||
if len(parts) >= 2 && parts[0] == "projects" && strings.HasPrefix(parts[1], "project-") {
|
||||
scope.ProjectSlug = strings.TrimPrefix(parts[1], "project-")
|
||||
}
|
||||
if len(parts) >= 3 && parts[0] == "users" && parts[1] == "personals" && strings.HasPrefix(parts[2], "personal-") {
|
||||
scope.PersonalSlug = strings.TrimPrefix(parts[2], "personal-")
|
||||
}
|
||||
return scope
|
||||
}
|
||||
|
||||
func classifyPath(relPath string, isDir bool) (logicalType, fileRole string) {
|
||||
parts := strings.Split(relPath, "/")
|
||||
name := parts[len(parts)-1]
|
||||
if !isDir {
|
||||
fileRole = strings.TrimSuffix(name, filepath.Ext(name))
|
||||
}
|
||||
|
||||
switch {
|
||||
case relPath == "settings.json":
|
||||
return "tenant", "settings"
|
||||
case relPath == "layout.json":
|
||||
return "tenant", "layout"
|
||||
case len(parts) >= 1 && parts[0] == "catalog":
|
||||
if isDir {
|
||||
if len(parts) == 1 {
|
||||
return "catalog", ""
|
||||
}
|
||||
if len(parts) >= 2 && parts[1] == "packs" {
|
||||
if len(parts) == 2 {
|
||||
return "catalog_packs", ""
|
||||
}
|
||||
if len(parts) == 3 {
|
||||
return "catalog_pack", ""
|
||||
}
|
||||
if len(parts) >= 4 && parts[3] == "entries" {
|
||||
return "catalog_pack_entries", ""
|
||||
}
|
||||
return "catalog_entry", ""
|
||||
}
|
||||
if len(parts) >= 2 && parts[1] == "standalone" {
|
||||
if len(parts) == 2 {
|
||||
return "catalog_standalone", ""
|
||||
}
|
||||
return "catalog_entry", ""
|
||||
}
|
||||
}
|
||||
return "catalog", fileRole
|
||||
case len(parts) >= 2 && parts[0] == "departments" && strings.HasPrefix(parts[1], "department-"):
|
||||
if isDir {
|
||||
if len(parts) == 2 {
|
||||
return "department", ""
|
||||
}
|
||||
if len(parts) == 3 && parts[2] == "teams" {
|
||||
return "department_teams", ""
|
||||
}
|
||||
if len(parts) >= 4 && strings.HasPrefix(parts[3], "team-") {
|
||||
return "team", ""
|
||||
}
|
||||
}
|
||||
if len(parts) >= 4 && strings.HasPrefix(parts[3], "team-") {
|
||||
return "team", fileRole
|
||||
}
|
||||
return "department", fileRole
|
||||
case len(parts) >= 2 && parts[0] == "projects" && strings.HasPrefix(parts[1], "project-"):
|
||||
if isDir {
|
||||
if len(parts) == 2 {
|
||||
return "project", ""
|
||||
}
|
||||
if len(parts) == 3 && parts[2] == "tree" {
|
||||
return "project_tree", ""
|
||||
}
|
||||
if strings.Contains(relPath, "/tree/") || strings.HasSuffix(relPath, "/tree") {
|
||||
if strings.HasPrefix(name, "folder-") {
|
||||
return "folder", ""
|
||||
}
|
||||
if strings.HasPrefix(name, "item-") {
|
||||
return "item", ""
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.Contains(relPath, "/tree/") {
|
||||
if strings.HasPrefix(parts[len(parts)-2], "item-") {
|
||||
return "item", fileRole
|
||||
}
|
||||
if strings.HasPrefix(parts[len(parts)-2], "folder-") {
|
||||
return "folder", fileRole
|
||||
}
|
||||
}
|
||||
return "project", fileRole
|
||||
case len(parts) >= 1 && parts[0] == "users":
|
||||
if isDir {
|
||||
if len(parts) == 1 {
|
||||
return "users", ""
|
||||
}
|
||||
if len(parts) == 2 && parts[1] == "personals" {
|
||||
return "personals", ""
|
||||
}
|
||||
if len(parts) >= 3 && parts[1] == "personals" && strings.HasPrefix(parts[2], "personal-") {
|
||||
return "personal", ""
|
||||
}
|
||||
if strings.Contains(relPath, "/tree/") || strings.HasSuffix(relPath, "/tree") {
|
||||
if strings.HasPrefix(name, "folder-") {
|
||||
return "folder", ""
|
||||
}
|
||||
if strings.HasPrefix(name, "item-") {
|
||||
return "item", ""
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(parts) >= 3 && parts[1] == "personals" && strings.HasPrefix(parts[2], "personal-") {
|
||||
if strings.Contains(relPath, "/tree/") {
|
||||
if strings.HasPrefix(parts[len(parts)-2], "item-") {
|
||||
return "item", fileRole
|
||||
}
|
||||
if strings.HasPrefix(parts[len(parts)-2], "folder-") {
|
||||
return "folder", fileRole
|
||||
}
|
||||
}
|
||||
return "personal", fileRole
|
||||
}
|
||||
return "users", fileRole
|
||||
default:
|
||||
if isDir {
|
||||
return "directory", ""
|
||||
}
|
||||
return "file", fileRole
|
||||
}
|
||||
}
|
||||
|
||||
func projectionParentPath(relPath string) *string {
|
||||
if relPath == "" || relPath == rootProjectionPath {
|
||||
return nil
|
||||
}
|
||||
parent := filepath.ToSlash(filepath.Dir(relPath))
|
||||
if parent == "." || parent == "" {
|
||||
root := rootProjectionPath
|
||||
return &root
|
||||
}
|
||||
return &parent
|
||||
}
|
||||
|
||||
func inferredResourceSlug(logicalType string, scope Scope) string {
|
||||
switch logicalType {
|
||||
case "department":
|
||||
return scope.DepartmentSlug
|
||||
case "team":
|
||||
return scope.TeamSlug
|
||||
case "project":
|
||||
return scope.ProjectSlug
|
||||
case "personal":
|
||||
return scope.PersonalSlug
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func parentEntityName(logicalType string, scope Scope) string {
|
||||
switch logicalType {
|
||||
case "department":
|
||||
return scope.DepartmentSlug
|
||||
case "team":
|
||||
return scope.TeamSlug
|
||||
case "project":
|
||||
return scope.ProjectSlug
|
||||
case "personal":
|
||||
return scope.PersonalSlug
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func stringValue(value any) string {
|
||||
stringValue, _ := value.(string)
|
||||
return strings.TrimSpace(stringValue)
|
||||
}
|
||||
|
||||
func firstNonEmpty(values ...string) string {
|
||||
for _, value := range values {
|
||||
trimmed := strings.TrimSpace(value)
|
||||
if trimmed != "" {
|
||||
return trimmed
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func summarizeNodes(nodes []Node) RebuildSummary {
|
||||
summary := RebuildSummary{TotalNodes: len(nodes)}
|
||||
for _, node := range nodes {
|
||||
switch node.NodeKind {
|
||||
case NodeKindDirectory:
|
||||
summary.DirectoryCount++
|
||||
case NodeKindFile:
|
||||
summary.FileCount++
|
||||
}
|
||||
}
|
||||
return summary
|
||||
}
|
||||
|
||||
func errorsIsNotExist(err error) bool {
|
||||
return err != nil && os.IsNotExist(err)
|
||||
}
|
||||
148
Backend/internal/posixproj/projector_test.go
Normal file
148
Backend/internal/posixproj/projector_test.go
Normal file
@@ -0,0 +1,148 @@
|
||||
package posixproj
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScanRootBuildsProjectedNodesFromBootstrapShape(t *testing.T) {
|
||||
root := filepath.Join(t.TempDir(), "POSIX")
|
||||
|
||||
mustMkdirAll(t, filepath.Join(root, "catalog", "packs"))
|
||||
mustMkdirAll(t, filepath.Join(root, "catalog", "standalone"))
|
||||
mustMkdirAll(t, filepath.Join(root, "departments", "department-primary-department", "teams", "team-primary-team"))
|
||||
mustMkdirAll(t, filepath.Join(root, "projects", "project-primary-project", "tree"))
|
||||
mustMkdirAll(t, filepath.Join(root, "users", "personals"))
|
||||
|
||||
mustWriteJSON(t, filepath.Join(root, "settings.json"), map[string]any{
|
||||
"installation": map[string]any{
|
||||
"id": "installation-1",
|
||||
"name": "MangoPig",
|
||||
"isBootstrapped": true,
|
||||
},
|
||||
"organization": map[string]any{
|
||||
"id": "org-1",
|
||||
"name": "Primary Organization",
|
||||
"slug": "primary-organization",
|
||||
},
|
||||
})
|
||||
mustWriteJSON(t, filepath.Join(root, "layout.json"), map[string]any{
|
||||
"type": "tenant-layout",
|
||||
"home": map[string]any{"defaultProjectSlug": "primary-project"},
|
||||
})
|
||||
mustWriteJSON(t, filepath.Join(root, "departments", "department-primary-department", "settings.json"), map[string]any{
|
||||
"id": "dept-1",
|
||||
"name": "Primary Department",
|
||||
"slug": "primary-department",
|
||||
"type": "department",
|
||||
})
|
||||
mustWriteJSON(t, filepath.Join(root, "departments", "department-primary-department", "users.json"), map[string]any{
|
||||
"users": []map[string]any{{"id": "admin-1"}},
|
||||
})
|
||||
mustWriteJSON(t, filepath.Join(root, "departments", "department-primary-department", "teams", "team-primary-team", "settings.json"), map[string]any{
|
||||
"id": "team-1",
|
||||
"name": "Primary Team",
|
||||
"slug": "primary-team",
|
||||
"type": "team",
|
||||
})
|
||||
mustWriteJSON(t, filepath.Join(root, "projects", "project-primary-project", "settings.json"), map[string]any{
|
||||
"id": "project-1",
|
||||
"name": "Primary Project",
|
||||
"slug": "primary-project",
|
||||
"type": "project",
|
||||
})
|
||||
mustWriteJSON(t, filepath.Join(root, "projects", "project-primary-project", "home.json"), map[string]any{
|
||||
"type": "project-home",
|
||||
"project": "primary-project",
|
||||
})
|
||||
mustWriteJSON(t, filepath.Join(root, "users", "settings.json"), map[string]any{
|
||||
"primaryAdminId": "admin-1",
|
||||
})
|
||||
mustWriteJSON(t, filepath.Join(root, "users", "data.json"), map[string]any{
|
||||
"users": []map[string]any{{"id": "admin-1", "email": "ronald@example.com"}},
|
||||
})
|
||||
|
||||
nodes, err := ScanRoot(root)
|
||||
if err != nil {
|
||||
t.Fatalf("ScanRoot() error = %v", err)
|
||||
}
|
||||
|
||||
index := make(map[string]Node, len(nodes))
|
||||
for _, node := range nodes {
|
||||
index[node.Path] = node
|
||||
}
|
||||
|
||||
rootNode, ok := index[rootProjectionPath]
|
||||
if !ok {
|
||||
t.Fatalf("expected synthetic root node")
|
||||
}
|
||||
if rootNode.LogicalType != "tenant_root" {
|
||||
t.Fatalf("expected root logical type tenant_root, got %q", rootNode.LogicalType)
|
||||
}
|
||||
if rootNode.OrganizationSlug != "primary-organization" {
|
||||
t.Fatalf("expected root organization slug primary-organization, got %q", rootNode.OrganizationSlug)
|
||||
}
|
||||
|
||||
tenantSettings := index["settings.json"]
|
||||
if tenantSettings.LogicalType != "tenant" || tenantSettings.FileRole != "settings" {
|
||||
t.Fatalf("unexpected tenant settings classification: %#v", tenantSettings)
|
||||
}
|
||||
if tenantSettings.InstallationID != "installation-1" {
|
||||
t.Fatalf("expected installation id installation-1, got %q", tenantSettings.InstallationID)
|
||||
}
|
||||
|
||||
deptSettings := index["departments/department-primary-department/settings.json"]
|
||||
if deptSettings.DepartmentSlug != "primary-department" {
|
||||
t.Fatalf("expected department slug primary-department, got %q", deptSettings.DepartmentSlug)
|
||||
}
|
||||
if deptSettings.ResourceID != "dept-1" {
|
||||
t.Fatalf("expected department resource id dept-1, got %q", deptSettings.ResourceID)
|
||||
}
|
||||
|
||||
teamSettings := index["departments/department-primary-department/teams/team-primary-team/settings.json"]
|
||||
if teamSettings.TeamSlug != "primary-team" {
|
||||
t.Fatalf("expected team slug primary-team, got %q", teamSettings.TeamSlug)
|
||||
}
|
||||
|
||||
projectSettings := index["projects/project-primary-project/settings.json"]
|
||||
if projectSettings.ProjectSlug != "primary-project" {
|
||||
t.Fatalf("expected project slug primary-project, got %q", projectSettings.ProjectSlug)
|
||||
}
|
||||
if projectSettings.ResourceName != "Primary Project" {
|
||||
t.Fatalf("expected project resource name Primary Project, got %q", projectSettings.ResourceName)
|
||||
}
|
||||
|
||||
projectTree := index["projects/project-primary-project/tree"]
|
||||
if projectTree.LogicalType != "project_tree" || projectTree.NodeKind != NodeKindDirectory {
|
||||
t.Fatalf("unexpected project tree node: %#v", projectTree)
|
||||
}
|
||||
|
||||
usersData := index["users/data.json"]
|
||||
if usersData.LogicalType != "users" || usersData.FileRole != "data" {
|
||||
t.Fatalf("unexpected users data classification: %#v", usersData)
|
||||
}
|
||||
if usersData.Checksum == "" || usersData.SizeBytes == 0 {
|
||||
t.Fatalf("expected users/data.json checksum and size to be populated: %#v", usersData)
|
||||
}
|
||||
}
|
||||
|
||||
func mustMkdirAll(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(path, 0o755); err != nil {
|
||||
t.Fatalf("MkdirAll(%q) error = %v", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
func mustWriteJSON(t *testing.T, path string, payload any) {
|
||||
t.Helper()
|
||||
bytes, err := json.MarshalIndent(payload, "", " ")
|
||||
if err != nil {
|
||||
t.Fatalf("MarshalIndent(%q) error = %v", path, err)
|
||||
}
|
||||
bytes = append(bytes, '\n')
|
||||
if err := os.WriteFile(path, bytes, 0o644); err != nil {
|
||||
t.Fatalf("WriteFile(%q) error = %v", path, err)
|
||||
}
|
||||
}
|
||||
@@ -9,18 +9,22 @@ migrate-up:
|
||||
migrate-down:
|
||||
cd '{{backend_dir}}' && go run ./cmd/migrate down
|
||||
|
||||
# Reset all embedded database migrations and reapply from scratch.
|
||||
# Reset all embedded database migrations.
|
||||
migrate-reset:
|
||||
cd '{{backend_dir}}' && go run ./cmd/migrate reset
|
||||
|
||||
# Reset embedded database migrations and apply them again from scratch.
|
||||
migrate-rebuild:
|
||||
cd '{{backend_dir}}' && go run ./cmd/migrate reset && go run ./cmd/migrate up
|
||||
|
||||
# Show the embedded database migration status.
|
||||
migrate-status:
|
||||
cd '{{backend_dir}}' && go run ./cmd/migrate status
|
||||
|
||||
# Rebuild the POSIX-to-DB projection from the current POSIX root.
|
||||
posix-rebuild:
|
||||
cd '{{backend_dir}}' && go run ./cmd/posix rebuild
|
||||
|
||||
# Format backend Go source files.
|
||||
fmt:
|
||||
cd '{{backend_dir}}' && gofmt -w ./cmd ./db ./internal
|
||||
|
||||
# Run backend test suite.
|
||||
test:
|
||||
cd '{{backend_dir}}' && go test ./...
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
project_root := justfile_directory()
|
||||
proxy_bake := project_root + "/Proxy/docker-bake.hcl"
|
||||
backend_bake := project_root + "/Backend/docker-bake.hcl"
|
||||
local_compose := project_root + "/Docker/docker-compose.local.prod.yaml"
|
||||
proxy_image := "moku/work-proxy:local-prod"
|
||||
backend_api_image := "moku/work-backend:local-prod-api"
|
||||
backend_worker_image := "moku/work-backend:local-prod-worker"
|
||||
|
||||
# Build the local production proxy image locally.
|
||||
build:
|
||||
cd '{{project_root}}' && docker buildx bake -f '{{proxy_bake}}' prod
|
||||
cd '{{project_root}}' && docker buildx bake -f '{{backend_bake}}' prod-api prod-worker
|
||||
|
||||
# Start the local production stack in the background using the current image.
|
||||
up:
|
||||
@@ -17,6 +21,7 @@ start: build up
|
||||
# Rebuild the local production proxy image locally.
|
||||
rebuild:
|
||||
cd '{{project_root}}' && docker buildx bake -f '{{proxy_bake}}' --set '*.no-cache=true' prod
|
||||
cd '{{project_root}}' && docker buildx bake -f '{{backend_bake}}' --set '*.no-cache=true' prod-api prod-worker
|
||||
docker compose -f '{{local_compose}}' up -d --remove-orphans --force-recreate
|
||||
|
||||
# Stop and remove the local production stack.
|
||||
@@ -35,3 +40,5 @@ restart:
|
||||
clean:
|
||||
docker compose -f '{{local_compose}}' down --remove-orphans --volumes
|
||||
docker image rm -f '{{proxy_image}}' >/dev/null 2>&1 || true
|
||||
docker image rm -f '{{backend_api_image}}' >/dev/null 2>&1 || true
|
||||
docker image rm -f '{{backend_worker_image}}' >/dev/null 2>&1 || true
|
||||
|
||||
11
Commands/Test/backend.just
Normal file
11
Commands/Test/backend.just
Normal file
@@ -0,0 +1,11 @@
|
||||
project_root := justfile_directory()
|
||||
backend_dir := project_root + "/Backend"
|
||||
|
||||
# Run the full backend test suite.
|
||||
[default]
|
||||
all:
|
||||
cd '{{backend_dir}}' && go test ./...
|
||||
|
||||
# Run the isolated POSIX bootstrap smoke test.
|
||||
posix-bootstrap:
|
||||
cd '{{backend_dir}}' && go test ./internal/bootstrap -run TestEnsureBootstrapPOSIXSkeletonInitializesEmptyRoot -count=1 -v
|
||||
1
Commands/Test/mod.just
Normal file
1
Commands/Test/mod.just
Normal file
@@ -0,0 +1 @@
|
||||
mod backend
|
||||
@@ -6,6 +6,7 @@ x-backend-service: &backend-service
|
||||
environment:
|
||||
DATABASE_URL: postgres://moku:moku_dev_password@postgres:5432/moku?sslmode=disable
|
||||
VALKEY_URL: redis://valkey:6379/0
|
||||
POSIX_ROOT: /posix
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
@@ -13,6 +14,7 @@ x-backend-service: &backend-service
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- ../Backend:/app
|
||||
- ../POSIX:/posix
|
||||
- moku_work_backend_go_pkg:/go/pkg/mod
|
||||
- moku_work_backend_go_build:/root/.cache/go-build
|
||||
|
||||
|
||||
@@ -1,7 +1,70 @@
|
||||
x-backend-service: &backend-service
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- ../Env/.env.local
|
||||
environment:
|
||||
DATABASE_URL: postgres://moku:moku_dev_password@postgres:5432/moku?sslmode=disable
|
||||
VALKEY_URL: redis://valkey:6379/0
|
||||
POSIX_ROOT: /posix
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
valkey:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- ../POSIX:/posix
|
||||
|
||||
services:
|
||||
proxy:
|
||||
image: moku/work-proxy:local-prod
|
||||
container_name: moku-work-proxy-local
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8080:80"
|
||||
postgres:
|
||||
image: postgres:17-alpine
|
||||
container_name: moku-work-postgres-prod
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: moku
|
||||
POSTGRES_USER: moku
|
||||
POSTGRES_PASSWORD: moku_dev_password
|
||||
volumes:
|
||||
- moku_work_postgres_prod_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U moku -d moku"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 10s
|
||||
|
||||
valkey:
|
||||
image: valkey/valkey:8-alpine
|
||||
container_name: moku-work-valkey-prod
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- moku_work_valkey_prod_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "valkey-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 5s
|
||||
|
||||
api:
|
||||
<<: *backend-service
|
||||
image: moku/work-backend:local-prod-api
|
||||
container_name: moku-work-backend-api-prod
|
||||
|
||||
worker:
|
||||
<<: *backend-service
|
||||
image: moku/work-backend:local-prod-worker
|
||||
container_name: moku-work-backend-worker-prod
|
||||
|
||||
proxy:
|
||||
image: moku/work-proxy:local-prod
|
||||
container_name: moku-work-proxy-local
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
api:
|
||||
condition: service_started
|
||||
ports:
|
||||
- "8080:80"
|
||||
|
||||
volumes:
|
||||
moku_work_postgres_prod_data:
|
||||
moku_work_valkey_prod_data:
|
||||
|
||||
61
Documentation/POSIX-Structure.md
Normal file
61
Documentation/POSIX-Structure.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# POSIX Structure
|
||||
|
||||
``` markdown
|
||||
Personal or Organization (server)/
|
||||
├── settings.json
|
||||
├── layout.json
|
||||
├── catalog/
|
||||
│ ├── packs/
|
||||
│ │ └── pack-<slug>/
|
||||
│ │ ├── manifest.json
|
||||
│ │ └── entries/
|
||||
│ │ └── app-<slug>/
|
||||
│ │ └── manifest.json
|
||||
│ └── standalone/
|
||||
│ └── app-<slug>/
|
||||
│ └── manifest.json
|
||||
├── departments/
|
||||
│ └── department-<slug>/
|
||||
│ ├── settings.json
|
||||
│ ├── users.json
|
||||
│ └── teams/
|
||||
│ └── team-<slug>/
|
||||
│ ├── settings.json
|
||||
│ └── users.json
|
||||
├── projects/
|
||||
│ └── project-<slug>/
|
||||
│ ├── settings.json
|
||||
│ ├── home.json
|
||||
│ └── tree/
|
||||
│ ├── item-<slug>/
|
||||
│ │ ├── item.json
|
||||
│ │ ├── schema.json
|
||||
│ │ └── data.json
|
||||
│ └── folder-<slug>/
|
||||
│ ├── folder.json
|
||||
│ └── item-<slug>/
|
||||
│ ├── item.json
|
||||
│ ├── schema.json
|
||||
│ └── data.json
|
||||
└── users/
|
||||
├── settings.json
|
||||
├── data.json
|
||||
└── personals/
|
||||
└── personal-<slug>/
|
||||
├── layout.json
|
||||
├── settings.json
|
||||
├── home.json
|
||||
└── tree/
|
||||
```
|
||||
|
||||
## File Responsibilities
|
||||
|
||||
- `settings.json` — Metadata and presentation config for the thing, such as display name, icon, description, and simple settings.
|
||||
- `layout.json` — Layout configuration for the current server or personal space.
|
||||
- `home.json` — Home surface configuration, such as widgets, sections, and how they are arranged.
|
||||
- `folder.json` — Metadata for a folder node in a tree.
|
||||
- `item.json` — Instance metadata for a created item, including what it is and how it should behave.
|
||||
- `schema.json` — The structure expected by that item's data.
|
||||
- `data.json` — The actual content or state data for that item.
|
||||
- `manifest.json` — Catalog definition metadata, including versioning, description, and capabilities for reusable apps or entries.
|
||||
- `users.json` — User membership or assignment data for departments and teams.
|
||||
@@ -4,87 +4,149 @@
|
||||
|
||||
### Version 0.1.0
|
||||
|
||||
**Goal:** Barebone frontend with a real backend core.
|
||||
**Goal:** Finish the base application shell, auth, and platform foundations.
|
||||
|
||||
#### Architecture
|
||||
#### Architecture and Delivery
|
||||
|
||||
- [ ] Project-Structure
|
||||
- [ ] Stack-Decisions
|
||||
- [ ] Proxy
|
||||
- [ ] Local-Prod-NGINX-Proxy
|
||||
- [ ] Static-Frontend-Serving
|
||||
- [ ] First-Request-Web-Loader
|
||||
- [ ] Bootstrap-Document
|
||||
- [ ] Route-Intent-Handoff
|
||||
- [ ] Tiny-First-Paint-Budget
|
||||
- [ ] Dev-and-Prod-Builds
|
||||
- [x] Project-Structure
|
||||
- [x] Stack-Decisions
|
||||
- [x] Proxy
|
||||
- [x] Local-Dev-Vite-Proxy
|
||||
- [x] Local-Prod-NGINX-Proxy
|
||||
- [x] First-Request-Web-Loader
|
||||
- [x] Bootstrap-Document
|
||||
- [x] Route-Intent-Handoff
|
||||
- [x] Tiny-First-Paint-Budget
|
||||
- [x] Dev-and-Prod-Builds
|
||||
- [x] Local-Dev-Just-Commands
|
||||
- [x] Local-Dev-Docker-Compose
|
||||
- [ ] Local-Prod-Just-Commands
|
||||
- [ ] Local-Prod-Docker-Compose
|
||||
- [ ] Frontend-Production-Dockerfile
|
||||
- [ ] Frontend-docker-bake
|
||||
- [x] Local-Prod-Just-Commands
|
||||
- [x] Local-Prod-Docker-Compose
|
||||
- [x] Frontend-Production-Dockerfile
|
||||
- [x] Frontend-docker-bake
|
||||
|
||||
#### Backend
|
||||
#### Backend — Done Foundations
|
||||
|
||||
- [x] Bootstrap-Persistence
|
||||
- [x] Installation-Step
|
||||
- [x] Mode-Step
|
||||
- [x] Admin-Step
|
||||
- [x] Structure-Step
|
||||
- [x] Bootstrap-State-Authority
|
||||
- [x] Development-Bootstrap-Reset
|
||||
- [x] Base-Schema
|
||||
- [x] Installations
|
||||
- [x] Users
|
||||
- [x] User-Homes
|
||||
- [x] Organizations
|
||||
- [x] Departments
|
||||
- [x] Teams
|
||||
- [x] Projects
|
||||
- [x] Workspaces
|
||||
- [x] Membership-Tables
|
||||
- [x] App-Shell-Read-API
|
||||
- [x] App-Shell-State-Endpoint
|
||||
- [x] Bootstrap-Read-Endpoints
|
||||
- [x] Shell-Tree-Hydration
|
||||
- [x] Web-Route-Scaffolds
|
||||
- [x] Session-Endpoint-Scaffold
|
||||
- [x] Bootstrap-Endpoint-Scaffold
|
||||
- [x] Current-User-Endpoint-Scaffold
|
||||
|
||||
#### Backend — Remaining for 0.1.0
|
||||
|
||||
- [ ] Auth
|
||||
- [ ] Session-Flow
|
||||
- [ ] Login-Logout-Foundation
|
||||
- [ ] Authentication
|
||||
- [ ] User
|
||||
- [ ] Base-Model
|
||||
- [ ] Current-User-Implementation
|
||||
- [ ] POSIX-Lite-File-Persistence-Foundation
|
||||
- [ ] Mounted-Storage-Root-Config
|
||||
- [ ] Project-Folder-Creation-On-Backend
|
||||
- [ ] moku.project.json
|
||||
- [ ] Item-Folder-Creation
|
||||
- [ ] item.json
|
||||
- [ ] schema.json
|
||||
- [ ] data.json
|
||||
- [ ] DB-To-Files-Write-Flow
|
||||
- [ ] User-and-Workspace-Domain-Readiness
|
||||
- [ ] Base-Workspace
|
||||
- [ ] Folders-and-Subfolders
|
||||
- [ ] Boards
|
||||
- [ ] Dashboard
|
||||
- [ ] Organization
|
||||
- [ ] Base-Model
|
||||
- [ ] Access-Rules-and-Membership
|
||||
- [ ] Workspace
|
||||
- [ ] Folders-and-Subfolders
|
||||
- [ ] Boards
|
||||
- [ ] Dashboard
|
||||
- [ ] API
|
||||
- [ ] Real-Organizations-Read-Endpoint
|
||||
- [ ] Real-Workspaces-Read-Endpoint
|
||||
- [ ] Tree-Mutation-Endpoints
|
||||
- [ ] Project-Creation-Endpoint
|
||||
|
||||
#### Frontend
|
||||
#### Frontend — Done Foundations
|
||||
|
||||
- [x] Foundation
|
||||
- [x] Typography
|
||||
- [x] Icons
|
||||
- [ ] App Shell
|
||||
- [x] App-Shell
|
||||
- [x] Left-Rail
|
||||
- [x] Top-Bar
|
||||
- [x] Server-Dock
|
||||
- [x] Department-Selector
|
||||
- [x] Theme-Toggle
|
||||
- [x] Notifications-Menu
|
||||
- [x] Profile-Menu
|
||||
- [x] Responsive-Shell
|
||||
- [x] Collapsible-Shell
|
||||
- [x] Mobile-Bottom-Nav
|
||||
- [x] Mobile-Workspace-Browser
|
||||
- [x] Mobile-Workspace-Views
|
||||
- [x] Context-Menus
|
||||
- [x] Workspace-Context-Menu
|
||||
- [x] Project-Context-Menu
|
||||
- [x] Bootstrap-Workspace-Home
|
||||
- [x] Bootstrap-Wizard
|
||||
- [x] Bootstrap-Step-Submission
|
||||
- [x] App-Shell-Reload-After-Bootstrap
|
||||
- [x] Project-Menu
|
||||
- [x] Folders-and-Subfolders
|
||||
- [x] Rooted-From-Department
|
||||
- [x] Long-Press-Drag-and-Drop
|
||||
- [x] Workspace-Tree
|
||||
- [x] Folders-and-Subfolders
|
||||
- [x] Long-Press-Drag-and-Drop
|
||||
- [x] App-Shell-Hydration
|
||||
|
||||
#### Frontend — Remaining for 0.1.0
|
||||
|
||||
- [ ] Primitives
|
||||
- [ ] Button
|
||||
- [ ] IconButton
|
||||
- [ ] Input
|
||||
- [ ] Surface
|
||||
- [ ] Nav-Bar
|
||||
- [ ] Workspace-Switching
|
||||
- [ ] Workspace-Home
|
||||
- [ ] Real-Workspace-Home
|
||||
- [ ] Real-Workspace-Tree-Hydration
|
||||
- [ ] Create-Project-Flow
|
||||
- [ ] Persist-Tree-Mutations
|
||||
- [ ] Connect-Tree-Interactions-To-Backend-Data
|
||||
|
||||
### Version 0.2.0
|
||||
|
||||
**Goal:** First real work surface.
|
||||
|
||||
- [ ] Table
|
||||
- [ ] CVA
|
||||
- [ ] Storyboard
|
||||
- [ ] Theme-System
|
||||
- [ ] Theme-Registry
|
||||
- [ ] Built-In-Theme-Presets
|
||||
- [ ] Active-Theme-Persistence
|
||||
- [ ] Theme-Switcher
|
||||
- [ ] Theme-JSON-Upload
|
||||
- [ ] Theme-JSON-Import-Validation
|
||||
- [ ] Community-Theme-Readiness
|
||||
**Goal:** Build the plugin app system on top of the base platform. And core app plugins like calendar, board, docs and text channels
|
||||
|
||||
### Version 0.3.0
|
||||
|
||||
**Goal:** Documents and system hardening.
|
||||
|
||||
- [ ] Document
|
||||
- [ ] Accessibility-Rules
|
||||
- [ ] Motion-Foundation
|
||||
**Goal:** Communications and Collaboration (Email System, Reminder System, and Live Collaboration on Documents)
|
||||
|
||||
### Version 0.4.0
|
||||
|
||||
- [ ] Gantt-Board
|
||||
- [ ] Calendar
|
||||
- [ ] Timeline
|
||||
**Goal:** Introduce the POSIX-based file system drive direction with OnlyOffice + S3 blob storage + Per File Versioning
|
||||
|
||||
### Version 0.5.0
|
||||
|
||||
**Goal:** File Sharing and Per File Permissions
|
||||
|
||||
### Version 0.6.0
|
||||
|
||||
**Goal:** Git as a core plugin
|
||||
|
||||
### Version 0.7.0
|
||||
|
||||
**Goal:** Full Automation System (Extensive)
|
||||
|
||||
@@ -10,3 +10,10 @@ BACKEND_SHUTDOWN_TIMEOUT=10s
|
||||
|
||||
DATABASE_URL=postgres://moku:moku_dev_password@localhost:5432/moku?sslmode=disable
|
||||
VALKEY_URL=redis://localhost:6379/0
|
||||
POSIX_ROOT=../POSIX
|
||||
|
||||
VITE_API_BASE_URL=/v1
|
||||
|
||||
# Local frontend dev uses the Vite proxy for /v1 requests.
|
||||
# Override only if the browser must call the API directly:
|
||||
# VITE_API_BASE_URL=http://localhost:8081/v1
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { createSignal, onCleanup, onMount, Show, type JSX } from "solid-js";
|
||||
import { getDocumentTheme, setTheme, type Theme } from "../../../theme/runtime";
|
||||
import { WorkspaceHome } from "../../workspace-home/WorkspaceHome/WorkspaceHome";
|
||||
import { AppShellDataProvider, useAppShellData } from "../data/app-shell.context";
|
||||
import { LeftRail } from "../LeftRail/LeftRail";
|
||||
import { MobileBottomNav } from "../MobileBottomNav/MobileBottomNav";
|
||||
import { MobileWorkspaceBrowser } from "../MobileWorkspaceBrowser/MobileWorkspaceBrowser";
|
||||
@@ -16,13 +17,14 @@ import styles from "./AppShell.module.scss";
|
||||
type MobileWorkspaceView = "notifications" | "profile" | null;
|
||||
const MOBILE_VIEWPORT_QUERY = "(max-width: 48rem)";
|
||||
|
||||
export const AppShell = (): JSX.Element => {
|
||||
const AppShellContent = (): JSX.Element => {
|
||||
const [themeState, setThemeState] = createSignal<Theme>("light");
|
||||
const [isRailCollapsed, setIsRailCollapsed] = createSignal(false);
|
||||
const [isSidebarCollapsed, setIsSidebarCollapsed] = createSignal(false);
|
||||
const [isMobileViewport, setIsMobileViewport] = createSignal(false);
|
||||
const [isMobileWorkspaceBrowserOpen, setIsMobileWorkspaceBrowserOpen] = createSignal(false);
|
||||
const [activeMobileWorkspaceView, setActiveMobileWorkspaceView] = createSignal<MobileWorkspaceView>(null);
|
||||
const appShellData = useAppShellData();
|
||||
|
||||
onMount((): void => {
|
||||
setThemeState(getDocumentTheme());
|
||||
@@ -79,7 +81,7 @@ export const AppShell = (): JSX.Element => {
|
||||
};
|
||||
|
||||
return (
|
||||
<div class={styles.shell} data-ui="app-shell">
|
||||
<div class={styles.shell} data-ui="app-shell" data-app-shell-status={appShellData.status()}>
|
||||
<TopBar
|
||||
theme={themeState()}
|
||||
onToggleTheme={toggleTheme}
|
||||
@@ -163,3 +165,11 @@ export const AppShell = (): JSX.Element => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const AppShell = (): JSX.Element => {
|
||||
return (
|
||||
<AppShellDataProvider>
|
||||
<AppShellContent />
|
||||
</AppShellDataProvider>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
import { For, createSignal, onCleanup, onMount, type JSX } from "solid-js";
|
||||
import { For, createEffect, createSignal, onCleanup, onMount, type JSX } from "solid-js";
|
||||
import { ChevronDown } from "../../../lib/icons";
|
||||
import { activeDepartment, departmentItems, type DepartmentItem } from "../data/shell.data";
|
||||
import { useAppShellData } from "../data/app-shell.context";
|
||||
import { type DepartmentItem } from "../data/shell.data";
|
||||
import styles from "./DepartmentSelector.module.scss";
|
||||
|
||||
const defaultDepartment = departmentItems.find((item) => item.id === activeDepartment.id) ?? departmentItems[0];
|
||||
const defaultTeamName = departmentItems
|
||||
.find((item) => item.id === activeDepartment.id)
|
||||
?.teams.find((teamName) => teamName === activeDepartment.teamName)
|
||||
?? defaultDepartment?.teams[0]
|
||||
?? "";
|
||||
|
||||
export const DepartmentSelector = (): JSX.Element => {
|
||||
const appShellData = useAppShellData();
|
||||
const [isOpen, setIsOpen] = createSignal(false);
|
||||
const [selectedDepartment, setSelectedDepartment] = createSignal<DepartmentItem>(defaultDepartment);
|
||||
const [selectedTeamName, setSelectedTeamName] = createSignal(defaultTeamName);
|
||||
const [selectedDepartment, setSelectedDepartment] = createSignal<DepartmentItem>(appShellData.departmentItems()[0] ?? appShellData.activeDepartment());
|
||||
const [selectedTeamName, setSelectedTeamName] = createSignal(appShellData.activeDepartment().teamName);
|
||||
|
||||
let rootRef: HTMLDivElement | undefined;
|
||||
|
||||
createEffect(() => {
|
||||
const activeDepartment = appShellData.activeDepartment();
|
||||
const matchingDepartment = appShellData.departmentItems().find((item) => item.id === activeDepartment.id) ?? appShellData.departmentItems()[0];
|
||||
|
||||
if (!matchingDepartment) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSelectedDepartment(matchingDepartment);
|
||||
setSelectedTeamName(activeDepartment.teamName || matchingDepartment.teams[0] || "");
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
const handlePointerDown = (event: PointerEvent): void => {
|
||||
if (!isOpen()) return;
|
||||
@@ -66,7 +73,7 @@ export const DepartmentSelector = (): JSX.Element => {
|
||||
<div class={styles.menuSection}>
|
||||
<span class={styles.menuSectionLabel}>Departments</span>
|
||||
|
||||
<For each={departmentItems}>
|
||||
<For each={appShellData.departmentItems()}>
|
||||
{(item): JSX.Element => (
|
||||
<button
|
||||
classList={{ [styles.menuItem]: true, [styles.menuItemActive]: item.id === selectedDepartment().id }}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Path: Frontend/src/components/shell/LeftRail/LeftRail.tsx
|
||||
|
||||
import { For, Show, type JSX } from "solid-js";
|
||||
import { railItems, type RailItem } from "../data/shell.data";
|
||||
import { useAppShellData } from "../data/app-shell.context";
|
||||
import { type RailItem } from "../data/shell.data";
|
||||
import styles from "./LeftRail.module.scss";
|
||||
|
||||
type RailEntryProps = {
|
||||
@@ -46,8 +47,9 @@ type LeftRailProps = {
|
||||
};
|
||||
|
||||
export const LeftRail = (props: LeftRailProps): JSX.Element => {
|
||||
const personalItem = railItems.find((item) => item.kind === "personal");
|
||||
const organizationItems = railItems.filter((item) => item.kind === "organization");
|
||||
const appShellData = useAppShellData();
|
||||
const personalItem = () => appShellData.railItems().find((item) => item.kind === "personal");
|
||||
const organizationItems = () => appShellData.railItems().filter((item) => item.kind === "organization");
|
||||
|
||||
return (
|
||||
<aside
|
||||
@@ -58,7 +60,7 @@ export const LeftRail = (props: LeftRailProps): JSX.Element => {
|
||||
aria-label="Server rail"
|
||||
>
|
||||
<div class={styles.topCluster}>
|
||||
<Show when={!props.collapsed && personalItem}>
|
||||
<Show when={!props.collapsed && personalItem()}>
|
||||
{(item): JSX.Element => (
|
||||
<RailEntry item={item()} label={item().label} abbreviation={item().abbreviation} personal />
|
||||
)}
|
||||
@@ -71,7 +73,7 @@ export const LeftRail = (props: LeftRailProps): JSX.Element => {
|
||||
|
||||
<Show when={!props.collapsed}>
|
||||
<div class={styles.items}>
|
||||
<For each={organizationItems}>
|
||||
<For each={organizationItems()}>
|
||||
{(item): JSX.Element => <RailEntry item={item} label={item.label} abbreviation={item.abbreviation} />}
|
||||
</For>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Path: Frontend/src/components/shell/MobileBottomNav/MobileBottomNav.tsx
|
||||
|
||||
import { For, type JSX } from "solid-js";
|
||||
import { activeProject, activeServer, mobileBottomNavItems, type MobileBottomNavItem } from "../data/shell.data";
|
||||
import { useAppShellData } from "../data/app-shell.context";
|
||||
import { mobileBottomNavItems, type MobileBottomNavItem } from "../data/shell.data";
|
||||
import styles from "./MobileBottomNav.module.scss";
|
||||
|
||||
type MobileBottomNavProps = {
|
||||
@@ -39,12 +40,14 @@ const MobileNavEntry = (props: {
|
||||
};
|
||||
|
||||
export const MobileBottomNav = (props: MobileBottomNavProps): JSX.Element => {
|
||||
const appShellData = useAppShellData();
|
||||
|
||||
return (
|
||||
<nav class={styles.mobileNav} aria-label="Mobile workspace navigation">
|
||||
<div class={styles.contextBar}>
|
||||
<span class={styles.contextServer}>{activeServer.name}</span>
|
||||
<span class={styles.contextServer}>{appShellData.activeServer().name}</span>
|
||||
<span class={styles.contextDivider}>/</span>
|
||||
<span class={styles.contextProject}>{activeProject.name}</span>
|
||||
<span class={styles.contextProject}>{appShellData.activeProject().name}</span>
|
||||
</div>
|
||||
|
||||
<div class={styles.navGrid}>
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { For, Show, createSignal, type JSX } from "solid-js";
|
||||
import { ChevronRight, Plus, X } from "../../../lib/icons";
|
||||
import { useAppShellData } from "../data/app-shell.context";
|
||||
import { createLongPressGesture } from "../createLongPressGesture";
|
||||
import {
|
||||
activeProject,
|
||||
activeServer,
|
||||
createWorkspaceStaticTarget,
|
||||
createWorkspaceSurfaceTarget,
|
||||
createWorkspaceTreeTarget,
|
||||
getWorkspaceNodeIcon,
|
||||
workspaceStaticItems,
|
||||
workspaceTree,
|
||||
type SidebarItem,
|
||||
type WorkspaceContextMenuAction,
|
||||
type WorkspaceContextMenuTarget,
|
||||
@@ -149,10 +147,11 @@ const WorkspaceTreeBranch = (props: {
|
||||
};
|
||||
|
||||
export const MobileWorkspaceBrowser = (props: MobileWorkspaceBrowserProps): JSX.Element => {
|
||||
const appShellData = useAppShellData();
|
||||
const [actionSheetTarget, setActionSheetTarget] = createSignal<WorkspaceContextMenuTarget | null>(null);
|
||||
const sectionNodes = workspaceTree.filter((node) => (node.children?.length ?? 0) > 0);
|
||||
const looseNodes = workspaceTree.filter((node) => (node.children?.length ?? 0) === 0);
|
||||
const workspaceTarget = createWorkspaceSurfaceTarget(activeProject);
|
||||
const sectionNodes = () => appShellData.workspaceTree().filter((node) => (node.children?.length ?? 0) > 0);
|
||||
const looseNodes = () => appShellData.workspaceTree().filter((node) => (node.children?.length ?? 0) === 0);
|
||||
const workspaceTarget = () => createWorkspaceSurfaceTarget(appShellData.activeProject());
|
||||
const openActionSheet = (target: WorkspaceContextMenuTarget): void => {
|
||||
setActionSheetTarget(target);
|
||||
};
|
||||
@@ -160,7 +159,7 @@ export const MobileWorkspaceBrowser = (props: MobileWorkspaceBrowserProps): JSX.
|
||||
setActionSheetTarget(null);
|
||||
};
|
||||
const openWorkspaceActionSheet = (): void => {
|
||||
openActionSheet(workspaceTarget);
|
||||
openActionSheet(workspaceTarget());
|
||||
};
|
||||
|
||||
const handleActionSelect = (_action: WorkspaceContextMenuAction, _target: WorkspaceContextMenuTarget): void => {
|
||||
@@ -187,8 +186,8 @@ export const MobileWorkspaceBrowser = (props: MobileWorkspaceBrowserProps): JSX.
|
||||
>
|
||||
{/* Long-pressing the browser header exposes workspace-level actions on mobile. */}
|
||||
<span class={styles.brandEyebrow}>Moku Work</span>
|
||||
<strong class={styles.brandTitle}>{activeProject.name}</strong>
|
||||
<span class={styles.brandContext}>{activeServer.name}</span>
|
||||
<strong class={styles.brandTitle}>{appShellData.activeProject().name}</strong>
|
||||
<span class={styles.brandContext}>{appShellData.activeServer().name}</span>
|
||||
</div>
|
||||
|
||||
<div class={styles.headerActions} data-slot="mobile-workspace-header-actions">
|
||||
@@ -222,15 +221,15 @@ export const MobileWorkspaceBrowser = (props: MobileWorkspaceBrowserProps): JSX.
|
||||
<section class={styles.sectionBlock} data-slot="mobile-workspace-section" data-section-id="items">
|
||||
<span class={styles.sectionLabel}>Items</span>
|
||||
<ul class={styles.treeList} data-slot="mobile-workspace-list" data-section-id="items">
|
||||
<WorkspaceTreeBranch nodes={sectionNodes} onOpenActionSheet={openActionSheet} />
|
||||
<WorkspaceTreeBranch nodes={sectionNodes()} onOpenActionSheet={openActionSheet} />
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<Show when={looseNodes.length > 0}>
|
||||
<Show when={looseNodes().length > 0}>
|
||||
<section class={styles.sectionBlock} data-slot="mobile-workspace-section" data-section-id="more">
|
||||
<span class={styles.sectionLabel}>More</span>
|
||||
<ul class={styles.treeList} data-slot="mobile-workspace-list" data-section-id="more">
|
||||
<WorkspaceTreeBranch nodes={looseNodes} onOpenActionSheet={openActionSheet} />
|
||||
<WorkspaceTreeBranch nodes={looseNodes()} onOpenActionSheet={openActionSheet} />
|
||||
</ul>
|
||||
</section>
|
||||
</Show>
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
import { For, Show, createEffect, createMemo, createSignal, onMount, type JSX } from "solid-js";
|
||||
import { Portal } from "solid-js/web";
|
||||
import { ChevronRight, Plus } from "../../../lib/icons";
|
||||
import {
|
||||
getProjectContextMenuEyebrow,
|
||||
getProjectContextMenuSections,
|
||||
type ProjectContextMenuAction,
|
||||
type ProjectMenuTarget,
|
||||
type WorkspaceContextMenuShortcut,
|
||||
} from "../data/shell.data";
|
||||
import styles from "../WorkspaceContextMenu/WorkspaceContextMenu.module.scss";
|
||||
|
||||
type ShortcutPlatform = "mac" | "windows";
|
||||
|
||||
type NavigatorWithUserAgentData = Navigator & {
|
||||
userAgentData?: {
|
||||
platform?: string;
|
||||
};
|
||||
};
|
||||
|
||||
type ProjectContextMenuPosition = {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
|
||||
type ProjectContextMenuProps = {
|
||||
target: ProjectMenuTarget | null;
|
||||
position: ProjectContextMenuPosition | null;
|
||||
onClose: VoidFunction;
|
||||
onSelect: (action: ProjectContextMenuAction, target: ProjectMenuTarget) => void;
|
||||
menuRef: (element: HTMLDivElement) => void;
|
||||
};
|
||||
|
||||
const getShortcutPlatform = (): ShortcutPlatform => {
|
||||
if (typeof navigator === "undefined") {
|
||||
return "mac";
|
||||
}
|
||||
|
||||
const navigatorWithUserAgentData = navigator as NavigatorWithUserAgentData;
|
||||
const platform =
|
||||
typeof navigatorWithUserAgentData.userAgentData?.platform === "string"
|
||||
? navigatorWithUserAgentData.userAgentData.platform
|
||||
: navigator.platform;
|
||||
|
||||
return /mac|iphone|ipad|ipod/i.test(platform) ? "mac" : "windows";
|
||||
};
|
||||
|
||||
const formatShortcut = (shortcut: WorkspaceContextMenuShortcut, platform: ShortcutPlatform): string => {
|
||||
const keyLabel = (() => {
|
||||
switch (shortcut.key) {
|
||||
case "enter":
|
||||
return platform === "mac" ? "↩" : "Enter";
|
||||
case "delete":
|
||||
return platform === "mac" ? "⌫" : "Del";
|
||||
default:
|
||||
return shortcut.key.toUpperCase();
|
||||
}
|
||||
})();
|
||||
|
||||
const modifierLabels =
|
||||
shortcut.modifiers?.map((modifier) => {
|
||||
switch (modifier) {
|
||||
case "meta":
|
||||
return platform === "mac" ? "⌘" : "Ctrl";
|
||||
case "alt":
|
||||
return platform === "mac" ? "⌥" : "Alt";
|
||||
case "shift":
|
||||
return platform === "mac" ? "⇧" : "Shift";
|
||||
}
|
||||
}) ?? [];
|
||||
|
||||
return platform === "mac" ? `${modifierLabels.join("")}${keyLabel}` : [...modifierLabels, keyLabel].join("+");
|
||||
};
|
||||
|
||||
export const ProjectContextMenu = (props: ProjectContextMenuProps): JSX.Element => {
|
||||
const [activeSubmenuActionId, setActiveSubmenuActionId] = createSignal<string | null>(null);
|
||||
const [shortcutPlatform, setShortcutPlatform] = createSignal<ShortcutPlatform>("mac");
|
||||
const sections = createMemo(() => (props.target ? getProjectContextMenuSections(props.target) : []));
|
||||
const isCreateAction = (action: ProjectContextMenuAction): boolean => action.id.startsWith("new-");
|
||||
const menuState = createMemo<{
|
||||
target: ProjectMenuTarget;
|
||||
position: ProjectContextMenuPosition;
|
||||
} | null>(() => (props.target && props.position ? { target: props.target, position: props.position } : null));
|
||||
|
||||
onMount(() => {
|
||||
setShortcutPlatform(getShortcutPlatform());
|
||||
});
|
||||
|
||||
createEffect(() => {
|
||||
void props.target;
|
||||
setActiveSubmenuActionId(null);
|
||||
});
|
||||
|
||||
return (
|
||||
<Show when={menuState()}>
|
||||
{(resolvedMenuState): JSX.Element => {
|
||||
const target = resolvedMenuState().target;
|
||||
const position = resolvedMenuState().position;
|
||||
|
||||
return (
|
||||
<Portal>
|
||||
<div
|
||||
ref={props.menuRef}
|
||||
class={styles.menu}
|
||||
role="menu"
|
||||
aria-label={`${target.label} project context menu`}
|
||||
style={{ left: `${position.x}px`, top: `${position.y}px` }}
|
||||
>
|
||||
<Show when={target.kind !== "surface"}>
|
||||
<header class={styles.header}>
|
||||
<span class={styles.eyebrow}>{getProjectContextMenuEyebrow(target)}</span>
|
||||
<strong class={styles.title}>{target.label}</strong>
|
||||
</header>
|
||||
</Show>
|
||||
|
||||
<div class={styles.sectionList}>
|
||||
<For each={sections()}>
|
||||
{(section): JSX.Element => (
|
||||
<section class={styles.section}>
|
||||
<Show when={section.label}>
|
||||
<span class={styles.sectionLabel}>{section.label}</span>
|
||||
</Show>
|
||||
<div class={styles.actionList}>
|
||||
<For each={section.items}>
|
||||
{(action): JSX.Element => {
|
||||
const isSubmenuOpen = () => activeSubmenuActionId() === action.id;
|
||||
|
||||
return (
|
||||
<div class={styles.actionItem} onMouseEnter={() => setActiveSubmenuActionId(action.children ? action.id : null)}>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
classList={{
|
||||
[styles.action]: true,
|
||||
[styles.actionCreate]: isCreateAction(action),
|
||||
[styles.actionDanger]: action.tone === "danger",
|
||||
[styles.actionSubmenuOpen]: isSubmenuOpen(),
|
||||
}}
|
||||
onClick={() => {
|
||||
if (action.children) {
|
||||
setActiveSubmenuActionId(isSubmenuOpen() ? null : action.id);
|
||||
return;
|
||||
}
|
||||
|
||||
props.onSelect(action, target);
|
||||
props.onClose();
|
||||
}}
|
||||
>
|
||||
<Show when={isCreateAction(action)}>
|
||||
<span class={styles.actionCreateIcon} aria-hidden="true">
|
||||
<Plus size={14} strokeWidth={2.25} />
|
||||
</span>
|
||||
</Show>
|
||||
<span class={styles.actionLabel}>{action.label}</span>
|
||||
<div class={styles.actionMeta}>
|
||||
<Show when={action.shortcut}>
|
||||
<span class={styles.actionShortcut}>{formatShortcut(action.shortcut!, shortcutPlatform())}</span>
|
||||
</Show>
|
||||
<Show when={action.children}>
|
||||
<ChevronRight class={styles.actionChevron} size={16} strokeWidth={2} />
|
||||
</Show>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<Show when={action.children && isSubmenuOpen()}>
|
||||
<div class={styles.submenu} role="menu" aria-label={`${action.label} submenu`}>
|
||||
<div class={styles.submenuList}>
|
||||
<For each={action.children ?? []}>
|
||||
{(childAction): JSX.Element => (
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
classList={{
|
||||
[styles.action]: true,
|
||||
[styles.actionDanger]: childAction.tone === "danger",
|
||||
}}
|
||||
onClick={() => {
|
||||
props.onSelect(childAction, target);
|
||||
props.onClose();
|
||||
}}
|
||||
>
|
||||
<span class={styles.actionLabel}>{childAction.label}</span>
|
||||
</button>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</For>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
</div>
|
||||
</Portal>
|
||||
);
|
||||
}}
|
||||
</Show>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,120 @@
|
||||
import { createEffect, createSignal, onCleanup } from "solid-js";
|
||||
import type { ProjectMenuTarget } from "../data/shell.data";
|
||||
|
||||
type ProjectContextMenuState = {
|
||||
target: ProjectMenuTarget;
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
|
||||
const readRootPixelToken = (name: string, fallback: number): number => {
|
||||
if (typeof window === "undefined") {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const value = window.getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
||||
const parsed = Number.parseFloat(value);
|
||||
|
||||
if (!Number.isFinite(parsed)) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
if (value.endsWith("px")) {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
return parsed * 16;
|
||||
};
|
||||
|
||||
const clampMenuPosition = (value: number, min: number, max: number): number => {
|
||||
if (max <= min) {
|
||||
return min;
|
||||
}
|
||||
|
||||
return Math.min(Math.max(value, min), max);
|
||||
};
|
||||
|
||||
export const createProjectContextMenuController = () => {
|
||||
const [menuState, setMenuState] = createSignal<ProjectContextMenuState | null>(null);
|
||||
let menuRef: HTMLDivElement | undefined;
|
||||
|
||||
const closeMenu = (): void => {
|
||||
setMenuState(null);
|
||||
};
|
||||
|
||||
const repositionMenu = (): void => {
|
||||
if (typeof window === "undefined" || !menuRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
const current = menuState();
|
||||
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const viewportPadding = readRootPixelToken("--space-4", 16);
|
||||
const rect = menuRef.getBoundingClientRect();
|
||||
const nextX = clampMenuPosition(current.x, viewportPadding, window.innerWidth - rect.width - viewportPadding);
|
||||
const nextY = clampMenuPosition(current.y, viewportPadding, window.innerHeight - rect.height - viewportPadding);
|
||||
|
||||
if (nextX === current.x && nextY === current.y) {
|
||||
return;
|
||||
}
|
||||
|
||||
setMenuState({ ...current, x: nextX, y: nextY });
|
||||
};
|
||||
|
||||
const openMenu = (event: MouseEvent, target: ProjectMenuTarget): void => {
|
||||
event.preventDefault();
|
||||
setMenuState({ target, x: event.clientX, y: event.clientY });
|
||||
};
|
||||
|
||||
createEffect(() => {
|
||||
if (!menuState() || typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
const frame = window.requestAnimationFrame(() => {
|
||||
repositionMenu();
|
||||
});
|
||||
|
||||
const handlePointerDown = (event: PointerEvent): void => {
|
||||
if (!menuRef?.contains(event.target as Node)) {
|
||||
closeMenu();
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent): void => {
|
||||
if (event.key === "Escape") {
|
||||
closeMenu();
|
||||
}
|
||||
};
|
||||
|
||||
const handleViewportChange = (): void => {
|
||||
closeMenu();
|
||||
};
|
||||
|
||||
document.addEventListener("pointerdown", handlePointerDown);
|
||||
window.addEventListener("resize", handleViewportChange);
|
||||
window.addEventListener("scroll", handleViewportChange, true);
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
onCleanup(() => {
|
||||
window.cancelAnimationFrame(frame);
|
||||
document.removeEventListener("pointerdown", handlePointerDown);
|
||||
window.removeEventListener("resize", handleViewportChange);
|
||||
window.removeEventListener("scroll", handleViewportChange, true);
|
||||
window.removeEventListener("keydown", handleKeyDown);
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
menuState,
|
||||
openMenu,
|
||||
closeMenu,
|
||||
setMenuRef: (element: HTMLDivElement): void => {
|
||||
menuRef = element;
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -9,6 +9,15 @@
|
||||
justify-items: center;
|
||||
}
|
||||
|
||||
.rootDragMode {
|
||||
user-select: none;
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.rootDragMode .treeItem {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.trigger {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
@@ -38,9 +47,9 @@
|
||||
}
|
||||
|
||||
.triggerOpen {
|
||||
border-color: color-mix(in srgb, var(--color-border-strong) 22%, transparent);
|
||||
background: color-mix(in srgb, var(--color-surface) 92%, transparent);
|
||||
box-shadow: var(--shadow-soft);
|
||||
border-color: color-mix(in srgb, var(--color-accent-strong) 22%, var(--color-border-strong));
|
||||
background: color-mix(in srgb, var(--color-accent-soft) 26%, var(--color-surface));
|
||||
box-shadow: 0 10px 28px color-mix(in srgb, black 8%, transparent);
|
||||
}
|
||||
|
||||
.triggerCompact {
|
||||
@@ -83,19 +92,14 @@
|
||||
gap: 0.12rem;
|
||||
}
|
||||
|
||||
.eyebrow,
|
||||
.projectItemDescription {
|
||||
.eyebrow {
|
||||
@include text-caption;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.value,
|
||||
.projectItemName {
|
||||
.value {
|
||||
@include text-label;
|
||||
}
|
||||
|
||||
@@ -175,7 +179,7 @@
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
align-content: start;
|
||||
gap: var(--space-3);
|
||||
gap: var(--space-2);
|
||||
padding: var(--space-4);
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
@@ -186,49 +190,148 @@
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.projectList {
|
||||
.treeSectionLabel {
|
||||
@include text-caption;
|
||||
margin: 0 0 var(--space-2);
|
||||
padding: 0 var(--space-3);
|
||||
color: var(--color-text-subtle);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.treeList {
|
||||
list-style: none;
|
||||
display: grid;
|
||||
gap: 0.2rem;
|
||||
gap: var(--space-1);
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.projectItem {
|
||||
.treeEmptySlot {
|
||||
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px dashed color-mix(in srgb, var(--color-border) 38%, transparent);
|
||||
opacity: 0.35;
|
||||
}
|
||||
|
||||
.treeInputRow {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||
padding: var(--space-2) var(--space-3);
|
||||
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||
border: 1px solid color-mix(in srgb, var(--color-border) 42%, transparent);
|
||||
border-radius: var(--radius-lg);
|
||||
background: color-mix(in srgb, var(--color-surface) 94%, transparent);
|
||||
}
|
||||
|
||||
.treeInput {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--color-text);
|
||||
font: inherit;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.treeInput::placeholder {
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.treeItem {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
min-height: calc(var(--control-size-md) + var(--space-2));
|
||||
display: grid;
|
||||
grid-template-columns: auto auto minmax(0, 1fr) auto;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||
padding: var(--space-2) var(--space-3);
|
||||
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--radius-sm);
|
||||
border-radius: var(--radius-lg);
|
||||
background: transparent;
|
||||
color: var(--color-text-muted);
|
||||
transition:
|
||||
background 160ms var(--easing-standard),
|
||||
color 160ms var(--easing-standard),
|
||||
border-color 160ms var(--easing-standard),
|
||||
box-shadow 160ms var(--easing-standard),
|
||||
transform 180ms var(--easing-standard);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.projectItem:hover {
|
||||
background: color-mix(in srgb, var(--color-surface-hover) 82%, transparent);
|
||||
.treeItem:hover,
|
||||
.treeItem:focus-visible {
|
||||
background: color-mix(in srgb, var(--color-surface-hover) 80%, var(--color-accent-soft) 20%);
|
||||
color: var(--color-text);
|
||||
border-color: color-mix(in srgb, var(--color-border) 22%, transparent);
|
||||
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||
}
|
||||
|
||||
.projectItemActive {
|
||||
border-color: color-mix(in srgb, var(--color-border) 28%, transparent);
|
||||
background: color-mix(in srgb, var(--color-surface) 82%, transparent);
|
||||
.treeItemFolder {
|
||||
color: var(--color-text);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.projectItemCopy {
|
||||
.treeItemDragging {
|
||||
opacity: 0.45;
|
||||
transform: scale(0.985);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.treeItemDropBefore {
|
||||
box-shadow: inset 0 2px 0 color-mix(in srgb, var(--color-accent-strong) 78%, transparent);
|
||||
}
|
||||
|
||||
.treeItemDropAfter {
|
||||
box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--color-accent-strong) 78%, transparent);
|
||||
}
|
||||
|
||||
.treeItemDropInside {
|
||||
border-color: color-mix(in srgb, var(--color-accent-strong) 55%, transparent);
|
||||
background: color-mix(in srgb, var(--color-accent-soft) 36%, var(--color-surface));
|
||||
color: var(--color-text);
|
||||
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||
}
|
||||
|
||||
.folderChevron {
|
||||
color: var(--color-text-muted);
|
||||
transition: transform 160ms var(--easing-standard);
|
||||
}
|
||||
|
||||
.folderChevronOpen {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.treeItemActive {
|
||||
border-color: var(--color-border);
|
||||
background: var(--color-surface);
|
||||
color: var(--color-text);
|
||||
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||
}
|
||||
|
||||
.icon {
|
||||
color: inherit;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.label {
|
||||
@include text-label;
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
gap: 0.05rem;
|
||||
}
|
||||
|
||||
.projectItemDescription {
|
||||
color: color-mix(in srgb, var(--color-text-muted) 84%, transparent);
|
||||
.itemMeta {
|
||||
@include text-caption;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.rootCompact .scrim,
|
||||
.rootCompact .drawer {
|
||||
width: min(18rem, calc(100vw - 5rem));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
// Path: Frontend/src/components/shell/ProjectSelector/ProjectSelector.tsx
|
||||
|
||||
import { For, createSignal, onCleanup, onMount, type JSX } from "solid-js";
|
||||
import { ChevronDown, Folder } from "../../../lib/icons";
|
||||
import { activeProject, projectItems } from "../data/shell.data";
|
||||
import { For, Show, createEffect, createSignal, onCleanup, onMount, type JSX } from "solid-js";
|
||||
import { ChevronDown, ChevronRight, Folder, LayoutGrid } from "../../../lib/icons";
|
||||
import { ProjectContextMenu } from "../ProjectContextMenu/ProjectContextMenu";
|
||||
import { useAppShellData } from "../data/app-shell.context";
|
||||
import {
|
||||
createProjectFolderTarget,
|
||||
createProjectSurfaceTarget,
|
||||
createProjectTarget,
|
||||
type ProjectItem,
|
||||
type ProjectMenuTarget,
|
||||
} from "../data/shell.data";
|
||||
import { createProjectContextMenuController } from "../ProjectContextMenu/createProjectContextMenuController";
|
||||
import styles from "./ProjectSelector.module.scss";
|
||||
|
||||
type ProjectSelectorProps = {
|
||||
@@ -12,38 +21,621 @@ type ProjectSelectorProps = {
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
const defaultProject = projectItems.find((item) => item.id === activeProject.id) ?? projectItems[0];
|
||||
type ProjectFolderNode = {
|
||||
kind: "folder";
|
||||
id: string;
|
||||
label: string;
|
||||
meta?: string;
|
||||
children: ProjectTreeNode[];
|
||||
};
|
||||
|
||||
export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
||||
const [selectedProject, setSelectedProject] = createSignal({ id: defaultProject.id, name: defaultProject.name });
|
||||
const [drawerTop, setDrawerTop] = createSignal<number>(0);
|
||||
let triggerRef: HTMLButtonElement | undefined;
|
||||
type ProjectLeafNode = {
|
||||
kind: "project";
|
||||
item: ProjectItem;
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
if (!triggerRef) {
|
||||
return;
|
||||
type ProjectTreeNode = ProjectFolderNode | ProjectLeafNode;
|
||||
|
||||
type PendingProjectFolderDraft = {
|
||||
parentId: string | null;
|
||||
depth: number;
|
||||
};
|
||||
|
||||
type ProjectDragTarget = {
|
||||
parentId: string | null;
|
||||
index: number;
|
||||
intent: "before" | "after" | "inside";
|
||||
targetNodeId?: string;
|
||||
};
|
||||
|
||||
type ProjectDragState = {
|
||||
draggedNodeId: string;
|
||||
dropTarget: ProjectDragTarget | null;
|
||||
};
|
||||
|
||||
type ProjectNodeLocation = {
|
||||
parentId: string | null;
|
||||
index: number;
|
||||
node: ProjectTreeNode;
|
||||
};
|
||||
|
||||
const LONG_PRESS_MS = 320;
|
||||
|
||||
const createProjectFolderId = (): string => `project-folder-${Math.random().toString(36).slice(2, 10)}`;
|
||||
|
||||
const getProjectTreeNodeId = (node: ProjectTreeNode): string =>
|
||||
node.kind === "folder" ? node.id : node.item.id;
|
||||
|
||||
const buildProjectTree = (items: readonly ProjectItem[]): ProjectTreeNode[] =>
|
||||
items.map((item) => ({
|
||||
kind: "project",
|
||||
item,
|
||||
}));
|
||||
|
||||
const cloneProjectTreeNode = (node: ProjectTreeNode): ProjectTreeNode => {
|
||||
if (node.kind === "project") {
|
||||
return {
|
||||
kind: "project",
|
||||
item: { ...node.item },
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
kind: "folder",
|
||||
id: node.id,
|
||||
label: node.label,
|
||||
meta: node.meta,
|
||||
children: node.children.map(cloneProjectTreeNode),
|
||||
};
|
||||
};
|
||||
|
||||
const insertProjectFolderNode = (
|
||||
nodes: readonly ProjectTreeNode[],
|
||||
parentId: string | null,
|
||||
folder: ProjectFolderNode,
|
||||
): ProjectTreeNode[] => {
|
||||
if (parentId === null) {
|
||||
return [...nodes, folder];
|
||||
}
|
||||
|
||||
return nodes.map((node) => {
|
||||
if (node.kind !== "folder") {
|
||||
return node;
|
||||
}
|
||||
|
||||
const updateDrawerTop = (): void => {
|
||||
if (!triggerRef) {
|
||||
if (node.id === parentId) {
|
||||
return {
|
||||
...node,
|
||||
children: [...node.children, folder],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...node,
|
||||
children: insertProjectFolderNode(node.children, parentId, folder),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const findProjectNodeLocation = (
|
||||
nodes: readonly ProjectTreeNode[],
|
||||
nodeId: string,
|
||||
parentId: string | null = null,
|
||||
): ProjectNodeLocation | null => {
|
||||
for (let index = 0; index < nodes.length; index += 1) {
|
||||
const node = nodes[index];
|
||||
|
||||
if (getProjectTreeNodeId(node) === nodeId) {
|
||||
return { parentId, index, node };
|
||||
}
|
||||
|
||||
if (node.kind === "folder") {
|
||||
const nestedLocation = findProjectNodeLocation(node.children, nodeId, node.id);
|
||||
|
||||
if (nestedLocation) {
|
||||
return nestedLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const findProjectNodeDepth = (nodes: readonly ProjectTreeNode[], nodeId: string, depth = 0): number | null => {
|
||||
for (const node of nodes) {
|
||||
if (getProjectTreeNodeId(node) === nodeId) {
|
||||
return depth;
|
||||
}
|
||||
|
||||
if (node.kind === "folder") {
|
||||
const nestedDepth = findProjectNodeDepth(node.children, nodeId, depth + 1);
|
||||
|
||||
if (nestedDepth !== null) {
|
||||
return nestedDepth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const projectTreeContainsNode = (nodes: readonly ProjectTreeNode[], nodeId: string): boolean => {
|
||||
for (const node of nodes) {
|
||||
if (getProjectTreeNodeId(node) === nodeId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.kind === "folder" && projectTreeContainsNode(node.children, nodeId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const removeProjectTreeNode = (
|
||||
nodes: readonly ProjectTreeNode[],
|
||||
nodeId: string,
|
||||
): { nodes: ProjectTreeNode[]; removed: ProjectTreeNode | null } => {
|
||||
const nextNodes: ProjectTreeNode[] = [];
|
||||
let removed: ProjectTreeNode | null = null;
|
||||
|
||||
for (const node of nodes) {
|
||||
if (getProjectTreeNodeId(node) === nodeId) {
|
||||
removed = node;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.kind === "folder") {
|
||||
const result = removeProjectTreeNode(node.children, nodeId);
|
||||
|
||||
if (result.removed) {
|
||||
removed = result.removed;
|
||||
nextNodes.push({
|
||||
...node,
|
||||
children: result.nodes,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
nextNodes.push(node);
|
||||
}
|
||||
|
||||
return { nodes: nextNodes, removed };
|
||||
};
|
||||
|
||||
const insertProjectTreeNode = (
|
||||
nodes: readonly ProjectTreeNode[],
|
||||
parentId: string | null,
|
||||
index: number,
|
||||
nodeToInsert: ProjectTreeNode,
|
||||
): ProjectTreeNode[] => {
|
||||
if (parentId === null) {
|
||||
const nextNodes = [...nodes];
|
||||
nextNodes.splice(Math.max(0, Math.min(index, nextNodes.length)), 0, nodeToInsert);
|
||||
return nextNodes;
|
||||
}
|
||||
|
||||
return nodes.map((node) => {
|
||||
if (node.kind !== "folder") {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (node.id === parentId) {
|
||||
const nextChildren = [...node.children];
|
||||
nextChildren.splice(Math.max(0, Math.min(index, nextChildren.length)), 0, nodeToInsert);
|
||||
return {
|
||||
...node,
|
||||
children: nextChildren,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...node,
|
||||
children: insertProjectTreeNode(node.children, parentId, index, nodeToInsert),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const moveProjectTreeNode = (
|
||||
nodes: readonly ProjectTreeNode[],
|
||||
draggedNodeId: string,
|
||||
dropTarget: ProjectDragTarget,
|
||||
): ProjectTreeNode[] => {
|
||||
const location = findProjectNodeLocation(nodes, draggedNodeId);
|
||||
|
||||
if (!location) {
|
||||
return [...nodes];
|
||||
}
|
||||
|
||||
if (
|
||||
location.node.kind === "folder" &&
|
||||
dropTarget.parentId !== null &&
|
||||
(projectTreeContainsNode(location.node.children, dropTarget.parentId) || dropTarget.parentId === location.node.id)
|
||||
) {
|
||||
return [...nodes];
|
||||
}
|
||||
|
||||
let normalizedIndex = dropTarget.index;
|
||||
|
||||
if (dropTarget.parentId === location.parentId && dropTarget.index > location.index) {
|
||||
normalizedIndex -= 1;
|
||||
}
|
||||
|
||||
if (dropTarget.parentId === location.parentId && normalizedIndex === location.index) {
|
||||
return [...nodes];
|
||||
}
|
||||
|
||||
const removalResult = removeProjectTreeNode(nodes, draggedNodeId);
|
||||
|
||||
if (!removalResult.removed) {
|
||||
return [...nodes];
|
||||
}
|
||||
|
||||
return insertProjectTreeNode(removalResult.nodes, dropTarget.parentId, normalizedIndex, removalResult.removed);
|
||||
};
|
||||
|
||||
const ProjectFolderDraftRow = (props: {
|
||||
depth: number;
|
||||
value: string;
|
||||
onInput: (value: string) => void;
|
||||
onSubmit: () => void;
|
||||
onCancel: () => void;
|
||||
}): JSX.Element => {
|
||||
let inputRef: HTMLInputElement | undefined;
|
||||
|
||||
queueMicrotask(() => inputRef?.focus());
|
||||
|
||||
return (
|
||||
<li>
|
||||
<div class={styles.treeInputRow} style={{ "--tree-depth": String(props.depth) }}>
|
||||
<Folder class={styles.icon} size={18} strokeWidth={2} />
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="text"
|
||||
class={styles.treeInput}
|
||||
value={props.value}
|
||||
placeholder="Folder name"
|
||||
onInput={(event): void => props.onInput(event.currentTarget.value)}
|
||||
onBlur={props.onSubmit}
|
||||
onKeyDown={(event): void => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
event.currentTarget.blur();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
props.onCancel();
|
||||
event.currentTarget.blur();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
};
|
||||
|
||||
const ProjectFolderBranch = (props: {
|
||||
nodes: readonly ProjectTreeNode[];
|
||||
depth: number;
|
||||
parentId: string | null;
|
||||
selectedProjectId: string;
|
||||
isFolderCollapsed: (folderId: string) => boolean;
|
||||
onToggleFolder: (folderId: string) => void;
|
||||
onSelectProject: (projectId: string) => void;
|
||||
onOpenFolderMenu: (event: MouseEvent, folder: ProjectFolderNode) => void;
|
||||
onOpenProjectMenu: (event: MouseEvent, item: ProjectItem) => void;
|
||||
onNodePointerDown: (event: PointerEvent, nodeId: string) => void;
|
||||
onNodePointerMove: (event: PointerEvent, parentId: string | null, index: number, node: ProjectTreeNode) => void;
|
||||
pendingFolderDraft: PendingProjectFolderDraft | null;
|
||||
pendingFolderName: string;
|
||||
onPendingFolderNameChange: (value: string) => void;
|
||||
onSubmitPendingFolder: () => void;
|
||||
onCancelPendingFolder: () => void;
|
||||
dragState: ProjectDragState | null;
|
||||
}): JSX.Element => (
|
||||
<ul class={styles.treeList} role="list">
|
||||
<Show when={props.nodes.length === 0 && props.pendingFolderDraft?.parentId !== props.parentId}>
|
||||
<li>
|
||||
<div class={styles.treeEmptySlot} style={{ "--tree-depth": String(props.depth) }} />
|
||||
</li>
|
||||
</Show>
|
||||
|
||||
<For each={props.nodes}>
|
||||
{(node, indexAccessor): JSX.Element => {
|
||||
const nodeId = (): string => getProjectTreeNodeId(node);
|
||||
const isDraggedNode = (): boolean => props.dragState?.draggedNodeId === nodeId();
|
||||
const dropIntent = (): ProjectDragTarget["intent"] | null => {
|
||||
if (props.dragState?.dropTarget?.targetNodeId !== nodeId()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return props.dragState.dropTarget.intent;
|
||||
};
|
||||
|
||||
if (node.kind === "folder") {
|
||||
const isCollapsed = (): boolean => props.isFolderCollapsed(node.id);
|
||||
|
||||
return (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
classList={{
|
||||
[styles.treeItem]: true,
|
||||
[styles.treeItemFolder]: true,
|
||||
[styles.treeItemDragging]: isDraggedNode(),
|
||||
[styles.treeItemDropBefore]: dropIntent() === "before",
|
||||
[styles.treeItemDropAfter]: dropIntent() === "after",
|
||||
[styles.treeItemDropInside]: dropIntent() === "inside",
|
||||
}}
|
||||
style={{ "--tree-depth": String(props.depth) }}
|
||||
aria-expanded={!isCollapsed()}
|
||||
onClick={() => {
|
||||
if (props.dragState || suppressNextTreeClick()) {
|
||||
return;
|
||||
}
|
||||
|
||||
props.onToggleFolder(node.id);
|
||||
}}
|
||||
onContextMenu={(event): void => props.onOpenFolderMenu(event, node)}
|
||||
onPointerDown={(event): void => props.onNodePointerDown(event, node.id)}
|
||||
onPointerMove={(event): void =>
|
||||
props.onNodePointerMove(event, props.parentId, indexAccessor(), node)
|
||||
}
|
||||
onPointerEnter={(event): void =>
|
||||
props.onNodePointerMove(event, props.parentId, indexAccessor(), node)
|
||||
}
|
||||
>
|
||||
<ChevronRight
|
||||
classList={{
|
||||
[styles.folderChevron]: true,
|
||||
[styles.folderChevronOpen]: !isCollapsed(),
|
||||
}}
|
||||
size={16}
|
||||
strokeWidth={2}
|
||||
/>
|
||||
<Folder class={styles.icon} size={18} strokeWidth={2} />
|
||||
<span class={styles.label}>{node.label}</span>
|
||||
<Show when={node.meta}>
|
||||
<span class={styles.itemMeta}>{node.meta}</span>
|
||||
</Show>
|
||||
</button>
|
||||
|
||||
<Show when={!isCollapsed() && (node.children.length > 0 || props.pendingFolderDraft?.parentId === node.id)}>
|
||||
<ProjectFolderBranch
|
||||
nodes={node.children}
|
||||
depth={props.depth + 1}
|
||||
parentId={node.id}
|
||||
selectedProjectId={props.selectedProjectId}
|
||||
isFolderCollapsed={props.isFolderCollapsed}
|
||||
onToggleFolder={props.onToggleFolder}
|
||||
onSelectProject={props.onSelectProject}
|
||||
onOpenFolderMenu={props.onOpenFolderMenu}
|
||||
onOpenProjectMenu={props.onOpenProjectMenu}
|
||||
onNodePointerDown={props.onNodePointerDown}
|
||||
onNodePointerMove={props.onNodePointerMove}
|
||||
pendingFolderDraft={props.pendingFolderDraft}
|
||||
pendingFolderName={props.pendingFolderName}
|
||||
onPendingFolderNameChange={props.onPendingFolderNameChange}
|
||||
onSubmitPendingFolder={props.onSubmitPendingFolder}
|
||||
onCancelPendingFolder={props.onCancelPendingFolder}
|
||||
dragState={props.dragState}
|
||||
/>
|
||||
</Show>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
classList={{
|
||||
[styles.treeItem]: true,
|
||||
[styles.treeItemActive]: props.selectedProjectId === node.item.id,
|
||||
[styles.treeItemDragging]: isDraggedNode(),
|
||||
[styles.treeItemDropBefore]: dropIntent() === "before",
|
||||
[styles.treeItemDropAfter]: dropIntent() === "after",
|
||||
}}
|
||||
style={{ "--tree-depth": String(props.depth) }}
|
||||
onClick={(): void => {
|
||||
if (props.dragState || suppressNextTreeClick()) {
|
||||
return;
|
||||
}
|
||||
|
||||
props.onSelectProject(node.item.id);
|
||||
}}
|
||||
onContextMenu={(event): void => props.onOpenProjectMenu(event, node.item)}
|
||||
onPointerDown={(event): void => props.onNodePointerDown(event, node.item.id)}
|
||||
onPointerMove={(event): void =>
|
||||
props.onNodePointerMove(event, props.parentId, indexAccessor(), node)
|
||||
}
|
||||
onPointerEnter={(event): void =>
|
||||
props.onNodePointerMove(event, props.parentId, indexAccessor(), node)
|
||||
}
|
||||
>
|
||||
<LayoutGrid class={styles.icon} size={18} strokeWidth={2} />
|
||||
<span class={styles.label}>{node.item.name}</span>
|
||||
<Show when={node.item.meta}>
|
||||
<span class={styles.itemMeta}>{node.item.meta}</span>
|
||||
</Show>
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
}}
|
||||
</For>
|
||||
|
||||
<Show when={props.pendingFolderDraft?.parentId === props.parentId}>
|
||||
<ProjectFolderDraftRow
|
||||
depth={props.pendingFolderDraft?.depth ?? props.depth}
|
||||
value={props.pendingFolderName}
|
||||
onInput={props.onPendingFolderNameChange}
|
||||
onSubmit={props.onSubmitPendingFolder}
|
||||
onCancel={props.onCancelPendingFolder}
|
||||
/>
|
||||
</Show>
|
||||
</ul>
|
||||
);
|
||||
|
||||
export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
||||
const appShellData = useAppShellData();
|
||||
const [selectedProject, setSelectedProject] = createSignal(appShellData.activeProject());
|
||||
const [drawerTop, setDrawerTop] = createSignal<number>(0);
|
||||
const [collapsedFolderIds, setCollapsedFolderIds] = createSignal<readonly string[]>([]);
|
||||
const [projectTreeNodes, setProjectTreeNodes] = createSignal<ProjectTreeNode[]>(
|
||||
buildProjectTree(appShellData.projectItems()),
|
||||
);
|
||||
const [pendingFolderDraft, setPendingFolderDraft] = createSignal<PendingProjectFolderDraft | null>(null);
|
||||
const [pendingFolderName, setPendingFolderName] = createSignal("");
|
||||
const [dragState, setDragState] = createSignal<ProjectDragState | null>(null);
|
||||
const [suppressNextTreeClick, setSuppressNextTreeClick] = createSignal(false);
|
||||
let rootRef: HTMLDivElement | undefined;
|
||||
let triggerRef: HTMLButtonElement | undefined;
|
||||
let contextMenuRef: HTMLDivElement | undefined;
|
||||
let longPressTimer: number | undefined;
|
||||
let suppressClickTimer: number | undefined;
|
||||
const contextMenu = createProjectContextMenuController();
|
||||
|
||||
const clearLongPressTimer = (): void => {
|
||||
if (longPressTimer !== undefined) {
|
||||
window.clearTimeout(longPressTimer);
|
||||
longPressTimer = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const suppressTreeClickTemporarily = (): void => {
|
||||
setSuppressNextTreeClick(true);
|
||||
|
||||
if (suppressClickTimer !== undefined) {
|
||||
window.clearTimeout(suppressClickTimer);
|
||||
}
|
||||
|
||||
suppressClickTimer = window.setTimeout(() => {
|
||||
setSuppressNextTreeClick(false);
|
||||
suppressClickTimer = undefined;
|
||||
}, 80);
|
||||
};
|
||||
|
||||
const isFolderCollapsed = (folderId: string): boolean => collapsedFolderIds().includes(folderId);
|
||||
|
||||
const toggleFolder = (folderId: string): void => {
|
||||
setCollapsedFolderIds((current) =>
|
||||
current.includes(folderId) ? current.filter((id) => id !== folderId) : [...current, folderId],
|
||||
);
|
||||
};
|
||||
|
||||
createEffect(() => {
|
||||
setSelectedProject(appShellData.activeProject());
|
||||
});
|
||||
|
||||
createEffect(() => {
|
||||
setProjectTreeNodes(buildProjectTree(appShellData.projectItems()));
|
||||
setCollapsedFolderIds([]);
|
||||
setPendingFolderDraft(null);
|
||||
setPendingFolderName("");
|
||||
setDragState(null);
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
if (triggerRef) {
|
||||
const updateDrawerTop = (): void => {
|
||||
if (!triggerRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDrawerTop(triggerRef.offsetTop + triggerRef.offsetHeight + 8);
|
||||
};
|
||||
|
||||
updateDrawerTop();
|
||||
|
||||
const observer = new ResizeObserver(() => {
|
||||
updateDrawerTop();
|
||||
});
|
||||
|
||||
observer.observe(triggerRef);
|
||||
window.addEventListener("resize", updateDrawerTop);
|
||||
|
||||
onCleanup(() => {
|
||||
observer.disconnect();
|
||||
window.removeEventListener("resize", updateDrawerTop);
|
||||
});
|
||||
}
|
||||
|
||||
const handlePointerDown = (event: PointerEvent): void => {
|
||||
if (!props.isOpen || !rootRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDrawerTop(triggerRef.offsetTop + triggerRef.offsetHeight);
|
||||
const target = event.target;
|
||||
|
||||
if (target instanceof Node && rootRef.contains(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (target instanceof Node && contextMenuRef?.contains(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
props.onClose();
|
||||
};
|
||||
|
||||
updateDrawerTop();
|
||||
const handlePointerUp = (): void => {
|
||||
clearLongPressTimer();
|
||||
|
||||
const observer = new ResizeObserver(() => {
|
||||
updateDrawerTop();
|
||||
});
|
||||
const nextDragState = dragState();
|
||||
|
||||
observer.observe(triggerRef);
|
||||
window.addEventListener("resize", updateDrawerTop);
|
||||
if (!nextDragState?.dropTarget) {
|
||||
if (nextDragState) {
|
||||
suppressTreeClickTemporarily();
|
||||
}
|
||||
setDragState(null);
|
||||
return;
|
||||
}
|
||||
|
||||
suppressTreeClickTemporarily();
|
||||
setProjectTreeNodes((current) =>
|
||||
moveProjectTreeNode(current, nextDragState.draggedNodeId, nextDragState.dropTarget as ProjectDragTarget),
|
||||
);
|
||||
setDragState(null);
|
||||
};
|
||||
|
||||
const handleEscape = (event: KeyboardEvent): void => {
|
||||
if (event.key !== "Escape") {
|
||||
return;
|
||||
}
|
||||
|
||||
clearLongPressTimer();
|
||||
|
||||
if (dragState()) {
|
||||
setDragState(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!props.isOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
props.onClose();
|
||||
triggerRef?.focus();
|
||||
};
|
||||
|
||||
document.addEventListener("pointerdown", handlePointerDown);
|
||||
window.addEventListener("pointerup", handlePointerUp);
|
||||
window.addEventListener("pointercancel", handlePointerUp);
|
||||
window.addEventListener("keydown", handleEscape);
|
||||
|
||||
onCleanup(() => {
|
||||
observer.disconnect();
|
||||
window.removeEventListener("resize", updateDrawerTop);
|
||||
clearLongPressTimer();
|
||||
if (suppressClickTimer !== undefined) {
|
||||
window.clearTimeout(suppressClickTimer);
|
||||
}
|
||||
document.removeEventListener("pointerdown", handlePointerDown);
|
||||
window.removeEventListener("pointerup", handlePointerUp);
|
||||
window.removeEventListener("pointercancel", handlePointerUp);
|
||||
window.removeEventListener("keydown", handleEscape);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,27 +649,163 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
||||
};
|
||||
|
||||
const selectProject = (projectId: string): void => {
|
||||
const nextProject = projectItems.find((item): boolean => item.id === projectId);
|
||||
const location = findProjectNodeLocation(projectTreeNodes(), projectId);
|
||||
|
||||
if (!nextProject) {
|
||||
if (!location || location.node.kind !== "project") {
|
||||
return;
|
||||
}
|
||||
|
||||
setSelectedProject({ id: nextProject.id, name: nextProject.name });
|
||||
setSelectedProject({ id: location.node.item.id, name: location.node.item.name });
|
||||
props.onClose();
|
||||
};
|
||||
|
||||
const beginFolderDraft = (parentId: string | null, depth: number): void => {
|
||||
if (parentId) {
|
||||
setCollapsedFolderIds((current) => current.filter((id) => id !== parentId));
|
||||
}
|
||||
|
||||
setPendingFolderName("");
|
||||
setPendingFolderDraft({ parentId, depth });
|
||||
};
|
||||
|
||||
const submitPendingFolder = (): void => {
|
||||
const name = pendingFolderName().trim();
|
||||
const draft = pendingFolderDraft();
|
||||
|
||||
if (!draft) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
setPendingFolderDraft(null);
|
||||
setPendingFolderName("");
|
||||
return;
|
||||
}
|
||||
|
||||
setProjectTreeNodes((current) =>
|
||||
insertProjectFolderNode(current, draft.parentId, {
|
||||
kind: "folder",
|
||||
id: createProjectFolderId(),
|
||||
label: name,
|
||||
children: [],
|
||||
}),
|
||||
);
|
||||
setPendingFolderDraft(null);
|
||||
setPendingFolderName("");
|
||||
};
|
||||
|
||||
const cancelPendingFolder = (): void => {
|
||||
setPendingFolderDraft(null);
|
||||
setPendingFolderName("");
|
||||
};
|
||||
|
||||
const handleContextActionSelect = (action: { id: string; label: string }, target: ProjectMenuTarget): void => {
|
||||
if (action.id !== "new-folder") {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (target.kind) {
|
||||
case "surface":
|
||||
beginFolderDraft(null, 0);
|
||||
return;
|
||||
case "folder":
|
||||
beginFolderDraft(target.id, (findProjectNodeDepth(projectTreeNodes(), target.id) ?? 0) + 1);
|
||||
return;
|
||||
case "project": {
|
||||
const parentId = findProjectNodeLocation(projectTreeNodes(), target.id)?.parentId ?? null;
|
||||
beginFolderDraft(parentId, parentId ? (findProjectNodeDepth(projectTreeNodes(), parentId) ?? 0) + 1 : 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleSurfaceContextMenu = (event: MouseEvent): void => {
|
||||
event.stopPropagation();
|
||||
contextMenu.openMenu(event, createProjectSurfaceTarget("Projects"));
|
||||
};
|
||||
|
||||
const handleNodePointerDown = (event: PointerEvent, nodeId: string): void => {
|
||||
if (event.button !== 0 || pendingFolderDraft()) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearLongPressTimer();
|
||||
longPressTimer = window.setTimeout(() => {
|
||||
suppressTreeClickTemporarily();
|
||||
setDragState({ draggedNodeId: nodeId, dropTarget: null });
|
||||
}, LONG_PRESS_MS);
|
||||
};
|
||||
|
||||
const handleNodePointerMove = (
|
||||
event: PointerEvent,
|
||||
parentId: string | null,
|
||||
index: number,
|
||||
node: ProjectTreeNode,
|
||||
): void => {
|
||||
const nextDragState = dragState();
|
||||
|
||||
if (!nextDragState) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextDragState.draggedNodeId === getProjectTreeNodeId(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bounds = event.currentTarget.getBoundingClientRect();
|
||||
const relativeY = bounds.height <= 0 ? 0.5 : (event.clientY - bounds.top) / bounds.height;
|
||||
let nextTarget: ProjectDragTarget;
|
||||
|
||||
if (node.kind === "folder") {
|
||||
if (relativeY < 0.28) {
|
||||
nextTarget = {
|
||||
parentId,
|
||||
index,
|
||||
intent: "before",
|
||||
targetNodeId: node.id,
|
||||
};
|
||||
} else if (relativeY > 0.72) {
|
||||
nextTarget = {
|
||||
parentId,
|
||||
index: index + 1,
|
||||
intent: "after",
|
||||
targetNodeId: node.id,
|
||||
};
|
||||
} else {
|
||||
nextTarget = {
|
||||
parentId: node.id,
|
||||
index: node.children.length,
|
||||
intent: "inside",
|
||||
targetNodeId: node.id,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
nextTarget = {
|
||||
parentId,
|
||||
index: relativeY < 0.5 ? index : index + 1,
|
||||
intent: relativeY < 0.5 ? "before" : "after",
|
||||
targetNodeId: node.item.id,
|
||||
};
|
||||
}
|
||||
|
||||
setDragState({
|
||||
...nextDragState,
|
||||
dropTarget: nextTarget,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={rootRef}
|
||||
classList={{
|
||||
[styles.root]: true,
|
||||
[styles.rootCompact]: !!props.compact,
|
||||
[styles.rootDragMode]: !!dragState(),
|
||||
}}
|
||||
style={{
|
||||
"--project-drawer-top": `${drawerTop()}px`,
|
||||
}}
|
||||
>
|
||||
{/* Project trigger */}
|
||||
<button
|
||||
type="button"
|
||||
ref={triggerRef}
|
||||
@@ -86,8 +814,9 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
||||
[styles.triggerCompact]: !!props.compact,
|
||||
[styles.triggerOpen]: props.isOpen,
|
||||
}}
|
||||
aria-label={`Open left workspace sidebar menu for ${selectedProject().name}`}
|
||||
aria-label={`Open project menu for ${selectedProject().name}`}
|
||||
aria-expanded={props.isOpen}
|
||||
aria-haspopup="menu"
|
||||
title={selectedProject().name}
|
||||
onClick={toggleOpen}
|
||||
>
|
||||
@@ -110,54 +839,75 @@ export const ProjectSelector = (props: ProjectSelectorProps): JSX.Element => {
|
||||
/>
|
||||
</button>
|
||||
|
||||
{/* Outside-click scrim */}
|
||||
<button
|
||||
type="button"
|
||||
classList={{
|
||||
[styles.scrim]: true,
|
||||
[styles.scrimOpen]: props.isOpen,
|
||||
<Show when={props.isOpen}>
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
classList={{
|
||||
[styles.scrim]: true,
|
||||
[styles.scrimOpen]: props.isOpen,
|
||||
}}
|
||||
aria-hidden={!props.isOpen}
|
||||
tabIndex={props.isOpen ? 0 : -1}
|
||||
onClick={props.onClose}
|
||||
/>
|
||||
|
||||
<div
|
||||
classList={{
|
||||
[styles.drawer]: true,
|
||||
[styles.drawerOpen]: props.isOpen,
|
||||
}}
|
||||
aria-hidden={!props.isOpen}
|
||||
onContextMenu={handleSurfaceContextMenu}
|
||||
>
|
||||
<div class={styles.drawerBody}>
|
||||
<Show when={!props.compact}>
|
||||
<div class={styles.treeSectionLabel}>Projects</div>
|
||||
</Show>
|
||||
|
||||
<ProjectFolderBranch
|
||||
nodes={projectTreeNodes()}
|
||||
depth={0}
|
||||
parentId={null}
|
||||
selectedProjectId={selectedProject().id}
|
||||
isFolderCollapsed={isFolderCollapsed}
|
||||
onToggleFolder={toggleFolder}
|
||||
onSelectProject={selectProject}
|
||||
onOpenFolderMenu={(event, folder): void => {
|
||||
event.stopPropagation();
|
||||
contextMenu.openMenu(event, createProjectFolderTarget(folder.id, folder.label));
|
||||
}}
|
||||
onOpenProjectMenu={(event, item): void => {
|
||||
event.stopPropagation();
|
||||
contextMenu.openMenu(event, createProjectTarget(item));
|
||||
}}
|
||||
onNodePointerDown={handleNodePointerDown}
|
||||
onNodePointerMove={handleNodePointerMove}
|
||||
pendingFolderDraft={pendingFolderDraft()}
|
||||
pendingFolderName={pendingFolderName()}
|
||||
onPendingFolderNameChange={setPendingFolderName}
|
||||
onSubmitPendingFolder={submitPendingFolder}
|
||||
onCancelPendingFolder={cancelPendingFolder}
|
||||
dragState={dragState()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
</Show>
|
||||
|
||||
<ProjectContextMenu
|
||||
target={contextMenu.menuState()?.target ?? null}
|
||||
position={(() => {
|
||||
const state = contextMenu.menuState();
|
||||
return state ? { x: state.x, y: state.y } : null;
|
||||
})()}
|
||||
menuRef={(element) => {
|
||||
contextMenuRef = element;
|
||||
contextMenu.setMenuRef(element);
|
||||
}}
|
||||
aria-hidden={!props.isOpen}
|
||||
tabIndex={props.isOpen ? 0 : -1}
|
||||
onClick={props.onClose}
|
||||
onClose={contextMenu.closeMenu}
|
||||
onSelect={handleContextActionSelect}
|
||||
/>
|
||||
|
||||
{/* Slide-out project list */}
|
||||
<div
|
||||
classList={{
|
||||
[styles.drawer]: true,
|
||||
[styles.drawerOpen]: props.isOpen,
|
||||
}}
|
||||
aria-hidden={!props.isOpen}
|
||||
>
|
||||
<div class={styles.drawerBody}>
|
||||
<ul class={styles.projectList} role="list">
|
||||
<For each={projectItems}>
|
||||
{(item): JSX.Element => {
|
||||
const isSelected = (): boolean => selectedProject().id === item.id;
|
||||
|
||||
return (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
classList={{
|
||||
[styles.projectItem]: true,
|
||||
[styles.projectItemActive]: isSelected(),
|
||||
}}
|
||||
onClick={(): void => selectProject(item.id)}
|
||||
>
|
||||
<span class={styles.projectItemCopy}>
|
||||
<span class={styles.projectItemName}>{item.name}</span>
|
||||
<span class={styles.projectItemDescription}>{item.description}</span>
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
}}
|
||||
</For>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
// Path: Frontend/src/components/shell/ServerDock/ServerDock.tsx
|
||||
|
||||
import { For, Show, type JSX } from "solid-js";
|
||||
import { activeServer } from "../data/shell.data";
|
||||
import { useAppShellData } from "../data/app-shell.context";
|
||||
import styles from "./ServerDock.module.scss";
|
||||
|
||||
export const ServerDock = (): JSX.Element => {
|
||||
const appShellData = useAppShellData();
|
||||
const activeServer = () => appShellData.activeServer();
|
||||
|
||||
return (
|
||||
<section class={styles.panel} aria-label="Server dock" data-ui="server-dock" data-server-kind={activeServer.kind}>
|
||||
<section class={styles.panel} aria-label="Server dock" data-ui="server-dock" data-server-kind={activeServer().kind}>
|
||||
<div class={styles.identity} data-slot="server-dock-identity">
|
||||
<div class={styles.glyph} aria-hidden="true">
|
||||
{activeServer.abbreviation}
|
||||
{activeServer().abbreviation}
|
||||
</div>
|
||||
<div class={styles.copy} data-slot="server-dock-copy">
|
||||
<span class={styles.name}>{activeServer.name}</span>
|
||||
<span class={styles.name}>{activeServer().name}</span>
|
||||
<Show
|
||||
when={activeServer.kind === "organization"}
|
||||
fallback={<span class={styles.subtitle}>{activeServer.subtitle}</span>}
|
||||
when={activeServer().kind === "organization"}
|
||||
fallback={<span class={styles.subtitle}>{activeServer().subtitle}</span>}
|
||||
>
|
||||
<span class={styles.status}>
|
||||
<span class={styles.statusDot} aria-hidden="true" />
|
||||
<span>{activeServer.connectedLabel}</span>
|
||||
<span>{activeServer().connectedLabel}</span>
|
||||
</span>
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Show when={activeServer.dockActions.length > 0}>
|
||||
<Show when={activeServer().dockActions.length > 0}>
|
||||
<div class={styles.actions} data-slot="server-dock-actions">
|
||||
<For each={activeServer.dockActions}>
|
||||
<For each={activeServer().dockActions}>
|
||||
{(item): JSX.Element => {
|
||||
const Icon = item.icon;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { For, type JSX } from "solid-js";
|
||||
import { User } from "../../../lib/icons";
|
||||
import { activeUserProfile, profileMenuSections } from "../data/shell.data";
|
||||
import { useAppShellData } from "../data/app-shell.context";
|
||||
import { profileMenuSections } from "../data/shell.data";
|
||||
import styles from "./ProfileMenu.module.scss";
|
||||
|
||||
type ProfileMenuProps = {
|
||||
@@ -12,6 +13,8 @@ type ProfileMenuProps = {
|
||||
|
||||
export const ProfileMenu = (props: ProfileMenuProps): JSX.Element => {
|
||||
const variant = props.variant ?? "popover";
|
||||
const appShellData = useAppShellData();
|
||||
const activeUserProfile = () => appShellData.activeUserProfile();
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -35,10 +38,10 @@ export const ProfileMenu = (props: ProfileMenuProps): JSX.Element => {
|
||||
</div>
|
||||
|
||||
<div class={styles.summaryCopy}>
|
||||
<strong class={styles.name}>{activeUserProfile.name}</strong>
|
||||
<span class={styles.email}>{activeUserProfile.email}</span>
|
||||
<span class={styles.role}>{activeUserProfile.roleLabel}</span>
|
||||
<span class={styles.context}>{activeUserProfile.contextLabel}</span>
|
||||
<strong class={styles.name}>{activeUserProfile().name}</strong>
|
||||
<span class={styles.email}>{activeUserProfile().email}</span>
|
||||
<span class={styles.role}>{activeUserProfile().roleLabel}</span>
|
||||
<span class={styles.context}>{activeUserProfile().contextLabel}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -12,6 +12,15 @@
|
||||
isolation: isolate;
|
||||
}
|
||||
|
||||
.sidebarDragMode {
|
||||
user-select: none;
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.sidebarDragMode .treeItem {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
@@ -123,6 +132,43 @@
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.treeEmptySlot {
|
||||
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px dashed color-mix(in srgb, var(--color-border) 38%, transparent);
|
||||
opacity: 0.35;
|
||||
}
|
||||
|
||||
.treeInputRow {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||
padding: var(--space-2) var(--space-3);
|
||||
padding-left: calc(var(--space-3) + (var(--tree-depth, 0) * var(--space-4)));
|
||||
border: 1px solid color-mix(in srgb, var(--color-border) 42%, transparent);
|
||||
border-radius: var(--radius-lg);
|
||||
background: color-mix(in srgb, var(--color-surface) 94%, transparent);
|
||||
}
|
||||
|
||||
.treeInput {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--color-text);
|
||||
font: inherit;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.treeInput::placeholder {
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.navItem {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
@@ -141,7 +187,7 @@
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr) auto;
|
||||
grid-template-columns: auto auto minmax(0, 1fr) auto;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
min-height: calc(var(--control-size-lg) - var(--space-2));
|
||||
@@ -156,19 +202,51 @@
|
||||
background 160ms var(--easing-standard),
|
||||
color 160ms var(--easing-standard),
|
||||
border-color 160ms var(--easing-standard),
|
||||
box-shadow 160ms var(--easing-standard),
|
||||
transform 180ms var(--easing-standard);
|
||||
}
|
||||
|
||||
.treeItem:hover,
|
||||
.treeItem:focus-visible {
|
||||
background: var(--color-surface-hover);
|
||||
background: color-mix(in srgb, var(--color-surface-hover) 80%, var(--color-accent-soft) 20%);
|
||||
color: var(--color-text);
|
||||
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||
}
|
||||
|
||||
.treeItemFolder {
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.treeItemDragging {
|
||||
opacity: 0.45;
|
||||
transform: scale(0.985);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.treeItemDropBefore {
|
||||
box-shadow: inset 0 2px 0 color-mix(in srgb, var(--color-accent-strong) 78%, transparent);
|
||||
}
|
||||
|
||||
.treeItemDropAfter {
|
||||
box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--color-accent-strong) 78%, transparent);
|
||||
}
|
||||
|
||||
.treeItemDropInside {
|
||||
border-color: color-mix(in srgb, var(--color-accent-strong) 55%, transparent);
|
||||
background: color-mix(in srgb, var(--color-accent-soft) 36%, var(--color-surface));
|
||||
color: var(--color-text);
|
||||
box-shadow: inset 0 1px 0 color-mix(in srgb, white 4%, transparent);
|
||||
}
|
||||
|
||||
.folderChevron {
|
||||
color: var(--color-text-muted);
|
||||
transition: transform 160ms var(--easing-standard);
|
||||
}
|
||||
|
||||
.folderChevronOpen {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.treeItemActive {
|
||||
border-color: var(--color-border);
|
||||
background: var(--color-surface);
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
// Path: Frontend/src/components/shell/WorkspaceSidebar/WorkspaceSidebar.tsx
|
||||
|
||||
import { For, Show, createMemo, createSignal, type JSX } from "solid-js";
|
||||
import { ChevronLeft, ChevronRight } from "../../../lib/icons";
|
||||
import { For, Show, createEffect, createSignal, onCleanup, onMount, type JSX } from "solid-js";
|
||||
import { ChevronLeft, ChevronRight, Folder } from "../../../lib/icons";
|
||||
import { useAppShellData } from "../data/app-shell.context";
|
||||
import { ProjectSelector } from "../ProjectSelector/ProjectSelector";
|
||||
import {
|
||||
activeProject,
|
||||
createWorkspaceStaticTarget,
|
||||
createWorkspaceSurfaceTarget,
|
||||
createWorkspaceTreeTarget,
|
||||
getWorkspaceNodeIcon,
|
||||
workspaceSidebarHeaderActions,
|
||||
workspaceStaticItems,
|
||||
workspaceTree,
|
||||
type WorkspaceContextMenuAction,
|
||||
type WorkspaceContextMenuTarget,
|
||||
type WorkspaceStaticItem,
|
||||
@@ -27,12 +26,276 @@ type WorkspaceSidebarProps = {
|
||||
onToggleRailCollapse: () => void;
|
||||
};
|
||||
|
||||
type PendingWorkspaceFolderDraft = {
|
||||
parentId: string | null;
|
||||
depth: number;
|
||||
};
|
||||
|
||||
type WorkspaceDragTarget = {
|
||||
parentId: string | null;
|
||||
index: number;
|
||||
intent: "before" | "after" | "inside";
|
||||
targetNodeId?: string;
|
||||
};
|
||||
|
||||
type WorkspaceDragState = {
|
||||
draggedNodeId: string;
|
||||
dropTarget: WorkspaceDragTarget | null;
|
||||
};
|
||||
|
||||
type WorkspaceNodeLocation = {
|
||||
parentId: string | null;
|
||||
index: number;
|
||||
node: WorkspaceTreeNode;
|
||||
};
|
||||
|
||||
const LONG_PRESS_MS = 320;
|
||||
|
||||
const createWorkspaceFolderId = (): string => `folder-${Math.random().toString(36).slice(2, 10)}`;
|
||||
|
||||
const getWorkspaceTreeNodeId = (node: WorkspaceTreeNode): string => node.id;
|
||||
|
||||
const insertWorkspaceFolderNode = (
|
||||
nodes: readonly WorkspaceTreeNode[],
|
||||
parentId: string | null,
|
||||
folder: WorkspaceTreeNode,
|
||||
): readonly WorkspaceTreeNode[] => {
|
||||
if (parentId === null) {
|
||||
return [...nodes, folder];
|
||||
}
|
||||
|
||||
return nodes.map((node) => {
|
||||
if (node.kind !== "folder") {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (node.id === parentId) {
|
||||
return {
|
||||
...node,
|
||||
children: [...(node.children ?? []), folder],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...node,
|
||||
children: node.children ? insertWorkspaceFolderNode(node.children, parentId, folder) : node.children,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const findWorkspaceFolderDepth = (nodes: readonly WorkspaceTreeNode[], folderId: string, depth = 0): number | null => {
|
||||
for (const node of nodes) {
|
||||
if (node.kind !== "folder") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.id === folderId) {
|
||||
return depth;
|
||||
}
|
||||
|
||||
const nestedDepth = node.children ? findWorkspaceFolderDepth(node.children, folderId, depth + 1) : null;
|
||||
if (nestedDepth !== null) {
|
||||
return nestedDepth;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const findWorkspaceNodeLocation = (
|
||||
nodes: readonly WorkspaceTreeNode[],
|
||||
nodeId: string,
|
||||
parentId: string | null = null,
|
||||
): WorkspaceNodeLocation | null => {
|
||||
for (let index = 0; index < nodes.length; index += 1) {
|
||||
const node = nodes[index];
|
||||
|
||||
if (node.id === nodeId) {
|
||||
return { parentId, index, node };
|
||||
}
|
||||
|
||||
if (node.kind === "folder" && node.children) {
|
||||
const nestedLocation = findWorkspaceNodeLocation(node.children, nodeId, node.id);
|
||||
|
||||
if (nestedLocation) {
|
||||
return nestedLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const workspaceTreeContainsNode = (nodes: readonly WorkspaceTreeNode[], nodeId: string): boolean => {
|
||||
for (const node of nodes) {
|
||||
if (node.id === nodeId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.kind === "folder" && node.children && workspaceTreeContainsNode(node.children, nodeId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const removeWorkspaceTreeNode = (
|
||||
nodes: readonly WorkspaceTreeNode[],
|
||||
nodeId: string,
|
||||
): { nodes: WorkspaceTreeNode[]; removed: WorkspaceTreeNode | null } => {
|
||||
const nextNodes: WorkspaceTreeNode[] = [];
|
||||
let removed: WorkspaceTreeNode | null = null;
|
||||
|
||||
for (const node of nodes) {
|
||||
if (node.id === nodeId) {
|
||||
removed = node;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node.kind === "folder" && node.children) {
|
||||
const result = removeWorkspaceTreeNode(node.children, nodeId);
|
||||
|
||||
if (result.removed) {
|
||||
removed = result.removed;
|
||||
nextNodes.push({
|
||||
...node,
|
||||
children: result.nodes,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
nextNodes.push(node);
|
||||
}
|
||||
|
||||
return { nodes: nextNodes, removed };
|
||||
};
|
||||
|
||||
const insertWorkspaceTreeNode = (
|
||||
nodes: readonly WorkspaceTreeNode[],
|
||||
parentId: string | null,
|
||||
index: number,
|
||||
nodeToInsert: WorkspaceTreeNode,
|
||||
): WorkspaceTreeNode[] => {
|
||||
if (parentId === null) {
|
||||
const nextNodes = [...nodes];
|
||||
nextNodes.splice(Math.max(0, Math.min(index, nextNodes.length)), 0, nodeToInsert);
|
||||
return nextNodes;
|
||||
}
|
||||
|
||||
return nodes.map((node) => {
|
||||
if (node.kind !== "folder") {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (node.id === parentId) {
|
||||
const nextChildren = [...(node.children ?? [])];
|
||||
nextChildren.splice(Math.max(0, Math.min(index, nextChildren.length)), 0, nodeToInsert);
|
||||
return {
|
||||
...node,
|
||||
children: nextChildren,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...node,
|
||||
children: node.children ? insertWorkspaceTreeNode(node.children, parentId, index, nodeToInsert) : node.children,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const moveWorkspaceTreeNode = (
|
||||
nodes: readonly WorkspaceTreeNode[],
|
||||
draggedNodeId: string,
|
||||
dropTarget: WorkspaceDragTarget,
|
||||
): WorkspaceTreeNode[] => {
|
||||
const location = findWorkspaceNodeLocation(nodes, draggedNodeId);
|
||||
|
||||
if (!location) {
|
||||
return [...nodes];
|
||||
}
|
||||
|
||||
if (
|
||||
location.node.kind === "folder" &&
|
||||
dropTarget.parentId !== null &&
|
||||
((location.node.children && workspaceTreeContainsNode(location.node.children, dropTarget.parentId)) ||
|
||||
dropTarget.parentId === location.node.id)
|
||||
) {
|
||||
return [...nodes];
|
||||
}
|
||||
|
||||
let normalizedIndex = dropTarget.index;
|
||||
|
||||
if (dropTarget.parentId === location.parentId && dropTarget.index > location.index) {
|
||||
normalizedIndex -= 1;
|
||||
}
|
||||
|
||||
if (dropTarget.parentId === location.parentId && normalizedIndex === location.index) {
|
||||
return [...nodes];
|
||||
}
|
||||
|
||||
const removalResult = removeWorkspaceTreeNode(nodes, draggedNodeId);
|
||||
|
||||
if (!removalResult.removed) {
|
||||
return [...nodes];
|
||||
}
|
||||
|
||||
return insertWorkspaceTreeNode(removalResult.nodes, dropTarget.parentId, normalizedIndex, removalResult.removed);
|
||||
};
|
||||
|
||||
const FolderDraftRow = (props: {
|
||||
depth: number;
|
||||
value: string;
|
||||
onInput: (value: string) => void;
|
||||
onSubmit: () => void;
|
||||
onCancel: () => void;
|
||||
}): JSX.Element => {
|
||||
let inputRef: HTMLInputElement | undefined;
|
||||
|
||||
queueMicrotask(() => inputRef?.focus());
|
||||
|
||||
return (
|
||||
<li>
|
||||
<div class={styles.treeInputRow} style={{ "--tree-depth": String(props.depth) }}>
|
||||
<Folder class={styles.icon} size={18} strokeWidth={2} />
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="text"
|
||||
class={styles.treeInput}
|
||||
value={props.value}
|
||||
placeholder="Folder name"
|
||||
onInput={(event): void => props.onInput(event.currentTarget.value)}
|
||||
onBlur={props.onSubmit}
|
||||
onKeyDown={(event): void => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
event.currentTarget.blur();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
props.onCancel();
|
||||
event.currentTarget.blur();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
};
|
||||
|
||||
const isContextMenuKeyboardTrigger = (event: KeyboardEvent): boolean => event.key === "ContextMenu" || (event.shiftKey && event.key === "F10");
|
||||
|
||||
const WorkspaceHomeEntry = (props: {
|
||||
item: WorkspaceStaticItem;
|
||||
onOpenContextMenu: (event: MouseEvent, target: WorkspaceContextMenuTarget) => void;
|
||||
onOpenContextMenuFromKeyboard: (element: HTMLElement, target: WorkspaceContextMenuTarget) => void;
|
||||
onNodePointerDown: (event: PointerEvent, nodeId: string) => void;
|
||||
onNodePointerMove: (event: PointerEvent, parentId: string | null, index: number, node: WorkspaceTreeNode) => void;
|
||||
dragState: WorkspaceDragState | null;
|
||||
isTreeClickSuppressed: () => boolean;
|
||||
}): JSX.Element => {
|
||||
const Icon = props.item.icon;
|
||||
const target = createWorkspaceStaticTarget(props.item);
|
||||
@@ -76,18 +339,41 @@ const WorkspaceHomeEntry = (props: {
|
||||
|
||||
const WorkspaceTreeBranch = (props: {
|
||||
nodes: readonly WorkspaceTreeNode[];
|
||||
parentId?: string | null;
|
||||
depth?: number;
|
||||
isFolderCollapsed: (folderId: string) => boolean;
|
||||
onToggleFolder: (folderId: string) => void;
|
||||
pendingFolderDraft: PendingWorkspaceFolderDraft | null;
|
||||
pendingFolderName: string;
|
||||
onPendingFolderNameChange: (value: string) => void;
|
||||
onSubmitPendingFolder: () => void;
|
||||
onCancelPendingFolder: () => void;
|
||||
onOpenContextMenu: (event: MouseEvent, target: WorkspaceContextMenuTarget) => void;
|
||||
onOpenContextMenuFromKeyboard: (element: HTMLElement, target: WorkspaceContextMenuTarget) => void;
|
||||
}): JSX.Element => {
|
||||
const depth = () => props.depth ?? 0;
|
||||
const parentId = () => props.parentId ?? null;
|
||||
|
||||
return (
|
||||
<ul class={styles.treeList} role="list">
|
||||
<Show when={props.nodes.length === 0 && props.pendingFolderDraft?.parentId !== parentId()}>
|
||||
<li>
|
||||
<div class={styles.treeEmptySlot} style={{ "--tree-depth": String(depth()) }} />
|
||||
</li>
|
||||
</Show>
|
||||
<For each={props.nodes}>
|
||||
{(node): JSX.Element => {
|
||||
{(node, indexAccessor): JSX.Element => {
|
||||
const Icon = getWorkspaceNodeIcon(node);
|
||||
const target = createWorkspaceTreeTarget(node);
|
||||
const isCollapsed = (): boolean => (node.kind === "folder" ? props.isFolderCollapsed(node.id) : false);
|
||||
const isDraggedNode = (): boolean => props.dragState?.draggedNodeId === node.id;
|
||||
const dropIntent = (): WorkspaceDragTarget["intent"] | null => {
|
||||
if (props.dragState?.dropTarget?.targetNodeId !== node.id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return props.dragState.dropTarget.intent;
|
||||
};
|
||||
|
||||
return (
|
||||
<li>
|
||||
@@ -97,8 +383,13 @@ const WorkspaceTreeBranch = (props: {
|
||||
[styles.treeItem]: true,
|
||||
[styles.treeItemActive]: !!node.active,
|
||||
[styles.treeItemFolder]: node.kind === "folder",
|
||||
[styles.treeItemDragging]: isDraggedNode(),
|
||||
[styles.treeItemDropBefore]: dropIntent() === "before",
|
||||
[styles.treeItemDropAfter]: dropIntent() === "after",
|
||||
[styles.treeItemDropInside]: dropIntent() === "inside",
|
||||
}}
|
||||
style={{ "--tree-depth": String(depth()) }}
|
||||
aria-expanded={node.kind === "folder" ? !isCollapsed() : undefined}
|
||||
aria-current={node.active ? "page" : undefined}
|
||||
aria-label={node.label}
|
||||
title={node.label}
|
||||
@@ -106,10 +397,28 @@ const WorkspaceTreeBranch = (props: {
|
||||
data-kind={node.kind}
|
||||
data-item-type={node.kind === "item" ? node.itemType : undefined}
|
||||
data-active={node.active ? "true" : "false"}
|
||||
onClick={(): void => {
|
||||
if (props.dragState || props.isTreeClickSuppressed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.kind !== "folder") {
|
||||
return;
|
||||
}
|
||||
|
||||
props.onToggleFolder(node.id);
|
||||
}}
|
||||
onContextMenu={(event): void => {
|
||||
event.stopPropagation();
|
||||
props.onOpenContextMenu(event, target);
|
||||
}}
|
||||
onPointerDown={(event): void => props.onNodePointerDown(event, node.id)}
|
||||
onPointerMove={(event): void =>
|
||||
props.onNodePointerMove(event, parentId(), indexAccessor(), node)
|
||||
}
|
||||
onPointerEnter={(event): void =>
|
||||
props.onNodePointerMove(event, parentId(), indexAccessor(), node)
|
||||
}
|
||||
onKeyDown={(event): void => {
|
||||
if (!isContextMenuKeyboardTrigger(event)) {
|
||||
return;
|
||||
@@ -119,6 +428,16 @@ const WorkspaceTreeBranch = (props: {
|
||||
props.onOpenContextMenuFromKeyboard(event.currentTarget, target);
|
||||
}}
|
||||
>
|
||||
<Show when={node.kind === "folder"}>
|
||||
<ChevronRight
|
||||
classList={{
|
||||
[styles.folderChevron]: true,
|
||||
[styles.folderChevronOpen]: !isCollapsed(),
|
||||
}}
|
||||
size={16}
|
||||
strokeWidth={2}
|
||||
/>
|
||||
</Show>
|
||||
<Icon class={styles.icon} size={18} strokeWidth={2} />
|
||||
<span class={styles.label}>{node.label}</span>
|
||||
<Show when={node.meta}>
|
||||
@@ -126,41 +445,250 @@ const WorkspaceTreeBranch = (props: {
|
||||
</Show>
|
||||
</button>
|
||||
|
||||
<Show when={node.children?.length}>
|
||||
<Show when={node.kind === "folder" && !isCollapsed() && (((node.children?.length ?? 0) > 0) || props.pendingFolderDraft?.parentId === node.id)}>
|
||||
<WorkspaceTreeBranch
|
||||
nodes={node.children ?? []}
|
||||
parentId={node.id}
|
||||
depth={depth() + 1}
|
||||
isFolderCollapsed={props.isFolderCollapsed}
|
||||
onToggleFolder={props.onToggleFolder}
|
||||
pendingFolderDraft={props.pendingFolderDraft}
|
||||
pendingFolderName={props.pendingFolderName}
|
||||
onPendingFolderNameChange={props.onPendingFolderNameChange}
|
||||
onSubmitPendingFolder={props.onSubmitPendingFolder}
|
||||
onCancelPendingFolder={props.onCancelPendingFolder}
|
||||
onOpenContextMenu={props.onOpenContextMenu}
|
||||
onOpenContextMenuFromKeyboard={props.onOpenContextMenuFromKeyboard}
|
||||
onNodePointerDown={props.onNodePointerDown}
|
||||
onNodePointerMove={props.onNodePointerMove}
|
||||
dragState={props.dragState}
|
||||
isTreeClickSuppressed={props.isTreeClickSuppressed}
|
||||
/>
|
||||
</Show>
|
||||
</li>
|
||||
);
|
||||
}}
|
||||
</For>
|
||||
|
||||
<Show when={props.pendingFolderDraft && props.pendingFolderDraft.parentId === parentId()}>
|
||||
<FolderDraftRow
|
||||
depth={props.pendingFolderDraft?.depth ?? depth()}
|
||||
value={props.pendingFolderName}
|
||||
onInput={props.onPendingFolderNameChange}
|
||||
onSubmit={props.onSubmitPendingFolder}
|
||||
onCancel={props.onCancelPendingFolder}
|
||||
/>
|
||||
</Show>
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
|
||||
export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
||||
export const WorkspaceSidebar = (props: WorkspaceSidebarProps): JSX.Element => {
|
||||
const appShellData = useAppShellData();
|
||||
const [isProjectDrawerOpen, setIsProjectDrawerOpen] = createSignal(false);
|
||||
const [workspaceTreeNodes, setWorkspaceTreeNodes] = createSignal<readonly WorkspaceTreeNode[]>(appShellData.workspaceTree());
|
||||
const [collapsedFolderIds, setCollapsedFolderIds] = createSignal<readonly string[]>([]);
|
||||
const [pendingFolderDraft, setPendingFolderDraft] = createSignal<PendingWorkspaceFolderDraft | null>(null);
|
||||
const [pendingFolderName, setPendingFolderName] = createSignal("");
|
||||
const [dragState, setDragState] = createSignal<WorkspaceDragState | null>(null);
|
||||
const [suppressNextTreeClick, setSuppressNextTreeClick] = createSignal(false);
|
||||
const contextMenu = createWorkspaceContextMenuController();
|
||||
let longPressTimer: number | undefined;
|
||||
let suppressClickTimer: number | undefined;
|
||||
const railToggleLabel = (): string => (props.railCollapsed ? "Expand server rail" : "Collapse server rail");
|
||||
const sidebarContextMenuTarget = createWorkspaceSurfaceTarget(activeProject);
|
||||
const contextMenuTarget = createMemo(() => contextMenu.menuState()?.target ?? null);
|
||||
const contextMenuPosition = createMemo(() => {
|
||||
const state = contextMenu.menuState();
|
||||
const sidebarContextMenuTarget = createWorkspaceSurfaceTarget(appShellData.activeProject());
|
||||
const isFolderCollapsed = (folderId: string): boolean => collapsedFolderIds().includes(folderId);
|
||||
const toggleFolder = (folderId: string): void => {
|
||||
setCollapsedFolderIds((current) =>
|
||||
current.includes(folderId) ? current.filter((id) => id !== folderId) : [...current, folderId],
|
||||
);
|
||||
};
|
||||
const clearLongPressTimer = (): void => {
|
||||
if (longPressTimer !== undefined) {
|
||||
window.clearTimeout(longPressTimer);
|
||||
longPressTimer = undefined;
|
||||
}
|
||||
};
|
||||
const suppressTreeClickTemporarily = (): void => {
|
||||
setSuppressNextTreeClick(true);
|
||||
|
||||
return state
|
||||
? {
|
||||
x: state.x,
|
||||
y: state.y,
|
||||
}
|
||||
: null;
|
||||
if (suppressClickTimer !== undefined) {
|
||||
window.clearTimeout(suppressClickTimer);
|
||||
}
|
||||
|
||||
suppressClickTimer = window.setTimeout(() => {
|
||||
setSuppressNextTreeClick(false);
|
||||
suppressClickTimer = undefined;
|
||||
}, 80);
|
||||
};
|
||||
|
||||
createEffect(() => {
|
||||
setWorkspaceTreeNodes(appShellData.workspaceTree());
|
||||
setCollapsedFolderIds([]);
|
||||
setPendingFolderDraft(null);
|
||||
setPendingFolderName("");
|
||||
setDragState(null);
|
||||
});
|
||||
|
||||
const handleContextActionSelect = (_action: WorkspaceContextMenuAction, _target: WorkspaceContextMenuTarget): void => {
|
||||
// Initial implementation only establishes the menu IA and placement.
|
||||
onMount(() => {
|
||||
const handlePointerUp = (): void => {
|
||||
clearLongPressTimer();
|
||||
|
||||
const nextDragState = dragState();
|
||||
|
||||
if (!nextDragState?.dropTarget) {
|
||||
if (nextDragState) {
|
||||
suppressTreeClickTemporarily();
|
||||
}
|
||||
setDragState(null);
|
||||
return;
|
||||
}
|
||||
|
||||
suppressTreeClickTemporarily();
|
||||
setWorkspaceTreeNodes((current) =>
|
||||
moveWorkspaceTreeNode(current, nextDragState.draggedNodeId, nextDragState.dropTarget as WorkspaceDragTarget),
|
||||
);
|
||||
setDragState(null);
|
||||
};
|
||||
|
||||
const handleEscape = (event: KeyboardEvent): void => {
|
||||
if (event.key !== "Escape") {
|
||||
return;
|
||||
}
|
||||
|
||||
clearLongPressTimer();
|
||||
|
||||
if (dragState()) {
|
||||
setDragState(null);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("pointerup", handlePointerUp);
|
||||
window.addEventListener("pointercancel", handlePointerUp);
|
||||
window.addEventListener("keydown", handleEscape);
|
||||
|
||||
onCleanup(() => {
|
||||
clearLongPressTimer();
|
||||
if (suppressClickTimer !== undefined) {
|
||||
window.clearTimeout(suppressClickTimer);
|
||||
}
|
||||
window.removeEventListener("pointerup", handlePointerUp);
|
||||
window.removeEventListener("pointercancel", handlePointerUp);
|
||||
window.removeEventListener("keydown", handleEscape);
|
||||
});
|
||||
});
|
||||
|
||||
const beginFolderDraft = (parentId: string | null, depth: number): void => {
|
||||
if (parentId) {
|
||||
setCollapsedFolderIds((current) => current.filter((id) => id !== parentId));
|
||||
}
|
||||
|
||||
setPendingFolderName("");
|
||||
setPendingFolderDraft({ parentId, depth });
|
||||
};
|
||||
|
||||
const submitPendingFolder = (): void => {
|
||||
const name = pendingFolderName().trim();
|
||||
const draft = pendingFolderDraft();
|
||||
|
||||
if (!draft) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
setPendingFolderDraft(null);
|
||||
setPendingFolderName("");
|
||||
return;
|
||||
}
|
||||
|
||||
setWorkspaceTreeNodes((current) =>
|
||||
insertWorkspaceFolderNode(current, draft.parentId, {
|
||||
id: createWorkspaceFolderId(),
|
||||
label: name,
|
||||
kind: "folder",
|
||||
icon: Folder,
|
||||
children: [],
|
||||
}),
|
||||
);
|
||||
setPendingFolderDraft(null);
|
||||
setPendingFolderName("");
|
||||
};
|
||||
|
||||
const cancelPendingFolder = (): void => {
|
||||
setPendingFolderDraft(null);
|
||||
setPendingFolderName("");
|
||||
};
|
||||
|
||||
const handleNodePointerDown = (event: PointerEvent, nodeId: string): void => {
|
||||
if (event.button !== 0 || pendingFolderDraft()) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearLongPressTimer();
|
||||
longPressTimer = window.setTimeout(() => {
|
||||
suppressTreeClickTemporarily();
|
||||
setDragState({ draggedNodeId: nodeId, dropTarget: null });
|
||||
}, LONG_PRESS_MS);
|
||||
};
|
||||
|
||||
const handleNodePointerMove = (
|
||||
event: PointerEvent,
|
||||
parentId: string | null,
|
||||
index: number,
|
||||
node: WorkspaceTreeNode,
|
||||
): void => {
|
||||
const nextDragState = dragState();
|
||||
|
||||
if (!nextDragState || nextDragState.draggedNodeId === getWorkspaceTreeNodeId(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bounds = event.currentTarget.getBoundingClientRect();
|
||||
const relativeY = bounds.height <= 0 ? 0.5 : (event.clientY - bounds.top) / bounds.height;
|
||||
let nextTarget: WorkspaceDragTarget;
|
||||
|
||||
if (node.kind === "folder") {
|
||||
if (relativeY < 0.28) {
|
||||
nextTarget = { parentId, index, intent: "before", targetNodeId: node.id };
|
||||
} else if (relativeY > 0.72) {
|
||||
nextTarget = { parentId, index: index + 1, intent: "after", targetNodeId: node.id };
|
||||
} else {
|
||||
nextTarget = {
|
||||
parentId: node.id,
|
||||
index: (node.children ?? []).length,
|
||||
intent: "inside",
|
||||
targetNodeId: node.id,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
nextTarget = {
|
||||
parentId,
|
||||
index: relativeY < 0.5 ? index : index + 1,
|
||||
intent: relativeY < 0.5 ? "before" : "after",
|
||||
targetNodeId: node.id,
|
||||
};
|
||||
}
|
||||
|
||||
setDragState({ ...nextDragState, dropTarget: nextTarget });
|
||||
};
|
||||
|
||||
const handleContextActionSelect = (action: WorkspaceContextMenuAction, target: WorkspaceContextMenuTarget): void => {
|
||||
if (action.id !== "new-folder") {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (target.kind) {
|
||||
case "workspace":
|
||||
case "home":
|
||||
beginFolderDraft(null, 0);
|
||||
return;
|
||||
case "folder":
|
||||
beginFolderDraft(target.id, (findWorkspaceFolderDepth(workspaceTreeNodes(), target.id) ?? 0) + 1);
|
||||
return;
|
||||
case "settings":
|
||||
case "item":
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -169,6 +697,7 @@ const WorkspaceTreeBranch = (props: {
|
||||
classList={{
|
||||
[styles.sidebar]: true,
|
||||
[styles.sidebarCollapsed]: props.collapsed,
|
||||
[styles.sidebarDragMode]: !!dragState(),
|
||||
}}
|
||||
aria-label="Left workspace sidebar"
|
||||
data-ui="workspace-sidebar"
|
||||
@@ -255,19 +784,39 @@ const WorkspaceTreeBranch = (props: {
|
||||
</Show>
|
||||
|
||||
<div data-slot="workspace-tree-root">
|
||||
<WorkspaceTreeBranch
|
||||
nodes={workspaceTree}
|
||||
onOpenContextMenu={contextMenu.openMenu}
|
||||
onOpenContextMenuFromKeyboard={contextMenu.openMenuFromElement}
|
||||
/>
|
||||
<WorkspaceTreeBranch
|
||||
nodes={workspaceTreeNodes()}
|
||||
parentId={null}
|
||||
isFolderCollapsed={isFolderCollapsed}
|
||||
onToggleFolder={toggleFolder}
|
||||
pendingFolderDraft={pendingFolderDraft()}
|
||||
pendingFolderName={pendingFolderName()}
|
||||
onPendingFolderNameChange={setPendingFolderName}
|
||||
onSubmitPendingFolder={submitPendingFolder}
|
||||
onCancelPendingFolder={cancelPendingFolder}
|
||||
onOpenContextMenu={contextMenu.openMenu}
|
||||
onOpenContextMenuFromKeyboard={contextMenu.openMenuFromElement}
|
||||
onNodePointerDown={handleNodePointerDown}
|
||||
onNodePointerMove={handleNodePointerMove}
|
||||
dragState={dragState()}
|
||||
isTreeClickSuppressed={suppressNextTreeClick}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<WorkspaceContextMenu
|
||||
target={contextMenuTarget()}
|
||||
position={contextMenuPosition()}
|
||||
target={contextMenu.menuState()?.target ?? null}
|
||||
position={(() => {
|
||||
const state = contextMenu.menuState();
|
||||
return state
|
||||
? {
|
||||
x: state.x,
|
||||
y: state.y,
|
||||
}
|
||||
: null;
|
||||
})()}
|
||||
menuRef={contextMenu.setMenuRef}
|
||||
onClose={contextMenu.closeMenu}
|
||||
onSelect={handleContextActionSelect}
|
||||
|
||||
352
Frontend/src/components/shell/data/app-shell.context.tsx
Normal file
352
Frontend/src/components/shell/data/app-shell.context.tsx
Normal file
@@ -0,0 +1,352 @@
|
||||
// Path: Frontend/src/components/shell/data/app-shell.context.tsx
|
||||
|
||||
import {
|
||||
createContext,
|
||||
createMemo,
|
||||
createSignal,
|
||||
onMount,
|
||||
useContext,
|
||||
type Accessor,
|
||||
type JSX,
|
||||
} from "solid-js";
|
||||
import { Folder } from "../../../lib/icons";
|
||||
import { resolveAPIBase } from "../../../lib/api";
|
||||
import {
|
||||
activeDepartment as fallbackActiveDepartment,
|
||||
activeProject as fallbackActiveProject,
|
||||
activeServer as fallbackActiveServer,
|
||||
activeUserProfile as fallbackActiveUserProfile,
|
||||
departmentItems as fallbackDepartmentItems,
|
||||
organizationAdminDockActions,
|
||||
personalDockActions,
|
||||
projectItems as fallbackProjectItems,
|
||||
railItems as fallbackRailItems,
|
||||
workspaceTree as fallbackWorkspaceTree,
|
||||
type ActiveDepartment,
|
||||
type ActiveProject,
|
||||
type ActiveServer,
|
||||
type ActiveUserProfile,
|
||||
type DepartmentItem,
|
||||
type ProjectItem,
|
||||
type RailItem,
|
||||
type WorkspaceTreeNode,
|
||||
} from "./shell.data";
|
||||
|
||||
type AppShellInstallation = {
|
||||
id: string;
|
||||
name: string;
|
||||
mode: "personal" | "organizational" | string;
|
||||
access: string;
|
||||
protocol: string;
|
||||
host: string;
|
||||
isBootstrapped: boolean;
|
||||
};
|
||||
|
||||
type AppShellAdmin = {
|
||||
id: string;
|
||||
email: string;
|
||||
displayName: string;
|
||||
isInstanceAdmin: boolean;
|
||||
homeTitle: string;
|
||||
};
|
||||
|
||||
type AppShellOrganization = {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
|
||||
type AppShellDepartment = {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
|
||||
type AppShellTeam = {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
departmentId?: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
|
||||
type AppShellProject = {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
departmentId?: string;
|
||||
teamId?: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
|
||||
type AppShellWorkspace = {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
kind: "organization" | "department" | "team" | "project" | string;
|
||||
departmentId?: string;
|
||||
teamId?: string;
|
||||
projectId?: string;
|
||||
};
|
||||
|
||||
type AppShellPayload = {
|
||||
installation?: AppShellInstallation;
|
||||
admin?: AppShellAdmin;
|
||||
organizations: AppShellOrganization[];
|
||||
departments: AppShellDepartment[];
|
||||
teams: AppShellTeam[];
|
||||
projects: AppShellProject[];
|
||||
workspaces: AppShellWorkspace[];
|
||||
};
|
||||
|
||||
const normalizeAppShellPayload = (payload: AppShellPayload | null | undefined): AppShellPayload => ({
|
||||
installation: payload?.installation,
|
||||
admin: payload?.admin,
|
||||
organizations: Array.isArray(payload?.organizations) ? payload.organizations : [],
|
||||
departments: Array.isArray(payload?.departments) ? payload.departments : [],
|
||||
teams: Array.isArray(payload?.teams) ? payload.teams : [],
|
||||
projects: Array.isArray(payload?.projects) ? payload.projects : [],
|
||||
workspaces: Array.isArray(payload?.workspaces) ? payload.workspaces : [],
|
||||
});
|
||||
|
||||
type AppShellContextValue = {
|
||||
status: Accessor<"idle" | "loading" | "success" | "error">;
|
||||
error: Accessor<string>;
|
||||
installation: Accessor<AppShellInstallation | undefined>;
|
||||
railItems: Accessor<readonly RailItem[]>;
|
||||
activeServer: Accessor<ActiveServer>;
|
||||
activeProject: Accessor<ActiveProject>;
|
||||
activeDepartment: Accessor<ActiveDepartment>;
|
||||
projectItems: Accessor<readonly ProjectItem[]>;
|
||||
departmentItems: Accessor<readonly DepartmentItem[]>;
|
||||
workspaceTree: Accessor<readonly WorkspaceTreeNode[]>;
|
||||
activeUserProfile: Accessor<ActiveUserProfile>;
|
||||
reload: () => Promise<void>;
|
||||
};
|
||||
|
||||
const AppShellContext = createContext<AppShellContextValue>();
|
||||
|
||||
const buildAbbreviation = (name: string, fallback: string): string => {
|
||||
const parts = name
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.filter(Boolean);
|
||||
|
||||
if (parts.length === 0) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const abbreviation = parts
|
||||
.slice(0, 2)
|
||||
.map((part) => part[0]?.toUpperCase() ?? "")
|
||||
.join("");
|
||||
|
||||
return abbreviation || fallback;
|
||||
};
|
||||
|
||||
const buildRailItems = (payload: AppShellPayload | null): readonly RailItem[] => {
|
||||
if (!payload?.installation || payload.organizations.length === 0) {
|
||||
return fallbackRailItems;
|
||||
}
|
||||
|
||||
const kind = payload.installation.mode === "personal" ? "personal" : "organization";
|
||||
const serverName = payload.installation.name || payload.organizations[0]?.name || payload.installation.host;
|
||||
|
||||
return payload.organizations.map((organization, index) => ({
|
||||
id: organization.id,
|
||||
label: serverName || organization.name,
|
||||
abbreviation: buildAbbreviation(serverName || organization.name, kind === "personal" ? "P" : "O"),
|
||||
kind,
|
||||
active: index === 0,
|
||||
}));
|
||||
};
|
||||
|
||||
const buildActiveServer = (payload: AppShellPayload | null): ActiveServer => {
|
||||
const installation = payload?.installation;
|
||||
const organization = payload?.organizations[0];
|
||||
|
||||
if (!installation || !organization) {
|
||||
return fallbackActiveServer;
|
||||
}
|
||||
|
||||
const kind = installation.mode === "personal" ? "personal" : "organization";
|
||||
const serverName = installation.name || organization.name || installation.host;
|
||||
|
||||
return {
|
||||
id: installation.id,
|
||||
name: serverName || fallbackActiveServer.name,
|
||||
abbreviation: buildAbbreviation(serverName, kind === "personal" ? "P" : "O"),
|
||||
kind,
|
||||
connectedLabel: kind === "organization" ? `${payload?.teams.length ?? 0} connected` : undefined,
|
||||
subtitle: kind === "personal" ? installation.host || payload?.admin?.homeTitle || "Personal home" : undefined,
|
||||
dockActions: kind === "personal" ? personalDockActions : organizationAdminDockActions,
|
||||
};
|
||||
};
|
||||
|
||||
const buildProjectItems = (payload: AppShellPayload | null): readonly ProjectItem[] => {
|
||||
if (!payload?.projects.length) {
|
||||
return fallbackProjectItems;
|
||||
}
|
||||
|
||||
return payload.projects.map((project, index) => ({
|
||||
id: project.id,
|
||||
name: project.name,
|
||||
description: project.slug || "Persisted project workspace",
|
||||
groupLabel: payload.departments.find((department) => department.id === project.departmentId)?.name || "Projects",
|
||||
parentLabel:
|
||||
payload.teams.find((team) => team.id === project.teamId)?.name ||
|
||||
payload.departments.find((department) => department.id === project.departmentId)?.name ||
|
||||
"Shared project",
|
||||
meta: (() => {
|
||||
const workspaceCount = payload.workspaces.filter((workspace) => workspace.projectId === project.id).length;
|
||||
|
||||
return workspaceCount > 0 ? `${workspaceCount} workspace${workspaceCount === 1 ? "" : "s"}` : undefined;
|
||||
})(),
|
||||
active: index === 0,
|
||||
}));
|
||||
};
|
||||
|
||||
const buildActiveProject = (payload: AppShellPayload | null): ActiveProject => {
|
||||
const firstProject = payload?.projects[0];
|
||||
|
||||
if (!firstProject) {
|
||||
return fallbackActiveProject;
|
||||
}
|
||||
|
||||
return {
|
||||
id: firstProject.id,
|
||||
name: firstProject.name,
|
||||
};
|
||||
};
|
||||
|
||||
const buildDepartmentItems = (payload: AppShellPayload | null): readonly DepartmentItem[] => {
|
||||
if (!payload?.departments.length) {
|
||||
return fallbackDepartmentItems;
|
||||
}
|
||||
|
||||
return payload.departments.map((department, index) => ({
|
||||
id: department.id,
|
||||
name: department.name,
|
||||
teams: payload.teams
|
||||
.filter((team) => team.departmentId === department.id)
|
||||
.map((team) => team.name),
|
||||
active: index === 0,
|
||||
}));
|
||||
};
|
||||
|
||||
const buildActiveDepartment = (payload: AppShellPayload | null): ActiveDepartment => {
|
||||
const firstDepartment = payload?.departments[0];
|
||||
|
||||
if (!firstDepartment) {
|
||||
return fallbackActiveDepartment;
|
||||
}
|
||||
|
||||
const firstTeamName = payload?.teams.find((team) => team.departmentId === firstDepartment.id)?.name ?? "";
|
||||
|
||||
return {
|
||||
id: firstDepartment.id,
|
||||
name: firstDepartment.name,
|
||||
teamName: firstTeamName,
|
||||
};
|
||||
};
|
||||
|
||||
const buildWorkspaceTree = (payload: AppShellPayload | null): readonly WorkspaceTreeNode[] => {
|
||||
if (!payload?.projects.length) {
|
||||
return fallbackWorkspaceTree;
|
||||
}
|
||||
|
||||
// The workspace tree should represent items inside the current project, not the
|
||||
// project container itself. We do not have project-contents hydration yet, so
|
||||
// return an empty tree rather than showing the project root as a fake item.
|
||||
return [];
|
||||
};
|
||||
|
||||
const buildActiveUserProfile = (payload: AppShellPayload | null): ActiveUserProfile => {
|
||||
if (!payload?.admin) {
|
||||
return fallbackActiveUserProfile;
|
||||
}
|
||||
|
||||
const organizationName = payload.installation?.name || payload.organizations[0]?.name || fallbackActiveServer.name;
|
||||
const departmentName = payload.departments[0]?.name;
|
||||
|
||||
return {
|
||||
name: payload.admin.displayName,
|
||||
email: payload.admin.email,
|
||||
roleLabel: payload.admin.isInstanceAdmin ? "Instance admin" : "Member",
|
||||
contextLabel: departmentName ? `${organizationName} • ${departmentName}` : organizationName,
|
||||
};
|
||||
};
|
||||
|
||||
export const AppShellDataProvider = (props: { children: JSX.Element }): JSX.Element => {
|
||||
const [status, setStatus] = createSignal<"idle" | "loading" | "success" | "error">("idle");
|
||||
const [error, setError] = createSignal("");
|
||||
const [payload, setPayload] = createSignal<AppShellPayload | null>(null);
|
||||
|
||||
const load = async (): Promise<void> => {
|
||||
setStatus("loading");
|
||||
setError("");
|
||||
|
||||
try {
|
||||
const response = await fetch(`${resolveAPIBase()}/app-shell`, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
const body = (await response.json()) as {
|
||||
data?: AppShellPayload;
|
||||
error?: { message?: string } | string;
|
||||
message?: string;
|
||||
};
|
||||
const errorMessage =
|
||||
typeof body.message === "string"
|
||||
? body.message
|
||||
: typeof body.error === "string"
|
||||
? body.error
|
||||
: body.error?.message;
|
||||
|
||||
if (!response.ok || !body.data) {
|
||||
throw new Error(errorMessage || "Failed to load app shell state.");
|
||||
}
|
||||
|
||||
setPayload(normalizeAppShellPayload(body.data));
|
||||
setStatus("success");
|
||||
} catch (loadError) {
|
||||
setStatus("error");
|
||||
setError(loadError instanceof Error ? loadError.message : "Failed to load app shell state.");
|
||||
}
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
void load();
|
||||
});
|
||||
|
||||
const value: AppShellContextValue = {
|
||||
status,
|
||||
error,
|
||||
installation: createMemo(() => payload()?.installation),
|
||||
railItems: createMemo(() => buildRailItems(payload())),
|
||||
activeServer: createMemo(() => buildActiveServer(payload())),
|
||||
activeProject: createMemo(() => buildActiveProject(payload())),
|
||||
activeDepartment: createMemo(() => buildActiveDepartment(payload())),
|
||||
projectItems: createMemo(() => buildProjectItems(payload())),
|
||||
departmentItems: createMemo(() => buildDepartmentItems(payload())),
|
||||
workspaceTree: createMemo(() => buildWorkspaceTree(payload())),
|
||||
activeUserProfile: createMemo(() => buildActiveUserProfile(payload())),
|
||||
reload: load,
|
||||
};
|
||||
|
||||
return <AppShellContext.Provider value={value}>{props.children}</AppShellContext.Provider>;
|
||||
};
|
||||
|
||||
export const useAppShellData = (): AppShellContextValue => {
|
||||
const context = useContext(AppShellContext);
|
||||
|
||||
if (!context) {
|
||||
throw new Error("useAppShellData must be used within AppShellDataProvider");
|
||||
}
|
||||
|
||||
return context;
|
||||
};
|
||||
@@ -71,9 +71,43 @@ export type ProjectItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
groupLabel?: string;
|
||||
parentLabel?: string;
|
||||
meta?: string;
|
||||
active?: boolean;
|
||||
};
|
||||
|
||||
export type ProjectMenuTarget =
|
||||
| {
|
||||
id: string;
|
||||
label: string;
|
||||
kind: "surface";
|
||||
}
|
||||
| {
|
||||
id: string;
|
||||
label: string;
|
||||
kind: "folder";
|
||||
}
|
||||
| {
|
||||
id: string;
|
||||
label: string;
|
||||
kind: "project";
|
||||
};
|
||||
|
||||
export type ProjectContextMenuAction = {
|
||||
id: string;
|
||||
label: string;
|
||||
tone?: "default" | "danger";
|
||||
shortcut?: WorkspaceContextMenuShortcut;
|
||||
children?: readonly ProjectContextMenuAction[];
|
||||
};
|
||||
|
||||
export type ProjectContextMenuSection = {
|
||||
id: string;
|
||||
label?: string;
|
||||
items: readonly ProjectContextMenuAction[];
|
||||
};
|
||||
|
||||
export type SidebarItem = {
|
||||
id: string;
|
||||
label: string;
|
||||
@@ -325,12 +359,12 @@ export type ActiveUserProfile = {
|
||||
contextLabel: string;
|
||||
};
|
||||
|
||||
const personalDockActions: readonly ServerDockAction[] = [
|
||||
export const personalDockActions: readonly ServerDockAction[] = [
|
||||
{ id: "account", label: "Account", icon: User },
|
||||
{ id: "settings", label: "Settings", icon: Settings },
|
||||
] as const;
|
||||
|
||||
const organizationAdminDockActions: readonly ServerDockAction[] = [
|
||||
export const organizationAdminDockActions: readonly ServerDockAction[] = [
|
||||
{ id: "members", label: "Members", icon: User },
|
||||
{ id: "server", label: "Server", icon: Settings },
|
||||
] as const;
|
||||
@@ -364,9 +398,31 @@ export const activeDepartment: ActiveDepartment = {
|
||||
};
|
||||
|
||||
export const projectItems: readonly ProjectItem[] = [
|
||||
{ id: "general", name: "General", description: "Default shared project", active: true },
|
||||
{ id: "operations", name: "Operations", description: "Cross-team planning and delivery" },
|
||||
{ id: "hiring", name: "Hiring", description: "Candidate pipeline and interview loops" },
|
||||
{
|
||||
id: "general",
|
||||
name: "General",
|
||||
description: "Default shared project",
|
||||
groupLabel: "Shared space",
|
||||
parentLabel: "Workspace home",
|
||||
meta: "1 workspace",
|
||||
active: true,
|
||||
},
|
||||
{
|
||||
id: "operations",
|
||||
name: "Operations",
|
||||
description: "Cross-team planning and delivery",
|
||||
groupLabel: "Team folders",
|
||||
parentLabel: "Shared Services",
|
||||
meta: "2 workspaces",
|
||||
},
|
||||
{
|
||||
id: "hiring",
|
||||
name: "Hiring",
|
||||
description: "Candidate pipeline and interview loops",
|
||||
groupLabel: "Team folders",
|
||||
parentLabel: "People Ops",
|
||||
meta: "1 workspace",
|
||||
},
|
||||
] as const;
|
||||
|
||||
export const departmentItems: readonly DepartmentItem[] = [
|
||||
@@ -533,6 +589,69 @@ export const getWorkspaceContextMenuSections = (
|
||||
}
|
||||
};
|
||||
|
||||
const getProjectCreateActions = (): readonly ProjectContextMenuAction[] =>
|
||||
[
|
||||
{ id: "new-project", label: "New project" },
|
||||
{ id: "new-folder", label: "New folder" },
|
||||
] as const;
|
||||
|
||||
export const createProjectSurfaceTarget = (label = "Projects"): ProjectMenuTarget => ({
|
||||
id: "project-surface",
|
||||
label,
|
||||
kind: "surface",
|
||||
});
|
||||
|
||||
export const createProjectFolderTarget = (id: string, label: string): ProjectMenuTarget => ({
|
||||
id,
|
||||
label,
|
||||
kind: "folder",
|
||||
});
|
||||
|
||||
export const createProjectTarget = (project: ProjectItem): ProjectMenuTarget => ({
|
||||
id: project.id,
|
||||
label: project.name,
|
||||
kind: "project",
|
||||
});
|
||||
|
||||
export const getProjectContextMenuEyebrow = (target: ProjectMenuTarget): string => {
|
||||
switch (target.kind) {
|
||||
case "surface":
|
||||
return "Projects";
|
||||
case "folder":
|
||||
return "Folder";
|
||||
case "project":
|
||||
return "Project";
|
||||
}
|
||||
};
|
||||
|
||||
export const getProjectContextMenuSections = (target: ProjectMenuTarget): readonly ProjectContextMenuSection[] => {
|
||||
const createActions = getProjectCreateActions();
|
||||
|
||||
switch (target.kind) {
|
||||
case "surface":
|
||||
return [
|
||||
{
|
||||
id: "create",
|
||||
items: createActions,
|
||||
},
|
||||
] as const;
|
||||
case "folder":
|
||||
return [
|
||||
{
|
||||
id: "create",
|
||||
items: createActions,
|
||||
},
|
||||
] as const;
|
||||
case "project":
|
||||
return [
|
||||
{
|
||||
id: "create",
|
||||
items: createActions,
|
||||
},
|
||||
] as const;
|
||||
}
|
||||
};
|
||||
|
||||
export const topBarActions: readonly TopBarAction[] = [
|
||||
{ id: "search", label: "Search", icon: Search },
|
||||
] as const;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
.viewport {
|
||||
.viewport,
|
||||
.wizardLayer {
|
||||
--workspace-content-max-width: var(--content-width-wide);
|
||||
--workspace-card-min-height: calc(var(--space-12) * 3);
|
||||
--bootstrap-accent: var(--color-accent-primary, var(--color-primary-2, hsl(272 80% 70%)));
|
||||
--bootstrap-accent-contrast: var(--color-accent-primary-contrast, white);
|
||||
}
|
||||
|
||||
.viewport {
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
@@ -81,10 +86,10 @@
|
||||
max-width: var(--workspace-content-max-width);
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
@include text-caption;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
.heroActions {
|
||||
display: flex;
|
||||
gap: var(--space-3);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.title {
|
||||
@@ -98,18 +103,12 @@
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.grid {
|
||||
width: 100%;
|
||||
max-width: var(--workspace-content-max-width);
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: var(--space-4);
|
||||
}
|
||||
|
||||
.card {
|
||||
.overviewCard,
|
||||
.summaryCard,
|
||||
.wizardSidebarSection,
|
||||
.wizardStepPanel {
|
||||
display: grid;
|
||||
gap: var(--space-2);
|
||||
min-height: var(--workspace-card-min-height);
|
||||
padding: var(--space-4);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-xl);
|
||||
@@ -117,23 +116,390 @@
|
||||
box-shadow: var(--shadow-soft);
|
||||
}
|
||||
|
||||
.cardTitle {
|
||||
.overviewCard {
|
||||
width: 100%;
|
||||
max-width: var(--workspace-content-max-width);
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.summaryGrid {
|
||||
width: 100%;
|
||||
max-width: var(--workspace-content-max-width);
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: var(--space-4);
|
||||
}
|
||||
|
||||
.summaryCard {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.summaryCardHeader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.summaryStepNumber,
|
||||
.wizardStepEyebrow {
|
||||
@include text-caption;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
}
|
||||
|
||||
.sectionHeader {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.sectionTitle,
|
||||
.cardTitle,
|
||||
.wizardTitle,
|
||||
.sidebarTitle {
|
||||
@include text-title;
|
||||
}
|
||||
|
||||
.cardCopy {
|
||||
.sectionCopy,
|
||||
.cardCopy,
|
||||
.cardMeta {
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.statusBadge {
|
||||
@include text-caption;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: calc(var(--control-size-sm) - 0.25rem);
|
||||
padding: 0 var(--space-2);
|
||||
border-radius: var(--radius-pill);
|
||||
border: 1px solid color-mix(in srgb, var(--color-border-strong) 44%, transparent);
|
||||
background: color-mix(in srgb, var(--color-surface-secondary) 92%, transparent);
|
||||
color: var(--color-text-muted);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.statusBadge[data-status="submitting"] {
|
||||
color: var(--bootstrap-accent);
|
||||
border-color: color-mix(in srgb, var(--bootstrap-accent) 38%, transparent);
|
||||
}
|
||||
|
||||
.statusBadge[data-status="success"] {
|
||||
color: var(--color-success-text, var(--color-text));
|
||||
border-color: color-mix(in srgb, var(--color-success-border, var(--color-border)) 64%, transparent);
|
||||
background: color-mix(in srgb, var(--color-success-surface, var(--color-surface-secondary)) 80%, transparent);
|
||||
}
|
||||
|
||||
.statusBadge[data-status="error"] {
|
||||
color: var(--color-danger-text, var(--color-text));
|
||||
border-color: color-mix(in srgb, var(--color-danger-border, var(--color-border)) 68%, transparent);
|
||||
background: color-mix(in srgb, var(--color-danger-surface, var(--color-surface-secondary)) 80%, transparent);
|
||||
}
|
||||
|
||||
.endpointMeta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.endpointMeta span {
|
||||
@include text-caption;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.endpointMeta code,
|
||||
.cardMeta {
|
||||
@include text-caption;
|
||||
}
|
||||
|
||||
.endpointMeta code {
|
||||
padding: 0.125rem 0.5rem;
|
||||
border-radius: var(--radius-pill);
|
||||
background: color-mix(in srgb, var(--color-surface-secondary) 90%, transparent);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.form {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.field {
|
||||
display: grid;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.fieldLabel {
|
||||
@include text-caption;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.fieldHelp {
|
||||
@include text-caption;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.field input,
|
||||
.field select {
|
||||
min-height: var(--control-size-md);
|
||||
width: 100%;
|
||||
font: inherit;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
background: var(--color-surface-elevated);
|
||||
color: var(--color-text);
|
||||
padding: 0 var(--space-3);
|
||||
transition:
|
||||
border-color 160ms var(--easing-standard),
|
||||
box-shadow 160ms var(--easing-standard),
|
||||
background 160ms var(--easing-standard);
|
||||
}
|
||||
|
||||
.field input:disabled,
|
||||
.field select:disabled {
|
||||
cursor: not-allowed;
|
||||
color: var(--color-text-muted);
|
||||
background: color-mix(in srgb, var(--color-surface-secondary) 92%, transparent);
|
||||
border-color: color-mix(in srgb, var(--color-border) 72%, transparent);
|
||||
}
|
||||
|
||||
.field input:focus-visible,
|
||||
.field select:focus-visible {
|
||||
outline: none;
|
||||
border-color: color-mix(in srgb, var(--bootstrap-accent) 60%, var(--color-border));
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--bootstrap-accent) 16%, transparent);
|
||||
}
|
||||
|
||||
.wizardFormActions,
|
||||
.heroActions,
|
||||
.primaryButton,
|
||||
.secondaryButton {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.wizardFormActions {
|
||||
justify-content: space-between;
|
||||
gap: var(--space-3);
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
.wizardFormActions .primaryButton {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.primaryButton,
|
||||
.secondaryButton,
|
||||
.wizardStepButton,
|
||||
.wizardCloseButton {
|
||||
appearance: none;
|
||||
justify-content: center;
|
||||
gap: var(--space-2);
|
||||
min-height: var(--control-size-md);
|
||||
border-radius: var(--radius-pill);
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
transform 180ms var(--easing-standard),
|
||||
background 160ms var(--easing-standard),
|
||||
border-color 160ms var(--easing-standard),
|
||||
color 160ms var(--easing-standard),
|
||||
box-shadow 160ms var(--easing-standard);
|
||||
}
|
||||
|
||||
.primaryButton,
|
||||
.secondaryButton,
|
||||
.wizardCloseButton {
|
||||
padding: 0 var(--space-4);
|
||||
}
|
||||
|
||||
.primaryButton {
|
||||
border: 1px solid color-mix(in srgb, var(--bootstrap-accent) 72%, black 8%);
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
color-mix(in srgb, var(--bootstrap-accent) 88%, white 12%),
|
||||
color-mix(in srgb, var(--bootstrap-accent) 92%, black 8%)
|
||||
);
|
||||
color: var(--bootstrap-accent-contrast);
|
||||
box-shadow:
|
||||
inset 0 1px 0 color-mix(in srgb, white 28%, transparent),
|
||||
0 10px 24px color-mix(in srgb, var(--bootstrap-accent) 26%, transparent);
|
||||
}
|
||||
|
||||
.secondaryButton,
|
||||
.wizardCloseButton {
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-surface-secondary);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.primaryButton:hover,
|
||||
.secondaryButton:hover,
|
||||
.wizardCloseButton:hover,
|
||||
.wizardStepButton:hover {
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.primaryButton:hover,
|
||||
.primaryButton:focus-visible {
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
color-mix(in srgb, var(--bootstrap-accent) 84%, white 16%),
|
||||
color-mix(in srgb, var(--bootstrap-accent) 90%, black 10%)
|
||||
);
|
||||
border-color: color-mix(in srgb, var(--bootstrap-accent) 78%, black 10%);
|
||||
box-shadow:
|
||||
inset 0 1px 0 color-mix(in srgb, white 32%, transparent),
|
||||
0 14px 32px color-mix(in srgb, var(--bootstrap-accent) 30%, transparent);
|
||||
}
|
||||
|
||||
.primaryButton:disabled,
|
||||
.secondaryButton:disabled {
|
||||
opacity: 0.72;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.errorText {
|
||||
@include text-caption;
|
||||
color: var(--color-danger-text, var(--color-text));
|
||||
}
|
||||
|
||||
.wizardLayer {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: var(--z-modal);
|
||||
}
|
||||
|
||||
.wizardBackdrop {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border: 0;
|
||||
background: color-mix(in srgb, black 56%, transparent);
|
||||
backdrop-filter: blur(var(--blur-overlay));
|
||||
}
|
||||
|
||||
.wizardPanel {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
width: min(calc(100vw - (var(--space-6) * 2)), 72rem);
|
||||
max-height: calc(100dvh - (var(--space-6) * 2));
|
||||
margin: var(--space-6) auto;
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
padding: var(--space-4);
|
||||
border: 1px solid color-mix(in srgb, var(--color-border) 88%, transparent);
|
||||
border-radius: var(--radius-xl);
|
||||
background: color-mix(in srgb, var(--color-surface) 94%, var(--color-surface-elevated, var(--color-surface)) 6%);
|
||||
box-shadow: var(--shadow-strong);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.wizardHeader {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-4);
|
||||
}
|
||||
|
||||
.wizardHeaderCopy {
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.wizardBody {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(17rem, 20rem) minmax(0, 1fr);
|
||||
gap: var(--space-4);
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.wizardSidebar {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
.wizardSidebarSection {
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.wizardSteps {
|
||||
display: grid;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.wizardStepButton {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
align-items: center;
|
||||
text-align: left;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
border: 1px solid color-mix(in srgb, var(--color-border) 88%, transparent);
|
||||
background: color-mix(in srgb, var(--color-surface-secondary) 84%, transparent);
|
||||
}
|
||||
|
||||
.wizardStepButton[data-active="true"] {
|
||||
border-color: color-mix(in srgb, var(--bootstrap-accent) 42%, transparent);
|
||||
background: color-mix(in srgb, var(--bootstrap-accent) 10%, var(--color-surface));
|
||||
}
|
||||
|
||||
.wizardStepButton:disabled {
|
||||
opacity: 0.56;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.wizardStepIndex {
|
||||
width: calc(var(--control-size-md) - var(--space-2));
|
||||
height: calc(var(--control-size-md) - var(--space-2));
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: var(--radius-pill);
|
||||
background: color-mix(in srgb, var(--color-surface) 80%, transparent);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.wizardStepCopy {
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
gap: 0.125rem;
|
||||
}
|
||||
|
||||
.wizardStepCopy strong {
|
||||
@include text-label;
|
||||
}
|
||||
|
||||
.wizardStepCopy small {
|
||||
@include text-caption;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.wizardStepPanel {
|
||||
align-content: start;
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
@include respond-down(tablet) {
|
||||
.grid {
|
||||
.summaryGrid,
|
||||
.wizardBody {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.sectionHeader,
|
||||
.wizardHeader {
|
||||
display: grid;
|
||||
}
|
||||
}
|
||||
|
||||
@include respond-down(mobile) {
|
||||
@@ -155,4 +521,51 @@
|
||||
.workspaceTopBarCenter {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.summaryGrid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.wizardPanel {
|
||||
width: 100vw;
|
||||
max-height: 100dvh;
|
||||
margin: 0;
|
||||
padding: var(--space-3);
|
||||
padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.wizardHeader,
|
||||
.wizardBody,
|
||||
.wizardSidebar {
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.wizardSteps {
|
||||
grid-auto-flow: column;
|
||||
grid-auto-columns: minmax(10rem, 1fr);
|
||||
overflow-x: auto;
|
||||
padding-bottom: var(--space-1);
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.wizardStepButton {
|
||||
min-width: 10rem;
|
||||
}
|
||||
|
||||
.wizardFormActions {
|
||||
gap: var(--space-2);
|
||||
flex-direction: column-reverse;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.wizardFormActions .primaryButton {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.wizardFormActions .primaryButton,
|
||||
.wizardFormActions .secondaryButton,
|
||||
.wizardCloseButton {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,85 +1,582 @@
|
||||
// Path: Frontend/src/components/workspace-home/WorkspaceHome/WorkspaceHome.tsx
|
||||
|
||||
import { For, type JSX } from "solid-js";
|
||||
import { For, Show, createEffect, createMemo, createSignal, type JSX } from "solid-js";
|
||||
import { Portal } from "solid-js/web";
|
||||
import { createStore } from "solid-js/store";
|
||||
import { resolveAPIBase } from "../../../lib/api";
|
||||
import { ChevronLeft, ChevronRight } from "../../../lib/icons";
|
||||
import { activeProject, activeServer } from "../../shell/data/shell.data";
|
||||
import { useAppShellData } from "../../shell/data/app-shell.context";
|
||||
import styles from "./WorkspaceHome.module.scss";
|
||||
|
||||
type ShellCheckpointCard = {
|
||||
type BootstrapStepKey = "instance" | "mode" | "admin" | "structure";
|
||||
|
||||
type BootstrapStepDefinition = {
|
||||
id: BootstrapStepKey;
|
||||
title: string;
|
||||
copy: string;
|
||||
meta: string;
|
||||
buttonLabel: string;
|
||||
};
|
||||
|
||||
const shellCheckpointCards: readonly ShellCheckpointCard[] = [
|
||||
type BootstrapSubmissionState = {
|
||||
status: "idle" | "submitting" | "success" | "error";
|
||||
error: string;
|
||||
};
|
||||
|
||||
const bootstrapStepDefinitions: readonly BootstrapStepDefinition[] = [
|
||||
{
|
||||
title: "Server shell",
|
||||
copy: "Top bar, server rail, sidebar, and content viewport are now split into modular components.",
|
||||
meta: "Layout foundation",
|
||||
id: "instance",
|
||||
title: "Instance shape",
|
||||
buttonLabel: "Save and continue",
|
||||
},
|
||||
{
|
||||
title: "Presence foundation",
|
||||
copy: "The dock now distinguishes personal and organization servers, leaving clear space for future presence and server-aware controls.",
|
||||
meta: "Server foundation",
|
||||
id: "mode",
|
||||
title: "Server mode",
|
||||
buttonLabel: "Save and continue",
|
||||
},
|
||||
{
|
||||
title: "Next build target",
|
||||
copy: "You can now plug in auth state, server onboarding, and live presence without redesigning the whole frame.",
|
||||
meta: "Ready for v0.1.0 work",
|
||||
id: "admin",
|
||||
title: "Admin account",
|
||||
buttonLabel: "Save and continue",
|
||||
},
|
||||
{
|
||||
id: "structure",
|
||||
title: "Initial structure",
|
||||
buttonLabel: "Submit",
|
||||
},
|
||||
];
|
||||
|
||||
const defaultInstanceForm = {
|
||||
protocol: "http",
|
||||
access: "local",
|
||||
host: "localhost",
|
||||
} as const;
|
||||
|
||||
const defaultModeForm = {
|
||||
mode: "personal",
|
||||
name: "",
|
||||
} as const;
|
||||
|
||||
const defaultAdminForm = {
|
||||
displayName: "Admin",
|
||||
email: "admin@example.com",
|
||||
password: "",
|
||||
} as const;
|
||||
|
||||
const personalStructureDefaults = {
|
||||
departmentName: "Default",
|
||||
teamName: "Personal",
|
||||
} as const;
|
||||
|
||||
const organizationalStructureDefaults = {
|
||||
departmentName: "Department",
|
||||
teamName: "Team",
|
||||
} as const;
|
||||
|
||||
const defaultStructureForm = {
|
||||
...personalStructureDefaults,
|
||||
projectName: "Project",
|
||||
} as const;
|
||||
|
||||
const initialSubmissionState = (): BootstrapSubmissionState => ({
|
||||
status: "idle",
|
||||
error: "",
|
||||
});
|
||||
|
||||
const readResponseBody = async (response: Response): Promise<unknown> => {
|
||||
const raw = await response.text();
|
||||
|
||||
if (!raw.trim()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch {
|
||||
return raw;
|
||||
}
|
||||
};
|
||||
|
||||
const readResponseError = (step: BootstrapStepKey, data: unknown): string => {
|
||||
const fallback = `Bootstrap ${step} request failed.`;
|
||||
|
||||
if (typeof data === "string") {
|
||||
const message = data.trim();
|
||||
return message || fallback;
|
||||
}
|
||||
|
||||
if (!data || typeof data !== "object") {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const record = data as {
|
||||
error?: string;
|
||||
message?: string;
|
||||
requestId?: string;
|
||||
};
|
||||
const message = typeof record.message === "string" ? record.message.trim() : "";
|
||||
const errorCode = typeof record.error === "string" ? record.error.trim() : "";
|
||||
const requestId = typeof record.requestId === "string" ? record.requestId.trim() : "";
|
||||
|
||||
if (!message && !errorCode && !requestId) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
const details: string[] = [];
|
||||
|
||||
if (errorCode) {
|
||||
details.push(`code: ${errorCode}`);
|
||||
}
|
||||
|
||||
if (requestId) {
|
||||
details.push(`request: ${requestId}`);
|
||||
}
|
||||
|
||||
if (message && details.length > 0) {
|
||||
return `${message} (${details.join(", ")})`;
|
||||
}
|
||||
|
||||
if (message) {
|
||||
return message;
|
||||
}
|
||||
|
||||
return `${fallback} (${details.join(", ")})`;
|
||||
};
|
||||
|
||||
type WorkspaceHomeProps = {
|
||||
sidebarCollapsed: boolean;
|
||||
onToggleSidebarCollapse: () => void;
|
||||
};
|
||||
|
||||
export const WorkspaceHome = (props: WorkspaceHomeProps): JSX.Element => {
|
||||
const sidebarToggleLabel = (): string => (props.sidebarCollapsed ? "Expand left workspace sidebar" : "Collapse left workspace sidebar");
|
||||
const breadcrumb = (): string => `${activeServer.name} / ${activeProject.name} / Home`;
|
||||
const appShellData = useAppShellData();
|
||||
const [instanceForm, setInstanceForm] = createStore({ ...defaultInstanceForm });
|
||||
const [modeForm, setModeForm] = createStore({ ...defaultModeForm });
|
||||
const [adminForm, setAdminForm] = createStore({ ...defaultAdminForm });
|
||||
const [structureForm, setStructureForm] = createStore({ ...defaultStructureForm });
|
||||
const [stepState, setStepState] = createStore<Record<BootstrapStepKey, BootstrapSubmissionState>>({
|
||||
instance: initialSubmissionState(),
|
||||
mode: initialSubmissionState(),
|
||||
admin: initialSubmissionState(),
|
||||
structure: initialSubmissionState(),
|
||||
});
|
||||
const [isBootstrapStateResolved, setIsBootstrapStateResolved] = createSignal(false);
|
||||
const [isBootstrapComplete, setIsBootstrapComplete] = createSignal(false);
|
||||
const [isWizardOpen, setIsWizardOpen] = createSignal(false);
|
||||
const [currentStepIndex, setCurrentStepIndex] = createSignal(0);
|
||||
|
||||
createEffect(() => {
|
||||
if (modeForm.mode === "personal") {
|
||||
setStructureForm("departmentName", personalStructureDefaults.departmentName);
|
||||
setStructureForm("teamName", personalStructureDefaults.teamName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (structureForm.departmentName === personalStructureDefaults.departmentName) {
|
||||
setStructureForm("departmentName", organizationalStructureDefaults.departmentName);
|
||||
}
|
||||
|
||||
if (structureForm.teamName === personalStructureDefaults.teamName) {
|
||||
setStructureForm("teamName", organizationalStructureDefaults.teamName);
|
||||
}
|
||||
});
|
||||
|
||||
createEffect(() => {
|
||||
const shellStatus = appShellData.status();
|
||||
|
||||
if (shellStatus === "idle" || shellStatus === "loading") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shellStatus !== "success") {
|
||||
return;
|
||||
}
|
||||
|
||||
const installationAccessor = appShellData.installation;
|
||||
const installation = typeof installationAccessor === "function" ? installationAccessor() : undefined;
|
||||
const isPersistedBootstrap = installation?.isBootstrapped ?? false;
|
||||
|
||||
if (!isPersistedBootstrap) {
|
||||
resetWizardState();
|
||||
}
|
||||
|
||||
setIsBootstrapComplete(isPersistedBootstrap);
|
||||
setIsWizardOpen(!isPersistedBootstrap);
|
||||
setIsBootstrapStateResolved(true);
|
||||
});
|
||||
|
||||
const sidebarToggleLabel = (): string =>
|
||||
props.sidebarCollapsed ? "Expand left workspace sidebar" : "Collapse left workspace sidebar";
|
||||
const breadcrumb = (): string => `${appShellData.activeServer().name} / ${appShellData.activeProject().name} / Home`;
|
||||
const apiBase = (): string => resolveAPIBase();
|
||||
const bootstrapTargetLabel = (): string =>
|
||||
modeForm.mode === "personal" ? "Personal server" : "Organization server";
|
||||
const bootstrapNamePlaceholder = (): string =>
|
||||
modeForm.mode === "personal" ? "Personal server name" : "Organization server name";
|
||||
const currentStep = createMemo<BootstrapStepDefinition>(
|
||||
() => bootstrapStepDefinitions[currentStepIndex()] ?? bootstrapStepDefinitions[0]!,
|
||||
);
|
||||
const currentStepState = createMemo<BootstrapSubmissionState>(() => stepState[currentStep().id]);
|
||||
const isFirstStep = (): boolean => currentStepIndex() === 0;
|
||||
const isLastStep = (): boolean => currentStepIndex() === bootstrapStepDefinitions.length - 1;
|
||||
const canDismissWizard = (): boolean => isBootstrapComplete();
|
||||
|
||||
const resetWizardState = (): void => {
|
||||
setInstanceForm({ ...defaultInstanceForm });
|
||||
setModeForm({ ...defaultModeForm });
|
||||
setAdminForm({ ...defaultAdminForm });
|
||||
setStructureForm({ ...defaultStructureForm });
|
||||
setStepState({
|
||||
instance: initialSubmissionState(),
|
||||
mode: initialSubmissionState(),
|
||||
admin: initialSubmissionState(),
|
||||
structure: initialSubmissionState(),
|
||||
});
|
||||
setCurrentStepIndex(0);
|
||||
};
|
||||
|
||||
const submitStep = async (step: BootstrapStepKey, payload: unknown): Promise<boolean> => {
|
||||
setStepState(step, { status: "submitting", error: "" });
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiBase()}/bootstrap/steps/${step}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
const data = await readResponseBody(response);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(readResponseError(step, data));
|
||||
}
|
||||
|
||||
setStepState(step, {
|
||||
status: "success",
|
||||
error: "",
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
setStepState(step, {
|
||||
status: "error",
|
||||
error: error instanceof Error ? error.message : `Bootstrap ${step} request failed.`,
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const payloadForStep = (step: BootstrapStepKey): unknown => {
|
||||
switch (step) {
|
||||
case "instance":
|
||||
return instanceForm;
|
||||
case "mode":
|
||||
return modeForm;
|
||||
case "admin":
|
||||
return adminForm;
|
||||
case "structure":
|
||||
return structureForm;
|
||||
}
|
||||
};
|
||||
|
||||
const submitCurrentStep = async (): Promise<void> => {
|
||||
const step = currentStep().id;
|
||||
const didSucceed = await submitStep(step, payloadForStep(step));
|
||||
|
||||
if (!didSucceed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLastStep()) {
|
||||
await appShellData.reload();
|
||||
const installationAccessor = appShellData.installation;
|
||||
const installation = typeof installationAccessor === "function" ? installationAccessor() : undefined;
|
||||
const isPersistedBootstrap = installation?.isBootstrapped ?? false;
|
||||
|
||||
setIsBootstrapComplete(isPersistedBootstrap);
|
||||
setIsWizardOpen(!isPersistedBootstrap);
|
||||
setIsBootstrapStateResolved(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentStepIndex((index) => Math.min(index + 1, bootstrapStepDefinitions.length - 1));
|
||||
};
|
||||
|
||||
const handleCurrentStepSubmit: JSX.EventHandler<HTMLFormElement, SubmitEvent> = (event): void => {
|
||||
event.preventDefault();
|
||||
void submitCurrentStep();
|
||||
};
|
||||
|
||||
const statusLabel = (state: BootstrapSubmissionState): string => {
|
||||
switch (state.status) {
|
||||
case "submitting":
|
||||
return "Sending";
|
||||
case "success":
|
||||
return "Saved";
|
||||
case "error":
|
||||
return "Request failed";
|
||||
default:
|
||||
return "Ready";
|
||||
}
|
||||
};
|
||||
|
||||
const stepStatusLabel = (step: BootstrapStepDefinition): string => {
|
||||
const state = stepState[step.id];
|
||||
|
||||
if (state.status === "success") {
|
||||
return "Done";
|
||||
}
|
||||
|
||||
if (state.status === "error") {
|
||||
return "Needs retry";
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
return (
|
||||
<main class={styles.viewport} data-ui="workspace-home">
|
||||
<div class={styles.workspaceTopBar} data-slot="workspace-home-top-bar">
|
||||
<div class={styles.workspaceTopBarStart} data-slot="workspace-home-top-bar-start">
|
||||
<button
|
||||
type="button"
|
||||
class={styles.workspaceCollapseButton}
|
||||
aria-label={sidebarToggleLabel()}
|
||||
title={sidebarToggleLabel()}
|
||||
data-slot="workspace-home-sidebar-toggle"
|
||||
onClick={props.onToggleSidebarCollapse}
|
||||
>
|
||||
{props.sidebarCollapsed ? <ChevronRight size={16} strokeWidth={2} /> : <ChevronLeft size={16} strokeWidth={2} />}
|
||||
</button>
|
||||
<>
|
||||
<main class={styles.viewport} data-ui="workspace-home">
|
||||
<div class={styles.workspaceTopBar} data-slot="workspace-home-top-bar">
|
||||
<div class={styles.workspaceTopBarStart} data-slot="workspace-home-top-bar-start">
|
||||
<button
|
||||
type="button"
|
||||
class={styles.workspaceCollapseButton}
|
||||
aria-label={sidebarToggleLabel()}
|
||||
title={sidebarToggleLabel()}
|
||||
data-slot="workspace-home-sidebar-toggle"
|
||||
onClick={props.onToggleSidebarCollapse}
|
||||
>
|
||||
{props.sidebarCollapsed ? <ChevronRight size={16} strokeWidth={2} /> : <ChevronLeft size={16} strokeWidth={2} />}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class={styles.workspaceTopBarCenter} data-slot="workspace-home-top-bar-center">
|
||||
<span class={styles.workspaceBreadcrumb}>{breadcrumb()}</span>
|
||||
</div>
|
||||
|
||||
<div class={styles.workspaceTopBarEnd} data-slot="workspace-home-top-bar-end" aria-hidden="true" />
|
||||
</div>
|
||||
|
||||
<div class={styles.workspaceTopBarCenter} data-slot="workspace-home-top-bar-center">
|
||||
<span class={styles.workspaceBreadcrumb}>{breadcrumb()}</span>
|
||||
<section class={styles.hero} data-slot="workspace-home-hero">
|
||||
<h1 class={styles.title}>{isBootstrapComplete() ? appShellData.activeServer().name : bootstrapTargetLabel()}</h1>
|
||||
<Show when={isBootstrapStateResolved() && !isBootstrapComplete()}>
|
||||
<div class={styles.heroActions}>
|
||||
<button type="button" class={styles.primaryButton} onClick={(): void => setIsWizardOpen(true)}>
|
||||
Open bootstrap wizard
|
||||
</button>
|
||||
</div>
|
||||
</Show>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<Show when={isBootstrapStateResolved() && isWizardOpen()}>
|
||||
<Portal>
|
||||
<div class={styles.wizardLayer} data-ui="bootstrap-wizard" data-step={currentStep().id}>
|
||||
<div class={styles.wizardBackdrop} aria-hidden="true" />
|
||||
|
||||
<section class={styles.wizardPanel} role="dialog" aria-modal="true" aria-labelledby="bootstrap-wizard-title" data-slot="bootstrap-wizard-panel">
|
||||
<header class={styles.wizardHeader} data-slot="bootstrap-wizard-header">
|
||||
<div class={styles.wizardHeaderCopy}>
|
||||
<h2 id="bootstrap-wizard-title" class={styles.wizardTitle}>
|
||||
Bootstrap {bootstrapTargetLabel()}
|
||||
</h2>
|
||||
</div>
|
||||
<Show when={canDismissWizard()}>
|
||||
<button type="button" class={styles.wizardCloseButton} onClick={(): void => setIsWizardOpen(false)}>
|
||||
Close
|
||||
</button>
|
||||
</Show>
|
||||
</header>
|
||||
|
||||
<div class={styles.wizardBody}>
|
||||
<aside class={styles.wizardSidebar} data-slot="bootstrap-wizard-sidebar">
|
||||
<nav class={styles.wizardSteps} aria-label="Bootstrap steps">
|
||||
<For each={bootstrapStepDefinitions}>
|
||||
{(step, index): JSX.Element => (
|
||||
<button
|
||||
type="button"
|
||||
class={styles.wizardStepButton}
|
||||
data-active={step.id === currentStep().id ? "true" : "false"}
|
||||
disabled={index() > currentStepIndex()}
|
||||
onClick={(): void => {
|
||||
if (index() <= currentStepIndex()) {
|
||||
setCurrentStepIndex(index());
|
||||
}
|
||||
}}
|
||||
>
|
||||
<span class={styles.wizardStepIndex}>{index() + 1}</span>
|
||||
<span class={styles.wizardStepCopy}>
|
||||
<strong>{step.title}</strong>
|
||||
<Show when={stepStatusLabel(step)}>
|
||||
<small>{stepStatusLabel(step)}</small>
|
||||
</Show>
|
||||
</span>
|
||||
</button>
|
||||
)}
|
||||
</For>
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
<div class={styles.wizardStepPanel} data-slot="bootstrap-wizard-step-panel">
|
||||
<div class={styles.sectionHeader}>
|
||||
<div>
|
||||
<span class={styles.wizardStepEyebrow}>{`Step ${currentStepIndex() + 1} of ${bootstrapStepDefinitions.length}`}</span>
|
||||
<h3 class={styles.sectionTitle}>{currentStep().title}</h3>
|
||||
</div>
|
||||
<div class={styles.statusBadge} data-status={currentStepState().status}>{statusLabel(currentStepState())}</div>
|
||||
</div>
|
||||
|
||||
<div class={styles.workspaceTopBarEnd} data-slot="workspace-home-top-bar-end" aria-hidden="true" />
|
||||
</div>
|
||||
<form class={styles.form} onSubmit={handleCurrentStepSubmit}>
|
||||
<Show when={currentStep().id === "instance"}>
|
||||
<>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Protocol</span>
|
||||
<select value={instanceForm.protocol} onInput={(event): void => setInstanceForm("protocol", event.currentTarget.value)}>
|
||||
<option value="http">http</option>
|
||||
<option value="https">https</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Access</span>
|
||||
<select value={instanceForm.access} onInput={(event): void => setInstanceForm("access", event.currentTarget.value)}>
|
||||
<option value="local">local</option>
|
||||
<option value="remote">remote</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Host</span>
|
||||
<input
|
||||
type="text"
|
||||
value={instanceForm.host}
|
||||
onInput={(event): void => setInstanceForm("host", event.currentTarget.value)}
|
||||
placeholder="localhost or app.example.com"
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
</Show>
|
||||
|
||||
<section class={styles.hero} data-slot="workspace-home-hero">
|
||||
<span class={styles.eyebrow}>Server home</span>
|
||||
<h1 class={styles.title}>{activeServer.name} is ready for its first real shell.</h1>
|
||||
<p class={styles.description}>
|
||||
This is the barebone app frame for v0.1.0 — enough structure to start building a real self-hosted server experience on top of the backend core.
|
||||
</p>
|
||||
</section>
|
||||
<Show when={currentStep().id === "mode"}>
|
||||
<>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Mode</span>
|
||||
<select value={modeForm.mode} onInput={(event): void => setModeForm("mode", event.currentTarget.value)}>
|
||||
<option value="personal">personal</option>
|
||||
<option value="organizational">organizational</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Server name</span>
|
||||
<input
|
||||
type="text"
|
||||
value={modeForm.name}
|
||||
required
|
||||
onInput={(event): void => setModeForm("name", event.currentTarget.value)}
|
||||
placeholder={bootstrapNamePlaceholder()}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
</Show>
|
||||
|
||||
<section class={styles.grid} aria-label="Shell checkpoints" data-slot="workspace-home-grid">
|
||||
<For each={shellCheckpointCards}>
|
||||
{(card): JSX.Element => (
|
||||
<article class={styles.card} data-slot="workspace-home-card">
|
||||
<h2 class={styles.cardTitle}>{card.title}</h2>
|
||||
<p class={styles.cardCopy}>{card.copy}</p>
|
||||
<span class={styles.cardMeta}>{card.meta}</span>
|
||||
</article>
|
||||
)}
|
||||
</For>
|
||||
</section>
|
||||
</main>
|
||||
<Show when={currentStep().id === "admin"}>
|
||||
<>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Display name</span>
|
||||
<input
|
||||
type="text"
|
||||
value={adminForm.displayName}
|
||||
onInput={(event): void => setAdminForm("displayName", event.currentTarget.value)}
|
||||
placeholder="Admin"
|
||||
/>
|
||||
</label>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Email</span>
|
||||
<input
|
||||
type="email"
|
||||
value={adminForm.email}
|
||||
onInput={(event): void => setAdminForm("email", event.currentTarget.value)}
|
||||
placeholder="admin@example.com"
|
||||
/>
|
||||
</label>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Password</span>
|
||||
<input
|
||||
type="password"
|
||||
value={adminForm.password}
|
||||
onInput={(event): void => setAdminForm("password", event.currentTarget.value)}
|
||||
placeholder="Create a strong password"
|
||||
/>
|
||||
<small class={styles.fieldHelp}>
|
||||
Use at least 12 characters with uppercase, lowercase, numbers, and symbols.
|
||||
</small>
|
||||
</label>
|
||||
</>
|
||||
</Show>
|
||||
|
||||
<Show when={currentStep().id === "structure"}>
|
||||
<>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Department</span>
|
||||
<input
|
||||
type="text"
|
||||
value={structureForm.departmentName}
|
||||
disabled={modeForm.mode === "personal"}
|
||||
onInput={(event): void => setStructureForm("departmentName", event.currentTarget.value)}
|
||||
placeholder={organizationalStructureDefaults.departmentName}
|
||||
/>
|
||||
</label>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Team</span>
|
||||
<input
|
||||
type="text"
|
||||
value={structureForm.teamName}
|
||||
disabled={modeForm.mode === "personal"}
|
||||
onInput={(event): void => setStructureForm("teamName", event.currentTarget.value)}
|
||||
placeholder={organizationalStructureDefaults.teamName}
|
||||
/>
|
||||
</label>
|
||||
<label class={styles.field}>
|
||||
<span class={styles.fieldLabel}>Project</span>
|
||||
<input
|
||||
type="text"
|
||||
value={structureForm.projectName}
|
||||
onInput={(event): void => setStructureForm("projectName", event.currentTarget.value)}
|
||||
placeholder="Moku"
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
</Show>
|
||||
|
||||
<div class={styles.wizardFormActions}>
|
||||
<button
|
||||
type="button"
|
||||
class={styles.secondaryButton}
|
||||
disabled={isFirstStep()}
|
||||
onClick={(): void => setCurrentStepIndex((index) => Math.max(index - 1, 0))}
|
||||
>
|
||||
Back
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
class={styles.primaryButton}
|
||||
disabled={currentStepState().status === "submitting"}
|
||||
>
|
||||
{currentStep().buttonLabel}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<Show when={currentStepState().error}>
|
||||
<p class={styles.errorText}>{currentStepState().error}</p>
|
||||
</Show>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</Portal>
|
||||
</Show>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
8
Frontend/src/global.d.ts
vendored
8
Frontend/src/global.d.ts
vendored
@@ -1,3 +1,11 @@
|
||||
// Path: Frontend/src/global.d.ts
|
||||
|
||||
/// <reference types="@solidjs/start/env" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_API_BASE_URL?: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
|
||||
11
Frontend/src/lib/api.ts
Normal file
11
Frontend/src/lib/api.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
// Path: Frontend/src/lib/api.ts
|
||||
|
||||
export const resolveAPIBase = (): string => {
|
||||
const configuredBase = import.meta.env.VITE_API_BASE_URL?.trim();
|
||||
|
||||
if (!configuredBase) {
|
||||
return "/v1";
|
||||
}
|
||||
|
||||
return configuredBase.replace(/\/$/, "");
|
||||
};
|
||||
@@ -9,10 +9,22 @@ const extraAllowedHosts = (process.env.ALLOWED_HOSTS ?? "")
|
||||
.map((host) => host.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
const backendAPIport = process.env.BACKEND_API_PORT?.trim() || "8081";
|
||||
const devAPIProxyTarget =
|
||||
process.env.FRONTEND_API_PROXY_TARGET?.trim() ||
|
||||
process.env.VITE_DEV_PROXY_TARGET?.trim() ||
|
||||
`http://api:${backendAPIport}`;
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [solidStart({ ssr: false })],
|
||||
server: {
|
||||
allowedHosts: ["localhost", ...extraAllowedHosts],
|
||||
proxy: {
|
||||
"/v1": {
|
||||
target: devAPIProxyTarget,
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
preview: {
|
||||
allowedHosts: ["localhost", ...extraAllowedHosts],
|
||||
|
||||
1
Justfile
1
Justfile
@@ -1,6 +1,7 @@
|
||||
set shell := ["bash", "-cu"]
|
||||
|
||||
mod local "Commands/Local"
|
||||
mod test "Commands/Test"
|
||||
|
||||
[default]
|
||||
help:
|
||||
|
||||
@@ -25,6 +25,15 @@ server {
|
||||
try_files $uri $uri/ $moku_bootstrap_document;
|
||||
}
|
||||
|
||||
location ^~ /v1/ {
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_pass http://api:8081;
|
||||
}
|
||||
|
||||
location /favicon.ico {
|
||||
try_files $uri =404;
|
||||
access_log off;
|
||||
|
||||
Reference in New Issue
Block a user