Skip to content

Commit

Permalink
Allow adding Tasks from menu
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Oct 9, 2024
1 parent 796425b commit f8a0d4c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
44 changes: 43 additions & 1 deletion app/web_ui/src/routes/(app)/select_tasks_menu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
})
goto(`/`, { replaceState: true })
close_menu()
}
function close_menu() {
// Close the menu
const menu = document.getElementById(id)
if (
Expand Down Expand Up @@ -123,6 +126,29 @@
</li>
{/each}
{/if}
<li class="">
<a
href="/setup/create_task?project_path={encodeURIComponent(
project.path,
)}"
>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools. https://www.svgrepo.com/svg/491465/plus-circle -->
<svg
class="w-4 h-4"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M1 12C1 5.92487 5.92487 1 12 1C18.0751 1 23 5.92487 23 12C23 18.0751 18.0751 23 12 23C5.92487 23 1 18.0751 1 12ZM12.5 5.5C13.0523 5.5 13.5 5.94772 13.5 6.5V10.5H17.5C18.0523 10.5 18.5 10.9477 18.5 11.5V12.5C18.5 13.0523 18.0523 13.5 17.5 13.5H13.5V17.5C13.5 18.0523 13.0523 18.5 12.5 18.5H11.5C10.9477 18.5 10.5 18.0523 10.5 17.5V13.5H6.5C5.94772 13.5 5.5 13.0523 5.5 12.5V11.5C5.5 10.9477 5.94772 10.5 6.5 10.5H10.5V6.5C10.5 5.94772 10.9477 5.5 11.5 5.5H12.5Z"
fill="#000000"
/>
</svg>
New Task
</a>
</li>
</ul>
</li>
{:else}
Expand Down Expand Up @@ -156,6 +182,22 @@
{/if}
{/each}
<li class="pt-4">
<a href="/setup/create_project" class="font-medium">+ New Project</a>
<a href="/setup/create_project">
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools. https://www.svgrepo.com/svg/491465/plus-circle -->
<svg
class="w-4 h-4"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M1 12C1 5.92487 5.92487 1 12 1C18.0751 1 23 5.92487 23 12C23 18.0751 18.0751 23 12 23C5.92487 23 1 18.0751 1 12ZM12.5 5.5C13.0523 5.5 13.5 5.94772 13.5 6.5V10.5H17.5C18.0523 10.5 18.5 10.9477 18.5 11.5V12.5C18.5 13.0523 18.0523 13.5 17.5 13.5H13.5V17.5C13.5 18.0523 13.0523 18.5 12.5 18.5H11.5C10.9477 18.5 10.5 18.0523 10.5 17.5V13.5H6.5C5.94772 13.5 5.5 13.0523 5.5 12.5V11.5C5.5 10.9477 5.94772 10.5 6.5 10.5H10.5V6.5C10.5 5.94772 10.9477 5.5 11.5 5.5H12.5Z"
fill="#000000"
/>
</svg>
New Project</a
>
</li>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
} from "$lib/utils/error_handlers"
import { ui_state } from "$lib/stores"
import { get } from "svelte/store"
import { browser } from "$app/environment"
// Prevents flash of complete UI if we're going to redirect
export let redirect_on_created: string | null = null
Expand All @@ -39,9 +40,22 @@
[task_name, task_description, task_instructions].some((value) => !!value) ||
task_requirements.some((req) => !!req.name || !!req.instruction)
let target_project_path: string | null = null
$: {
if (browser) {
target_project_path =
new URLSearchParams(window.location.search).get("project_path") ||
$current_project?.path ||
null
} else {
target_project_path = $current_project?.path || null
}
}
async function create_task() {
try {
if (!$current_project) {
if (!target_project_path) {
error = new KilnError(
"You must create a project before creating a task",
null,
Expand All @@ -64,7 +78,7 @@
schema_from_model(task_output_schema),
)
}
const project_path = $current_project?.path
const project_path = target_project_path
if (!project_path) {
throw new KilnError("Current project not found", null)
}
Expand All @@ -86,6 +100,7 @@
ui_state.set({
...get(ui_state),
current_task_id: data.id,
current_project_path: target_project_path,
})
if (redirect_on_created) {
goto(redirect_on_created)
Expand Down

0 comments on commit f8a0d4c

Please sign in to comment.