From 1c9480734d4991483fd08cbdb5dabbfffb319a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9ssica=20Lins?= Date: Thu, 18 Nov 2021 11:55:50 -0300 Subject: [PATCH] Extract to sanitizeComponent function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jéssica Lins --- mixin/dashboards/defaults.libsonnet | 5 +---- mixin/lib/utils.libsonnet | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) 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, }