Commit b7ad517
Drake Costa
🔨 Refactor app/components to TypeScript (codesandbox#2066)
This PR refactors (nearly) everything under app/components to TypeScript, adding new types and applying coding conventions.
Here are some basic rules regarding coding conventions (to be more thoroughly documented at a later date):
- Always use Named Exports (here's some good reasons why this is a good idea: https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/)
- Write functional components with hooks (makes it much easier to detect unused methods, among numerous other good reasons)
- Prefer arrow functions (death to `this`)
- Prefer destructuring to property accessors
- Components should always be their own file with a Capitalized name matching the component name
- Multiple file components should be in a Capitalized folder matching the component name, with an `index.ts` file handling all exports to be consumed by outside components
- Prefer `interface` over `type` for typing Props
- In general, prop interfaces should follow a IComponentNameProps naming scheme, though this is largely stylistic
- Prefer `const SomeComponent: React.FC<ISomeComponentProps> = ({ . . . }) => { }` over `const SomeComponent = ({ . . . }: ISomeComponentProps) => { }` to avoid needing to define common React component props
- For styled components, Inline types are fine where their footprint is small, ie:
```typescript
const SomeElement = styled.div<{ large: boolean }>`
${({ large }) => css`
/*
Always wrap style declarations in a single function call and don't forget to
use "css" for syntax highlighting!
*/
`}
`
```
- All type interface definitions should live in a `types.ts` file adjacent to the component to reduce clutter in the component definition
- If a component uses GraphQL queries/mutations, all GraphQL documents should live in their files adjacent to the component that uses them, ie: `queries.gql` and `mutations.gql` to reduce clutter in the component definition
- All styles should be applied with styled-components and all styled elements should be defined in elements.js to reduce clutter in the component definition
- Global styles should be defined using styled-components in a `GlobalStyles.ts` file adjacent to the root component that requires it
- When using props in styled components, always wrap all of the styles in a single arrow function to make it easy to destructure props all in one place and always wrap nested template literals with the `css` tagged template to enable style linting/syntax highlighting.
- Style rules should be well ordered (to be enforced by stylelint at a later date). In general this means rules should be grouped by category, starting with Position > Box Model > Fonts > Animation > Misc > pseudo-selectors. For now this is low-priority.
The general rule of thumb here is: avoid clutter and if you have to scroll a component file, it probably needs to be broken up into smaller pieces. By separating concerns into small, well-organized files, code will be easier to read and thus easier to maintain.
That should cover more than what's implemented by this PR. These rules will be applied progressively so as to make the initial code review for refactors easier (as for the most part it will just require some components to be broken up into multiple files).
Commit Log:
* 🔨 Refactor app/components: Convert files to be refactored to Typescript
Changing the file extension of all files to be refactored to `.ts/.tsx, this is to make it easier to compare before and after changes in later commits.
Each component will be refactored one at a time in it's own commit for review. The process will go as follows:
1. change extensions (this commit)
2. refactor component files as-is
3. rename files and reorganize files where necessary
4. update all import references across the app
* 🔨 Refactor app/components/Alert: Apply Coding Conventions, Make Generic
Implemented some minor changes to the Alert component to make it more general-purpose. It now has an additional prop `confirmMesage: string` that controls the confirm button text. The click handler has also been renamed to onConfirm. (Previously these were "Delete" and onDelete)
TODO: Update props on all instances of this component.
* 🔨 Refactor app/components/ConfirmLink: Apply Coding Conventions
* 📝 Add Types to app/components/DelayedAnimation
* 🔨 Refactor app/components/DeleteSandboxButton: Apply Coding Conventions
TODO: Test to verify that styles are still being applied correctly
* 🔨 Refactor app/components/DeploymentIntegration: Apply Conventions
TODO: Update renamed props on all instances of this component.
* 🔨 Refactor app/components/EditableTags: Apply Conventions
TODO: Split out GlobalStyles into separate file, import Template interface to create props interface for this component.
* 🧹 Cleanup app/components/GitHubLogo
Applied minor changes to conform with project coding style.
Perhaps we should move this icon to a separate package along with others like it? Are we even using this one or did we get it from an external library? Maybe we can just delete this altogether.
* 🔨 Refactor app/components/GitProgress: Apply Conventions
Removed unused prop noAnimation.
TODO: Maybe move GitHubLogo and OpagueLogo into this component as subcomponents? Are those two logos being used elsewhere?
* 🔨 Refactor app/components/HeaderSearchBar: Apply Conventions
Changed the search input to be a controlled component.
* 🔨 Refactor app/components/HoverMenu: Apply Conventions
@CompuIves can you explain why this component previously was applying an event listener to the root element to call handleViewClick in addition to the native React onClick prop? This may require some additional refactoring if there's something I'm misunderstanding here.
* 🔨 Refactor app/components/Integration: Apply Conventions
TODO: Update props on component instances.
* 🔨 Refactor app/components/IntegrationModal: Apply Conventions
TODO: Maybe move this to pages/common/modals? Also maybe move it's dependent sub-components if they aren't being used elsewhere?
* 🧹 Cleanup app/components/Loading
Minor changes to conform to coding style.
* 🔨 Refactor app/components/ModeIcons: Apply Conventions
May need further refactoring.
TODO: Test to see if this still works the same as before.
* 🧹 Cleanup app/components/NetlifyLogo
Minor changes to conform to coding style.
* 🧹 Cleanup app/components/NowLogo
Added props interface and applied coding style.
* 🧹 Cleanup app/components/OpaqueLogo
Added props interface and applied coding style.
* 🔨 Refactor app/components/Overlay: Apply Conventions
@CompuIves please review this, I'm not sure that this refactor will work as expected. The original implementation was a bit strange and Transition appears to not like that we were using a boolean in it's item prop.
* 🧹 Cleanup app/components/PrivacyStatus
Minor stylistic changes, added props interface.
* 🧹 Cleanup app/components/ReactIcon
Applied code style conventions.
Is this icon needed? Can we pull it from a library instead?
* 🧹 Cleanup app/components/SandboxList
Applied coding style conventions and adjusted types.
TODO: Address ignored type errors. See comments.
* 🧹 Cleanup app/components/Skeleton
Minor code style changes. Added props interface.
TODO: Shouldn't Fullscreen have height: 100vh already? Perhaps this should be added there to remove unnecessary style props.
* 🧹 Cleanup app/components/SocialInfo
Minor coding style changes. Moved repeated link attributes to element.ts
* 🔨 Refactor app/components/Stat: Apply Conventions
Reorganized and added props interface.
TODO: We probably want to add tests for the full component not just it's number formatting function.
* 🔨 Refactor app/components/SubscribeForm: Apply Conventions
Updated react-stripe-elements from ^v1.7 to ^v3.0.0
injectStripe doesn't appear to want to expose the CheckoutForm props and I'm not sure if there is a way I can work around it. Someone with better TypeScript knowledge than me will have to figure this one out.
Refactored all components to apply coding conventions. SubrscribeForm is basically unchanged, but CheckoutForm was re-written using hooks, so it needs to be tested to ensure that it still works.
* 🧹 Cleanup app/components/SubTitle
Minor coding style changes, added types.
* 🧹 Cleanup app/components/Title
Minor coding style changes, added types.
* 🧹 Cleanup app/components/TypescriptIcon
Minor coding style changes.
* 🔨 Refactor app/components/UploadProgress: Apply Conventions
Removed unused prop noAnimation.
Applied coding style conventions, added prop interfaces.
* 🧹 Cleanup app/components/ZeitLogo
Minor coding style changes.
* Update packages/app/src/app/components/DeploymentIntegration/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* Update packages/app/src/app/components/HoverMenu/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* Update packages/app/src/app/components/DeploymentIntegration/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* Update packages/app/src/app/components/HoverMenu/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* Update packages/app/src/app/components/Integration/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* Update packages/app/src/app/components/IntegrationModal/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* Update packages/app/src/app/components/IntegrationModal/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* Update packages/app/src/app/components/Overlay/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* Update packages/app/src/app/components/Overlay/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* Update packages/app/src/app/components/SandboxList/index.tsx
Co-Authored-By: Michaël De Boey <[email protected]>
* 🔧 Fix suggested change in HoverMenu
* 🚧 WIP Resolve Conversations, Fix Build Errors
* 🧹 Cleanup Types to follow Coding Conventions
* 🔧 Add missing key prop to Overlay items
* 🧹 Reorganize files, Update Import References and Props, Fix Types
* 🔧 Fix missing key error, add note to remove DOM prop error later
* 🔧 Fix DeploymentIntegration not showing DetailInfo Children
* Prevent the websocket errors to appear in console
* 📦 Add React Display Name Babel Plugin, Deduplicate Cude Component
* Convert ContextMenu to types
* Fix ContextMenu usage
* Move JSX.Element to React.ReactNode1 parent 5ba9ac9 commit b7ad517
File tree
185 files changed
+2093
-1968
lines changed- packages
- app
- config
- scripts
- src
- app
- components
- Alert
- CodeEditor
- ConfirmLink
- ContextMenu
- Cube
- DeleteSandboxButton
- DeploymentIntegration
- DetailInfo
- EditableTags
- GitHubLogo
- GitProgress
- Cube
- HeaderSearchBar
- HoverMenu
- IntegrationModal
- Integration
- DetailInfo
- LinkButton
- Loading
- ModeIcons
- NetlifyLogo
- NowLogo
- OpaqueLogo
- Overlay
- PrivacyStatus
- SandboxList
- Skeleton
- SocialInfo
- Stat
- SubTitle
- SubscribeForm
- Title
- TypescriptIcon
- UploadProgress
- Cube
- ZeitLogo
- pages
- CLI/Prompt
- CliInstructions
- Curator
- Dashboard
- Content
- CreateNewSandbox/NewSandboxModal/MyTemplates
- SandboxCard
- Sandboxes
- Filters
- FilterOptions
- SortOptions
- routes
- Templates
- Sidebar/SandboxesItem
- GitHub
- Live
- Patron
- PricingModal
- PricingChoice
- Profile
- Header/UserInfo/Stats
- Sandboxes
- Showcase/SandboxInfo
- Sandbox
- Editor/Workspace
- Files/DirectoryEntry
- Project
- items/Deployment
- Netlify/DeployButton
- Zeit/DeployButton
- SearchDependencies/DependencyHit
- Search
- common
- GithubIntegration
- Modals
- CommitModal
- DeleteDeploymentModal
- DeleteProfileSandboxModal
- DeleteSandboxModal
- DeploymentModal
- EmptyTrash
- ExportGitHubModal
- PRModal
- PreferencesModal
- PaymentInfo
- UploadModal
- SignIn
- UserMenu
- ZeitAuth
- ZeitIntegration
- store
- modules
- server
- user-notifications
- providers
- utils
- embed/components
- App
- Header
- sandbox/eval
- common/src/components/Button
- homepage/content/docs
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
185 files changed
+2093
-1968
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
251 | 252 | | |
252 | 253 | | |
253 | 254 | | |
254 | | - | |
| 255 | + | |
255 | 256 | | |
256 | 257 | | |
257 | 258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
| 297 | + | |
297 | 298 | | |
298 | 299 | | |
299 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
Lines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | | - | |
15 | | - | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
| 2 | + | |
| 3 | + | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| 19 | + | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
0 commit comments