From 3daa0584ea72eb3ad117c4efb98cbb1f2a5d1070 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Mon, 24 Sep 2018 15:00:05 +0200 Subject: [PATCH] SONAR-11296 Display language name after bulk activation of rules --- server/sonar-web/src/main/js/api/languages.ts | 6 +----- server/sonar-web/src/main/js/app/types.ts | 9 +++++++++ .../js/apps/coding-rules/components/App.tsx | 19 +++++++++++++++++-- .../coding-rules/components/BulkChange.tsx | 3 +++ .../components/BulkChangeModal.tsx | 12 +++++++++--- .../overview/meta/MetaQualityProfiles.tsx | 4 ++-- .../components/ProjectCardLanguages.tsx | 2 +- .../apps/projects/filters/LanguagesFilter.tsx | 3 ++- .../apps/quality-profiles/components/App.tsx | 2 +- .../charts/LanguageDistribution.tsx | 2 +- .../sonar-web/src/main/js/store/languages.ts | 5 +---- .../src/main/js/store/rootReducer.ts | 4 ++-- 12 files changed, 49 insertions(+), 22 deletions(-) diff --git a/server/sonar-web/src/main/js/api/languages.ts b/server/sonar-web/src/main/js/api/languages.ts index c49c1290672..ebf3efdb631 100644 --- a/server/sonar-web/src/main/js/api/languages.ts +++ b/server/sonar-web/src/main/js/api/languages.ts @@ -18,13 +18,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { getJSON } from '../helpers/request'; +import { Language } from '../app/types'; import throwGlobalError from '../app/utils/throwGlobalError'; -export interface Language { - key: string; - name: string; -} - export function getLanguages(): Promise { return getJSON('/api/languages/list').then(r => r.languages, throwGlobalError); } diff --git a/server/sonar-web/src/main/js/app/types.ts b/server/sonar-web/src/main/js/app/types.ts index 4df5d148def..c706a55e75b 100644 --- a/server/sonar-web/src/main/js/app/types.ts +++ b/server/sonar-web/src/main/js/app/types.ts @@ -343,6 +343,15 @@ export enum IssueType { Hotspot = 'SECURITY_HOTSPOT' } +export interface Language { + key: string; + name: string; +} + +export interface Languages { + [key: string]: Language; +} + export interface LightComponent { key: string; organization: string; 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 685d0583940..e91c19c790b 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 @@ -51,11 +51,23 @@ import FiltersHeader from '../../../components/common/FiltersHeader'; import SearchBox from '../../../components/controls/SearchBox'; import { searchRules, getRulesApp } from '../../../api/rules'; import { searchQualityProfiles, Profile } from '../../../api/quality-profiles'; -import { getCurrentUser, getMyOrganizations, Store } from '../../../store/rootReducer'; +import { + getCurrentUser, + getLanguages, + getMyOrganizations, + Store +} from '../../../store/rootReducer'; import { translate } from '../../../helpers/l10n'; import { RawQuery } from '../../../helpers/query'; import { scrollToElement } from '../../../helpers/scrolling'; -import { Paging, Rule, RuleActivation, Organization, CurrentUser } from '../../../app/types'; +import { + CurrentUser, + Languages, + Paging, + Organization, + Rule, + RuleActivation +} from '../../../app/types'; import '../../../components/search-navigator.css'; import '../styles.css'; import { hasPrivateAccess } from '../../../helpers/organizations'; @@ -65,6 +77,7 @@ const LIMIT_BEFORE_LOAD_MORE = 5; interface StateToProps { currentUser: CurrentUser; + languages: Languages; userOrganizations: Organization[]; } @@ -544,6 +557,7 @@ export class App extends React.PureComponent { ) : ( this.state.paging && ( ({ currentUser: getCurrentUser(state), + languages: getLanguages(state), userOrganizations: getMyOrganizations(state) }); 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 6b47b2d704d..80a997a3f16 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,8 +24,10 @@ import { Profile } from '../../../api/quality-profiles'; import Dropdown from '../../../components/controls/Dropdown'; import { Button } from '../../../components/ui/buttons'; import { translate } from '../../../helpers/l10n'; +import { Languages } from '../../../app/types'; interface Props { + languages: Languages; organization: string | undefined; query: Query; referencedProfiles: { [profile: string]: Profile }; @@ -129,6 +131,7 @@ export default class BulkChange extends React.PureComponent { this.state.action && ( void; organization: string | undefined; - referencedProfiles: { [profile: string]: Profile }; profile?: Profile; query: Query; + referencedProfiles: { [profile: string]: Profile }; total: number; } @@ -148,6 +150,10 @@ export default class BulkChangeModal extends React.PureComponent { if (!profile) { return null; } + const { languages } = this.props; + const language = languages[profile.language] + ? languages[profile.language].name + : profile.language; return (
{ ? translateWithParameters( 'coding_rules.bulk_change.warning', profile.name, - profile.language, + language, result.succeeded, result.failed ) : translateWithParameters( 'coding_rules.bulk_change.success', profile.name, - profile.language, + language, result.succeeded )}
diff --git a/server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.tsx b/server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.tsx index eb8f8fc45f0..06452143c33 100644 --- a/server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.tsx +++ b/server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.tsx @@ -26,10 +26,10 @@ import { translate, translateWithParameters } from '../../../helpers/l10n'; import { getQualityProfileUrl } from '../../../helpers/urls'; import { searchRules } from '../../../api/rules'; import { getLanguages, Store } from '../../../store/rootReducer'; -import { ComponentQualityProfile } from '../../../app/types'; +import { ComponentQualityProfile, Languages } from '../../../app/types'; interface StateProps { - languages: { [key: string]: { name: string } }; + languages: Languages; } interface OwnProps { diff --git a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLanguages.tsx b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLanguages.tsx index 1fd92c29037..507c75ef39c 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLanguages.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/ProjectCardLanguages.tsx @@ -21,7 +21,7 @@ import * as React from 'react'; import { sortBy } from 'lodash'; import Tooltip from '../../../components/controls/Tooltip'; import { translate } from '../../../helpers/l10n'; -import { Languages } from '../../../store/languages'; +import { Languages } from '../../../app/types'; interface Props { distribution?: string; diff --git a/server/sonar-web/src/main/js/apps/projects/filters/LanguagesFilter.tsx b/server/sonar-web/src/main/js/apps/projects/filters/LanguagesFilter.tsx index 33229e381b7..7d875b5ae85 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/LanguagesFilter.tsx +++ b/server/sonar-web/src/main/js/apps/projects/filters/LanguagesFilter.tsx @@ -23,10 +23,11 @@ import Filter from './Filter'; import FilterHeader from './FilterHeader'; import SearchableFilterFooter from './SearchableFilterFooter'; import SearchableFilterOption from './SearchableFilterOption'; -import { getLanguageByKey, Languages } from '../../../store/languages'; +import { getLanguageByKey } from '../../../store/languages'; import { translate } from '../../../helpers/l10n'; import { Facet } from '../types'; import { RawQuery } from '../../../helpers/query'; +import { Languages } from '../../../app/types'; interface Props { facet?: Facet; diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx index 5fa5abf6642..dc123ff9963 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx @@ -24,7 +24,7 @@ import { sortProfiles } from '../utils'; import { Exporter, Profile } from '../types'; import OrganizationHelmet from '../../../components/common/OrganizationHelmet'; import { translate } from '../../../helpers/l10n'; -import { Languages } from '../../../store/languages'; +import { Languages } from '../../../app/types'; import '../styles.css'; interface Props { diff --git a/server/sonar-web/src/main/js/components/charts/LanguageDistribution.tsx b/server/sonar-web/src/main/js/components/charts/LanguageDistribution.tsx index 9c4fbe34a9a..1ff1acac6c6 100644 --- a/server/sonar-web/src/main/js/components/charts/LanguageDistribution.tsx +++ b/server/sonar-web/src/main/js/components/charts/LanguageDistribution.tsx @@ -22,7 +22,7 @@ import { sortBy } from 'lodash'; import Histogram from './Histogram'; import { formatMeasure } from '../../helpers/measures'; import { translate } from '../../helpers/l10n'; -import { Languages } from '../../store/languages'; +import { Languages } from '../../app/types'; interface Props { alignTicks?: boolean; diff --git a/server/sonar-web/src/main/js/store/languages.ts b/server/sonar-web/src/main/js/store/languages.ts index 2cc95fe3006..e80c9d2cdbc 100644 --- a/server/sonar-web/src/main/js/store/languages.ts +++ b/server/sonar-web/src/main/js/store/languages.ts @@ -19,6 +19,7 @@ */ import { keyBy } from 'lodash'; import { ActionType } from './utils/actions'; +import { Languages } from '../app/types'; export function receiveLanguages(languages: Array<{ key: string; name: string }>) { return { type: 'RECEIVE_LANGUAGES', languages }; @@ -26,10 +27,6 @@ export function receiveLanguages(languages: Array<{ key: string; name: string }> type Action = ActionType; -export interface Languages { - [key: string]: { key: string; name: string }; -} - export default function(state: Languages = {}, action: Action): Languages { if (action.type === 'RECEIVE_LANGUAGES') { return keyBy(action.languages, 'key'); diff --git a/server/sonar-web/src/main/js/store/rootReducer.ts b/server/sonar-web/src/main/js/store/rootReducer.ts index 8dfc49d857f..6a913690bdb 100644 --- a/server/sonar-web/src/main/js/store/rootReducer.ts +++ b/server/sonar-web/src/main/js/store/rootReducer.ts @@ -24,7 +24,7 @@ import languages, * as fromLanguages from './languages'; import metrics, * as fromMetrics from './metrics'; import organizations, * as fromOrganizations from './organizations'; import users, * as fromUsers from './users'; -import { AppState } from '../app/types'; +import { AppState, Languages } from '../app/types'; import permissionsApp, * as fromPermissionsApp from '../apps/permissions/shared/store/rootReducer'; import projectAdminApp, * as fromProjectAdminApp from '../apps/project-admin/store/rootReducer'; import settingsApp, * as fromSettingsApp from '../apps/settings/store/rootReducer'; @@ -32,7 +32,7 @@ import settingsApp, * as fromSettingsApp from '../apps/settings/store/rootReduce export type Store = { appState: AppState; globalMessages: fromGlobalMessages.State; - languages: fromLanguages.Languages; + languages: Languages; metrics: fromMetrics.State; organizations: fromOrganizations.State; users: fromUsers.State; -- 2.39.5