From d44769152acc168740a5156134687d82207f6d88 Mon Sep 17 00:00:00 2001 From: daminort Date: Fri, 17 Jan 2020 12:26:55 +0200 Subject: [PATCH] Improved indicators --- lib/modules/CommonUtils.js | 33 +++++++++++++++++++++++++-------- lib/modules/PluginManager.js | 19 ++++++++++++++----- spec/deepcode-spec.js | 4 +++- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/lib/modules/CommonUtils.js b/lib/modules/CommonUtils.js index 65c87dc..44e47b9 100644 --- a/lib/modules/CommonUtils.js +++ b/lib/modules/CommonUtils.js @@ -1,6 +1,6 @@ 'use babel'; -import { groupBy, isArray, keys } from 'lodash'; +import { groupBy, isArray, keys, values, find } from 'lodash'; import { DB } from './Database'; import { Store } from './Store'; @@ -74,7 +74,7 @@ export class CommonUtils { // Others ----------------------------------------------------------------------------------------------------------- static getIndicators() { - const { table } = Store.get(STORE_KEYS.analysisResults); + const { table, origin } = Store.get(STORE_KEYS.analysisResults); if (!isArray(table)) { return { info: 0, @@ -85,20 +85,37 @@ export class CommonUtils { }; } - const info = table.filter(row => row.severity === SEVERITY.info).length; - const warning = table.filter(row => row.severity === SEVERITY.warning).length; - const critical = table.filter(row => row.severity === SEVERITY.critical).length; + const { files, suggestions } = origin; + + const filesCount = keys(files).length; + const suggestionsList = values(suggestions); + const messagesGroups = groupBy(suggestionsList, suggestion => suggestion.id); + + let info = 0; + let warning = 0; + let critical = 0; + + keys(messagesGroups).forEach(id => { + const suggestion = find(suggestionsList, { id }); + if (!suggestion) { + return; + } + + const { severity } = suggestion; + + info += (severity === SEVERITY.info) ? 1 : 0; + warning += (severity === SEVERITY.warning) ? 1 : 0; + critical += (severity === SEVERITY.critical) ? 1 : 0; + }); const total = info + warning + critical; - const fileGroups = groupBy(table, (row) => row.fileName); - const files = keys(fileGroups).length; return { info, warning, critical, total, - files, + files: filesCount, }; } } diff --git a/lib/modules/PluginManager.js b/lib/modules/PluginManager.js index 340bdce..a58e2d5 100644 --- a/lib/modules/PluginManager.js +++ b/lib/modules/PluginManager.js @@ -114,15 +114,21 @@ class PluginManager { } openLoginDialog() { + if (this.loginDialog) { + return; + } const onClickLogin = async () => { - Store.set(STORE_KEYS.loginInProcess, true); if (this.loginDialog) { + Store.set(STORE_KEYS.loginInProcess, true); + this.loginDialog.dismiss(); this.loginDialog = null; + + await AuthModule.login(); } - await AuthModule.login(); + }; this.loginDialog = atom.notifications.addInfo(MESSAGES.loginPrompt, { @@ -254,14 +260,17 @@ class PluginManager { } didLogout() { + const loginInProcess = Store.get(STORE_KEYS.loginInProcess); + if (loginInProcess) { + return; + } + Store.setMany({ [STORE_KEYS.accountType]: '', [STORE_KEYS.sessionToken]: '', }); - if (!this.loginDialog) { - this.openLoginDialog(); - } + this.openLoginDialog(); } // Utils ------------------------------------------------------------------------------------------------------------ diff --git a/spec/deepcode-spec.js b/spec/deepcode-spec.js index 141a05c..d5d9f8e 100644 --- a/spec/deepcode-spec.js +++ b/spec/deepcode-spec.js @@ -69,7 +69,9 @@ describe('Deepcode Plugin tests', () => { const checkFiltersPromise = new Promise(resolve => { dcPackage.checkFilters(); - resolve(); + setTimeout(() => { + resolve(); + }, 100); }); waitsForPromise(() => checkFiltersPromise);