mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Add support for multiselect - Add filters param to Dimensions - Update existing tests - Add MultiSelect component - Add helper function to determine valid options - Update labels hook to account for custom values - Update go type - Add function to build valid filters string * Additional go tests - Ensure query targets are built correctly * Update DimensionFields frontend test - Corrently rerender components - Additional test for multiple labels selection - Better selection of options in react-select components * Fix lint issue * Reset filters when operator or dimension changes * Terminology * Update test * Add backend migration - Update types (deprecate Filter field) - Add migration logic - Update tests - Update dimension filters buliding * Add migration test code * Simplify some logic * Add frontend deprecation notice * Add frontend migration logic and migration tests * Update setting of filter values * Update DimensionFields test * Fix linting issues * PR comment updates - Remove unnecessary if/else condition - Don't set filter default value as queries should be migrated - Add comment explaining why sw operator only accepts one value - Remove unnecessary test for merging of old and new filters * Nit on terminology Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com> * Rename migrations for clarity Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package metrics
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/types"
|
|
)
|
|
|
|
func MigrateDimensionFilters(filters []types.AzureMonitorDimensionFilter) []types.AzureMonitorDimensionFilter {
|
|
var newFilters []types.AzureMonitorDimensionFilter
|
|
for _, filter := range filters {
|
|
newFilter := filter
|
|
// Ignore the deprecation check as this is a migration
|
|
// nolint:staticcheck
|
|
newFilter.Filter = nil
|
|
// If there is no old field and the new field is specified - append as this is valid
|
|
// nolint:staticcheck
|
|
if filter.Filter == nil && filter.Filters != nil {
|
|
newFilters = append(newFilters, newFilter)
|
|
} else {
|
|
// nolint:staticcheck
|
|
oldFilter := *filter.Filter
|
|
// If there is an old filter and no new ones then construct the new array and append
|
|
if filter.Filters == nil && oldFilter != "*" {
|
|
newFilter.Filters = []string{oldFilter}
|
|
// If both the new and old fields are specified (edge case) then construct the appropriate values
|
|
} else {
|
|
hasFilter := false
|
|
oldFilters := filter.Filters
|
|
for _, filterValue := range oldFilters {
|
|
if filterValue == oldFilter {
|
|
hasFilter = true
|
|
break
|
|
}
|
|
}
|
|
if !hasFilter && oldFilter != "*" {
|
|
oldFilters = append(oldFilters, oldFilter)
|
|
newFilter.Filters = oldFilters
|
|
}
|
|
}
|
|
newFilters = append(newFilters, newFilter)
|
|
}
|
|
}
|
|
return newFilters
|
|
}
|