feat: enhance model move functionality with cache entry updates

- Return cache entry data from model move operations for immediate UI updates
- Add recalculate_type parameter to update_single_model_cache for proper type adjustment
- Propagate cache entry through API layer to frontend MoveManager
- Enable virtual scroller to update moved items with new cache data
This commit is contained in:
Will Miao
2025-12-31 10:33:22 +08:00
parent 2b239c3747
commit 8120716cd8
4 changed files with 39 additions and 15 deletions

View File

@@ -936,7 +936,8 @@ export class BaseModelApiClient {
if (result.success) {
return {
original_file_path: result.original_file_path || filePath,
new_file_path: result.new_file_path
new_file_path: result.new_file_path,
cache_entry: result.cache_entry
};
}
return null;

View File

@@ -327,15 +327,22 @@ class MoveManager {
if (!isVisible) {
state.virtualScroller.removeItemByFilePath(result.original_file_path);
} else if (result.new_file_path !== result.original_file_path) {
} else {
const newFileNameWithExt = result.new_file_path.substring(result.new_file_path.lastIndexOf('/') + 1);
const baseFileName = newFileNameWithExt.substring(0, newFileNameWithExt.lastIndexOf('.'));
state.virtualScroller.updateSingleItem(result.original_file_path, {
const updateData = {
file_path: result.new_file_path,
file_name: baseFileName,
folder: newRelativeFolder
});
};
// Only update model_type if it's present in the cache_entry
if (result.cache_entry && result.cache_entry.model_type) {
updateData.model_type = result.cache_entry.model_type;
}
state.virtualScroller.updateSingleItem(result.original_file_path, updateData);
}
}
});
@@ -352,15 +359,21 @@ class MoveManager {
if (!isVisible) {
state.virtualScroller.removeItemByFilePath(this.currentFilePath);
} else {
// Update the model card even if it stays visible
const newFileNameWithExt = result.new_file_path.substring(result.new_file_path.lastIndexOf('/') + 1);
const baseFileName = newFileNameWithExt.substring(0, newFileNameWithExt.lastIndexOf('.'));
state.virtualScroller.updateSingleItem(this.currentFilePath, {
const updateData = {
file_path: result.new_file_path,
file_name: baseFileName,
folder: newRelativeFolder
});
};
// Only update model_type if it's present in the cache_entry
if (result.cache_entry && result.cache_entry.model_type) {
updateData.model_type = result.cache_entry.model_type;
}
state.virtualScroller.updateSingleItem(this.currentFilePath, updateData);
}
}
}