Skip to content

Commit 8373127

Browse files
committed
Fix lint and tests
1 parent a5a23a6 commit 8373127

File tree

5 files changed

+67
-70
lines changed

5 files changed

+67
-70
lines changed

packages/chaire-lib-common/src/config/defaultPreferences.config.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,23 @@ const defaultPreferences: PreferencesModel = {
283283
},
284284
custom: {
285285
name: {
286-
fr: '+ Ajouter des périodes personnalisées',
287-
en: '+ Add custom periods'
286+
fr: '+ Ajouter des périodes personnalisées',
287+
en: '+ Add custom periods'
288288
},
289289
periods: [
290-
{
291-
shortname: 'custom_period_1',
292-
name: {
293-
fr: 'Période personnalisée 1',
294-
en: 'Custom Period 1'
295-
},
296-
startAtHour: 8,
297-
endAtHour: 10,
298-
isCustom: true
299-
}
290+
{
291+
shortname: 'custom_period_1',
292+
name: {
293+
fr: 'Période personnalisée 1',
294+
en: 'Custom Period 1'
295+
},
296+
startAtHour: 8,
297+
endAtHour: 10,
298+
isCustom: true
299+
}
300300
],
301-
icon: 'faPlus',
302301
isCustomizable: true
303-
},
302+
}
304303
},
305304
stations: {
306305
defaultColor: '#0086FF'

packages/chaire-lib-frontend/src/components/input/InputModal.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ const InputModal: React.FC<InputModalProps> = ({
4848
setIsValid(inputData.valid);
4949
};
5050

51-
const handleConfirm = (e: React.MouseEvent) => {
51+
const handleConfirm = () => {
5252
if (isValid) {
5353
onConfirm(inputValue);
5454
onClose();
5555
}
5656
};
5757

58-
const handleCancel = (e: React.MouseEvent) => {
58+
const handleCancel = () => {
5959
onClose();
6060
};
6161

@@ -89,7 +89,11 @@ const InputModal: React.FC<InputModalProps> = ({
8989

9090
<div className={'tr__form-buttons-container _center'}>
9191
<div className="center">
92-
<button className={`button ${confirmButtonColor || 'blue'}`} onClick={handleConfirm} disabled={!isValid}>
92+
<button
93+
className={`button ${confirmButtonColor || 'blue'}`}
94+
onClick={handleConfirm}
95+
disabled={!isValid}
96+
>
9397
{confirmButtonLabel || t('Confirm')}
9498
</button>
9599
</div>
@@ -104,4 +108,4 @@ const InputModal: React.FC<InputModalProps> = ({
104108
);
105109
};
106110

107-
export default InputModal;
111+
export default InputModal;

packages/chaire-lib-frontend/src/components/input/InputSelect.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,14 @@ const InputSelect: React.FunctionComponent<InputSelectProps> = ({
7171
<option
7272
key={`choice_${childChoice.value}`}
7373
value={childChoice.value}
74-
disabled={childChoice.disabled === true}
74+
disabled={childChoice.disabled}
7575
>
7676
{childChoice.label || t(`${localePrefix}:${childChoice.value}`)}
7777
</option>
7878
);
7979
});
8080
selectChoices.push(
81-
<optgroup
82-
key={`group_${choice.value}`}
83-
label={choice.label || t(`${localePrefix}:${choice.value}`)}
84-
>
81+
<optgroup key={`group_${choice.value}`} label={choice.label || t(`${localePrefix}:${choice.value}`)}>
8582
{childChoices}
8683
</optgroup>
8784
);
@@ -90,7 +87,7 @@ const InputSelect: React.FunctionComponent<InputSelectProps> = ({
9087
<option
9188
key={`choice_${choice.value}`}
9289
value={choice.value}
93-
disabled={choice.disabled === true}
90+
disabled={choice.disabled}
9491
className={choice.className}
9592
>
9693
{choice.label || t(`${localePrefix}:${choice.value}`)}
@@ -100,7 +97,16 @@ const InputSelect: React.FunctionComponent<InputSelectProps> = ({
10097
}
10198

10299
return (
103-
<select {...defaultAttributes}>
100+
<select
101+
autoComplete="none"
102+
className="tr__form-input-select apptr__input _input-select"
103+
{...defaultAttributes}
104+
style={{
105+
overflow: 'hidden',
106+
whiteSpace: 'nowrap',
107+
textOverflow: 'ellipsis'
108+
}}
109+
>
104110
{!noBlank && <option value=""></option>}
105111
{selectChoices}
106112
</select>

packages/transition-frontend/src/components/forms/schedules/TransitScheduleEdit.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
* License text available at https://opensource.org/licenses/MIT
66
*/
77
import React from 'react';
8-
import _toString from 'lodash/toString';
98
import { withTranslation, WithTranslation } from 'react-i18next';
10-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
119
import { faUndoAlt } from '@fortawesome/free-solid-svg-icons/faUndoAlt';
1210
import { faRedoAlt } from '@fortawesome/free-solid-svg-icons/faRedoAlt';
1311
import { faTrash } from '@fortawesome/free-solid-svg-icons/faTrash';
@@ -16,26 +14,16 @@ import { faPlus } from '@fortawesome/free-solid-svg-icons/faPlus';
1614
import { faSyncAlt } from '@fortawesome/free-solid-svg-icons/faSyncAlt';
1715
import { faTrashAlt } from '@fortawesome/free-solid-svg-icons/faTrashAlt';
1816
import { faCheckCircle } from '@fortawesome/free-solid-svg-icons/faCheckCircle';
19-
import { faClock } from '@fortawesome/free-solid-svg-icons/faClock';
20-
import { faArrowDown } from '@fortawesome/free-solid-svg-icons/faArrowDown';
2117

22-
import InputString from 'chaire-lib-frontend/lib/components/input/InputString';
23-
import InputStringFormatted from 'chaire-lib-frontend/lib/components/input/InputStringFormatted';
2418
import InputSelect, { choiceType } from 'chaire-lib-frontend/lib/components/input/InputSelect';
2519
import InputRadio from 'chaire-lib-frontend/lib/components/input/InputRadio';
2620
import Button from 'chaire-lib-frontend/lib/components/input/Button';
2721
import FormErrors from 'chaire-lib-frontend/lib/components/pageParts/FormErrors';
2822
import Preferences from 'chaire-lib-common/lib/config/Preferences';
2923
import serviceLocator from 'chaire-lib-common/lib/utils/ServiceLocator';
3024
import { SaveableObjectForm, SaveableObjectState } from 'chaire-lib-frontend/lib/components/forms/SaveableObjectForm';
31-
import { _isBlank, _toInteger } from 'chaire-lib-common/lib/utils/LodashExtensions';
32-
import { roundToDecimals } from 'chaire-lib-common/lib/utils/MathUtils';
33-
import {
34-
decimalHourToTimeStr,
35-
secondsSinceMidnightToTimeStr,
36-
secondsToMinutes,
37-
minutesToSeconds
38-
} from 'chaire-lib-common/lib/utils/DateTimeUtils';
25+
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';
26+
import { decimalHourToTimeStr } from 'chaire-lib-common/lib/utils/DateTimeUtils';
3927
import ConfirmModal from 'chaire-lib-frontend/lib/components/modal/ConfirmModal';
4028
import Schedule, { SchedulePeriod } from 'transition-common/lib/services/schedules/Schedule';
4129
import Line from 'transition-common/lib/services/line/Line';
@@ -170,7 +158,7 @@ class TransitScheduleEdit extends SaveableObjectForm<Schedule, ScheduleFormProps
170158
const data = this.getCustomizablePeriodsGroup();
171159
if (!data) return;
172160

173-
const { group, groupKey } = data;
161+
const { group } = data;
174162
const nextPeriodId = group.periods.length + 1;
175163

176164
// TODO: The name of each period is imposed and not customizable at the moment
@@ -226,7 +214,7 @@ class TransitScheduleEdit extends SaveableObjectForm<Schedule, ScheduleFormProps
226214
isCustomizable: true
227215
};
228216

229-
template.periods.forEach(p => {
217+
template.periods.forEach((p) => {
230218
if (!p.name) p.name = { en: p.shortname, fr: p.shortname };
231219
});
232220

@@ -322,9 +310,10 @@ class TransitScheduleEdit extends SaveableObjectForm<Schedule, ScheduleFormProps
322310

323311
return {
324312
value: periodsGroupShortname,
325-
label: periodsGroup.name && periodsGroup.name[this.props.i18n.language]
326-
? periodsGroup.name[this.props.i18n.language]
327-
: periodsGroupShortname,
313+
label:
314+
periodsGroup.name && periodsGroup.name[this.props.i18n.language]
315+
? periodsGroup.name[this.props.i18n.language]
316+
: periodsGroupShortname,
328317
isCustomOption,
329318
className: isUserTemplate ? 'user-template-option' : isCustomOption ? 'custom-option-button' : ''
330319
};
@@ -447,7 +436,11 @@ class TransitScheduleEdit extends SaveableObjectForm<Schedule, ScheduleFormProps
447436
icon={faSyncAlt}
448437
iconClass="_icon"
449438
label={this.props.t('transit:transitSchedule:UpdateTemplate')}
450-
onClick={() => this.savePeriodsTemplate(periodsGroups[periodsGroupShortname].name?.en || 'Updated Template')}
439+
onClick={() =>
440+
this.savePeriodsTemplate(
441+
periodsGroups[periodsGroupShortname].name?.en || 'Updated Template'
442+
)
443+
}
451444
disabled={isFrozen}
452445
/>
453446
<Button

packages/transition-frontend/src/components/forms/schedules/TransitSchedulePeriod.tsx

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ const TransitSchedulePeriod: React.FC<TransitSchedulePeriodProps> = (props) => {
6969
const tripsCount = trips.length;
7070

7171
const actualOutboundPathId = schedulePeriod.outbound_path_id;
72-
const outboundPathId = actualOutboundPathId || (outboundPathsChoices.length === 1 ? outboundPathsChoices[0].value : '');
72+
const outboundPathId =
73+
actualOutboundPathId || (outboundPathsChoices.length === 1 ? outboundPathsChoices[0].value : '');
7374

7475
const actualInboundPathId = schedulePeriod.inbound_path_id;
7576
const inboundPathId = actualInboundPathId || (inboundPathsChoices.length === 1 ? inboundPathsChoices[0].value : '');
@@ -84,21 +85,13 @@ const TransitSchedulePeriod: React.FC<TransitSchedulePeriodProps> = (props) => {
8485
// outbound trip
8586
outboundTripsCells.push(
8687
<td key={`outboundTrip_${tripI}`}>
87-
{secondsSinceMidnightToTimeStr(
88-
trip.departure_time_seconds,
89-
true,
90-
allowSecondsBasedSchedules
91-
)}
88+
{secondsSinceMidnightToTimeStr(trip.departure_time_seconds, true, allowSecondsBasedSchedules)}
9289
</td>
9390
);
9491
} else if (inboundPathIds.includes(trip.path_id)) {
9592
inboundTripsCells.push(
9693
<td key={`inboundTrip_${tripI}`}>
97-
{secondsSinceMidnightToTimeStr(
98-
trip.departure_time_seconds,
99-
true,
100-
allowSecondsBasedSchedules
101-
)}
94+
{secondsSinceMidnightToTimeStr(trip.departure_time_seconds, true, allowSecondsBasedSchedules)}
10295
</td>
10396
);
10497
}
@@ -162,7 +155,9 @@ const TransitSchedulePeriod: React.FC<TransitSchedulePeriodProps> = (props) => {
162155
<span
163156
className="_strong clickable-time"
164157
onClick={() => {
165-
const startTimeInput = document.getElementById(`formFieldTransitScheduleCustomStartAtPeriod${periodShortname}${scheduleId}`);
158+
const startTimeInput = document.getElementById(
159+
`formFieldTransitScheduleCustomStartAtPeriod${periodShortname}${scheduleId}`
160+
);
166161
if (startTimeInput) startTimeInput.focus();
167162
}}
168163
style={{ cursor: 'pointer', textDecoration: 'underline' }}
@@ -173,7 +168,9 @@ const TransitSchedulePeriod: React.FC<TransitSchedulePeriodProps> = (props) => {
173168
<span
174169
className="_strong clickable-time"
175170
onClick={() => {
176-
const endTimeInput = document.getElementById(`formFieldTransitScheduleCustomEndAtPeriod${periodShortname}${scheduleId}`);
171+
const endTimeInput = document.getElementById(
172+
`formFieldTransitScheduleCustomEndAtPeriod${periodShortname}${scheduleId}`
173+
);
177174
if (endTimeInput) endTimeInput.focus();
178175
}}
179176
style={{ cursor: 'pointer', textDecoration: 'underline' }}
@@ -271,9 +268,7 @@ const TransitSchedulePeriod: React.FC<TransitSchedulePeriodProps> = (props) => {
271268
stringToValue={_toInteger}
272269
valueToString={_toString}
273270
key={`formFieldTransitScheduleNumberOfUnitsPeriod${periodShortname}${scheduleId}${resetChangesCount}`}
274-
onValueUpdated={(value) =>
275-
onValueChange(`periods[${periodIndex}].number_of_units`, value)
276-
}
271+
onValueUpdated={(value) => onValueChange(`periods[${periodIndex}].number_of_units`, value)}
277272
/>
278273
</div>
279274
<p className="_small _oblique">
@@ -312,14 +307,14 @@ const TransitSchedulePeriod: React.FC<TransitSchedulePeriodProps> = (props) => {
312307
{!_isBlank(outboundPathId) &&
313308
((!_isBlank(intervalSeconds) && _isBlank(numberOfUnits)) ||
314309
(!_isBlank(numberOfUnits) && _isBlank(intervalSeconds))) && (
315-
<Button
316-
color="blue"
317-
icon={faSyncAlt}
318-
iconClass="_icon"
319-
label={t('transit:transitSchedule:GenerateSchedule')}
320-
onClick={handleGenerateSchedule}
321-
/>
322-
)}
310+
<Button
311+
color="blue"
312+
icon={faSyncAlt}
313+
iconClass="_icon"
314+
label={t('transit:transitSchedule:GenerateSchedule')}
315+
onClick={handleGenerateSchedule}
316+
/>
317+
)}
323318
</div>
324319
)}
325320
{isFrozen !== true && tripsCount > 0 && (
@@ -352,4 +347,4 @@ const TransitSchedulePeriod: React.FC<TransitSchedulePeriodProps> = (props) => {
352347
);
353348
};
354349

355-
export default TransitSchedulePeriod;
350+
export default TransitSchedulePeriod;

0 commit comments

Comments
 (0)