Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
0eb2ca3f
Commit
0eb2ca3f
authored
Mar 18, 2019
by
Hugo Häggmark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: Cleaning up implicit anys in DashboardExporter and tests
progress: #14714
parent
d1e48a07
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
23 deletions
+61
-23
packages/grafana-ui/src/types/plugin.ts
+1
-0
public/app/core/config.ts
+1
-1
public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts
+10
-7
public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts
+47
-14
public/test/specs/helpers.ts
+2
-1
No files found.
packages/grafana-ui/src/types/plugin.ts
View file @
0eb2ca3f
...
...
@@ -91,6 +91,7 @@ export interface PluginMeta {
includes
:
PluginInclude
[];
// Datasource-specific
builtIn
?:
boolean
;
metrics
?:
boolean
;
tables
?:
boolean
;
logs
?:
boolean
;
...
...
public/app/core/config.ts
View file @
0eb2ca3f
...
...
@@ -13,7 +13,7 @@ export interface BuildInfo {
export
class
Settings
{
datasources
:
any
;
panels
:
PanelPlugin
[]
;
panels
:
{
[
key
:
string
]:
PanelPlugin
}
;
appSubUrl
:
string
;
windowTitlePrefix
:
string
;
buildInfo
:
BuildInfo
;
...
...
public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts
View file @
0eb2ca3f
...
...
@@ -4,13 +4,16 @@ jest.mock('app/core/store', () => {
};
});
// @ts-ignore
import
_
from
'lodash'
;
import
config
from
'app/core/config'
;
import
{
DashboardExporter
}
from
'./DashboardExporter'
;
import
{
DashboardModel
}
from
'../../state/DashboardModel'
;
import
{
DatasourceSrv
}
from
'app/features/plugins/datasource_srv'
;
import
{
PanelPlugin
}
from
'app/types'
;
describe
(
'given dashboard with repeated panels'
,
()
=>
{
let
dash
,
exported
;
let
dash
:
any
,
exported
:
any
;
beforeEach
(
done
=>
{
dash
=
{
...
...
@@ -89,25 +92,25 @@ describe('given dashboard with repeated panels', () => {
config
.
buildInfo
.
version
=
'3.0.2'
;
//Stubs test function calls
const
datasourceSrvStub
=
{
get
:
jest
.
fn
(
arg
=>
getStub
(
arg
))
}
;
const
datasourceSrvStub
=
({
get
:
jest
.
fn
(
arg
=>
getStub
(
arg
))
}
as
any
)
as
DatasourceSrv
;
config
.
panels
[
'graph'
]
=
{
id
:
'graph'
,
name
:
'Graph'
,
info
:
{
version
:
'1.1.0'
},
};
}
as
PanelPlugin
;
config
.
panels
[
'table'
]
=
{
id
:
'table'
,
name
:
'Table'
,
info
:
{
version
:
'1.1.1'
},
};
}
as
PanelPlugin
;
config
.
panels
[
'heatmap'
]
=
{
id
:
'heatmap'
,
name
:
'Heatmap'
,
info
:
{
version
:
'1.1.2'
},
};
}
as
PanelPlugin
;
dash
=
new
DashboardModel
(
dash
,
{});
const
exporter
=
new
DashboardExporter
(
datasourceSrvStub
);
...
...
@@ -213,7 +216,7 @@ describe('given dashboard with repeated panels', () => {
});
// Stub responses
const
stubs
=
[]
;
const
stubs
:
{
[
key
:
string
]:
{}
}
=
{}
;
stubs
[
'gfdb'
]
=
{
name
:
'gfdb'
,
meta
:
{
id
:
'testdb'
,
info
:
{
version
:
'1.2.1'
},
name
:
'TestDB'
},
...
...
@@ -249,6 +252,6 @@ stubs['-- Grafana --'] = {
},
};
function
getStub
(
arg
)
{
function
getStub
(
arg
:
string
)
{
return
Promise
.
resolve
(
stubs
[
arg
||
'gfdb'
]);
}
public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts
View file @
0eb2ca3f
import
config
from
'app/core/config'
;
// @ts-ignore
import
_
from
'lodash'
;
import
config
from
'app/core/config'
;
import
{
DashboardModel
}
from
'../../state/DashboardModel'
;
import
DatasourceSrv
from
'app/features/plugins/datasource_srv'
;
import
{
PanelModel
}
from
'app/features/dashboard/state'
;
import
{
PanelPlugin
}
from
'app/types/plugins'
;
interface
Input
{
name
:
string
;
type
:
string
;
label
:
string
;
value
:
any
;
description
:
string
;
}
interface
Requires
{
[
key
:
string
]:
{
type
:
string
;
id
:
string
;
name
:
string
;
version
:
string
;
};
}
interface
DataSources
{
[
key
:
string
]:
{
name
:
string
;
label
:
string
;
description
:
string
;
type
:
string
;
pluginId
:
string
;
pluginName
:
string
;
};
}
export
class
DashboardExporter
{
constructor
(
private
datasourceSrv
)
{}
constructor
(
private
datasourceSrv
:
DatasourceSrv
)
{}
makeExportable
(
dashboard
:
DashboardModel
)
{
// clean up repeated rows and panels,
...
...
@@ -18,19 +51,19 @@ export class DashboardExporter {
// undo repeat cleanup
dashboard
.
processRepeats
();
const
inputs
=
[];
const
requires
=
{};
const
datasources
=
{};
const
promises
=
[];
const
variableLookup
:
any
=
{};
const
inputs
:
Input
[]
=
[];
const
requires
:
Requires
=
{};
const
datasources
:
DataSources
=
{};
const
promises
:
Array
<
Promise
<
void
>>
=
[];
const
variableLookup
:
{
[
key
:
string
]:
any
}
=
{};
for
(
const
variable
of
saveModel
.
templating
.
list
)
{
variableLookup
[
variable
.
name
]
=
variable
;
}
const
templateizeDatasourceUsage
=
obj
=>
{
let
datasource
=
obj
.
datasource
;
let
datasourceVariable
=
null
;
const
templateizeDatasourceUsage
=
(
obj
:
any
)
=>
{
let
datasource
:
string
=
obj
.
datasource
;
let
datasourceVariable
:
any
=
null
;
// ignore data source properties that contain a variable
if
(
datasource
&&
datasource
.
indexOf
(
'$'
)
===
0
)
{
...
...
@@ -74,7 +107,7 @@ export class DashboardExporter {
);
};
const
processPanel
=
panel
=>
{
const
processPanel
=
(
panel
:
PanelModel
)
=>
{
if
(
panel
.
datasource
!==
undefined
)
{
templateizeDatasourceUsage
(
panel
);
}
...
...
@@ -87,7 +120,7 @@ export class DashboardExporter {
}
}
const
panelDef
=
config
.
panels
[
panel
.
type
];
const
panelDef
:
PanelPlugin
=
config
.
panels
[
panel
.
type
];
if
(
panelDef
)
{
requires
[
'panel'
+
panelDef
.
id
]
=
{
type
:
'panel'
,
...
...
@@ -135,7 +168,7 @@ export class DashboardExporter {
return
Promise
.
all
(
promises
)
.
then
(()
=>
{
_
.
each
(
datasources
,
(
value
,
ke
y
)
=>
{
_
.
each
(
datasources
,
(
value
:
an
y
)
=>
{
inputs
.
push
(
value
);
});
...
...
@@ -160,7 +193,7 @@ export class DashboardExporter {
}
// make inputs and requires a top thing
const
newObj
=
{};
const
newObj
:
{
[
key
:
string
]:
{}
}
=
{};
newObj
[
'__inputs'
]
=
inputs
;
newObj
[
'__requires'
]
=
_
.
sortBy
(
requires
,
[
'id'
]);
...
...
public/test/specs/helpers.ts
View file @
0eb2ca3f
...
...
@@ -3,6 +3,7 @@ import config from 'app/core/config';
import
*
as
dateMath
from
'app/core/utils/datemath'
;
import
{
angularMocks
,
sinon
}
from
'../lib/common'
;
import
{
PanelModel
}
from
'app/features/dashboard/state/PanelModel'
;
import
{
PanelPlugin
}
from
'app/types'
;
export
function
ControllerTestContext
(
this
:
any
)
{
const
self
=
this
;
...
...
@@ -62,7 +63,7 @@ export function ControllerTestContext(this: any) {
$rootScope
.
colors
.
push
(
'#'
+
i
);
}
config
.
panels
[
'test'
]
=
{
info
:
{}
};
config
.
panels
[
'test'
]
=
{
info
:
{}
}
as
PanelPlugin
;
self
.
ctrl
=
$controller
(
Ctrl
,
{
$scope
:
self
.
scope
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment