Skip to content

Commit

Permalink
Use cluster_uuid as localStorage key.
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-jung committed Aug 25, 2017
1 parent 9c16578 commit 4edff41
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readdirSync, lstatSync } from 'fs';
import { resolve } from 'path';
import { init } from './server/init';
import { replaceInjectedVars } from './server/lib/replace_injected_vars';

export default function (kibana) {
const translations = (function getTranslations(translationsPath) {
Expand All @@ -24,7 +25,9 @@ export default function (kibana) {

chromeNavControls: [
'plugins/notification_center/nav_control'
]
],

replaceInjectedVars

},

Expand Down
6 changes: 3 additions & 3 deletions public/components/notification_center/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const module = uiModules.get('notification_center', []);

module.run(pollingNotifications);

module.service('NotificationCenter', () => {
const notifications = new StoredNotifications().load();
const config = new StoredConfig({
module.service('NotificationCenter', (clusterUuid) => {
const notifications = new StoredNotifications(clusterUuid).load();
const config = new StoredConfig(clusterUuid, {
pollingInterval: 10000,
lastPulledAt: Date.now()
}).load().save();
Expand Down
4 changes: 2 additions & 2 deletions public/components/notification_center/lib/stored_config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { has, get, set, isObject } from 'lodash';

export class StoredConfig {
constructor(defaultConfig = {}, key = 'KBN::NOTIFS::CONFIG') {
this.key = key;
constructor(key, defaultConfig = {}) {
this.key = `KBN::NOTIFS::CONFIG-${key}`;
this.config = defaultConfig;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { find, isArray, remove, chain, pick, defaults, union } from 'lodash';

const NOT_INSERTABLE_ERROR = new Error('StoredNotifications cannot insert directly. Please use `StoredNotifications.merge`.');
export class StoredNotifications extends Array {
constructor(key = 'KBN::NOTIFS') {
constructor(key) {
super();
this.key = key;
this.key = `KBN::NOTIFS-${key}`;

this.push = (...items) => {
throw NOT_INSERTABLE_ERROR;
Expand Down
10 changes: 10 additions & 0 deletions server/lib/replace_injected_vars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { extend } from 'lodash';

export async function replaceInjectedVars(originalInjectedVars, request, server) {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
return callWithRequest(request, 'info')
.then(resp => extend(originalInjectedVars, {
clusterUuid: resp.cluster_uuid
}));
};

0 comments on commit 4edff41

Please sign in to comment.