diff --git a/mixin/dashboards/defaults.libsonnet b/mixin/dashboards/defaults.libsonnet index 5dff5f2648..57f6191249 100644 --- a/mixin/dashboards/defaults.libsonnet +++ b/mixin/dashboards/defaults.libsonnet @@ -14,10 +14,7 @@ local utils = import '../lib/utils.libsonnet'; // Automatically add a uid to each dashboard based on the base64 encoding // of the file name and set the timezone to be 'default'. grafanaDashboards:: { - local componentName = std.split(filename, '.')[0], - local componentParts = std.split(componentName, '_'), - local camelCase = utils.toCamelCase(componentParts), - local component = if std.length(componentParts) > 1 then camelCase else componentName, + local component = utils.sanitizeComponent(std.split(filename, '.')[0]), [filename]: grafanaDashboards[filename] { uid: std.md5(filename), diff --git a/mixin/lib/utils.libsonnet b/mixin/lib/utils.libsonnet index c114cb002e..ddf1e3a8c6 100644 --- a/mixin/lib/utils.libsonnet +++ b/mixin/lib/utils.libsonnet @@ -25,4 +25,8 @@ ), toCamelCase(parts): std.join('', [parts[0], self.firstCharUppercase(parts)]), + + componentParts(name): std.split(name, '_'), + + sanitizeComponent(name): if std.length(self.componentParts(name)) > 1 then self.toCamelCase(self.componentParts(name)) else name, }