Skip to content

Commit

Permalink
336 - Removes duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardovdheijden committed Oct 9, 2023
1 parent 3551a4f commit c1e0c75
Showing 1 changed file with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ export const WFOWorkflowStepList = React.forwardRef(
}));
const [stepListItems, setStepListItems] =
useState(initialStepListItems);
const updateStepListItem = (
stepListItemToUpdate: StepListItem,
updateFunction: (stepListItem: StepListItem) => StepListItem,
) =>
setStepListItems(
stepListItems.map((stepListItem) =>
stepListItem === stepListItemToUpdate
? updateFunction(stepListItem)
: stepListItem,
),
);

const allStepsAreExpanded = stepListItems.every(
(item) => item.isExpanded,
Expand All @@ -40,34 +51,17 @@ export const WFOWorkflowStepList = React.forwardRef(
);
};

const toggleExpandedStateStepListItem = (
stepListItem: StepListItem,
) => {
setStepListItems(
stepListItems.map((item) =>
item.step === stepListItem.step
? {
...item,
isExpanded: !item.isExpanded,
}
: item,
),
);
};
const toggleExpandedStateStepListItem = (stepListItem: StepListItem) =>
updateStepListItem(stepListItem, (item) => ({
...item,
isExpanded: !item.isExpanded,
}));

const handleExpandStepListItem = (stepListItem: StepListItem) => {
setStepListItems(
stepListItems.map((item) => {
if (item.step === stepListItem.step) {
return {
...item,
isExpanded: true,
};
}
return item;
}),
);
};
const handleExpandStepListItem = (stepListItem: StepListItem) =>
updateStepListItem(stepListItem, (item) => ({
...item,
isExpanded: true,
}));

return (
<>
Expand Down

0 comments on commit c1e0c75

Please sign in to comment.