diff options
author | Viktor Vorona <viktor.vorona@sonarsource.com> | 2024-05-30 12:16:28 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-06-03 20:02:58 +0000 |
commit | 6ebfd2bff3689af4e2115f212668445d18d24676 (patch) | |
tree | 66b54e97c6af455246492d4c71829fff01349592 /server/sonar-web/src/main/js/api | |
parent | 411f1d1ae8b2c7128cabfa7a791bc76f5b2f944d (diff) | |
download | sonarqube-6ebfd2bff3689af4e2115f212668445d18d24676.tar.gz sonarqube-6ebfd2bff3689af4e2115f212668445d18d24676.zip |
SONAR-22224 Get rule activation data after change in rule list
Diffstat (limited to 'server/sonar-web/src/main/js/api')
5 files changed, 46 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/CodingRulesServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/CodingRulesServiceMock.ts index 1da59e24767..c180408a466 100644 --- a/server/sonar-web/src/main/js/api/mocks/CodingRulesServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/CodingRulesServiceMock.ts @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { HttpStatusCode } from 'axios'; -import { cloneDeep, countBy, pick, trim } from 'lodash'; +import { cloneDeep, countBy, isEqual, pick, trim } from 'lodash'; import { ComponentQualifier, Visibility } from '~sonar-aligned/types/component'; import { RuleDescriptionSections } from '../../apps/coding-rules/rule'; import { mapRestRuleToRule } from '../../apps/coding-rules/utils'; @@ -542,18 +542,33 @@ export default class CodingRulesServiceMock { ({ qProfile }) => qProfile === data.key, )!; activation.inherit = 'INHERITED'; - activation.prioritized = parentActivation?.prioritized ?? false; + activation.prioritizedRule = parentActivation?.prioritizedRule ?? false; activation.severity = parentActivation?.severity ?? 'MAJOR'; activation.params = parentParams; return this.reply(undefined); } + const currentActivation = this.rulesActivations[data.rule]?.find( + (a) => a.qProfile === data.key, + ); + if ( + currentActivation && + isEqual( + currentActivation.params, + Object.entries(data.params ?? {}).map(([key, value]) => ({ key, value })), + ) && + currentActivation.severity === data.severity && + currentActivation.prioritizedRule === data.prioritizedRule + ) { + return this.reply(undefined); + } + const nextActivations = [ mockRuleActivation({ qProfile: data.key, severity: data.severity, - prioritized: data.prioritized, + prioritizedRule: data.prioritizedRule, params: Object.entries(data.params ?? {}).map(([key, value]) => ({ key, value })), }), ]; @@ -566,7 +581,7 @@ export default class CodingRulesServiceMock { mockRuleActivation({ qProfile: profile.key, severity: data.severity, - prioritized: data.prioritized, + prioritizedRule: data.prioritizedRule, inherit: 'INHERITED', params: Object.entries(data.params ?? {}).map(([key, value]) => ({ key, value })), }), diff --git a/server/sonar-web/src/main/js/api/mocks/data/ids.ts b/server/sonar-web/src/main/js/api/mocks/data/ids.ts index 53e23bf638e..cd3250ac6e1 100644 --- a/server/sonar-web/src/main/js/api/mocks/data/ids.ts +++ b/server/sonar-web/src/main/js/api/mocks/data/ids.ts @@ -53,6 +53,7 @@ export const RULE_12 = 'rule12'; // Quality Profiles. export const QP_1 = 'p1'; +export const QP_2_Parent = 'p2parent'; export const QP_2 = 'p2'; export const QP_3 = 'p3'; export const QP_4 = 'p4'; diff --git a/server/sonar-web/src/main/js/api/mocks/data/qualityProfiles.ts b/server/sonar-web/src/main/js/api/mocks/data/qualityProfiles.ts index 677e9d4e04e..080f8e4b259 100644 --- a/server/sonar-web/src/main/js/api/mocks/data/qualityProfiles.ts +++ b/server/sonar-web/src/main/js/api/mocks/data/qualityProfiles.ts @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { mockQualityProfile } from '../../../helpers/testMocks'; -import { QP_1, QP_2, QP_3, QP_4, QP_5, QP_6 } from './ids'; +import { QP_1, QP_2, QP_2_Parent, QP_3, QP_4, QP_5, QP_6 } from './ids'; export function mockQualityProfilesList() { return [ @@ -30,12 +30,19 @@ export function mockQualityProfilesList() { actions: { edit: true }, }), mockQualityProfile({ + key: QP_2_Parent, + name: 'QP Bar Parent', + language: 'py', + languageName: 'Python', + }), + mockQualityProfile({ key: QP_2, name: 'QP Bar', language: 'py', languageName: 'Python', - parentKey: 'sonar_way', - parentName: 'Sonar Way', + isInherited: true, + parentKey: QP_2_Parent, + parentName: 'QP Bar Parent', }), mockQualityProfile({ key: QP_3, name: 'QP FooBar', language: 'java', languageName: 'Java' }), mockQualityProfile({ diff --git a/server/sonar-web/src/main/js/api/mocks/data/rules.ts b/server/sonar-web/src/main/js/api/mocks/data/rules.ts index 611db57e802..472a90d49ba 100644 --- a/server/sonar-web/src/main/js/api/mocks/data/rules.ts +++ b/server/sonar-web/src/main/js/api/mocks/data/rules.ts @@ -29,6 +29,7 @@ import { ADVANCED_RULE, QP_1, QP_2, + QP_2_Parent, QP_4, QP_5, QP_6, @@ -269,7 +270,19 @@ export function mockRulesActivationsInQP() { ], [RULE_7]: [mockRuleActivation({ qProfile: QP_2 })], [RULE_8]: [mockRuleActivation({ qProfile: QP_2 })], - [RULE_9]: [mockRuleActivation({ qProfile: QP_2, inherit: 'INHERITED' })], - [RULE_10]: [mockRuleActivation({ qProfile: QP_2, inherit: 'OVERRIDES', prioritized: true })], + [RULE_9]: [ + mockRuleActivation({ + qProfile: QP_2, + params: [ + { key: '1', value: '' }, + { key: '2', value: 'default value for key 2' }, + ], + inherit: 'INHERITED', + }), + ], + [RULE_10]: [ + mockRuleActivation({ qProfile: QP_2, inherit: 'OVERRIDES', prioritizedRule: true }), + mockRuleActivation({ qProfile: QP_2_Parent, severity: 'MINOR' }), + ], }; } diff --git a/server/sonar-web/src/main/js/api/quality-profiles.ts b/server/sonar-web/src/main/js/api/quality-profiles.ts index b150c9a5301..f3e0123c13d 100644 --- a/server/sonar-web/src/main/js/api/quality-profiles.ts +++ b/server/sonar-web/src/main/js/api/quality-profiles.ts @@ -323,7 +323,7 @@ export interface ActivateRuleParameters { reset?: boolean; rule: string; severity?: string; - prioritized?: boolean; + prioritizedRule?: boolean; } export function activateRule(data: ActivateRuleParameters) { |