Merge ticket/022-edit-existing-metric-declarations

This commit is contained in:
Hugh Kaznowski
2026-09-05 19:41:59 +01:00
5 changed files with 467 additions and 21 deletions
+25
View File
@@ -557,6 +557,31 @@ impl ProfileStore {
Ok(())
}
/// Same as `record_metric_declaration`, for an in-place edit that may rename the metric: drops any persisted record under `old_name` first (when it differs from the new name) so a rename doesn't leave a stale duplicate declaration behind, then upserts by the new name as usual.
pub fn record_metric_declaration_update(
&mut self,
store_path: &Path,
profile_name: &str,
old_name: &str,
request: &DeclareMetricRequest,
) -> Result<(), ProfileError> {
let profile = self
.profiles
.iter_mut()
.find(|p| p.name == profile_name)
.ok_or(ProfileError::NotFound)?;
if old_name != request.name {
profile.metrics.retain(|r| r.name != old_name);
}
let record: MetricDeclarationRecord = request.into();
match profile.metrics.iter_mut().find(|r| r.name == record.name) {
Some(existing) => *existing = record,
None => profile.metrics.push(record),
}
self.save(store_path)?;
Ok(())
}
/// Lists the dashboards saved on `profile_name`; fails with `NotFound` if it doesn't exist.
pub fn list_dashboards(&self, profile_name: &str) -> Result<&[Dashboard], ProfileError> {
let profile = self.get(profile_name).ok_or(ProfileError::NotFound)?;