mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { filter, isArray, isNumber } from 'lodash';
|
|
|
|
import config from 'app/core/config';
|
|
import store from 'app/core/store';
|
|
|
|
export class ImpressionSrv {
|
|
constructor() {}
|
|
|
|
addDashboardImpression(dashboardId: number) {
|
|
const impressionsKey = this.impressionKey();
|
|
let impressions = [];
|
|
if (store.exists(impressionsKey)) {
|
|
impressions = JSON.parse(store.get(impressionsKey));
|
|
if (!isArray(impressions)) {
|
|
impressions = [];
|
|
}
|
|
}
|
|
|
|
impressions = impressions.filter((imp) => {
|
|
return dashboardId !== imp;
|
|
});
|
|
|
|
impressions.unshift(dashboardId);
|
|
|
|
if (impressions.length > 50) {
|
|
impressions.pop();
|
|
}
|
|
store.set(impressionsKey, JSON.stringify(impressions));
|
|
}
|
|
|
|
getDashboardOpened() {
|
|
let impressions = store.get(this.impressionKey()) || '[]';
|
|
|
|
impressions = JSON.parse(impressions);
|
|
|
|
impressions = filter(impressions, (el) => {
|
|
return isNumber(el);
|
|
});
|
|
|
|
return impressions;
|
|
}
|
|
|
|
impressionKey() {
|
|
return 'dashboard_impressions-' + config.bootData.user.orgId;
|
|
}
|
|
}
|
|
|
|
const impressionSrv = new ImpressionSrv();
|
|
export default impressionSrv;
|