From 825e6bc45a0927a93f35e4d1660550b8b226aa90 Mon Sep 17 00:00:00 2001 From: scosman Date: Sun, 6 Oct 2024 21:32:15 -0400 Subject: [PATCH] Store the current project, so it can be used anywhere in the app. Including saving on creating. --- app/web_ui/src/lib/stores.ts | 3 +++ app/web_ui/src/routes/(app)/+layout.svelte | 2 ++ .../(setup)/create_project/edit_project.svelte | 4 +++- .../setup/(setup)/create_task/edit_task.svelte | 18 +++++++++++++++++- app/web_ui/src/routes/+layout.svelte | 11 +++++------ libs/studio/kiln_studio/project_management.py | 5 ++++- .../kiln_studio/test_project_management.py | 13 +++++++++++-- 7 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 app/web_ui/src/lib/stores.ts diff --git a/app/web_ui/src/lib/stores.ts b/app/web_ui/src/lib/stores.ts new file mode 100644 index 0000000..81e1cc4 --- /dev/null +++ b/app/web_ui/src/lib/stores.ts @@ -0,0 +1,3 @@ +import { writable } from "svelte/store" + +export const current_project = writable(null) diff --git a/app/web_ui/src/routes/(app)/+layout.svelte b/app/web_ui/src/routes/(app)/+layout.svelte index 1a28e63..54764e1 100644 --- a/app/web_ui/src/routes/(app)/+layout.svelte +++ b/app/web_ui/src/routes/(app)/+layout.svelte @@ -1,5 +1,6 @@
@@ -54,6 +55,7 @@
  • Sidebar Item 1
  • Sidebar Item 2
  • +
  • {$current_project}
  • diff --git a/app/web_ui/src/routes/(fullscreen)/setup/(setup)/create_project/edit_project.svelte b/app/web_ui/src/routes/(fullscreen)/setup/(setup)/create_project/edit_project.svelte index a019641..9484de1 100644 --- a/app/web_ui/src/routes/(fullscreen)/setup/(setup)/create_project/edit_project.svelte +++ b/app/web_ui/src/routes/(fullscreen)/setup/(setup)/create_project/edit_project.svelte @@ -1,5 +1,6 @@ @@ -27,6 +41,8 @@ submit_label="Create Task" on:submit={create_task} bind:warn_before_unload + bind:custom_error_message + bind:submitting >
    Part 1: Overview
    { - if ($page.url.pathname.startsWith("/setup")) { - // We're already on a setup page, no need to redirect - return - } - try { let res = await fetch("http://localhost:8757/api/settings") let data = await res.json() let projects = data["projects"] + let current_project_path = data["current_project"] if (!projects || projects.length === 0) { goto("/setup") + } else { + // Set the current_project to the current project, or first project + current_project.set(current_project_path || projects[0]) } } catch (e) { console.error("check_needs_setup error", e) diff --git a/libs/studio/kiln_studio/project_management.py b/libs/studio/kiln_studio/project_management.py index 4c471c4..c9a6ff5 100644 --- a/libs/studio/kiln_studio/project_management.py +++ b/libs/studio/kiln_studio/project_management.py @@ -67,5 +67,8 @@ async def create_project(project: dict): return JSONResponse( status_code=200, - content={"message": "Project created successfully"}, + content={ + "message": "Project created successfully", + "project_path": project_file, + }, ) diff --git a/libs/studio/kiln_studio/test_project_management.py b/libs/studio/kiln_studio/test_project_management.py index 623e577..1041cc8 100644 --- a/libs/studio/kiln_studio/test_project_management.py +++ b/libs/studio/kiln_studio/test_project_management.py @@ -10,6 +10,7 @@ from libs.core.kiln_ai.utils.config import Config from libs.studio.kiln_studio.project_management import ( connect_project_management, + default_project_path, ) @@ -37,7 +38,12 @@ def test_create_project_success(client): }, ) - assert response.json() == {"message": "Project created successfully"} + assert response.json() == { + "message": "Project created successfully", + "project_path": os.path.join( + default_project_path(), "Test Project", "project.json" + ), + } assert response.status_code == 200 @@ -93,7 +99,10 @@ def test_create_and_load_project(client): ) assert response.status_code == 200 - assert response.json() == {"message": "Project created successfully"} + assert response.json() == { + "message": "Project created successfully", + "project_path": os.path.join(temp_dir, "Test Project", "project.json"), + } # Verify the project file was created project_path = os.path.join(temp_dir, "Test Project")