From 48f2c5c02b74662e10577dd0c91013dd6b34aba9 Mon Sep 17 00:00:00 2001 From: Shantanu Raj Date: Wed, 11 Dec 2024 21:40:40 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Apply=20project=20and=20task=20e?= =?UTF-8?q?dits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/edit.rs | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/commands/edit.rs b/src/commands/edit.rs index b891977..305e468 100644 --- a/src/commands/edit.rs +++ b/src/commands/edit.rs @@ -1,5 +1,6 @@ use crate::api::client::ApiClient; -use crate::models; +use crate::constants::DEFAULT_ENTITY_ID; +use crate::models::{self, TimeEntry}; use crate::parcel::Parcel; use crate::picker; use colored::Colorize; @@ -18,12 +19,38 @@ impl EditCommand { match entities.running_time_entry() { None => println!("{}", "No time entry is running at the moment".yellow()), Some(running_time_entry) => { - let updated_time_entry = running_time_entry - .launch_in_editor() - .inspect_err(|e| { - eprintln!("{}", e.to_string().red()); - }) - .unwrap(); + let updated_time_entry = { + let workspace_id = running_time_entry.workspace_id; + + let new_entry = running_time_entry + .launch_in_editor() + .inspect_err(|e| { + eprintln!("{}", e.to_string().red()); + }) + .unwrap(); + + let project = new_entry.project.and_then(|project| { + if project.id == DEFAULT_ENTITY_ID { + entities.project_for_name(workspace_id, &project.name) + } else { + Some(project) + } + }); + + let task = new_entry.task.and_then(|task| { + if task.id == DEFAULT_ENTITY_ID { + entities.task_for_name(workspace_id, &task.name) + } else { + Some(task) + } + }); + + TimeEntry { + project, + task, + ..new_entry + } + }; let updated_entry_id = api_client .update_time_entry(updated_time_entry.clone())