Skip to content

Commit

Permalink
Extract to sanitizeComponent function
Browse files Browse the repository at this point in the history
Signed-off-by: Jéssica Lins <[email protected]>
  • Loading branch information
Jéssica Lins committed Nov 18, 2021
1 parent 406b5e3 commit 1c94807
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 1 addition & 4 deletions mixin/dashboards/defaults.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions mixin/lib/utils.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

0 comments on commit 1c94807

Please sign in to comment.