mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Feat: expose reporting complete notifications (#19283)
This PR is a pretty small change to the Reporting job complete notification service. It converts the actual code to a simple object, instead of a class that needs to be instantiated. This makes the notification service a singleton, and also exports it so it can be used in non-Angular applications. - Converts `reportingJobCompletionNotifications` factory to a singleton - Exports the underlying jobCompletionNotifications - Allow use in non-angular plugins Example use: ```js import { jobCompletionNotifications } from 'plugins/reporting/services/job_completion_notifications'; createReportingJob() // pseudo code function that returns a reporting job id .then(jobId => jobCompletionNotifications.add(jobId)); ```
This commit is contained in:
parent
9f813be3bf
commit
bf3c40542e
1 changed files with 16 additions and 13 deletions
|
@ -7,18 +7,19 @@
|
|||
import { uiModules } from 'ui/modules';
|
||||
import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY } from '../../common/constants';
|
||||
|
||||
class JobCompletionNotifications {
|
||||
|
||||
export const jobCompletionNotifications = {
|
||||
add(jobId) {
|
||||
const jobs = this.getAll();
|
||||
jobs.push(jobId);
|
||||
this._set(jobs);
|
||||
}
|
||||
},
|
||||
|
||||
getAll() {
|
||||
const sessionValue = sessionStorage.getItem(JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY);
|
||||
const sessionValue = sessionStorage.getItem(
|
||||
JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY
|
||||
);
|
||||
return sessionValue ? JSON.parse(sessionValue) : [];
|
||||
}
|
||||
},
|
||||
|
||||
remove(jobId) {
|
||||
const jobs = this.getAll();
|
||||
|
@ -29,14 +30,16 @@ class JobCompletionNotifications {
|
|||
|
||||
jobs.splice(index, 1);
|
||||
this._set(jobs);
|
||||
}
|
||||
},
|
||||
|
||||
_set(jobs) {
|
||||
sessionStorage.setItem(JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY, JSON.stringify(jobs));
|
||||
}
|
||||
}
|
||||
sessionStorage.setItem(
|
||||
JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY,
|
||||
JSON.stringify(jobs)
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
uiModules.get('xpack/reporting')
|
||||
.factory('reportingJobCompletionNotifications', function () {
|
||||
return new JobCompletionNotifications();
|
||||
});
|
||||
uiModules
|
||||
.get('xpack/reporting')
|
||||
.factory('reportingJobCompletionNotifications', () => jobCompletionNotifications);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue