diff --git a/scm-ui/src/components/Page.js b/scm-ui/src/components/Page.js new file mode 100644 index 0000000000..67de0f59f2 --- /dev/null +++ b/scm-ui/src/components/Page.js @@ -0,0 +1,46 @@ +//@flow +import * as React from "react"; +import Loading from "./Loading"; +import ErrorNotification from "./ErrorNotification"; + +type Props = { + title: string, + subtitle?: string, + loading?: boolean, + error?: Error, + children: React.Node +}; + +class Page extends React.Component { + render() { + const { title, error } = this.props; + return ( +
+
+

{title}

+ {this.renderSubtitle()} + + {this.renderContent()} +
+
+ ); + } + + renderSubtitle() { + const { subtitle } = this.props; + if (subtitle) { + return

Users

; + } + return null; + } + + renderContent() { + const { loading, children } = this.props; + if (loading) { + return ; + } + return children; + } +} + +export default Page; diff --git a/scm-ui/src/users/containers/UserRow.js b/scm-ui/src/users/containers/UserRow.js index 3752386250..84ff684f5b 100644 --- a/scm-ui/src/users/containers/UserRow.js +++ b/scm-ui/src/users/containers/UserRow.js @@ -7,13 +7,12 @@ import type { UserEntry } from "../types/UserEntry"; type Props = { entry: UserEntry, - deleteUser: User => void, - editUser: User => void + deleteUser: User => void }; export default class UserRow extends React.Component { render() { - const { entry, deleteUser, editUser } = this.props; + const { entry, deleteUser } = this.props; const user = entry.entry; return ( @@ -27,7 +26,7 @@ export default class UserRow extends React.Component { - + ); diff --git a/scm-ui/src/users/containers/UserTable.js b/scm-ui/src/users/containers/UserTable.js index e90798054a..19d0766cb2 100644 --- a/scm-ui/src/users/containers/UserTable.js +++ b/scm-ui/src/users/containers/UserTable.js @@ -6,13 +6,12 @@ import type { UserEntry } from "../types/UserEntry"; type Props = { entries: Array, - deleteUser: User => void, - editUser: User => void + deleteUser: User => void }; class UserTable extends React.Component { render() { - const { deleteUser, editUser } = this.props; + const { deleteUser } = this.props; const entries = this.props.entries; return ( @@ -29,12 +28,7 @@ class UserTable extends React.Component { {entries.map((entry, index) => { return ( - + ); })} diff --git a/scm-ui/src/users/containers/Users.js b/scm-ui/src/users/containers/Users.js index d1ae790a18..13a4616c5f 100644 --- a/scm-ui/src/users/containers/Users.js +++ b/scm-ui/src/users/containers/Users.js @@ -3,7 +3,7 @@ import React from "react"; import { connect } from "react-redux"; import { fetchUsers, deleteUser, getUsersFromState } from "../modules/users"; -import Loading from "../../components/Loading"; +import Page from "../../components/Page"; import ErrorNotification from "../../components/ErrorNotification"; import UserTable from "./UserTable"; import type { User } from "../types/User"; @@ -11,7 +11,7 @@ import AddButton from "../../components/AddButton"; import type { UserEntry } from "../types/UserEntry"; type Props = { - login: boolean, + loading?: boolean, error: Error, userEntries: Array, fetchUsers: () => void, @@ -25,32 +25,20 @@ class Users extends React.Component { } render() { + const { userEntries, deleteUser, loading, error } = this.props; return ( -
-
-

SCM

-

Users

- {this.renderContent()} - {this.renderAddButton()} -
-
+ + + {this.renderAddButton()} + ); } - renderContent() { - const { userEntries, deleteUser, error } = this.props; - if (userEntries) { - return ( -
- - -
- ); - } else { - return ; - } - } - renderAddButton() { if (this.props.canAddUsers) { return ( @@ -67,14 +55,17 @@ class Users extends React.Component { const mapStateToProps = state => { const userEntries = getUsersFromState(state); let error = null; + let loading = false; let canAddUsers = false; if (state.users && state.users.users) { error = state.users.users.error; canAddUsers = state.users.users.userCreatePermission; + loading = state.users.users.loading; } return { userEntries, error, + loading, canAddUsers }; };