Skip to content

Commit d9271d8

Browse files
authored
confirm grafana initialization (#107)
* window event to confirm initialization * grafana start up status events
1 parent bdff8a8 commit d9271d8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

public/app/fn_app.ts

+38
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,37 @@ if (process.env.NODE_ENV === 'development') {
106106
initDevFeatures();
107107
}
108108

109+
export declare type FNGrafanaStartupState = {
110+
isLoading: boolean;
111+
isError: boolean;
112+
error?: unknown;
113+
isIdeal: boolean;
114+
};
115+
116+
export const DefaultGrafanaStartupState: FNGrafanaStartupState = {
117+
isLoading: false,
118+
isError: false,
119+
isIdeal: true,
120+
};
121+
122+
const dispatchFnEvent = (info: FNGrafanaStartupState = DefaultGrafanaStartupState, ek = 'grafana-startup') => {
123+
window.dispatchEvent(
124+
new CustomEvent(ek, {
125+
detail: info,
126+
})
127+
);
128+
};
129+
109130
export class GrafanaApp {
110131
context!: GrafanaContextType;
111132

112133
async init() {
113134
try {
135+
dispatchFnEvent({
136+
isIdeal: false,
137+
isLoading: true,
138+
isError: false,
139+
});
114140
// Let iframe container know grafana has started loading
115141
parent.postMessage('GrafanaAppInit', '*');
116142

@@ -224,7 +250,19 @@ export class GrafanaApp {
224250
keybindings: keybindingsService,
225251
config,
226252
};
253+
254+
dispatchFnEvent({
255+
isLoading: false,
256+
isError: false,
257+
isIdeal: false,
258+
});
227259
} catch (error) {
260+
dispatchFnEvent({
261+
isLoading: false,
262+
isError: true,
263+
error,
264+
isIdeal: false,
265+
});
228266
console.error('Failed to start Grafana', error);
229267
window.__grafana_load_failed();
230268
} finally {

0 commit comments

Comments
 (0)