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: card header file organisation and descriptionRadio story #3842

Merged
merged 4 commits into from
Oct 28, 2024

Conversation

jamdelion
Copy link
Contributor

@jamdelion jamdelion commented Oct 23, 2024

Another minor refactor that results in a large PR 😅

All I've done is split up CardHeader.tsx into smaller files (e.g. styled and types) and this has changed a lot of imports.

One other change in this PR is adding a storybook file for descriptionRadio as I was wondering if it would be useful for the upcoming feedback component work. I'm probably not going to use it in the end but still thought plugging storybook gaps might be useful!

@jamdelion jamdelion marked this pull request as ready for review October 23, 2024 15:59
Copy link

github-actions bot commented Oct 23, 2024

Removed vultr server and associated DNS entries

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

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

Very much in favour or tidy ups and organisations like this 🙌

One suggestion - it might be a little cleaner to use an index.ts for the main file in a module? So in this PR /CardHeader/CardHeader.ts which holds the main component would become /CardHeader/index.ts

This would let us use import syntax like this -

import { CardHeader } from "@planx/components/shared/Preview/CardHeader";

I think one of the nicest benefits from this approach is that it essentially forces us to be a bit more strict in having a folder with a single "main" component, alongside associated styles.ts, types.ts etc

@jamdelion
Copy link
Contributor Author

Very much in favour or tidy ups and organisations like this 🙌

One suggestion - it might be a little cleaner to use an index.ts for the main file in a module? So in this PR /CardHeader/CardHeader.ts which holds the main component would become /CardHeader/index.ts

This would let us use import syntax like this -

import { CardHeader } from "@planx/components/shared/Preview/CardHeader";

I think one of the nicest benefits from this approach is that it essentially forces us to be a bit more strict in having a folder with a single "main" component, alongside associated styles.ts, types.ts etc

Thanks Daf! I have updated the file to not use a default export so that we can import in the way you suggested import { CardHeader } from....

As for renaming the file to index.ts, I have conflicting feelings about this (and have had a few debates in the past at previous workplaces!). Personally I dislike having a lot of index files, as I find it hard to navigate by looking purely at the path, rather than things being clear by the filename. I often use Cmd + P to navigate in VSCode and usually go for the filename as my first search term.

But I guess the trade off is having the path name complicated by the double CardHeader.

@DafyddLlyr
Copy link
Contributor

Hey there, sorry for the slow reply here and for holding you up.

It's a very fair point - we're sort of in this world of less meaningful file names already with a lot of Editor.tsx and Public.tsx files for each graph component. It's certainly frustrating - I hit the same Cmd + P issue in VSCode a whole lot also.

I did think of suggesting the use of barrell files which is the the pattern that Bulletproof React uses - this repo is always a reliable touchpoint I find. This would give meaningful filenames and terse imports. Here's an example - https://github.com/alan2207/bulletproof-react/blob/master/apps/react-vite/src/components/ui/form/index.ts

Sidenote - I really want to talk properly about restructuring and rationalising the React app a lot so let's come back to this one as a template!

However, it turns out Vite specifically says not to follow this pattern, so I'd say this is a no-go as an option - https://vite.dev/guide/performance#avoid-barrel-files 🙃

I think this is one is worth opening up to the wider dev team (asap so we're not blocking!) but I'm leaning towards your proposal here which favours DX and bundling here over any other option 👍

@jamdelion jamdelion merged commit 186a721 into main Oct 28, 2024
12 checks passed
@jamdelion jamdelion deleted the jh/refactor-card-header branch October 28, 2024 16:43
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