• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CBIIT / crdc-datahub-ui / 9163061041

20 May 2024 06:09PM UTC coverage: 30.327%. First build
9163061041

Pull #376

github

web-flow
Merge c6ff5a713 into 3a88433db
Pull Request #376: Fix missing eslint extends

877 of 3630 branches covered (24.16%)

Branch coverage included in aggregate %.

2 of 7 new or added lines in 7 files covered. (28.57%)

1534 of 4320 relevant lines covered (35.51%)

95.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/content/users/Controller.tsx
1
import React, { memo } from "react";
2
import { Navigate, useParams } from "react-router-dom";
3
import { useAuthContext } from "../../components/Contexts/AuthContext";
4
import { OrganizationProvider } from "../../components/Contexts/OrganizationListContext";
5
import ListView from "./ListView";
6
import ProfileView from "./ProfileView";
7

8
type Props = {
9
  type: "users" | "profile";
10
};
11

12
/**
13
 * A memoized version of OrganizationProvider
14
 * which caches data between ListView and ProfileView
15
 *
16
 * @see OrganizationProvider
17
 */
18
const MemorizedProvider = memo(OrganizationProvider);
×
19

20
/**
21
 * Renders the correct view based on the URL and permissions-tier
22
 *
23
 * Implementation details:
24
 *
25
 * There are two types `ProfileView` "views": `users` and `profile`,
26
 * and based on the view type, the authenticated user will see slightly different content.
27
 *
28
 *   - `users` aka Edit User view:
29
 *     - allows editing `Role`, `Status`, and `Organization` for Admins,
30
 *       but allows Org Owners to only see that profile.
31
 *   - `profile` aka User Profile view:
32
 *     - is only shown to the authenticated user, and allows editing
33
 *       of `First Name` and `Last Name` only
34
 *
35
 * Most of the underlying logic is the same, hence the combination of
36
 * these two views into a single component. There's also a `ListView`
37
 * which is shown to Admins and Org Owners, and allows them to see
38
 * the list of users.
39
 *
40
 * @param {Props} props - React props
41
 * @returns {FC} - React component
42
 */
NEW
43
const UserController = ({ type }: Props) => {
×
44
  const { userId } = useParams();
×
45
  const { user } = useAuthContext();
×
46
  const { _id, role } = user || {};
×
47
  const isAdministrative = role === "Admin" || role === "Organization Owner";
×
48

49
  // Accounts can only view their own "profile", redirect to it
50
  if ((type === "profile" && userId !== _id) || (type === "users" && !isAdministrative)) {
×
51
    return <Navigate to={`/profile/${_id}`} />;
×
52
  }
53

54
  // Show list of users to Admin or Org Owner
55
  if (!userId && isAdministrative) {
×
56
    return (
×
57
      <MemorizedProvider preload filterInactive>
58
        <ListView />
59
      </MemorizedProvider>
60
    );
61
  }
62

63
  // Admin or Org Owner viewing a user's "Edit User" page or their own "Edit User" page
64
  return (
×
65
    <MemorizedProvider preload={isAdministrative && type === "users"} filterInactive>
×
66
      <ProfileView _id={userId} viewType={type} />
67
    </MemorizedProvider>
68
  );
69
};
70

71
export default UserController;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc