| Conditions | 1 | 
| Total Lines | 137 | 
| Code Lines | 113 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import React from "react"; | ||
| 39 | |||
| 40 | export function SkillSubform({ | ||
| 41 | jobId, | ||
| 42 | jobRequiredSkills, | ||
| 43 | jobOptionalSkills, | ||
| 44 | }: SkillSubformProps): React.ReactElement { | ||
| 45 | const intl = useIntl(); | ||
| 46 | const locale = getLocale(intl.locale); | ||
| 47 | |||
| 48 | const formikContext = useFormikContext(); | ||
| 49 |   const requiredMeta = formikContext.getFieldMeta<string[]>("requiredSkills"); | ||
| 50 |   const optionalMeta = formikContext.getFieldMeta<string[]>("optionalSkills"); | ||
| 51 | |||
| 52 | const linkToJob = (text): React.ReactElement => ( | ||
| 53 | <a | ||
| 54 |       href={jobShow(locale, jobId)} | ||
| 55 |       title={intl.formatMessage(messages.linkToJobTitle)} | ||
| 56 | target="_blank" | ||
| 57 | rel="noreferrer" | ||
| 58 | > | ||
| 59 |       {text} | ||
| 60 | </a> | ||
| 61 | ); | ||
| 62 | |||
| 63 | return ( | ||
| 64 | <> | ||
| 65 | <div data-c-container="medium"> | ||
| 66 | <p | ||
| 67 | data-c-margin="top(1) bottom(1)" | ||
| 68 | data-c-font-size="h4" | ||
| 69 | data-c-font-weight="bold" | ||
| 70 | data-c-color="c3" | ||
| 71 | > | ||
| 72 | <FormattedMessage | ||
| 73 | id="experienceModal.connectSubtitle" | ||
| 74 | defaultMessage="Connect This Experience to the Job" | ||
| 75 | description="Subtitle of Connect-to-skills section." | ||
| 76 | /> | ||
| 77 | </p> | ||
| 78 | <p data-c-margin="bottom(1)"> | ||
| 79 | <FormattedMessage | ||
| 80 | id="experienceModal.connectDescription" | ||
| 81 | defaultMessage="Below you can select which of the job skills you used during this experience. Later on, you’ll be asked to provide a few sentences to help managers understand how you used this skill. You can <a>review the definitions</a> of the skills on the job poster." | ||
| 82 | description="Explanation for Connect-to-skills section." | ||
| 83 |             values={{ | ||
| 84 | a: (...chunks): React.ReactElement => linkToJob(chunks), | ||
| 85 | }} | ||
| 86 | /> | ||
| 87 | </p> | ||
| 88 | <p data-c-margin="bottom(1)"> | ||
| 89 | <FormattedMessage | ||
| 90 | id="experienceModal.connectDescription.noSkillsOkay" | ||
| 91 | defaultMessage="If none of the skills apply to this experience, feel free to save it without any skills selected." | ||
| 92 | description="Explanation that you can save an experience without connecting it to skills yet." | ||
| 93 | /> | ||
| 94 | </p> | ||
| 95 | </div> | ||
| 96 | <div data-c-container="medium"> | ||
| 97 | <div data-c-grid="gutter(all, 1) middle"> | ||
| 98 | <div data-c-grid-item="base(1of1)"> | ||
| 99 | <p data-c-font-weight="bold"> | ||
| 100 | <FormattedMessage | ||
| 101 | id="experienceModal.requiredSkillsSubtitle" | ||
| 102 | defaultMessage="Please indicate which of the following <a>required skills</a> (if any) you used in this experience." | ||
| 103 | description="Title for the Required Skills checkbox." | ||
| 104 |                 values={{ | ||
| 105 | a: (...chunks): React.ReactElement => linkToJob(chunks), | ||
| 106 | }} | ||
| 107 | /> | ||
| 108 | </p> | ||
| 109 | </div> | ||
| 110 | <CheckboxGroup | ||
| 111 | id="requiredSkills" | ||
| 112 |             label={intl.formatMessage(messages.skillCheckboxGroupLabel)} | ||
| 113 | grid="base(1of1)" | ||
| 114 |             value={requiredMeta.value} | ||
| 115 |             error={requiredMeta.error} | ||
| 116 |             touched={requiredMeta.touched} | ||
| 117 |             onChange={formikContext.setFieldValue} | ||
| 118 |             onBlur={formikContext.setFieldTouched} | ||
| 119 | > | ||
| 120 |             {jobRequiredSkills.map( | ||
| 121 |               (name): React.ReactElement => { | ||
| 122 | return ( | ||
| 123 | <Field | ||
| 124 |                     key={name} | ||
| 125 |                     id={name} | ||
| 126 |                     name={name} | ||
| 127 |                     label={name} | ||
| 128 |                     component={CheckboxInput} | ||
| 129 | grid="base(1of1)" | ||
| 130 | /> | ||
| 131 | ); | ||
| 132 | }, | ||
| 133 | )} | ||
| 134 | </CheckboxGroup> | ||
| 135 | |||
| 136 | <div data-c-grid-item="base(1of1)"> | ||
| 137 | <p data-c-font-weight="bold"> | ||
| 138 | <FormattedMessage | ||
| 139 | id="experienceModal.optionalSkillsSubtitle" | ||
| 140 | defaultMessage="Please indicate which of the following <a>optional skills</a> (if any) you used in this experience." | ||
| 141 | description="Title for the Optional Skills checkbox." | ||
| 142 |                 values={{ | ||
| 143 | a: (...chunks): React.ReactElement => linkToJob(chunks), | ||
| 144 | }} | ||
| 145 | /> | ||
| 146 | </p> | ||
| 147 | </div> | ||
| 148 | <CheckboxGroup | ||
| 149 | id="optionalSkills" | ||
| 150 |             label={intl.formatMessage(messages.skillCheckboxGroupLabel)} | ||
| 151 | grid="base(1of1)" | ||
| 152 |             value={optionalMeta.value} | ||
| 153 |             error={optionalMeta.error} | ||
| 154 |             touched={optionalMeta.touched} | ||
| 155 |             onChange={formikContext.setFieldValue} | ||
| 156 |             onBlur={formikContext.setFieldTouched} | ||
| 157 | > | ||
| 158 |             {jobOptionalSkills.map( | ||
| 159 |               (name): React.ReactElement => { | ||
| 160 | return ( | ||
| 161 | <Field | ||
| 162 |                     key={name} | ||
| 163 |                     id={name} | ||
| 164 |                     name={name} | ||
| 165 |                     label={name} | ||
| 166 |                     component={CheckboxInput} | ||
| 167 | grid="base(1of1)" | ||
| 168 | /> | ||
| 169 | ); | ||
| 170 | }, | ||
| 171 | )} | ||
| 172 | </CheckboxGroup> | ||
| 173 | </div> | ||
| 174 | </div> | ||
| 175 | </> | ||
| 176 | ); | ||
| 180 |