Passed
Push — task/ci-test-actions ( aba228 )
by Tristan
06:05
created

resources/assets/js/components/AssessmentPlan/RatingGuideBuilder.tsx   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 103
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 80
dl 0
loc 103
rs 10
c 0
b 0
f 0
wmc 1
mnd 1
bc 1
fnc 0
bpm 0
cpm 0
noi 0
1
import React from "react";
2
import { FormattedMessage } from "react-intl";
3
import { connect } from "react-redux";
4
import { Assessment } from "../../models/types";
5
6
import { getUniqueAssessmentTypes } from "./assessmentHelpers";
7
import { AssessmentTypeId } from "../../models/lookupConstants";
8
import RatingGuideAssessment from "./RatingGuideAssessment";
9
import RatingGuideClipboard from "./RatingGuideClipboard";
10
import RatingGuideNarrativeAssessment from "./RatingGuideNarrativeAssessment";
11
import { RootState } from "../../store/store";
12
import { getAssessmentsByJob } from "../../store/Assessment/assessmentSelectorComplex";
13
14
interface RatingsGuideBuilderProps {
15
  assessments: Assessment[];
16
  jobId: number;
17
}
18
19
const RatingGuideBuilder: React.FunctionComponent<RatingsGuideBuilderProps> = ({
20
  assessments,
21
  jobId,
22
}): React.ReactElement => {
23
  let sectionCount = 0;
24
  const narrativeReview = assessments.filter(
25
    (assessment: Assessment): boolean =>
26
      assessment.assessment_type_id === AssessmentTypeId.NarrativeAssessment,
27
  );
28
  const otherAssessments = assessments.filter(
29
    (assessment: Assessment): boolean =>
30
      assessment.assessment_type_id !== AssessmentTypeId.NarrativeAssessment,
31
  );
32
  const isNarrativeAssessments = narrativeReview.length > 0;
33
  const narrativeAssessments = (
34
    <RatingGuideNarrativeAssessment jobId={jobId} assessmentIndex={1} />
35
  );
36
  return (
37
    <div>
38
      <h3
39
        data-c-font-size="h3"
40
        data-c-font-weight="bold"
41
        data-c-margin="top(triple) bottom(normal)"
42
      >
43
        <FormattedMessage
44
          id="ratingGuideBuilder.title"
45
          defaultMessage="3. Ratings Guide Builder"
46
          description="Title of the Rating Guide Builder section."
47
        />
48
      </h3>
49
      <p data-c-margin="bottom(normal)">
50
        <FormattedMessage
51
          id="ratingGuideBuilder.instructions"
52
          defaultMessage={`Below you will create your own ratings guide tool to help you assess your candidates. This tool allows you to build your own questions/evaluations for each assessment you've selected above, and then allows you to jot down the criteria for what a great candidate response might be. Please note that "Narrative Review" is unique in that the content is generated for you below.`}
53
          description="Instructions for using the Rating Guide Builder"
54
        />
55
      </p>
56
      {narrativeAssessments}
57
      {getUniqueAssessmentTypes(otherAssessments).map(
58
        (assessmentTypeId: number, index: number): React.ReactElement => {
59
          sectionCount = isNarrativeAssessments ? index + 2 : index + 1;
60
          return (
61
            <RatingGuideAssessment
62
              key={assessmentTypeId}
63
              assessmentIndex={sectionCount}
64
              assessmentTypeId={assessmentTypeId}
65
              jobId={jobId}
66
            />
67
          );
68
        },
69
      )}
70
71
      <hr data-c-margin="top(double) bottom(double)" />
72
      <p data-c-margin="top(normal) bottom(normal)">
73
        <FormattedMessage
74
          id="ratingGuideBuilder.copyInstructions"
75
          defaultMessage="Now that you've built your Ratings Guide, you can use the button below to copy the entire thing to your clipboard, making it easy to paste in your favourite Word Processor."
76
          description="Instructions for copying your rating guide."
77
        />
78
      </p>
79
80
      {jobId !== null && (
81
        <RatingGuideClipboard jobId={jobId} narrativeReview={narrativeReview} />
82
      )}
83
    </div>
84
  );
85
};
86
87
interface RatingGuideBuilderContainerProps {
88
  jobId: number;
89
}
90
91
const mapStateToProps = (
92
  state: RootState,
93
  ownProps: RatingGuideBuilderContainerProps,
94
): { assessments: Assessment[] } => ({
95
  assessments: getAssessmentsByJob(state, ownProps),
96
});
97
98
export const RatingGuideBuilderContainer = connect(mapStateToProps)(
99
  RatingGuideBuilder,
100
);
101
102
export default RatingGuideBuilderContainer;
103