diff options
author | Jeremy Davis <jeremy.davis@sonarsource.com> | 2019-08-30 17:31:15 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-09-24 20:21:17 +0200 |
commit | 3079907d1f13a509709c72a5dade87d129a4eb5c (patch) | |
tree | d3a79825cbf8ae25a3f473f5cfc07ffbfd36eba2 /server/sonar-web/src/main/js/apps/projectBaseline/utils.ts | |
parent | 45f8d835abdaf01287e2cf4a149b87ab2abfd156 (diff) | |
download | sonarqube-3079907d1f13a509709c72a5dade87d129a4eb5c.tar.gz sonarqube-3079907d1f13a509709c72a5dade87d129a4eb5c.zip |
SONAR-12430 Handle project baseline for Community Edition
Diffstat (limited to 'server/sonar-web/src/main/js/apps/projectBaseline/utils.ts')
-rw-r--r-- | server/sonar-web/src/main/js/apps/projectBaseline/utils.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/utils.ts b/server/sonar-web/src/main/js/apps/projectBaseline/utils.ts index afaa962b3dc..69b7cfabda0 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/utils.ts +++ b/server/sonar-web/src/main/js/apps/projectBaseline/utils.ts @@ -22,3 +22,44 @@ export function validateDays(days: string) { return !(days.length < 1 || isNaN(parsed) || parsed < 1 || String(parsed) !== days); } + +export function getSettingValue({ + analysis, + days, + type +}: { + analysis?: string; + days?: string; + type?: T.NewCodePeriodSettingType; +}) { + switch (type) { + case 'NUMBER_OF_DAYS': + return days; + case 'SPECIFIC_ANALYSIS': + return analysis; + default: + return undefined; + } +} + +export function validateSetting(state: { + analysis?: string; + currentSetting?: T.NewCodePeriodSettingType; + currentSettingValue?: string; + days: string; + selected?: T.NewCodePeriodSettingType; +}) { + const { analysis = '', currentSetting, currentSettingValue, days, selected } = state; + + const isChanged = + selected !== currentSetting || + (selected === 'NUMBER_OF_DAYS' && days !== currentSettingValue) || + (selected === 'SPECIFIC_ANALYSIS' && analysis !== currentSettingValue); + + const isValid = + selected === 'PREVIOUS_VERSION' || + (selected === 'SPECIFIC_ANALYSIS' && analysis.length > 0) || + (selected === 'NUMBER_OF_DAYS' && validateDays(days)); + + return { isChanged, isValid }; +} |