Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ const ItineraryModal = ({
commitSelectionForStep(stepId, formatChosenValue(suggestion, chosenCh));
resetOpSuggestions();
};

const isOnlyStep = pathSteps.filter((s) => !isEmptyStep(s, getInputForStep(s.id))).length <= 1;
const hasSingleStepWithTrailing =
pathSteps.length === 2 && isEmptyStep(pathSteps[1], getInputForStep(pathSteps[1].id));

const hasInvalidPathStep = pathSteps.some((step) => {
if (isEmptyStep(step, getInputForStep(step.id))) return false;
const meta = pathStepsMetadataById.get(step.id);
return !meta || meta.isInvalid;
});

const handleDeletePathStep = (stepId: string) => {
resetOpSuggestions();

if (activeStepId === stepId) setActiveStepId('');
if (pathSteps.length === 2) return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (pathSteps.length === 2) return;

You don't need this early return. You only call this function when hasSingleStepWithTrailing is false, meaning you'll have at least 3 pathSteps.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch thanks ! fixed in last fixup 👍


setPathSteps((prev) => {
const step = prev.find((s) => s.id === stepId);
Expand Down Expand Up @@ -482,7 +482,6 @@ const ItineraryModal = ({
(isInvalid || !!previousPathStepMetadata?.isInvalid)
}
onDelete={() => {
if (isOnlyStep) return;
handleDeletePathStep(pathStep.id);
}}
onOpFocus={() => markEditing(pathStep.id)}
Expand Down Expand Up @@ -522,7 +521,7 @@ const ItineraryModal = ({
resetOpSuggestions={resetOpSuggestions}
connectorLong={hoveredGapIndex === i}
isTrailingPlaceHolder={isTrailingPlaceholder}
isOnlyStep={isOnlyStep}
hasSingleStepWithTrailing={hasSingleStepWithTrailing}
isInvalidAndIsEditing={isInvalid}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type PathStepProps = {
connectorLong: boolean;
onDelete: () => void;
isTrailingPlaceHolder: boolean;
isOnlyStep: boolean;
hasSingleStepWithTrailing: boolean;
};

const PathStepItem = ({
Expand All @@ -73,7 +73,7 @@ const PathStepItem = ({
connectorLong,
onDelete,
isTrailingPlaceHolder,
isOnlyStep,
hasSingleStepWithTrailing,
}: PathStepProps) => {
const { t } = useTranslation('operational-studies', {
keyPrefix: 'manageTimetableItem.itineraryModal',
Expand Down Expand Up @@ -253,7 +253,7 @@ const PathStepItem = ({
type="button"
className={cx('path-step-counter', {
invalid: isInvalidAndIsEditing,
'is-only-step': isOnlyStep,
'has-single-step-with-trailing': hasSingleStepWithTrailing,
'is-trailing-placeholder': isTrailingPlaceHolder,
index: isIndexed,
'pathfinding-line': !hidePathfindingLine,
Expand All @@ -278,10 +278,11 @@ const PathStepItem = ({
}}
>
<span className="counter">{!isTrailingPlaceHolder && index}</span>

<span className="remove-path-step-icon">
<X />
</span>
{!hasSingleStepWithTrailing && (
<span className="remove-path-step-icon">
<X />
</span>
)}
</button>

<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@
padding-bottom: 14px;
}

.path-step-counter:not(.is-only-step):not(.is-trailing-placeholder):hover {
.path-step-counter:not(.is-trailing-placeholder):not(
.has-single-step-with-trailing
):hover {
opacity: 1;
background-color: var(--error60) !important;

Expand Down Expand Up @@ -287,7 +289,9 @@
background-color: var(--white100);
margin-right: 4px;
z-index: 1;

&.has-single-step-with-trailing {
pointer-events: none;
}
&.pathfinding-line::before {
content: '';
position: absolute;
Expand Down Expand Up @@ -335,9 +339,7 @@
background-color: var(--error60);
border-color: var(--error30);
}
&.is-only-step {
pointer-events: none;
}

&.is-trailing-placeholder {
pointer-events: none;
}
Expand Down
Loading