mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
bad048b7ba
* Performance: Standardize lodash imports to use destructured members Changes lodash imports of the form `import x from 'lodash/x'` to `import { x } from 'lodash'` to reduce bundle size. * Remove unnecessary _ import from Graph component * Enforce lodash import style * Fix remaining lodash imports
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import store from 'app/core/store';
|
|
import { filter, isArray, isNumber } from 'lodash';
|
|
import config from 'app/core/config';
|
|
|
|
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;
|