diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps/coding-rules')
30 files changed, 133 insertions, 99 deletions
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationButton.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationButton.tsx index 0d2b133c77c..da930cbf779 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationButton.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationButton.tsx @@ -20,16 +20,17 @@ import * as React from 'react'; import { Profile as BaseProfile } from '../../../api/quality-profiles'; import { Button } from '../../../components/controls/buttons'; +import { Rule, RuleActivation, RuleDetails } from '../../../types/types'; import ActivationFormModal from './ActivationFormModal'; interface Props { - activation?: T.RuleActivation; + activation?: RuleActivation; buttonText: string; className?: string; modalHeader: string; onDone: (severity: string) => Promise<void>; profiles: BaseProfile[]; - rule: T.Rule | T.RuleDetails; + rule: Rule | RuleDetails; } interface State { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx index dd4a680feb0..1c963c7702d 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx @@ -28,19 +28,20 @@ import { Alert } from '../../../components/ui/Alert'; import { SEVERITIES } from '../../../helpers/constants'; import { translate } from '../../../helpers/l10n'; import { sanitizeString } from '../../../helpers/sanitize'; +import { Dict, Rule, RuleActivation, RuleDetails } from '../../../types/types'; import { sortProfiles } from '../../quality-profiles/utils'; interface Props { - activation?: T.RuleActivation; + activation?: RuleActivation; modalHeader: string; onClose: () => void; onDone: (severity: string) => Promise<void>; profiles: Profile[]; - rule: T.Rule | T.RuleDetails; + rule: Rule | RuleDetails; } interface State { - params: T.Dict<string>; + params: Dict<string>; profile: string; severity: string; submitting: boolean; @@ -69,7 +70,7 @@ export default class ActivationFormModal extends React.PureComponent<Props, Stat } getParams = ({ activation, rule } = this.props) => { - const params: T.Dict<string> = {}; + const params: Dict<string> = {}; if (rule && rule.params) { for (const param of rule.params) { params[param.key] = param.defaultValue || ''; @@ -148,7 +149,7 @@ export default class ActivationFormModal extends React.PureComponent<Props, Stat const { profile, severity, submitting } = this.state; const { params = [] } = rule; const profilesWithDepth = this.getQualityProfilesWithDepth(); - const isCustomRule = !!(rule as T.RuleDetails).templateKey; + const isCustomRule = !!(rule as RuleDetails).templateKey; const activeInAllProfiles = profilesWithDepth.length <= 0; const isUpdateMode = !!activation; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx index 52157b66998..90ca67697d9 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/App.tsx @@ -45,6 +45,15 @@ import { isLoggedIn } from '../../../helpers/users'; import { getCurrentUser, getLanguages, Store } from '../../../store/rootReducer'; import { SecurityStandard } from '../../../types/security'; import { + CurrentUser, + Dict, + Languages, + Paging, + RawQuery, + Rule, + RuleActivation +} from '../../../types/types'; +import { shouldOpenSonarSourceSecurityFacet, shouldOpenStandardsChildFacet, shouldOpenStandardsFacet, @@ -78,8 +87,8 @@ const MAX_SEARCH_LENGTH = 200; const LIMIT_BEFORE_LOAD_MORE = 5; interface Props extends WithRouterProps { - currentUser: T.CurrentUser; - languages: T.Languages; + currentUser: CurrentUser; + languages: Languages; } interface State { @@ -88,12 +97,12 @@ interface State { facets?: Facets; loading: boolean; openFacets: OpenFacets; - openRule?: T.Rule; - paging?: T.Paging; + openRule?: Rule; + paging?: Paging; query: Query; - referencedProfiles: T.Dict<Profile>; - referencedRepositories: T.Dict<{ key: string; language: string; name: string }>; - rules: T.Rule[]; + referencedProfiles: Dict<Profile>; + referencedRepositories: Dict<{ key: string; language: string; name: string }>; + rules: Rule[]; selected?: string; usingPermalink?: boolean; } @@ -184,7 +193,7 @@ export class App extends React.PureComponent<Props, State> { detachShortcuts = () => key.deleteScope('coding-rules'); - getOpenRule = (props: Props, rules: T.Rule[]) => { + getOpenRule = (props: Props, rules: Rule[]) => { const open = getOpen(props.location.query); return open && rules.find(rule => rule.key === open); }; @@ -244,7 +253,7 @@ export class App extends React.PureComponent<Props, State> { ); }; - makeFetchRequest = (query?: T.RawQuery) => + makeFetchRequest = (query?: RawQuery) => searchRules({ ...this.getSearchParameters(), ...query }).then( ({ actives: rawActives, facets: rawFacets, p, ps, rules, total }) => { const actives = rawActives && parseActives(rawActives); @@ -254,7 +263,7 @@ export class App extends React.PureComponent<Props, State> { } ); - fetchFirstRules = (query?: T.RawQuery) => { + fetchFirstRules = (query?: RawQuery) => { this.setState({ loading: true }); this.makeFetchRequest(query).then(({ actives, facets, paging, rules }) => { if (this.mounted) { @@ -474,7 +483,7 @@ export class App extends React.PureComponent<Props, State> { handleReset = () => this.props.router.push({ pathname: this.props.location.pathname }); /** Tries to take rule by index, or takes the last one */ - pickRuleAround = (rules: T.Rule[], selectedIndex: number | undefined) => { + pickRuleAround = (rules: Rule[], selectedIndex: number | undefined) => { if (selectedIndex === undefined || rules.length === 0) { return undefined; } @@ -672,7 +681,7 @@ export class App extends React.PureComponent<Props, State> { } } -function parseActives(rawActives: T.Dict<T.RuleActivation[]>) { +function parseActives(rawActives: Dict<RuleActivation[]>) { const actives: Actives = {}; for (const [rule, activations] of Object.entries(rawActives)) { actives[rule] = {}; @@ -686,7 +695,7 @@ function parseActives(rawActives: T.Dict<T.RuleActivation[]>) { function parseFacets(rawFacets: { property: string; values: { count: number; val: string }[] }[]) { const facets: Facets = {}; for (const rawFacet of rawFacets) { - const values: T.Dict<number> = {}; + const values: Dict<number> = {}; for (const rawValue of rawFacet.values) { values[rawValue.val] = rawValue.count; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChange.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChange.tsx index c1fa64a8758..06b15dff35a 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChange.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChange.tsx @@ -24,13 +24,14 @@ import Dropdown from '../../../components/controls/Dropdown'; import Tooltip from '../../../components/controls/Tooltip'; import { PopupPlacement } from '../../../components/ui/popups'; import { translate } from '../../../helpers/l10n'; +import { Dict, Languages } from '../../../types/types'; import { Query } from '../query'; import BulkChangeModal from './BulkChangeModal'; interface Props { - languages: T.Languages; + languages: Languages; query: Query; - referencedProfiles: T.Dict<Profile>; + referencedProfiles: Dict<Profile>; total: number; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChangeModal.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChangeModal.tsx index bb853cf92c5..c286d89510e 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChangeModal.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/BulkChangeModal.tsx @@ -25,15 +25,16 @@ import SelectLegacy from '../../../components/controls/SelectLegacy'; import { Alert } from '../../../components/ui/Alert'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { formatMeasure } from '../../../helpers/measures'; +import { Dict, Languages } from '../../../types/types'; import { Query, serializeQuery } from '../query'; interface Props { action: string; - languages: T.Languages; + languages: Languages; onClose: () => void; profile?: Profile; query: Query; - referencedProfiles: T.Dict<Profile>; + referencedProfiles: Dict<Profile>; total: number; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleButton.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleButton.tsx index d6c87f1c5c1..d1b0d9f28d3 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleButton.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleButton.tsx @@ -18,13 +18,14 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import { RuleDetails } from '../../../types/types'; import CustomRuleFormModal from './CustomRuleFormModal'; interface Props { children: (props: { onClick: () => void }) => React.ReactNode; - customRule?: T.RuleDetails; - onDone: (newRuleDetails: T.RuleDetails) => void; - templateRule: T.RuleDetails; + customRule?: RuleDetails; + onDone: (newRuleDetails: RuleDetails) => void; + templateRule: RuleDetails; } interface State { @@ -53,7 +54,7 @@ export default class CustomRuleButton extends React.PureComponent<Props, State> } }; - handleDone = (newRuleDetails: T.RuleDetails) => { + handleDone = (newRuleDetails: RuleDetails) => { this.handleModalClose(); this.props.onDone(newRuleDetails); }; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx index 25fcb3c8e60..0d6482a6c73 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx @@ -33,12 +33,13 @@ import { csvEscape } from '../../../helpers/csv'; import { translate } from '../../../helpers/l10n'; import { sanitizeString } from '../../../helpers/sanitize'; import { latinize } from '../../../helpers/strings'; +import { Dict, RuleDetails, RuleParameter, RuleType } from '../../../types/types'; interface Props { - customRule?: T.RuleDetails; + customRule?: RuleDetails; onClose: () => void; - onDone: (newRuleDetails: T.RuleDetails) => void; - templateRule: T.RuleDetails; + onDone: (newRuleDetails: RuleDetails) => void; + templateRule: RuleDetails; } interface State { @@ -46,7 +47,7 @@ interface State { key: string; keyModifiedByUser: boolean; name: string; - params: T.Dict<string>; + params: Dict<string>; reactivating: boolean; severity: string; status: string; @@ -59,7 +60,7 @@ export default class CustomRuleFormModal extends React.PureComponent<Props, Stat constructor(props: Props) { super(props); - const params: T.Dict<string> = {}; + const params: Dict<string> = {}; if (props.customRule && props.customRule.params) { for (const param of props.customRule.params) { params[param.key] = param.defaultValue || ''; @@ -211,7 +212,7 @@ export default class CustomRuleFormModal extends React.PureComponent<Props, Stat </div> ); - renderTypeOption = ({ value }: { value: T.RuleType }) => { + renderTypeOption = ({ value }: { value: RuleType }) => { return <TypeHelper type={value} />; }; @@ -277,7 +278,7 @@ export default class CustomRuleFormModal extends React.PureComponent<Props, Stat </div> ); - renderParameterField = (param: T.RuleParameter) => ( + renderParameterField = (param: RuleParameter) => ( <div className="modal-field" key={param.key}> <label className="capitalize" htmlFor={param.key}> {param.key} diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/Facet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/Facet.tsx index c5af27f619f..6da6f1e5966 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/Facet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/Facet.tsx @@ -27,13 +27,14 @@ import FacetItem from '../../../components/facet/FacetItem'; import FacetItemsList from '../../../components/facet/FacetItemsList'; import { translate } from '../../../helpers/l10n'; import { formatMeasure } from '../../../helpers/measures'; +import { Dict } from '../../../types/types'; import { FacetKey } from '../query'; export interface BasicProps { - onChange: (changes: T.Dict<string | string[] | undefined>) => void; + onChange: (changes: Dict<string | string[] | undefined>) => void; onToggle: (facet: FacetKey) => void; open: boolean; - stats?: T.Dict<number>; + stats?: Dict<number>; values: string[]; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/FacetsList.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/FacetsList.tsx index 2cedf3297aa..fd68568f723 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/FacetsList.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/FacetsList.tsx @@ -19,6 +19,7 @@ */ import * as React from 'react'; import { Profile } from '../../../api/quality-profiles'; +import { Dict } from '../../../types/types'; import StandardFacet from '../../issues/sidebar/StandardFacet'; import { Facets, OpenFacets, Query } from '../query'; import ActivationSeverityFacet from './ActivationSeverityFacet'; @@ -40,8 +41,8 @@ export interface FacetsListProps { onFilterChange: (changes: Partial<Query>) => void; openFacets: OpenFacets; query: Query; - referencedProfiles: T.Dict<Profile>; - referencedRepositories: T.Dict<{ key: string; language: string; name: string }>; + referencedProfiles: Dict<Profile>; + referencedRepositories: Dict<{ key: string; language: string; name: string }>; selectedProfile?: Profile; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/InheritanceFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/InheritanceFacet.tsx index 73c9b85d5cb..839997efa8a 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/InheritanceFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/InheritanceFacet.tsx @@ -19,15 +19,16 @@ */ import * as React from 'react'; import { translate } from '../../../helpers/l10n'; +import { RuleInheritance } from '../../../types/types'; import Facet, { BasicProps } from './Facet'; -interface Props extends T.Omit<BasicProps, 'values'> { +interface Props extends Omit<BasicProps, 'values'> { disabled: boolean; - value: T.RuleInheritance | undefined; + value: RuleInheritance | undefined; } export default class InheritanceFacet extends React.PureComponent<Props> { - renderName = (value: T.RuleInheritance) => + renderName = (value: RuleInheritance) => translate('coding_rules.filters.inheritance', value.toLowerCase()); render() { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/PageActions.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/PageActions.tsx index 29a76efda9c..41f81b86009 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/PageActions.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/PageActions.tsx @@ -23,11 +23,12 @@ import ReloadButton from '../../../components/controls/ReloadButton'; import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import PageShortcutsTooltip from '../../../components/ui/PageShortcutsTooltip'; import { translate } from '../../../helpers/l10n'; +import { Paging } from '../../../types/types'; export interface PageActionsProps { loading: boolean; onReload: () => void; - paging?: T.Paging; + paging?: Paging; selectedIndex?: number; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/ProfileFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/ProfileFacet.tsx index bd968b073ab..95708f97f09 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/ProfileFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/ProfileFacet.tsx @@ -27,6 +27,7 @@ import FacetHeader from '../../../components/facet/FacetHeader'; import FacetItem from '../../../components/facet/FacetItem'; import FacetItemsList from '../../../components/facet/FacetItemsList'; import { translate } from '../../../helpers/l10n'; +import { Dict } from '../../../types/types'; import { FacetKey, Query } from '../query'; interface Props { @@ -36,7 +37,7 @@ interface Props { onChange: (changes: Partial<Query>) => void; onToggle: (facet: FacetKey) => void; open: boolean; - referencedProfiles: T.Dict<Profile>; + referencedProfiles: Dict<Profile>; value: string | undefined; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RepositoryFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RepositoryFacet.tsx index cc1b0767edb..b4588d7da8d 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RepositoryFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RepositoryFacet.tsx @@ -24,14 +24,15 @@ import ListStyleFacet from '../../../components/facet/ListStyleFacet'; import { translate } from '../../../helpers/l10n'; import { highlightTerm } from '../../../helpers/search'; import { getLanguages, Store } from '../../../store/rootReducer'; +import { Dict } from '../../../types/types'; import { BasicProps } from './Facet'; interface StateProps { - referencedLanguages: T.Dict<{ key: string; name: string }>; + referencedLanguages: Dict<{ key: string; name: string }>; } interface Props extends BasicProps, StateProps { - referencedRepositories: T.Dict<{ key: string; language: string; name: string }>; + referencedRepositories: Dict<{ key: string; language: string; name: string }>; } export class RepositoryFacet extends React.PureComponent<Props> { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetails.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetails.tsx index 09198ba7b40..df5379be796 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetails.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetails.tsx @@ -25,6 +25,7 @@ import ConfirmButton from '../../../components/controls/ConfirmButton'; import HelpTooltip from '../../../components/controls/HelpTooltip'; import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import { translate, translateWithParameters } from '../../../helpers/l10n'; +import { Dict, RuleActivation, RuleDetails as TypeRuleDetails } from '../../../types/types'; import { Activation, Query } from '../query'; import CustomRuleButton from './CustomRuleButton'; import RuleDetailsCustomRules from './RuleDetailsCustomRules'; @@ -42,16 +43,16 @@ interface Props { onDeactivate: (profile: string, rule: string) => void; onDelete: (rule: string) => void; onFilterChange: (changes: Partial<Query>) => void; - referencedProfiles: T.Dict<Profile>; - referencedRepositories: T.Dict<{ key: string; language: string; name: string }>; + referencedProfiles: Dict<Profile>; + referencedRepositories: Dict<{ key: string; language: string; name: string }>; ruleKey: string; selectedProfile?: Profile; } interface State { - actives?: T.RuleActivation[]; + actives?: RuleActivation[]; loading: boolean; - ruleDetails?: T.RuleDetails; + ruleDetails?: TypeRuleDetails; } export default class RuleDetails extends React.PureComponent<Props, State> { @@ -93,7 +94,7 @@ export default class RuleDetails extends React.PureComponent<Props, State> { ); }; - handleRuleChange = (ruleDetails: T.RuleDetails) => { + handleRuleChange = (ruleDetails: TypeRuleDetails) => { if (this.mounted) { this.setState({ ruleDetails }); } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsCustomRules.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsCustomRules.tsx index 7acce41dcb1..c6a867a8bed 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsCustomRules.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsCustomRules.tsx @@ -27,16 +27,17 @@ import SeverityHelper from '../../../components/shared/SeverityHelper'; import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { getRuleUrl } from '../../../helpers/urls'; +import { Rule, RuleDetails } from '../../../types/types'; import CustomRuleButton from './CustomRuleButton'; interface Props { canChange?: boolean; - ruleDetails: T.RuleDetails; + ruleDetails: RuleDetails; } interface State { loading: boolean; - rules?: T.Rule[]; + rules?: Rule[]; } export default class RuleDetailsCustomRules extends React.PureComponent<Props, State> { @@ -77,7 +78,7 @@ export default class RuleDetailsCustomRules extends React.PureComponent<Props, S ); }; - handleRuleCreate = (newRuleDetails: T.RuleDetails) => { + handleRuleCreate = (newRuleDetails: RuleDetails) => { if (this.mounted) { this.setState(({ rules = [] }: State) => ({ rules: [...rules, newRuleDetails] @@ -95,7 +96,7 @@ export default class RuleDetailsCustomRules extends React.PureComponent<Props, S }); }; - renderRule = (rule: T.Rule) => ( + renderRule = (rule: Rule) => ( <tr data-rule={rule.key} key={rule.key}> <td className="coding-rules-detail-list-name"> <Link to={getRuleUrl(rule.key)}>{rule.name}</Link> diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx index 79eb7b4007a..83be0999eb9 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsDescription.tsx @@ -23,12 +23,13 @@ import FormattingTips from '../../../components/common/FormattingTips'; import { Button, ResetButtonLink } from '../../../components/controls/buttons'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { sanitizeString } from '../../../helpers/sanitize'; +import { RuleDetails } from '../../../types/types'; import RemoveExtendedDescriptionModal from './RemoveExtendedDescriptionModal'; interface Props { canWrite: boolean | undefined; - onChange: (newRuleDetails: T.RuleDetails) => void; - ruleDetails: T.RuleDetails; + onChange: (newRuleDetails: RuleDetails) => void; + ruleDetails: RuleDetails; } interface State { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsIssues.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsIssues.tsx index af2f02e39ab..9012c4cbff8 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsIssues.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsIssues.tsx @@ -26,10 +26,11 @@ import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import { translate } from '../../../helpers/l10n'; import { formatMeasure } from '../../../helpers/measures'; import { getIssuesUrl } from '../../../helpers/urls'; +import { AppState, RuleDetails } from '../../../types/types'; interface Props { - appState: Pick<T.AppState, 'branchesEnabled'>; - ruleDetails: Pick<T.RuleDetails, 'key' | 'type'>; + appState: Pick<AppState, 'branchesEnabled'>; + ruleDetails: Pick<RuleDetails, 'key' | 'type'>; } interface Project { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsMeta.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsMeta.tsx index aa1a09e4e84..7f536e71b4d 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsMeta.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsMeta.tsx @@ -31,6 +31,7 @@ import TagsList from '../../../components/tags/TagsList'; import { PopupPlacement } from '../../../components/ui/popups'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { getRuleUrl } from '../../../helpers/urls'; +import { Dict, RuleDetails } from '../../../types/types'; import { Query } from '../query'; import RuleDetailsTagsPopup from './RuleDetailsTagsPopup'; import SimilarRulesFilter from './SimilarRulesFilter'; @@ -40,8 +41,8 @@ interface Props { hideSimilarRulesFilter?: boolean; onFilterChange: (changes: Partial<Query>) => void; onTagsChange: (tags: string[]) => void; - referencedRepositories: T.Dict<{ key: string; language: string; name: string }>; - ruleDetails: T.RuleDetails; + referencedRepositories: Dict<{ key: string; language: string; name: string }>; + ruleDetails: RuleDetails; } const EXTERNAL_RULE_REPO_PREFIX = 'external_'; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsParameters.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsParameters.tsx index 58ff41b223a..0ac6449d606 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsParameters.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsParameters.tsx @@ -20,13 +20,14 @@ import * as React from 'react'; import { translate } from '../../../helpers/l10n'; import { sanitizeString } from '../../../helpers/sanitize'; +import { RuleParameter } from '../../../types/types'; interface Props { - params: T.RuleParameter[]; + params: RuleParameter[]; } export default class RuleDetailsParameters extends React.PureComponent<Props> { - renderParameter = (param: T.RuleParameter) => ( + renderParameter = (param: RuleParameter) => ( <tr className="coding-rules-detail-parameter" key={param.key}> <td className="coding-rules-detail-parameter-name">{param.key}</td> <td className="coding-rules-detail-parameter-description"> diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsProfiles.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsProfiles.tsx index 5155a3d0dbf..28274295ed8 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsProfiles.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsProfiles.tsx @@ -28,17 +28,18 @@ import Tooltip from '../../../components/controls/Tooltip'; import SeverityHelper from '../../../components/shared/SeverityHelper'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { getQualityProfileUrl } from '../../../helpers/urls'; +import { Dict, RuleActivation, RuleDetails } from '../../../types/types'; import BuiltInQualityProfileBadge from '../../quality-profiles/components/BuiltInQualityProfileBadge'; import ActivationButton from './ActivationButton'; import RuleInheritanceIcon from './RuleInheritanceIcon'; interface Props { - activations: T.RuleActivation[] | undefined; + activations: RuleActivation[] | undefined; canWrite: boolean | undefined; onActivate: () => Promise<void>; onDeactivate: () => Promise<void>; - referencedProfiles: T.Dict<Profile>; - ruleDetails: T.RuleDetails; + referencedProfiles: Dict<Profile>; + ruleDetails: RuleDetails; } export default class RuleDetailsProfiles extends React.PureComponent<Props> { @@ -63,7 +64,7 @@ export default class RuleDetailsProfiles extends React.PureComponent<Props> { } }; - renderInheritedProfile = (activation: T.RuleActivation, profile: Profile) => { + renderInheritedProfile = (activation: RuleActivation, profile: Profile) => { if (!profile.parentName) { return null; } @@ -82,7 +83,7 @@ export default class RuleDetailsProfiles extends React.PureComponent<Props> { ); }; - renderSeverity = (activation: T.RuleActivation, parentActivation?: T.RuleActivation) => ( + renderSeverity = (activation: RuleActivation, parentActivation?: RuleActivation) => ( <td className="coding-rules-detail-quality-profile-severity"> <Tooltip overlay={translate('coding_rules.activation_severity')}> <span> @@ -97,10 +98,7 @@ export default class RuleDetailsProfiles extends React.PureComponent<Props> { </td> ); - renderParameter = ( - param: { key: string; value: string }, - parentActivation?: T.RuleActivation - ) => { + renderParameter = (param: { key: string; value: string }, parentActivation?: RuleActivation) => { const originalParam = parentActivation && parentActivation.params.find(p => p.key === param.key); const originalValue = originalParam && originalParam.value; @@ -121,13 +119,13 @@ export default class RuleDetailsProfiles extends React.PureComponent<Props> { ); }; - renderParameters = (activation: T.RuleActivation, parentActivation?: T.RuleActivation) => ( + renderParameters = (activation: RuleActivation, parentActivation?: RuleActivation) => ( <td className="coding-rules-detail-quality-profile-parameters"> {activation.params.map(param => this.renderParameter(param, parentActivation))} </td> ); - renderActions = (activation: T.RuleActivation, profile: Profile) => { + renderActions = (activation: RuleActivation, profile: Profile) => { const canEdit = profile.actions && profile.actions.edit && !profile.isBuiltIn; const { ruleDetails } = this.props; const hasParent = activation.inherit !== 'NONE' && profile.parentKey; @@ -189,7 +187,7 @@ export default class RuleDetailsProfiles extends React.PureComponent<Props> { ); }; - renderActivation = (activation: T.RuleActivation) => { + renderActivation = (activation: RuleActivation) => { const { activations = [], ruleDetails } = this.props; const profile = this.props.referencedProfiles[activation.qProfile]; if (!profile) { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleInheritanceIcon.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleInheritanceIcon.tsx index 958400360f5..4e872e4f751 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleInheritanceIcon.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleInheritanceIcon.tsx @@ -19,10 +19,11 @@ */ import * as React from 'react'; import { colors } from '../../../app/theme'; +import { RuleInheritance } from '../../../types/types'; interface Props { className?: string; - inheritance: T.RuleInheritance; + inheritance: RuleInheritance; } export default function RuleInheritanceIcon({ className, inheritance, ...other }: Props) { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleListItem.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleListItem.tsx index 8900d75c92b..3ad661d4fa9 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleListItem.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleListItem.tsx @@ -29,6 +29,7 @@ import SeverityIcon from '../../../components/icons/SeverityIcon'; import TagsList from '../../../components/tags/TagsList'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { getRuleUrl } from '../../../helpers/urls'; +import { Rule } from '../../../types/types'; import { Activation, Query } from '../query'; import ActivationButton from './ActivationButton'; import RuleInheritanceIcon from './RuleInheritanceIcon'; @@ -42,7 +43,7 @@ interface Props { onDeactivate: (profile: string, rule: string) => void; onFilterChange: (changes: Partial<Query>) => void; onOpen: (ruleKey: string) => void; - rule: T.Rule; + rule: Rule; selected: boolean; selectedProfile?: Profile; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/SimilarRulesFilter.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/SimilarRulesFilter.tsx index c859875597c..9ccadb9d90f 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/SimilarRulesFilter.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/SimilarRulesFilter.tsx @@ -25,11 +25,12 @@ import IssueTypeIcon from '../../../components/icons/IssueTypeIcon'; import TagsIcon from '../../../components/icons/TagsIcon'; import SeverityHelper from '../../../components/shared/SeverityHelper'; import { translate } from '../../../helpers/l10n'; +import { Rule } from '../../../types/types'; import { Query } from '../query'; interface Props { onFilterChange: (changes: Partial<Query>) => void; - rule: T.Rule; + rule: Rule; } export default class SimilarRulesFilter extends React.PureComponent<Props> { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/TemplateFacet.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/TemplateFacet.tsx index 7cd1a8bcc19..3dde2ac9a6d 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/TemplateFacet.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/TemplateFacet.tsx @@ -22,7 +22,7 @@ import HelpTooltip from '../../../components/controls/HelpTooltip'; import { translate } from '../../../helpers/l10n'; import Facet, { BasicProps } from './Facet'; -interface Props extends T.Omit<BasicProps, 'onChange' | 'values'> { +interface Props extends Omit<BasicProps, 'onChange' | 'values'> { onChange: (changes: { template: boolean | undefined }) => void; value: boolean | undefined; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/PageActions-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/PageActions-test.tsx index a4b82a0412a..8541df87275 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/PageActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/PageActions-test.tsx @@ -20,12 +20,13 @@ import { shallow } from 'enzyme'; import * as React from 'react'; +import { Paging } from '../../../../types/types'; import PageActions, { PageActionsProps } from '../PageActions'; it('should render correctly', () => { expect(shallowRender()).toMatchSnapshot('default'); expect(shallowRender({ loading: true })).toMatchSnapshot('loading'); - expect(shallowRender({ paging: { total: 100 } as T.Paging })).toMatchSnapshot('with paging'); + expect(shallowRender({ paging: { total: 100 } as Paging })).toMatchSnapshot('with paging'); }); function shallowRender(props: Partial<PageActionsProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetails-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetails-test.tsx index 2bda64184fe..bc56f355155 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetails-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetails-test.tsx @@ -23,6 +23,7 @@ import * as React from 'react'; import { deleteRule, getRuleDetails, updateRule } from '../../../../api/rules'; import { mockQualityProfile } from '../../../../helpers/testMocks'; import { waitAndUpdate } from '../../../../helpers/testUtils'; +import { RuleType } from '../../../../types/types'; import RuleDetails from '../RuleDetails'; jest.mock('../../../../api/rules', () => { @@ -104,7 +105,7 @@ it('should correctly handle rule changes', () => { repo: 'bar', severity: 'MAJOR', status: 'READY', - type: 'BUG' as T.RuleType + type: 'BUG' as RuleType }; wrapper.instance().handleRuleChange(ruleChange); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsDescription-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsDescription-test.tsx index 783583d9f57..4787fb62fe0 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsDescription-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsDescription-test.tsx @@ -20,13 +20,14 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { change, click, waitAndUpdate } from '../../../../helpers/testUtils'; +import { RuleDetails } from '../../../../types/types'; import RuleDetailsDescription from '../RuleDetailsDescription'; jest.mock('../../../../api/rules', () => ({ updateRule: jest.fn().mockResolvedValue('updatedrule') })); -const RULE: T.RuleDetails = { +const RULE: RuleDetails = { key: 'squid:S1133', repo: 'squid', name: 'Deprecated code should be removed', @@ -40,7 +41,7 @@ const RULE: T.RuleDetails = { type: 'CODE_SMELL' }; -const EXTERNAL_RULE: T.RuleDetails = { +const EXTERNAL_RULE: RuleDetails = { createdAt: '2013-07-26T09:40:51+0200', key: 'external_xoo:OneExternalIssuePerLine', repo: 'external_xoo', @@ -51,7 +52,7 @@ const EXTERNAL_RULE: T.RuleDetails = { type: 'UNKNOWN' }; -const EXTERNAL_RULE_WITH_DATA: T.RuleDetails = { +const EXTERNAL_RULE_WITH_DATA: RuleDetails = { key: 'external_xoo:OneExternalIssueWithDetailsPerLine', repo: 'external_xoo', name: 'One external issue per line', diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx index cddc097c872..a8fe6708c9d 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx @@ -19,10 +19,11 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; +import { RuleDetails } from '../../../../types/types'; import RuleDetailsMeta from '../RuleDetailsMeta'; import RuleDetailsTagsPopup from '../RuleDetailsTagsPopup'; -const RULE: T.RuleDetails = { +const RULE: RuleDetails = { key: 'squid:S1133', repo: 'squid', name: 'Deprecated code should be removed', @@ -35,7 +36,7 @@ const RULE: T.RuleDetails = { type: 'CODE_SMELL' }; -const EXTERNAL_RULE: T.RuleDetails = { +const EXTERNAL_RULE: RuleDetails = { key: 'external_xoo:OneExternalIssuePerLine', repo: 'external_xoo', name: 'xoo:OneExternalIssuePerLine', @@ -47,7 +48,7 @@ const EXTERNAL_RULE: T.RuleDetails = { type: 'UNKNOWN' }; -const EXTERNAL_RULE_WITH_DATA: T.RuleDetails = { +const EXTERNAL_RULE_WITH_DATA: RuleDetails = { key: 'external_xoo:OneExternalIssueWithDetailsPerLine', repo: 'external_xoo', name: 'One external issue per line', diff --git a/server/sonar-web/src/main/js/apps/coding-rules/query.ts b/server/sonar-web/src/main/js/apps/coding-rules/query.ts index b851a8a2369..0407fef13fc 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/query.ts +++ b/server/sonar-web/src/main/js/apps/coding-rules/query.ts @@ -30,6 +30,7 @@ import { serializeString, serializeStringArray } from '../../helpers/query'; +import { Dict, RawQuery, RuleInheritance } from '../../types/types'; export interface Query { activation: boolean | undefined; @@ -37,7 +38,7 @@ export interface Query { availableSince: Date | undefined; compareToProfile: string | undefined; cwe: string[]; - inheritance: T.RuleInheritance | undefined; + inheritance: RuleInheritance | undefined; languages: string[]; owaspTop10: string[]; profile: string | undefined; @@ -61,10 +62,10 @@ export interface Facet { export type Facets = { [F in FacetKey]?: Facet }; -export type OpenFacets = T.Dict<boolean>; +export type OpenFacets = Dict<boolean>; export interface Activation { - inherit: T.RuleInheritance; + inherit: RuleInheritance; severity: string; } @@ -74,7 +75,7 @@ export interface Actives { }; } -export function parseQuery(query: T.RawQuery): Query { +export function parseQuery(query: RawQuery): Query { return { activation: parseAsOptionalBoolean(query.activation), activationSeverities: parseAsArray(query.active_severities, parseAsString), @@ -98,7 +99,7 @@ export function parseQuery(query: T.RawQuery): Query { }; } -export function serializeQuery(query: Query): T.RawQuery { +export function serializeQuery(query: Query): RawQuery { return cleanQuery({ activation: serializeOptionalBoolean(query.activation), active_severities: serializeStringArray(query.activationSeverities), @@ -122,7 +123,7 @@ export function serializeQuery(query: Query): T.RawQuery { }); } -export function areQueriesEqual(a: T.RawQuery, b: T.RawQuery) { +export function areQueriesEqual(a: RawQuery, b: RawQuery) { return queriesEqual(parseQuery(a), parseQuery(b)); } @@ -152,15 +153,15 @@ export function getAppFacet(serverFacet: string): FacetKey { return serverFacet === 'active_severities' ? 'activationSeverities' : (serverFacet as FacetKey); } -export function getOpen(query: T.RawQuery) { +export function getOpen(query: RawQuery) { return query.open; } -export function hasRuleKey(query: T.RawQuery) { +export function hasRuleKey(query: RawQuery) { return Boolean(query.rule_key); } -function parseAsInheritance(value?: string): T.RuleInheritance | undefined { +function parseAsInheritance(value?: string): RuleInheritance | undefined { if (value === 'INHERITED' || value === 'NONE' || value === 'OVERRIDES') { return value; } else { @@ -168,6 +169,6 @@ function parseAsInheritance(value?: string): T.RuleInheritance | undefined { } } -function serializeInheritance(value: T.RuleInheritance | undefined): string | undefined { +function serializeInheritance(value: RuleInheritance | undefined): string | undefined { return value; } diff --git a/server/sonar-web/src/main/js/apps/coding-rules/routes.ts b/server/sonar-web/src/main/js/apps/coding-rules/routes.ts index 8049584924b..24bbc0ca79b 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/routes.ts +++ b/server/sonar-web/src/main/js/apps/coding-rules/routes.ts @@ -19,10 +19,11 @@ */ import { RedirectFunction, RouterState } from 'react-router'; import { lazyLoadComponent } from '../../components/lazyLoadComponent'; +import { RawQuery } from '../../types/types'; import { parseQuery, serializeQuery } from './query'; -function parseHash(hash: string): T.RawQuery { - const query: T.RawQuery = {}; +function parseHash(hash: string): RawQuery { + const query: RawQuery = {}; const parts = hash.split('|'); parts.forEach(part => { const tokens = part.split('='); |