Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: checklist component subfolders #4038

Merged
merged 4 commits into from
Dec 4, 2024
Merged

Conversation

jamdelion
Copy link
Contributor

@jamdelion jamdelion commented Dec 4, 2024

Just another classic PR from me! 😅 I was beginning to look at the 'or' option in checklists ticket and started off with a minor refactor to help orient myself in the folder, which rapidly turned into a 600 line PR 🙈

Mostly this is moving stuff into sub-folders to reduce the size of the massively long files!

Here's what the file structure looks like now:
Screenshot 2024-12-04 at 12 22 56

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simply moved within an Editor subfolder to be co-located with related components

@@ -58,20 +49,6 @@ const ChecklistComponent: React.FC<Props> = (props) => {
return <VisibleChecklist {...props} />;
};

// An auto-answered Checklist won't be seen by the user, but still leaves a breadcrumb
const AutoAnsweredChecklist: React.FC<Props & { answerIds: string[] }> = (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to Public/components to clean-up the main component file a little bit

Comment on lines -35 to -40
function toggleInArray<T>(value: T, arr: Array<T>): Array<T> {
return arr.includes(value)
? arr.filter((val) => val !== value)
: [...arr, value];
}

Copy link
Contributor Author

@jamdelion jamdelion Dec 4, 2024

Choose a reason for hiding this comment

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

Moved to a helpers file

Comment on lines +94 to +96
const newCheckedIds = formik.values.checked.includes(id)
? formik.values.checked.filter((x) => x !== id)
: [...formik.values.checked, id];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a plugin that recommends cleaner ways to write code, it especially loves to refactor if...else blocks!

Copy link
Member

Choose a reason for hiding this comment

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

Are you satisfied with the readability outcomes of this though? (Honestly no wrong answer!)

Just double-checking that refactors are prioritising the preferences of our team made up of very real human developers and not blindly defaulting to what extensions/ai suggest 🙂 (in my opinion that's how we've inherited sometimes very opaque store methods heavy on reduce with too-minimalist variable names)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think switching the if...else to a ternary does not make it less readable imo :) sorry I made it sound like I was just letting the plugin run wild on its own (I definitely ignore a lot of what it says). I mainly made this change to reduce the number of lines of code without making any harder to understand. 🤞

>
<ImageButton
title={option.data.text}
{options?.map((option) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The plugin just recommended optional chaining instead of options &&...

Comment on lines -235 to -249
function getInitialExpandedGroups() {
return (groupedOptions ?? ([] as Group<Option>[])).reduce(
(acc, group, index) =>
groupHasOptionSelected(group, previouslySubmittedData?.answers ?? [])
? [...acc, index]
: acc,
[] as number[],
);

function groupHasOptionSelected(group: Group<Option>, answers: string[]) {
return group.children.some((child) =>
answers.some((id) => child.id === id),
);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to the helpers file

@@ -201,7 +85,7 @@ describe("Checklist Component - Grouped Layout", () => {
groupedOptions={groupedOptions}
/>,
);
const [section1Button, section2Button, section3Button, _continueButton] =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

_continueButton was unused

@jamdelion jamdelion marked this pull request as ready for review December 4, 2024 12:21
@jamdelion jamdelion requested a review from a team December 4, 2024 12:22
Copy link

github-actions bot commented Dec 4, 2024

Removed vultr server and associated DNS entries

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

A couple quick initial questions - happy to do final review & approve once pizza is healthy!

Comment on lines +94 to +96
const newCheckedIds = formik.values.checked.includes(id)
? formik.values.checked.filter((x) => x !== id)
: [...formik.values.checked, id];
Copy link
Member

Choose a reason for hiding this comment

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

Are you satisfied with the readability outcomes of this though? (Honestly no wrong answer!)

Just double-checking that refactors are prioritising the preferences of our team made up of very real human developers and not blindly defaulting to what extensions/ai suggest 🙂 (in my opinion that's how we've inherited sometimes very opaque store methods heavy on reduce with too-minimalist variable names)

@jessicamcinchak
Copy link
Member

Thanks for updates here - still getting ShareDB issues on pizza though when trying to connect to flows - Vultr might need a destroy/rebuild?

@jamdelion
Copy link
Contributor Author

@jessicamcinchak the pizza is working for me now, hopefully good for you too? 🤞

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

All working as expected on pizza , thanks !

Spotted one bug (not introduced here) though just to keep on your radar as you're working with this component next few days (ideally can get fixed-forward in a future PR):

  • When "Expandable" is toggled on and you set a data field, the validation to ensure that at least one option also sets a data field fails and prevents creating the component (it's fine if options are not grouped into expandable sections). Hasn't been raised externally yet, but definitely a bug on staging/prod too !

@jamdelion jamdelion merged commit b1c0630 into main Dec 4, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants