From b5f64429d4fa28c41daf553f5043bb2b0221360c Mon Sep 17 00:00:00 2001 From: Philipp Czora Date: Tue, 24 Jul 2018 17:05:38 +0200 Subject: [PATCH] Use Me-type --- scm-ui/src/components/Footer.js | 5 +++-- scm-ui/src/containers/App.js | 15 ++++++--------- scm-ui/src/modules/auth.js | 4 +++- scm-ui/src/modules/auth.test.js | 7 +++++-- scm-ui/src/types/Me.js | 6 ++++++ scm-ui/src/users/modules/users.js | 1 - 6 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 scm-ui/src/types/Me.js diff --git a/scm-ui/src/components/Footer.js b/scm-ui/src/components/Footer.js index db051ef791..2600924adf 100644 --- a/scm-ui/src/components/Footer.js +++ b/scm-ui/src/components/Footer.js @@ -1,8 +1,9 @@ //@flow import React from "react"; +import { Me } from "../types/Me"; type Props = { - me?: string + me?: Me }; class Footer extends React.Component { @@ -14,7 +15,7 @@ class Footer extends React.Component { return (
-

{me}

+

{me.displayName}

); diff --git a/scm-ui/src/containers/App.js b/scm-ui/src/containers/App.js index 95a4970def..7e581a56ff 100644 --- a/scm-ui/src/containers/App.js +++ b/scm-ui/src/containers/App.js @@ -14,11 +14,10 @@ import ErrorPage from "../components/ErrorPage"; import Footer from "../components/Footer"; type Props = { - me: any, + me: Me, error: Error, loading: boolean, authenticated?: boolean, - displayName: string, t: string => string, fetchMe: () => void }; @@ -29,7 +28,7 @@ class App extends Component { } render() { - const { loading, error, authenticated, displayName, t } = this.props; + const { me, loading, error, authenticated, t } = this.props; let content; const navigation = authenticated ? : ""; @@ -51,7 +50,7 @@ class App extends Component {
{navigation}
{content} -
); } @@ -65,16 +64,14 @@ const mapDispatchToProps = (dispatch: any) => { const mapStateToProps = state => { let mapped = state.auth.me || {}; - let displayName; + if (state.auth.login) { mapped.authenticated = state.auth.login.authenticated; } - if (state.auth.me && state.auth.me.entry) { - displayName = state.auth.me.entry.displayName; - } + return { ...mapped, - displayName + me: mapped.entry }; }; diff --git a/scm-ui/src/modules/auth.js b/scm-ui/src/modules/auth.js index 5540063ee5..8f6e580960 100644 --- a/scm-ui/src/modules/auth.js +++ b/scm-ui/src/modules/auth.js @@ -205,7 +205,9 @@ export const fetchMe = () => { return response.json(); }) .then(me => { - dispatch(fetchMeSuccess(me)); + dispatch( + fetchMeSuccess({ userName: me.name, displayName: me.displayName }) + ); }) .catch((error: Error) => { if (error === UNAUTHORIZED_ERROR) { diff --git a/scm-ui/src/modules/auth.test.js b/scm-ui/src/modules/auth.test.js index 689a74c047..6701aace33 100644 --- a/scm-ui/src/modules/auth.test.js +++ b/scm-ui/src/modules/auth.test.js @@ -166,13 +166,16 @@ describe("auth actions", () => { it("should dispatch fetch me success", () => { fetchMock.getOnce("/scm/api/rest/v2/me", { - body: { username: "sorbot" }, + body: { name: "sorbot", displayName: "Sorbot" }, headers: { "content-type": "application/json" } }); const expectedActions = [ { type: FETCH_ME_REQUEST }, - { type: FETCH_ME_SUCCESS, payload: { username: "sorbot" } } + { + type: FETCH_ME_SUCCESS, + payload: { userName: "sorbot", displayName: "Sorbot" } + } ]; const store = mockStore({}); diff --git a/scm-ui/src/types/Me.js b/scm-ui/src/types/Me.js new file mode 100644 index 0000000000..18594ebe7a --- /dev/null +++ b/scm-ui/src/types/Me.js @@ -0,0 +1,6 @@ +// @flow + +export type Me = { + userName: string, + displayName: string +}; diff --git a/scm-ui/src/users/modules/users.js b/scm-ui/src/users/modules/users.js index 7fbb4c33c5..1b6c2d269d 100644 --- a/scm-ui/src/users/modules/users.js +++ b/scm-ui/src/users/modules/users.js @@ -26,7 +26,6 @@ export const DELETE_USER_SUCCESS = "scm/users/DELETE_SUCCESS"; export const DELETE_USER_FAILURE = "scm/users/DELETE_FAILURE"; const USERS_URL = "users"; -const USER_URL = "users/"; const CONTENT_TYPE_USER = "application/vnd.scmm-user+json;v=2";