Passed
Push — feature/azure-webapp-pipeline-... ( 33e0f0...f382c1 )
by Grant
05:11
created

resources/assets/js/components/ApplicationReview/ApplicantBucket.tsx   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 93
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 71
mnd 2
bc 2
fnc 0
dl 0
loc 93
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React from "react";
2
import { FormattedMessage } from "react-intl";
3
import { Application } from "../../models/types";
4
import { SelectOption } from "../Select";
5
import ApplicationReview from "./ApplicationReview";
6
import { whereFirst } from "../../helpers/queries";
7
import {
8
  applicationCompare,
9
  applicationComparePrioritizeVeterans,
10
} from "./helpers";
11
import { Portal } from "../../models/app";
12
13
interface ApplicantBucketProps {
14
  title: string;
15
  description: string;
16
  applications: Application[];
17
  reviewStatusOptions: SelectOption[];
18
  onStatusChange: (applicationId: number, statusId: number | null) => void;
19
  onNotesChange: (applicationId: number, notes: string | null) => void;
20
  savingStatuses: { applicationId: number; isSaving: boolean }[];
21
  prioritizeVeterans: boolean;
22
  portal: Portal;
23
}
24
25
const ApplicantBucket: React.StatelessComponent<ApplicantBucketProps> = ({
26
  title,
27
  description,
28
  applications,
29
  reviewStatusOptions,
30
  onStatusChange,
31
  onNotesChange,
32
  savingStatuses,
33
  prioritizeVeterans,
34
  portal,
35
}: ApplicantBucketProps): React.ReactElement | null => {
36
  if (applications.length === 0) {
37
    return null;
38
  }
39
40
  const compareFunction = prioritizeVeterans
41
    ? applicationComparePrioritizeVeterans
42
    : applicationCompare;
43
  const sortedApplications = applications.slice().sort(compareFunction);
44
  return (
45
    <div className="accordion applicant-bucket">
46
      <button
47
        aria-expanded="false"
48
        className="accordion-trigger"
49
        tabIndex={0}
50
        type="button"
51
      >
52
        <span className="bucket-title">
53
          {title} ({applications.length})
54
        </span>
55
56
        <span className="invisible">
57
          <FormattedMessage
58
            id="button.toggleAccordion"
59
            defaultMessage="Toggle this step to view relevant applicants."
60
            description="Instructions to reveal hidden list data."
61
          />
62
        </span>
63
64
        <i className="fas fa-chevron-up" />
65
      </button>
66
67
      {/* Accordion Content */}
68
      <div aria-hidden="true" className="accordion-content">
69
        <p>{description}</p>
70
71
        {sortedApplications.map(
72
          (application: Application): React.ReactElement => (
73
            <ApplicationReview
74
              key={application.id}
75
              application={application}
76
              reviewStatusOptions={reviewStatusOptions}
77
              onStatusChange={onStatusChange}
78
              onNotesChange={onNotesChange}
79
              isSaving={
80
                whereFirst(savingStatuses, "applicationId", application.id)
81
                  .isSaving
82
              }
83
              portal={portal}
84
            />
85
          ),
86
        )}
87
      </div>
88
    </div>
89
  );
90
};
91
92
export default ApplicantBucket;
93