aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-web/src/main/js/helpers')
-rw-r--r--server/sonar-web/src/main/js/helpers/__tests__/request-test.ts3
-rw-r--r--server/sonar-web/src/main/js/helpers/component.ts4
-rw-r--r--server/sonar-web/src/main/js/helpers/constants.ts5
-rw-r--r--server/sonar-web/src/main/js/helpers/cookies.ts5
-rw-r--r--server/sonar-web/src/main/js/helpers/extensionsHandler.ts3
-rw-r--r--server/sonar-web/src/main/js/helpers/issues.ts31
-rw-r--r--server/sonar-web/src/main/js/helpers/l10n.ts3
-rw-r--r--server/sonar-web/src/main/js/helpers/measures.ts17
-rw-r--r--server/sonar-web/src/main/js/helpers/mocks/component.ts17
-rw-r--r--server/sonar-web/src/main/js/helpers/mocks/issues.ts3
-rw-r--r--server/sonar-web/src/main/js/helpers/mocks/permissions.ts5
-rw-r--r--server/sonar-web/src/main/js/helpers/mocks/quality-gates.ts3
-rw-r--r--server/sonar-web/src/main/js/helpers/mocks/users.ts4
-rw-r--r--server/sonar-web/src/main/js/helpers/periods.ts5
-rw-r--r--server/sonar-web/src/main/js/helpers/projectLinks.ts5
-rw-r--r--server/sonar-web/src/main/js/helpers/query.ts5
-rw-r--r--server/sonar-web/src/main/js/helpers/request.ts5
-rw-r--r--server/sonar-web/src/main/js/helpers/strings.ts5
-rw-r--r--server/sonar-web/src/main/js/helpers/testMocks.ts117
-rw-r--r--server/sonar-web/src/main/js/helpers/urls.ts7
-rw-r--r--server/sonar-web/src/main/js/helpers/users.ts8
21 files changed, 155 insertions, 105 deletions
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts
index 55818d0e7d9..89fab57bd62 100644
--- a/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts
+++ b/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts
@@ -20,6 +20,7 @@
/* eslint-disable no-await-in-loop */
+import { Dict } from '../../types/types';
import handleRequiredAuthentication from '../handleRequiredAuthentication';
import {
checkStatus,
@@ -345,7 +346,7 @@ describe('isSuccessStatus', () => {
});
});
-function mockResponse(headers: T.Dict<string> = {}, status = HttpStatus.Ok, value?: any): Response {
+function mockResponse(headers: Dict<string> = {}, status = HttpStatus.Ok, value?: any): Response {
const body = value && value instanceof Object ? JSON.stringify(value) : value;
const response = new Response(body, { headers, status });
response.json = jest.fn().mockResolvedValue(value);
diff --git a/server/sonar-web/src/main/js/helpers/component.ts b/server/sonar-web/src/main/js/helpers/component.ts
index c3820cb2a2d..7e702b2acbf 100644
--- a/server/sonar-web/src/main/js/helpers/component.ts
+++ b/server/sonar-web/src/main/js/helpers/component.ts
@@ -18,8 +18,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { ComponentMeasure, ComponentMeasureEnhanced } from '../types/types';
+
export function getComponentMeasureUniqueKey(
- component?: T.ComponentMeasure | T.ComponentMeasureEnhanced
+ component?: ComponentMeasure | ComponentMeasureEnhanced
) {
return component ? [component.key, component.branch].filter(s => !!s).join('/') : undefined;
}
diff --git a/server/sonar-web/src/main/js/helpers/constants.ts b/server/sonar-web/src/main/js/helpers/constants.ts
index 96f776c6af8..8ccab49087f 100644
--- a/server/sonar-web/src/main/js/helpers/constants.ts
+++ b/server/sonar-web/src/main/js/helpers/constants.ts
@@ -21,10 +21,11 @@ import { colors } from '../app/theme';
import { AlmKeys } from '../types/alm-settings';
import { ComponentQualifier } from '../types/component';
import { IssueScope, IssueType } from '../types/issues';
+import { RuleType } from '../types/types';
export const SEVERITIES = ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'];
export const STATUSES = ['OPEN', 'REOPENED', 'CONFIRMED', 'RESOLVED', 'CLOSED'];
-export const ISSUE_TYPES: T.IssueType[] = [
+export const ISSUE_TYPES: IssueType[] = [
IssueType.Bug,
IssueType.Vulnerability,
IssueType.CodeSmell,
@@ -34,7 +35,7 @@ export const SOURCE_SCOPES = [
{ scope: IssueScope.Main, qualifier: ComponentQualifier.File },
{ scope: IssueScope.Test, qualifier: ComponentQualifier.TestFile }
];
-export const RULE_TYPES: T.RuleType[] = ['BUG', 'VULNERABILITY', 'CODE_SMELL', 'SECURITY_HOTSPOT'];
+export const RULE_TYPES: RuleType[] = ['BUG', 'VULNERABILITY', 'CODE_SMELL', 'SECURITY_HOTSPOT'];
export const RULE_STATUSES = ['READY', 'BETA', 'DEPRECATED'];
export const CHART_COLORS_RANGE_PERCENT = [
diff --git a/server/sonar-web/src/main/js/helpers/cookies.ts b/server/sonar-web/src/main/js/helpers/cookies.ts
index d717044f4b0..3a4aef6b501 100644
--- a/server/sonar-web/src/main/js/helpers/cookies.ts
+++ b/server/sonar-web/src/main/js/helpers/cookies.ts
@@ -18,11 +18,12 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { memoize } from 'lodash';
+import { Dict } from '../types/types';
const parseCookies = memoize(
- (documentCookie: string): T.Dict<string> => {
+ (documentCookie: string): Dict<string> => {
const rawCookies = documentCookie.split('; ');
- const cookies: T.Dict<string> = {};
+ const cookies: Dict<string> = {};
rawCookies.forEach(candidate => {
const [key, value] = candidate.split('=');
cookies[key] = value;
diff --git a/server/sonar-web/src/main/js/helpers/extensionsHandler.ts b/server/sonar-web/src/main/js/helpers/extensionsHandler.ts
index 078cc9ca6e3..1af989fd0c2 100644
--- a/server/sonar-web/src/main/js/helpers/extensionsHandler.ts
+++ b/server/sonar-web/src/main/js/helpers/extensionsHandler.ts
@@ -20,11 +20,12 @@
// Do not import dependencies in this helper, to keep initial bundle load as small as possible
import { ExtensionRegistryEntry, ExtensionStartMethod } from '../types/extension';
+import { Dict } from '../types/types';
import { getEnhancedWindow } from './browser';
const WEB_ANALYTICS_EXTENSION = 'sq-web-analytics';
-const extensions: T.Dict<ExtensionRegistryEntry> = {};
+const extensions: Dict<ExtensionRegistryEntry> = {};
function registerExtension(key: string, start: ExtensionStartMethod, providesCSSFile = false) {
extensions[key] = { start, providesCSSFile };
diff --git a/server/sonar-web/src/main/js/helpers/issues.ts b/server/sonar-web/src/main/js/helpers/issues.ts
index 75d2dfb0c58..fb5ed0ec043 100644
--- a/server/sonar-web/src/main/js/helpers/issues.ts
+++ b/server/sonar-web/src/main/js/helpers/issues.ts
@@ -24,6 +24,7 @@ import SecurityHotspotIcon from '../components/icons/SecurityHotspotIcon';
import VulnerabilityIcon from '../components/icons/VulnerabilityIcon';
import { IssueType, RawIssue } from '../types/issues';
import { MetricKey } from '../types/metrics';
+import { Dict, FlowLocation, Issue, TextRange, UserBase } from '../types/types';
import { ISSUE_TYPES } from './constants';
interface Rule {}
@@ -33,17 +34,17 @@ interface Component {
name: string;
}
-export function sortByType<T extends Pick<T.Issue, 'type'>>(issues: T[]): T[] {
- return sortBy(issues, issue => ISSUE_TYPES.indexOf(issue.type));
+export function sortByType<T extends Pick<Issue, 'type'>>(issues: T[]): T[] {
+ return sortBy(issues, issue => ISSUE_TYPES.indexOf(issue.type as IssueType));
}
function injectRelational(
- issue: T.Dict<any>,
+ issue: Dict<any>,
source: any[] | undefined,
baseField: string,
lookupField: string
) {
- const newFields: T.Dict<any> = {};
+ const newFields: Dict<any> = {};
const baseValue = issue[baseField];
if (baseValue !== undefined && source !== undefined) {
const lookupValue = source.find(candidate => candidate[lookupField] === baseValue);
@@ -57,7 +58,7 @@ function injectRelational(
return newFields;
}
-function injectCommentsRelational(issue: RawIssue, users?: T.UserBase[]) {
+function injectCommentsRelational(issue: RawIssue, users?: UserBase[]) {
if (!issue.comments) {
return {};
}
@@ -73,15 +74,15 @@ function injectCommentsRelational(issue: RawIssue, users?: T.UserBase[]) {
function prepareClosed(
issue: RawIssue,
- secondaryLocations: T.FlowLocation[],
- flows: T.FlowLocation[][]
+ secondaryLocations: FlowLocation[],
+ flows: FlowLocation[][]
) {
return issue.status === 'CLOSED'
? { flows: [], line: undefined, textRange: undefined, secondaryLocations: [] }
: { flows, secondaryLocations };
}
-function ensureTextRange(issue: RawIssue): { textRange?: T.TextRange } {
+function ensureTextRange(issue: RawIssue): { textRange?: TextRange } {
return issue.line && !issue.textRange
? {
textRange: {
@@ -94,7 +95,7 @@ function ensureTextRange(issue: RawIssue): { textRange?: T.TextRange } {
: {};
}
-function reverseLocations(locations: T.FlowLocation[]): T.FlowLocation[] {
+function reverseLocations(locations: FlowLocation[]): FlowLocation[] {
const x = [...locations];
x.reverse();
return x;
@@ -103,8 +104,8 @@ function reverseLocations(locations: T.FlowLocation[]): T.FlowLocation[] {
function splitFlows(
issue: RawIssue,
components: Component[] = []
-): { secondaryLocations: T.FlowLocation[]; flows: T.FlowLocation[][] } {
- const parsedFlows: T.FlowLocation[][] = (issue.flows || [])
+): { secondaryLocations: FlowLocation[]; flows: FlowLocation[][] } {
+ const parsedFlows: FlowLocation[][] = (issue.flows || [])
.filter(flow => flow.locations !== undefined)
.map(flow => flow.locations!.filter(location => location.textRange != null))
.map(flow =>
@@ -121,7 +122,7 @@ function splitFlows(
: { secondaryLocations: [], flows: parsedFlows.map(reverseLocations) };
}
-function orderLocations(locations: T.FlowLocation[]) {
+function orderLocations(locations: FlowLocation[]) {
return sortBy(
locations,
location => location.textRange && location.textRange.startLine,
@@ -132,9 +133,9 @@ function orderLocations(locations: T.FlowLocation[]) {
export function parseIssueFromResponse(
issue: RawIssue,
components?: Component[],
- users?: T.UserBase[],
+ users?: UserBase[],
rules?: Rule[]
-): T.Issue {
+): Issue {
const { secondaryLocations, flows } = splitFlows(issue, components);
return {
...issue,
@@ -146,7 +147,7 @@ export function parseIssueFromResponse(
...injectCommentsRelational(issue, users),
...prepareClosed(issue, secondaryLocations, flows),
...ensureTextRange(issue)
- } as T.Issue;
+ } as Issue;
}
export const ISSUETYPE_METRIC_KEYS_MAP = {
diff --git a/server/sonar-web/src/main/js/helpers/l10n.ts b/server/sonar-web/src/main/js/helpers/l10n.ts
index a57732333ca..cf01bde7d68 100644
--- a/server/sonar-web/src/main/js/helpers/l10n.ts
+++ b/server/sonar-web/src/main/js/helpers/l10n.ts
@@ -19,10 +19,11 @@
*/
import { fetchL10nBundle } from '../api/l10n';
import { L10nBundle, L10nBundleRequestParams } from '../types/l10n';
+import { Dict } from '../types/types';
import { toNotSoISOString } from './dates';
import { get as loadFromLocalStorage, save as saveInLocalStorage } from './storage';
-export type Messages = T.Dict<string>;
+export type Messages = Dict<string>;
export const DEFAULT_LOCALE = 'en';
export const DEFAULT_MESSAGES = {
diff --git a/server/sonar-web/src/main/js/helpers/measures.ts b/server/sonar-web/src/main/js/helpers/measures.ts
index 86451fc6e0b..27347cb7b69 100644
--- a/server/sonar-web/src/main/js/helpers/measures.ts
+++ b/server/sonar-web/src/main/js/helpers/measures.ts
@@ -22,13 +22,14 @@ import {
QualityGateStatusCondition,
QualityGateStatusConditionEnhanced
} from '../types/quality-gates';
+import { Dict, Measure, MeasureEnhanced, Metric } from '../types/types';
import { getCurrentLocale, translate, translateWithParameters } from './l10n';
import { isDefined } from './types';
export function enhanceMeasuresWithMetrics(
- measures: T.Measure[],
- metrics: T.Metric[]
-): T.MeasureEnhanced[] {
+ measures: Measure[],
+ metrics: Metric[]
+): MeasureEnhanced[] {
return measures
.map(measure => {
const metric = metrics.find(metric => metric.key === measure.metric);
@@ -39,7 +40,7 @@ export function enhanceMeasuresWithMetrics(
export function enhanceConditionWithMeasure(
condition: QualityGateStatusCondition,
- measures: T.MeasureEnhanced[]
+ measures: MeasureEnhanced[]
): QualityGateStatusConditionEnhanced | undefined {
const measure = measures.find(m => m.metric.key === condition.metric);
@@ -53,7 +54,7 @@ export function enhanceConditionWithMeasure(
return measure && { ...condition, period, measure };
}
-export function isPeriodBestValue(measure: T.Measure | T.MeasureEnhanced): boolean {
+export function isPeriodBestValue(measure: Measure | MeasureEnhanced): boolean {
return measure.period?.bestValue || false;
}
@@ -124,11 +125,11 @@ export function getRatingTooltip(metricKey: MetricKey | string, value: number |
: translate('metric', finalMetricKey, 'tooltip', ratingLetter);
}
-export function getDisplayMetrics(metrics: T.Metric[]) {
+export function getDisplayMetrics(metrics: Metric[]) {
return metrics.filter(metric => !metric.hidden && !['DATA', 'DISTRIB'].includes(metric.type));
}
-export function findMeasure(measures: T.MeasureEnhanced[], metric: MetricKey | string) {
+export function findMeasure(measures: MeasureEnhanced[], metric: MetricKey | string) {
return measures.find(measure => measure.metric.key === metric);
}
@@ -196,7 +197,7 @@ function useFormatter(
}
function getFormatter(type: string): Formatter {
- const FORMATTERS: T.Dict<Formatter> = {
+ const FORMATTERS: Dict<Formatter> = {
INT: intFormatter,
SHORT_INT: shortIntFormatter,
FLOAT: floatFormatter,
diff --git a/server/sonar-web/src/main/js/helpers/mocks/component.ts b/server/sonar-web/src/main/js/helpers/mocks/component.ts
index 19149a524c2..08074edb344 100644
--- a/server/sonar-web/src/main/js/helpers/mocks/component.ts
+++ b/server/sonar-web/src/main/js/helpers/mocks/component.ts
@@ -17,11 +17,12 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { ComponentQualifier, TreeComponent } from '../../types/component';
+import { ComponentQualifier, TreeComponent, Visibility } from '../../types/component';
import { MetricKey } from '../../types/metrics';
+import { Component, ComponentMeasure, ComponentMeasureEnhanced } from '../../types/types';
import { mockMeasureEnhanced } from '../testMocks';
-export function mockComponent(overrides: Partial<T.Component> = {}): T.Component {
+export function mockComponent(overrides: Partial<Component> = {}): Component {
return {
breadcrumbs: [],
key: 'my-project',
@@ -46,15 +47,15 @@ export function mockTreeComponent(overrides: Partial<TreeComponent>): TreeCompon
key: 'my-key',
qualifier: ComponentQualifier.Project,
name: 'component',
- visibility: 'public',
+ visibility: Visibility.Public,
...overrides
};
}
export function mockComponentMeasure(
file = false,
- overrides: Partial<T.ComponentMeasure> = {}
-): T.ComponentMeasure {
+ overrides: Partial<ComponentMeasure> = {}
+): ComponentMeasure {
if (file) {
return {
key: 'foo:src/index.tsx',
@@ -75,10 +76,10 @@ export function mockComponentMeasure(
}
export function mockComponentMeasureEnhanced(
- overrides: Partial<T.ComponentMeasureEnhanced> = {}
-): T.ComponentMeasureEnhanced {
+ overrides: Partial<ComponentMeasureEnhanced> = {}
+): ComponentMeasureEnhanced {
return {
- ...mockComponentMeasure(false, overrides as T.ComponentMeasure),
+ ...mockComponentMeasure(false, overrides as ComponentMeasure),
leak: undefined,
measures: [mockMeasureEnhanced()],
value: undefined,
diff --git a/server/sonar-web/src/main/js/helpers/mocks/issues.ts b/server/sonar-web/src/main/js/helpers/mocks/issues.ts
index 034eb0af139..a2c4bf1a2a2 100644
--- a/server/sonar-web/src/main/js/helpers/mocks/issues.ts
+++ b/server/sonar-web/src/main/js/helpers/mocks/issues.ts
@@ -18,6 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { ReferencedRule } from '../../types/issues';
+import { IssueChangelog } from '../../types/types';
export function mockReferencedRule(overrides: Partial<ReferencedRule> = {}): ReferencedRule {
return {
@@ -27,7 +28,7 @@ export function mockReferencedRule(overrides: Partial<ReferencedRule> = {}): Ref
};
}
-export function mockIssueChangelog(overrides: Partial<T.IssueChangelog> = {}): T.IssueChangelog {
+export function mockIssueChangelog(overrides: Partial<IssueChangelog> = {}): IssueChangelog {
return {
creationDate: '2018-10-01',
isUserActive: true,
diff --git a/server/sonar-web/src/main/js/helpers/mocks/permissions.ts b/server/sonar-web/src/main/js/helpers/mocks/permissions.ts
index 815074d0fd9..59564250d93 100644
--- a/server/sonar-web/src/main/js/helpers/mocks/permissions.ts
+++ b/server/sonar-web/src/main/js/helpers/mocks/permissions.ts
@@ -17,9 +17,10 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { PermissionGroup, PermissionUser } from '../../types/types';
import { mockUser } from '../testMocks';
-export function mockPermissionGroup(overrides: Partial<T.PermissionGroup> = {}): T.PermissionGroup {
+export function mockPermissionGroup(overrides: Partial<PermissionGroup> = {}): PermissionGroup {
return {
name: 'sonar-admins',
permissions: ['provisioning'],
@@ -27,7 +28,7 @@ export function mockPermissionGroup(overrides: Partial<T.PermissionGroup> = {}):
};
}
-export function mockPermissionUser(overrides: Partial<T.PermissionUser> = {}): T.PermissionUser {
+export function mockPermissionUser(overrides: Partial<PermissionUser> = {}): PermissionUser {
return {
...mockUser(),
active: true,
diff --git a/server/sonar-web/src/main/js/helpers/mocks/quality-gates.ts b/server/sonar-web/src/main/js/helpers/mocks/quality-gates.ts
index 546a32c7799..3ea683465a6 100644
--- a/server/sonar-web/src/main/js/helpers/mocks/quality-gates.ts
+++ b/server/sonar-web/src/main/js/helpers/mocks/quality-gates.ts
@@ -25,9 +25,10 @@ import {
QualityGateStatusCondition,
QualityGateStatusConditionEnhanced
} from '../../types/quality-gates';
+import { QualityGate } from '../../types/types';
import { mockMeasureEnhanced, mockMetric } from '../testMocks';
-export function mockQualityGate(overrides: Partial<T.QualityGate> = {}): T.QualityGate {
+export function mockQualityGate(overrides: Partial<QualityGate> = {}): QualityGate {
return {
id: '1',
name: 'qualitygate',
diff --git a/server/sonar-web/src/main/js/helpers/mocks/users.ts b/server/sonar-web/src/main/js/helpers/mocks/users.ts
index b1bd18b7566..358cc54a42c 100644
--- a/server/sonar-web/src/main/js/helpers/mocks/users.ts
+++ b/server/sonar-web/src/main/js/helpers/mocks/users.ts
@@ -18,7 +18,9 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-export function mockUserBase(overrides: Partial<T.UserBase> = {}): T.UserBase {
+import { UserBase } from '../../types/types';
+
+export function mockUserBase(overrides: Partial<UserBase> = {}): UserBase {
return {
login: 'userlogin',
...overrides
diff --git a/server/sonar-web/src/main/js/helpers/periods.ts b/server/sonar-web/src/main/js/helpers/periods.ts
index 63892450b9c..b776d0f966f 100644
--- a/server/sonar-web/src/main/js/helpers/periods.ts
+++ b/server/sonar-web/src/main/js/helpers/periods.ts
@@ -20,9 +20,10 @@
import { parseDate } from '../helpers/dates';
import { translate, translateWithParameters } from '../helpers/l10n';
import { ApplicationPeriod } from '../types/application';
+import { Period } from '../types/types';
export function getPeriodLabel(
- period: T.Period | undefined,
+ period: Period | undefined,
dateFormatter: (date: string) => string
) {
if (!period) {
@@ -63,7 +64,7 @@ export function getPeriodDate(period?: { date?: string }): Date | undefined {
}
export function isApplicationPeriod(
- period: T.Period | ApplicationPeriod
+ period: Period | ApplicationPeriod
): period is ApplicationPeriod {
return (period as ApplicationPeriod).project !== undefined;
}
diff --git a/server/sonar-web/src/main/js/helpers/projectLinks.ts b/server/sonar-web/src/main/js/helpers/projectLinks.ts
index cf567cdb4cd..30d9b6fa637 100644
--- a/server/sonar-web/src/main/js/helpers/projectLinks.ts
+++ b/server/sonar-web/src/main/js/helpers/projectLinks.ts
@@ -19,11 +19,12 @@
*/
import { partition, sortBy } from 'lodash';
import { translate } from '../helpers/l10n';
+import { ProjectLink } from '../types/types';
const PROVIDED_TYPES = ['homepage', 'ci', 'issue', 'scm', 'scm_dev'];
-type NameAndType = Pick<T.ProjectLink, 'name' | 'type'>;
+type NameAndType = Pick<ProjectLink, 'name' | 'type'>;
-export function isProvided(link: Pick<T.ProjectLink, 'type'>) {
+export function isProvided(link: Pick<ProjectLink, 'type'>) {
return PROVIDED_TYPES.includes(link.type);
}
diff --git a/server/sonar-web/src/main/js/helpers/query.ts b/server/sonar-web/src/main/js/helpers/query.ts
index bc5fa4dd6d2..9df3777d6f7 100644
--- a/server/sonar-web/src/main/js/helpers/query.ts
+++ b/server/sonar-web/src/main/js/helpers/query.ts
@@ -18,9 +18,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { isEqual, isNil, omitBy } from 'lodash';
+import { RawQuery } from '../types/types';
import { isValidDate, parseDate, toNotSoISOString, toShortNotSoISOString } from './dates';
-export function queriesEqual(a: T.RawQuery, b: T.RawQuery): boolean {
+export function queriesEqual(a: RawQuery, b: RawQuery): boolean {
const keysA = Object.keys(a);
const keysB = Object.keys(b);
@@ -31,7 +32,7 @@ export function queriesEqual(a: T.RawQuery, b: T.RawQuery): boolean {
return keysA.every(key => isEqual(a[key], b[key]));
}
-export function cleanQuery(query: T.RawQuery): T.RawQuery {
+export function cleanQuery(query: RawQuery): RawQuery {
return omitBy(query, isNil);
}
diff --git a/server/sonar-web/src/main/js/helpers/request.ts b/server/sonar-web/src/main/js/helpers/request.ts
index 029ac9c37c4..7b342bf52c4 100644
--- a/server/sonar-web/src/main/js/helpers/request.ts
+++ b/server/sonar-web/src/main/js/helpers/request.ts
@@ -18,6 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { isNil, omitBy } from 'lodash';
+import { Dict } from '../types/types';
import { getCookie } from './cookies';
import { translate } from './l10n';
import { stringify } from './stringify-queryparams';
@@ -39,14 +40,14 @@ export function getCSRFTokenValue(): string {
/**
* Return an object containing a special http request header used to prevent CSRF attacks.
*/
-export function getCSRFToken(): T.Dict<string> {
+export function getCSRFToken(): Dict<string> {
// Fetch API in Edge doesn't work with empty header,
// so we ensure non-empty value
const value = getCSRFTokenValue();
return value ? { [getCSRFTokenName()]: value } : {};
}
-export type RequestData = T.Dict<any>;
+export type RequestData = Dict<any>;
export function omitNil(obj: RequestData): RequestData {
return omitBy(obj, isNil);
diff --git a/server/sonar-web/src/main/js/helpers/strings.ts b/server/sonar-web/src/main/js/helpers/strings.ts
index 7b701a7f7bd..a44a024ac0b 100644
--- a/server/sonar-web/src/main/js/helpers/strings.ts
+++ b/server/sonar-web/src/main/js/helpers/strings.ts
@@ -17,6 +17,9 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+
+import { Dict } from '../types/types';
+
/*
* Latinize string by removing all diacritics
* From http://stackoverflow.com/questions/990904/javascript-remove-accents-in-strings
@@ -393,7 +396,7 @@ const defaultDiacriticsRemovalap = [
}
];
-const diacriticsMap: T.Dict<string> = {};
+const diacriticsMap: Dict<string> = {};
defaultDiacriticsRemovalap.forEach(defaultDiacritic =>
defaultDiacritic.letters.split('').forEach(letter => {
diacriticsMap[letter] = defaultDiacritic.base;
diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts
index 1e77d0f4920..29b6497b232 100644
--- a/server/sonar-web/src/main/js/helpers/testMocks.ts
+++ b/server/sonar-web/src/main/js/helpers/testMocks.ts
@@ -25,8 +25,41 @@ import { DocumentationEntry } from '../apps/documentation/utils';
import { Exporter, Profile } from '../apps/quality-profiles/types';
import { DumpStatus, DumpTask } from '../types/project-dump';
import { TaskStatuses } from '../types/tasks';
-
-export function mockAlmApplication(overrides: Partial<T.AlmApplication> = {}): T.AlmApplication {
+import {
+ AlmApplication,
+ Analysis,
+ AnalysisEvent,
+ AppState,
+ Condition,
+ CurrentUser,
+ FlowLocation,
+ Group,
+ HealthType,
+ IdentityProvider,
+ Issue,
+ Language,
+ LoggedInUser,
+ Measure,
+ MeasureEnhanced,
+ Metric,
+ Paging,
+ ParsedAnalysis,
+ Period,
+ ProfileInheritanceDetails,
+ Rule,
+ RuleActivation,
+ RuleDetails,
+ RuleParameter,
+ SnippetsByComponent,
+ SourceLine,
+ SourceViewerFile,
+ SysInfoBase,
+ SysInfoCluster,
+ SysInfoStandalone,
+ User
+} from '../types/types';
+
+export function mockAlmApplication(overrides: Partial<AlmApplication> = {}): AlmApplication {
return {
backgroundColor: '#444444',
iconPath: '/images/sonarcloud/github-white.svg',
@@ -37,7 +70,7 @@ export function mockAlmApplication(overrides: Partial<T.AlmApplication> = {}): T
};
}
-export function mockAnalysis(overrides: Partial<T.Analysis> = {}): T.Analysis {
+export function mockAnalysis(overrides: Partial<Analysis> = {}): Analysis {
return {
date: '2017-03-01T09:36:01+0100',
events: [],
@@ -47,7 +80,7 @@ export function mockAnalysis(overrides: Partial<T.Analysis> = {}): T.Analysis {
};
}
-export function mockParsedAnalysis(overrides: Partial<T.ParsedAnalysis> = {}): T.ParsedAnalysis {
+export function mockParsedAnalysis(overrides: Partial<ParsedAnalysis> = {}): ParsedAnalysis {
return {
date: new Date('2017-03-01T09:37:01+0100'),
events: [],
@@ -57,7 +90,7 @@ export function mockParsedAnalysis(overrides: Partial<T.ParsedAnalysis> = {}): T
};
}
-export function mockAnalysisEvent(overrides: Partial<T.AnalysisEvent> = {}): T.AnalysisEvent {
+export function mockAnalysisEvent(overrides: Partial<AnalysisEvent> = {}): AnalysisEvent {
return {
category: 'QUALITY_GATE',
key: 'E11',
@@ -83,7 +116,7 @@ export function mockAnalysisEvent(overrides: Partial<T.AnalysisEvent> = {}): T.A
};
}
-export function mockAppState(overrides: Partial<T.AppState> = {}): T.AppState {
+export function mockAppState(overrides: Partial<AppState> = {}): AppState {
return {
edition: 'community',
productionDatabase: true,
@@ -94,9 +127,9 @@ export function mockAppState(overrides: Partial<T.AppState> = {}): T.AppState {
};
}
-export function mockBaseSysInfo(overrides: Partial<any> = {}): T.SysInfoBase {
+export function mockBaseSysInfo(overrides: Partial<any> = {}): SysInfoBase {
return {
- Health: 'GREEN' as T.HealthType,
+ Health: 'GREEN' as HealthType,
'Health Causes': [],
System: {
Version: '7.8'
@@ -122,7 +155,7 @@ export function mockBaseSysInfo(overrides: Partial<any> = {}): T.SysInfoBase {
};
}
-export function mockClusterSysInfo(overrides: Partial<any> = {}): T.SysInfoCluster {
+export function mockClusterSysInfo(overrides: Partial<any> = {}): SysInfoCluster {
const baseInfo = mockBaseSysInfo(overrides);
return {
...baseInfo,
@@ -139,7 +172,7 @@ export function mockClusterSysInfo(overrides: Partial<any> = {}): T.SysInfoClust
{
Name: 'server9.example.com',
Host: '10.0.0.0',
- Health: 'GREEN' as T.HealthType,
+ Health: 'GREEN' as HealthType,
'Health Causes': [],
System: {
Version: '7.8'
@@ -182,7 +215,7 @@ export function mockClusterSysInfo(overrides: Partial<any> = {}): T.SysInfoClust
{
Name: 'server9.example.com',
Host: '10.0.0.0',
- Health: 'GREEN' as T.HealthType,
+ Health: 'GREEN' as HealthType,
'Health Causes': [],
System: {
Version: '7.8'
@@ -257,7 +290,7 @@ export function mockClusterSysInfo(overrides: Partial<any> = {}): T.SysInfoClust
};
}
-export function mockCondition(overrides: Partial<T.Condition> = {}): T.Condition {
+export function mockCondition(overrides: Partial<Condition> = {}): Condition {
return {
error: '10',
id: 1,
@@ -270,8 +303,8 @@ export function mockCondition(overrides: Partial<T.Condition> = {}): T.Condition
export function mockSnippetsByComponent(
component = 'main.js',
lines: number[] = [16]
-): T.SnippetsByComponent {
- const sources = lines.reduce((lines: { [key: number]: T.SourceLine }, line) => {
+): SnippetsByComponent {
+ const sources = lines.reduce((lines: { [key: number]: SourceLine }, line) => {
lines[line] = mockSourceLine({ line });
return lines;
}, {});
@@ -284,7 +317,7 @@ export function mockSnippetsByComponent(
};
}
-export function mockSourceLine(overrides: Partial<T.SourceLine> = {}): T.SourceLine {
+export function mockSourceLine(overrides: Partial<SourceLine> = {}): SourceLine {
return {
line: 16,
code: '<span class="k">import</span> java.util.<span class="sym-9 sym">ArrayList</span>;',
@@ -299,14 +332,14 @@ export function mockSourceLine(overrides: Partial<T.SourceLine> = {}): T.SourceL
};
}
-export function mockCurrentUser(overrides: Partial<T.CurrentUser> = {}): T.CurrentUser {
+export function mockCurrentUser(overrides: Partial<CurrentUser> = {}): CurrentUser {
return {
isLoggedIn: false,
...overrides
};
}
-export function mockLoggedInUser(overrides: Partial<T.LoggedInUser> = {}): T.LoggedInUser {
+export function mockLoggedInUser(overrides: Partial<LoggedInUser> = {}): LoggedInUser {
return {
groups: [],
isLoggedIn: true,
@@ -317,7 +350,7 @@ export function mockLoggedInUser(overrides: Partial<T.LoggedInUser> = {}): T.Log
};
}
-export function mockGroup(overrides: Partial<T.Group> = {}): T.Group {
+export function mockGroup(overrides: Partial<Group> = {}): Group {
return {
id: 1,
membersCount: 1,
@@ -336,8 +369,8 @@ export function mockEvent(overrides = {}) {
} as any;
}
-export function mockIssue(withLocations = false, overrides: Partial<T.Issue> = {}) {
- const issue: T.Issue = {
+export function mockIssue(withLocations = false, overrides: Partial<Issue> = {}) {
+ const issue: Issue = {
actions: [],
component: 'main.js',
componentLongName: 'main.js',
@@ -391,9 +424,7 @@ export function mockLocation(overrides: Partial<Location> = {}): Location {
};
}
-export function mockMetric(
- overrides: Partial<Pick<T.Metric, 'key' | 'name' | 'type'>> = {}
-): T.Metric {
+export function mockMetric(overrides: Partial<Pick<Metric, 'key' | 'name' | 'type'>> = {}): Metric {
const key = overrides.key || 'coverage';
const name = overrides.name || key[0].toUpperCase() + key.substr(1);
const type = overrides.type || 'PERCENT';
@@ -405,7 +436,7 @@ export function mockMetric(
};
}
-export function mockMeasure(overrides: Partial<T.Measure> = {}): T.Measure {
+export function mockMeasure(overrides: Partial<Measure> = {}): Measure {
return {
bestValue: true,
metric: 'bugs',
@@ -419,7 +450,7 @@ export function mockMeasure(overrides: Partial<T.Measure> = {}): T.Measure {
};
}
-export function mockMeasureEnhanced(overrides: Partial<T.MeasureEnhanced> = {}): T.MeasureEnhanced {
+export function mockMeasureEnhanced(overrides: Partial<MeasureEnhanced> = {}): MeasureEnhanced {
return {
bestValue: true,
leak: '1',
@@ -434,7 +465,7 @@ export function mockMeasureEnhanced(overrides: Partial<T.MeasureEnhanced> = {}):
};
}
-export function mockPeriod(overrides: Partial<T.Period> = {}): T.Period {
+export function mockPeriod(overrides: Partial<Period> = {}): Period {
return {
date: '2019-04-23T02:12:32+0100',
index: 0,
@@ -462,8 +493,8 @@ export function mockQualityProfile(overrides: Partial<Profile> = {}): Profile {
}
export function mockQualityProfileInheritance(
- overrides: Partial<T.ProfileInheritanceDetails> = {}
-): T.ProfileInheritanceDetails {
+ overrides: Partial<ProfileInheritanceDetails> = {}
+): ProfileInheritanceDetails {
return {
activeRuleCount: 4,
isBuiltIn: false,
@@ -511,7 +542,7 @@ export function mockRouter(overrides: { push?: Function; replace?: Function } =
} as InjectedRouter;
}
-export function mockRule(overrides: Partial<T.Rule> = {}): T.Rule {
+export function mockRule(overrides: Partial<Rule> = {}): Rule {
return {
key: 'javascript:S1067',
lang: 'js',
@@ -523,10 +554,10 @@ export function mockRule(overrides: Partial<T.Rule> = {}): T.Rule {
tags: ['x'],
type: 'CODE_SMELL',
...overrides
- } as T.Rule;
+ } as Rule;
}
-export function mockRuleActivation(overrides: Partial<T.RuleActivation> = {}): T.RuleActivation {
+export function mockRuleActivation(overrides: Partial<RuleActivation> = {}): RuleActivation {
return {
createdAt: '2020-02-01',
inherit: 'NONE',
@@ -537,7 +568,7 @@ export function mockRuleActivation(overrides: Partial<T.RuleActivation> = {}): T
};
}
-export function mockRuleDetails(overrides: Partial<T.RuleDetails> = {}): T.RuleDetails {
+export function mockRuleDetails(overrides: Partial<RuleDetails> = {}): RuleDetails {
return {
key: 'squid:S1337',
repo: 'squid',
@@ -570,9 +601,7 @@ export function mockRuleDetails(overrides: Partial<T.RuleDetails> = {}): T.RuleD
};
}
-export function mockRuleDetailsParameter(
- overrides: Partial<T.RuleParameter> = {}
-): T.RuleParameter {
+export function mockRuleDetailsParameter(overrides: Partial<RuleParameter> = {}): RuleParameter {
return {
defaultValue: '1',
htmlDesc: 'description',
@@ -582,9 +611,7 @@ export function mockRuleDetailsParameter(
};
}
-export function mockSourceViewerFile(
- overrides: Partial<T.SourceViewerFile> = {}
-): T.SourceViewerFile {
+export function mockSourceViewerFile(overrides: Partial<SourceViewerFile> = {}): SourceViewerFile {
return {
key: 'foo',
measures: {
@@ -602,7 +629,7 @@ export function mockSourceViewerFile(
};
}
-export function mockStandaloneSysInfo(overrides: Partial<any> = {}): T.SysInfoStandalone {
+export function mockStandaloneSysInfo(overrides: Partial<any> = {}): SysInfoStandalone {
const baseInfo = mockBaseSysInfo(overrides);
return {
...baseInfo,
@@ -659,7 +686,7 @@ export function mockStore(state: any = {}, reducer = (state: any) => state): Sto
return createStore(reducer, state);
}
-export function mockUser(overrides: Partial<T.User> = {}): T.User {
+export function mockUser(overrides: Partial<User> = {}): User {
return {
active: true,
local: true,
@@ -705,7 +732,7 @@ export function mockDocumentationEntry(
};
}
-export function mockLanguage(overrides: Partial<T.Language> = {}): T.Language {
+export function mockLanguage(overrides: Partial<Language> = {}): Language {
return {
key: 'css',
name: 'CSS',
@@ -713,7 +740,7 @@ export function mockLanguage(overrides: Partial<T.Language> = {}): T.Language {
};
}
-export function mockFlowLocation(overrides: Partial<T.FlowLocation> = {}): T.FlowLocation {
+export function mockFlowLocation(overrides: Partial<FlowLocation> = {}): FlowLocation {
return {
component: 'main.js',
textRange: {
@@ -726,9 +753,7 @@ export function mockFlowLocation(overrides: Partial<T.FlowLocation> = {}): T.Flo
};
}
-export function mockIdentityProvider(
- overrides: Partial<T.IdentityProvider> = {}
-): T.IdentityProvider {
+export function mockIdentityProvider(overrides: Partial<IdentityProvider> = {}): IdentityProvider {
return {
backgroundColor: '#000000',
iconPath: '/path/icon.svg',
@@ -749,7 +774,7 @@ export function mockRef(
} as React.RefObject<HTMLElement>;
}
-export function mockPaging(overrides: Partial<T.Paging> = {}): T.Paging {
+export function mockPaging(overrides: Partial<Paging> = {}): Paging {
return {
pageIndex: 1,
pageSize: 100,
diff --git a/server/sonar-web/src/main/js/helpers/urls.ts b/server/sonar-web/src/main/js/helpers/urls.ts
index ee616508baa..85816bd3e70 100644
--- a/server/sonar-web/src/main/js/helpers/urls.ts
+++ b/server/sonar-web/src/main/js/helpers/urls.ts
@@ -24,13 +24,14 @@ import { ComponentQualifier, isApplication, isPortfolioLike } from '../types/com
import { MeasurePageView } from '../types/measures';
import { GraphType } from '../types/project-activity';
import { SecurityStandard } from '../types/security';
+import { Dict, HomePage } from '../types/types';
import { getBranchLikeQuery, isBranch, isMainBranch, isPullRequest } from './branch-like';
import { IS_SSR } from './browser';
import { getBaseUrl } from './system';
export interface Location {
pathname: string;
- query?: T.Dict<string | undefined | number>;
+ query?: Dict<string | undefined | number>;
}
type Query = Location['query'];
@@ -246,7 +247,7 @@ export function getQualityGatesUrl(): Location {
export function getGlobalSettingsUrl(
category?: string,
- query?: T.Dict<string | undefined | number>
+ query?: Dict<string | undefined | number>
): Location {
return {
pathname: '/admin/settings',
@@ -296,7 +297,7 @@ export function getCodeUrl(
};
}
-export function getHomePageUrl(homepage: T.HomePage) {
+export function getHomePageUrl(homepage: HomePage) {
switch (homepage.type) {
case 'APPLICATION':
return homepage.branch
diff --git a/server/sonar-web/src/main/js/helpers/users.ts b/server/sonar-web/src/main/js/helpers/users.ts
index ca64aa53277..0bec8925c3f 100644
--- a/server/sonar-web/src/main/js/helpers/users.ts
+++ b/server/sonar-web/src/main/js/helpers/users.ts
@@ -1,3 +1,5 @@
+import { CurrentUser, LoggedInUser, UserActive, UserBase } from '../types/types';
+
/*
* SonarQube
* Copyright (C) 2009-2021 SonarSource SA
@@ -17,17 +19,17 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-export function hasGlobalPermission(user: T.CurrentUser, permission: string): boolean {
+export function hasGlobalPermission(user: CurrentUser, permission: string): boolean {
if (!user.permissions) {
return false;
}
return user.permissions.global.includes(permission);
}
-export function isLoggedIn(user: T.CurrentUser): user is T.LoggedInUser {
+export function isLoggedIn(user: CurrentUser): user is LoggedInUser {
return user.isLoggedIn;
}
-export function isUserActive(user: T.UserBase): user is T.UserActive {
+export function isUserActive(user: UserBase): user is UserActive {
return user.active !== false && Boolean(user.name);
}