From 64d76164768f4b74d6bdc714191f65567baf8d10 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Thu, 20 Sep 2018 12:05:07 +0200 Subject: [PATCH] rewrite account app in ts --- server/sonar-web/src/main/js/api/users.ts | 4 +- .../__tests__/StartupModal-test.tsx | 2 + server/sonar-web/src/main/js/app/types.ts | 3 + .../components/{Account.js => Account.tsx} | 18 ++++-- .../account/components/{Nav.js => Nav.tsx} | 13 ++--- .../components/{Password.js => Password.tsx} | 55 +++++++++--------- .../components/{Security.js => Security.tsx} | 17 ++++-- .../components/{UserCard.js => UserCard.tsx} | 34 +++++------ .../profile/{Profile.js => Profile.tsx} | 39 ++++++------- ...alIdentity.js => UserExternalIdentity.tsx} | 22 ++++++-- .../profile/{UserGroups.js => UserGroups.tsx} | 39 ++++++------- ...UserScmAccounts.js => UserScmAccounts.tsx} | 56 +++++++++---------- .../__tests__/CreateProjectPage-test.tsx | 4 +- .../__tests__/ManualProjectCreate-test.tsx | 2 +- .../CreateProjectPage-test.tsx.snap | 2 + .../__tests__/AnalyzeTutorial-test.tsx | 4 +- .../AnalyzeTutorial-test.tsx.snap | 2 + 17 files changed, 167 insertions(+), 149 deletions(-) rename server/sonar-web/src/main/js/apps/account/components/{Account.js => Account.tsx} (82%) rename server/sonar-web/src/main/js/apps/account/components/{Nav.js => Nav.tsx} (92%) rename server/sonar-web/src/main/js/apps/account/components/{Password.js => Password.tsx} (80%) rename server/sonar-web/src/main/js/apps/account/components/{Security.js => Security.tsx} (76%) rename server/sonar-web/src/main/js/apps/account/components/{UserCard.js => UserCard.tsx} (63%) rename server/sonar-web/src/main/js/apps/account/profile/{Profile.js => Profile.tsx} (75%) rename server/sonar-web/src/main/js/apps/account/profile/{UserExternalIdentity.js => UserExternalIdentity.tsx} (85%) rename server/sonar-web/src/main/js/apps/account/profile/{UserGroups.js => UserGroups.tsx} (60%) rename server/sonar-web/src/main/js/apps/account/profile/{UserScmAccounts.js => UserScmAccounts.tsx} (52%) diff --git a/server/sonar-web/src/main/js/api/users.ts b/server/sonar-web/src/main/js/api/users.ts index f266f79bd41..1954f192c50 100644 --- a/server/sonar-web/src/main/js/api/users.ts +++ b/server/sonar-web/src/main/js/api/users.ts @@ -29,8 +29,8 @@ export function changePassword(data: { login: string; password: string; previousPassword?: string; -}): Promise { - return post('/api/users/change_password', data); +}) { + return post('/api/users/change_password', data).catch(throwGlobalError); } export interface UserGroup { diff --git a/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx index 7a1e2bf2d3d..374be478fcd 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx @@ -48,9 +48,11 @@ jest.mock('../../../helpers/dates', () => ({ })); const LOGGED_IN_USER: LoggedInUser = { + groups: [], isLoggedIn: true, login: 'luke', name: 'Skywalker', + scmAccounts: [], showOnboardingTutorial: false }; diff --git a/server/sonar-web/src/main/js/app/types.ts b/server/sonar-web/src/main/js/app/types.ts index 254817b7430..4df5d148def 100644 --- a/server/sonar-web/src/main/js/app/types.ts +++ b/server/sonar-web/src/main/js/app/types.ts @@ -362,10 +362,13 @@ export interface LoggedInUser extends CurrentUser { email?: string; externalIdentity?: string; externalProvider?: string; + groups: string[]; homepage?: HomePage; isLoggedIn: true; + local?: boolean; login: string; name: string; + scmAccounts: string[]; } export interface LongLivingBranch extends Branch { diff --git a/server/sonar-web/src/main/js/apps/account/components/Account.js b/server/sonar-web/src/main/js/apps/account/components/Account.tsx similarity index 82% rename from server/sonar-web/src/main/js/apps/account/components/Account.js rename to server/sonar-web/src/main/js/apps/account/components/Account.tsx index bb4e8645692..02711b9d407 100644 --- a/server/sonar-web/src/main/js/apps/account/components/Account.js +++ b/server/sonar-web/src/main/js/apps/account/components/Account.tsx @@ -17,18 +17,24 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import React from 'react'; +import * as React from 'react'; import { connect } from 'react-redux'; import Helmet from 'react-helmet'; import Nav from './Nav'; import UserCard from './UserCard'; -import { getCurrentUser, areThereCustomOrganizations } from '../../../store/rootReducer'; +import { CurrentUser, LoggedInUser } from '../../../app/types'; +import { getCurrentUser, areThereCustomOrganizations, Store } from '../../../store/rootReducer'; import { translate } from '../../../helpers/l10n'; import handleRequiredAuthentication from '../../../app/utils/handleRequiredAuthentication'; import Suggestions from '../../../app/components/embed-docs-modal/Suggestions'; import '../account.css'; -class Account extends React.PureComponent { +interface Props { + currentUser: CurrentUser; + customOrganizations?: boolean; +} + +class Account extends React.PureComponent { componentDidMount() { if (!this.props.currentUser.isLoggedIn) { handleRequiredAuthentication(); @@ -49,8 +55,8 @@ class Account extends React.PureComponent {
- -
@@ -60,7 +66,7 @@ class Account extends React.PureComponent { } } -const mapStateToProps = state => ({ +const mapStateToProps = (state: Store) => ({ currentUser: getCurrentUser(state), customOrganizations: areThereCustomOrganizations(state) }); diff --git a/server/sonar-web/src/main/js/apps/account/components/Nav.js b/server/sonar-web/src/main/js/apps/account/components/Nav.tsx similarity index 92% rename from server/sonar-web/src/main/js/apps/account/components/Nav.js rename to server/sonar-web/src/main/js/apps/account/components/Nav.tsx index 8688985c311..304ddb10ded 100644 --- a/server/sonar-web/src/main/js/apps/account/components/Nav.js +++ b/server/sonar-web/src/main/js/apps/account/components/Nav.tsx @@ -17,19 +17,16 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// @flow -import React from 'react'; +import * as React from 'react'; import { Link, IndexLink } from 'react-router'; import NavBarTabs from '../../../components/nav/NavBarTabs'; import { translate } from '../../../helpers/l10n'; -/*:: -type Props = { - customOrganizations: boolean -}; -*/ +interface Props { + customOrganizations?: boolean; +} -export default function Nav({ customOrganizations } /*: Props */) { +export default function Nav({ customOrganizations }: Props) { return (