Skip to content

Commit 2f67c6f

Browse files
Fix edit_task API to update entire task object
1 parent c207862 commit 2f67c6f

5 files changed

Lines changed: 105 additions & 12 deletions

File tree

meshwork/backend/core/graph.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ def get_all_tasks(self):
5959
return []
6060
return [self.graph.nodes[node]["task"] for node in self.graph.nodes]
6161

62-
def edit_task(self, task_id: str, fields: dict):
62+
def edit_task(self, task_id: str, task: Task):
6363
# TODO: take only the necessary fields from new_task
6464
"""Edit a task in the graph."""
65-
for key, value in fields.items():
66-
self.graph.nodes[task_id]["task"].key = value
65+
self.graph.nodes[task_id]["task"] = task
6766
self.set_blocked_tasks()
6867

6968
def connect_nodes(self, node_dependency: str, node_dependee: str):

meshwork/backend/core/task.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class Task(BaseModel):
3131
"""Task tags"""
3232
status: Status = Field(default=Status.TODO)
3333
"""Task status"""
34+
graph_id: str = Field(default="")
35+
"""Graph ID"""
3436
# completion_condition: Optional[CompletionCondition]
3537
# """Condition that need to be met for the task to be completed"""
3638
def __init__(self, **data):

meshwork/frontend/webapp/src/lib/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface Task {
77
users: string[];
88
tags: string[];
99
status: Status;
10+
graphId?: string;
1011
}
1112

1213
export enum Status {

meshwork/frontend/webapp/src/routes/graph/+page.svelte

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
id: task.id,
4949
type: 'task',
5050
position: { x: 100 + (index % 3) * 350, y: 100 + Math.floor(index / 3) * 200 },
51-
data: task
51+
data: { ...task, graphId: currentGraphId }
5252
}));
5353
5454
// Create a set of all existing node IDs for validation
@@ -118,6 +118,17 @@
118118
// Handle node updates here if needed
119119
console.log('Node changes:', changes);
120120
}
121+
122+
// Handle task updates from nodes
123+
async function onTaskUpdate(taskId, updatedData) {
124+
try {
125+
await api.updateTask(currentGraphId, taskId, updatedData);
126+
// Optionally reload tasks to ensure consistency
127+
// await loadTasks();
128+
} catch (error) {
129+
console.error('Failed to update task:', error);
130+
}
131+
}
121132
</script>
122133

123134
<div class="graph-container">

meshwork/frontend/webapp/src/routes/graph/TaskNode.svelte

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,69 @@
11
<script lang="ts">
22
import { useSvelteFlow, type NodeProps, Handle, Position } from '@xyflow/svelte';
3-
import { type Task, Status } from '$lib/api';
4-
import { Modal } from 'flowbite-svelte';
3+
import { type Task, Status, api } from '$lib/api';
4+
import { Modal, Button } from 'flowbite-svelte';
55
// import { transformWithEsbuild } from 'vite';
66
77
let { id, data }: NodeProps<Task> = $props();
88
let { updateNodeData } = useSvelteFlow();
99
10+
// Get graph ID from the data passed from parent
11+
let currentGraphId = data.graphId || 'abc123';
12+
1013
// Local state for editing
1114
let isEditing = $state(false);
1215
let editName = $state(data.name || '');
1316
let editDescription = $state(data.description || '');
1417
1518
let editModal = $state(false);
19+
let isSaving = $state(false);
20+
let errorMessage = $state('');
21+
22+
async function saveTask() {
23+
if (isSaving) return;
24+
25+
isSaving = true;
26+
errorMessage = '';
27+
28+
try {
29+
// Prepare the updated task data
30+
const updatedTask = {
31+
...data,
32+
name: data.name,
33+
description: data.description,
34+
tags:
35+
typeof data.tags === 'string'
36+
? data.tags
37+
.split(',')
38+
.map((t) => t.trim())
39+
.filter((t) => t)
40+
: data.tags,
41+
users:
42+
typeof data.users === 'string'
43+
? data.users
44+
.split(',')
45+
.map((u) => u.trim())
46+
.filter((u) => u)
47+
: data.users
48+
};
49+
50+
// Call the backend API
51+
const response = await api.updateTask(currentGraphId, id, updatedTask);
52+
53+
// Update the node data in the flow
54+
updateNodeData(id, updatedTask);
55+
56+
// Close the modal
57+
editModal = false;
58+
59+
console.log('Task updated successfully:', response);
60+
} catch (error) {
61+
console.error('Failed to update task:', error);
62+
errorMessage = 'Failed to save task. Please try again.';
63+
} finally {
64+
isSaving = false;
65+
}
66+
}
1667
1768
function toggleEdit() {
1869
if (isEditing) {
@@ -59,12 +110,41 @@
59110
<h3 class="task-title">{data.name || 'Unnamed Task'}</h3>
60111
<button class="edit-btn" onclick={() => (editModal = true)}> ✎ </button>
61112
<Modal title="Edit the task" bind:open={editModal} autoclose>
62-
<p class="text-base leading-relaxed text-gray-500 dark:text-gray-400">
63-
{data.name}
64-
</p>
65-
<p class="text-base leading-relaxed text-gray-500 dark:text-gray-400">
66-
{data.description}
67-
</p>
113+
<form class="flex flex-col space-y-2" onsubmit={saveTask}>
114+
{#if errorMessage}
115+
<div class="alert alert-error rounded bg-red-100 p-2 text-sm text-red-700">
116+
{errorMessage}
117+
</div>
118+
{/if}
119+
<input
120+
type="text"
121+
placeholder="Task name"
122+
class="input input-bordered w-full"
123+
bind:value={data.name}
124+
required
125+
/>
126+
<textarea
127+
bind:value={data.description}
128+
class="textarea textarea-bordered w-full"
129+
placeholder="Task description"
130+
rows="3"
131+
></textarea>
132+
<input
133+
type="text"
134+
placeholder="Tags (comma separated)"
135+
class="input input-bordered w-full"
136+
bind:value={data.tags}
137+
/>
138+
<input
139+
type="text"
140+
placeholder="Users (comma separated)"
141+
class="input input-bordered w-full"
142+
bind:value={data.users}
143+
/>
144+
<Button type="submit" class="w-full" disabled={isSaving}>
145+
{isSaving ? 'Saving...' : 'Save'}
146+
</Button>
147+
</form>
68148
</Modal>
69149
</div>
70150

0 commit comments

Comments
 (0)