Merge ticket/022-edit-existing-metric-declarations
This commit is contained in:
@@ -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)?;
|
||||
|
||||
Reference in New Issue
Block a user