-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Update 2: Thanks everyone who participated! We're asking that no one open any additional PRs at this point for Hacktoberfest. We've still got a lot of submissions to review and merge before the 31st and we'd like to make sure that everyone who contributed gets credited for their work.
Update: We've received a ton of submissions from this and we're really grateful to everyone who's participated this year! As you may have noticed, we're a bit behind on merging your PRs and updating the list of components to be refactored. This week we're going to go through all the remaining open PRs in order of submission and either request changes or merge them. Going forward, we're sticking with the first-come first-served approach, meaning any duplicate submissions will simply be closed. If you're still considering making a contribution, you can up your chances of getting your PR merged if you can make sure someone else hasn't beaten you to that part of the code base by searching through all of the Hacktoberfest PRs first.
Hey everyone! As you might already know, this month is #Hacktoberfest, which is an event that encourages people (especially newcomers) to participate in open source development. Since CodeSandbox's client is an open source project, we thought it would be a good idea to throw together a small guide on how you can make some quick contributions and rack up those PRs.
Right now we're working on overhauling the code base to transition everything to Typescript and replace our old state management solution (Cerebral) with Overmind (both developed by our own @christianalfoni). We're at a point where a lot of the groundwork for these big refactors has been done, and now all that's left is to implement changes across the application. We've come up with some patterns and best practices around how to do this, which we'll explain below.
About the Event
But first let's quickly go over Hacktoberfest and how you can use this issue as a guide to participating in the event. Here are the rules as explained on the official website:
Event details
Hacktoberfest® is open to everyone in our global community. Whether you’re a developer, student learning to code, event host, or company of any size, you can help drive growth of open source and make positive contributions to an ever-growing community. All backgrounds and skill levels are encouraged to complete the challenge.
Hacktoberfest is open to everyone in our global community!
Pull requests can be made in any GitHub-hosted repositories/projects.
Sign up anytime between October 1 and October 31.Rules
To qualify for the official limited edition Hacktoberfest shirt, you must register and make four pull requests (PRs) between October 1-31 (in any time zone). PRs can be made to any public repo on GitHub, not only the ones with issues labeled Hacktoberfest. If a maintainer reports your pull request as spam or behavior not in line with the project’s code of conduct, you will be ineligible to participate. This year, the first 50,000 participants who successfully complete the challenge will earn a T-shirt.
To help you get started, we've put together a list of components that still need to be refactored to use Overmind. We'd ask that you please choose up to 4 components from this list and create separate PRs for each. You can reply to this issue to let other participants know which components you plan on refactoring (and using your comment, we'll mark who's doing what on the list to help people choose). We'd like to make it so as many people as would like to be able to participate in the event, so that's why we would appreciate a maximum of 4 contributions per person.
Contributing
First, if you've never contributed to CodeSandbox before, we'd recommend you check out our Contributing Guide which covers some basics to help you get started running the project locally and how to submit your code.
To make a Hacktoberfest contribution, please create a new PR with:
- The component name your PR refactors
- Add the 🔨 Refactor, 🧠 Overmind, and most importantly the Hacktoberfest labels
- Request a review from @Saeris and @christianalfoni so that we can make sure your PR gets merged
Important! Your PR has to have the Hacktoberfest label such as in the screenshot above for it to count towards your 4 PRs! And don't forget to signup on the event homepage: https://hacktoberfest.digitalocean.com/profile
Hacktoberfest is an event run by a third party organization, so you have to follow their rules in order for your work to count towards a T-shirt!
For the refactor itself, in some cases it's really rather simple. Many of our components have already been re-written as functional components which use React hooks (in some cases, a component may need to be additionally refactored from a class component to a functional component). As part of our transition from Cerebral, we used to some glue code in our initial tests, which follow a pattern similar to this:
import { Button } from '@codesandbox/common/lib/components/Button';
import Input from '@codesandbox/common/lib/components/Input';
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
import track from '@codesandbox/common/lib/utils/analytics';
import { inject, hooksObserver } from 'app/componentConnectors';
import React from 'react';
import {
WorkspaceSubtitle,
WorkspaceInputContainer,
} from 'app/pages/Sandbox/Editor/Workspace/elements';
import { Error } from './elements';
type Props = {
style?: React.CSSProperties;
store: any;
signals: any;
};
export const CreateRepo = inject('store', 'signals')(
hooksObserver(
({
style,
signals: {
git: { repoTitleChanged, createRepoClicked },
},
store: {
editor: { isAllModulesSynced },
git: { repoTitle, error },
},
}: Props) => {
const updateRepoTitle = ({
target: { value: title },
}: React.ChangeEvent<HTMLInputElement>) => repoTitleChanged({ title });
const createRepo = () => {
track('Export to GitHub Clicked');
createRepoClicked();
};
return (
<div style={style}>
{!isAllModulesSynced && (
<Error>Save your files first before exporting.</Error>
)}
{error && <Error>{error}</Error>}
<WorkspaceSubtitle>Repository Name</WorkspaceSubtitle>
<WorkspaceInputContainer>
<Input onChange={updateRepoTitle} value={repoTitle} />
</WorkspaceInputContainer>
<Margin horizontal={1} bottom={1}>
<Button
block
disabled={error || !repoTitle || !isAllModulesSynced}
onClick={createRepo}
small
>
Create Repository
</Button>
</Margin>
</div>
);
}
)
);To this:
import { Button } from '@codesandbox/common/lib/components/Button';
import Input from '@codesandbox/common/lib/components/Input';
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
import track from '@codesandbox/common/lib/utils/analytics';
import { useOvermind } from 'app/overmind';
import React from 'react';
import {
WorkspaceSubtitle,
WorkspaceInputContainer,
} from 'app/pages/Sandbox/Editor/Workspace/elements';
import { Error } from './elements';
interface ICreateRepoProps {
style?: React.CSSProperties;
}
export const CreateRepo: React.FC<ICreateRepoProps> = ({ style }) => {
const {
state: {
editor: { isAllModulesSynced },
git: { repoTitle, error },
},
actions: {
git: { repoTitleChanged, createRepoClicked },
},
} = useOvermind();
const updateRepoTitle = ({
target: { value: title },
}: React.ChangeEvent<HTMLInputElement>) => repoTitleChanged({ title });
const createRepo = () => {
track('Export to GitHub Clicked');
createRepoClicked();
};
return (
<div style={style}>
{!isAllModulesSynced && (
<Error>Save your files first before exporting.</Error>
)}
{error && <Error>{error}</Error>}
<WorkspaceSubtitle>Repository Name</WorkspaceSubtitle>
<WorkspaceInputContainer>
<Input onChange={updateRepoTitle} value={repoTitle} />
</WorkspaceInputContainer>
<Margin horizontal={1} bottom={1}>
<Button
block
disabled={Boolean(error || !repoTitle || !isAllModulesSynced)}
onClick={createRepo}
small
>
Create Repository
</Button>
</Margin>
</div>
);
};Please take note how we were previously using the inject and hooksObserver higher order components to pass store and signals as props to the component. Those get replaced with a new useOvermind hook that returns an object containing the keys state and actions which are synonymous with store and signals. In most cases these simply need to be swapped out as in the example above (which also includes some extra tidying of types and code style changes).
One of the greatest benefits of this refactor is that Overmind now provides us full Typescript support for our global state management. However that does mean that in some cases there may be type errors that also need to be resolved. To go about resolving these, you may need to do one or more of a few things:
- Update the type definitions for the state itself (found under
app/overmind/namespaces) - Fix outdated or missing prop types for related components
- Or something more tricky is going on that we may need to help you with
What I've found is that this guide is a great resource for learning how to write types for React applications. I first check that before hitting up Google and StackOverflow for answers to type errors I encounter. Typescript can be a little difficult, but for the most part this refactor doesn't involve any of the really advanced Typescript wizardry.
So to summarize:
- You may need to refactor the component to a functional component (choose a different component if this seems to daunting!)
- Follow our coding style guide (explained below) to implement best practices
- The
injectandobserver/hooksObserverare to be removed, also remove the import at the top of the file - Introduce the
useOvermindhook fromapp/overmindimport:
import { useOvermind } from 'app/overmind'- Destructure the state and/or actions from the hook:
const SomeComponent: React.FunctionComponent = ({ store: { someState }, signals: { someTrigger } }) => {
const { state, actions } = useOvermind()
}- Use the existing store and/or signals and convert that into state and/or actions
const SomeComponent: React.FunctionComponent = () => {
const { state: { someState }, actions: { someTrigger } } = useOvermind()
}- Run
yarn typecheckandyarn lint, fix any errors that crop up (warnings can be ignored) - If you know where the component is used in the app, try manually testing it to check that it still works
- Submit your PR for review
- Implement any requested changes
Components to be refactored:
- [Completed by @HTMLGhozt (🔨 Refactored app/pages/CLI/index.tsx #2623)] /app/pages/CLI/index.tsx
- [PR by @iwgx (🔨 Refactored 🧠 Overmind Hacktober | /app/pages/CliInstructions/index.tsx : refactor to replace Cerebral with Overmind #2656)] /app/pages/CliInstructions/index.tsx
- [Completed by @vanya829 (🔨 Switch LikeHeart to use useOvermind #2635)] /app/pages/common/LikeHeart/index.tsx
- [Completed by @NabeelahY (🔨 Refactored 🧠 Overmind Hacktober | /app/pages/common/Modals/Changelog/Dashboard/index.js #2664)] /app/pages/common/Modals/Changelog/Dashboard/index.js
- [Completed by @darkmatter18 (🔨 Refactor, 🧠 Overmind, Hacktoberfest - /app/pages/common/Modals/DeleteDeploymentModal/inde… #2809)] /app/pages/common/Modals/DeleteDeploymentModal/index.js
- [Completed by @stevetangue (🔨 Refactor, 🧠 Overmind Hacktober | DeleteProfileSandboxModal to use useOvermind #2744)] /app/pages/common/Modals/DeleteProfileSandboxModal/index.js
- [PR by @sajadhsm (🔨 Refactor, 🧠 Overmind | /app/pages/common/Modals/DeploymentModal/index.js #2922)] /app/pages/common/Modals/DeploymentModal/index.js
- [Completed by @hardiked (refactor /app/pages/common/Modals/EmptyTrash/index.js to use OverMind… #2795)] /app/pages/common/Modals/EmptyTrash/index.js
- [Claimed by @ShahAnuj2610 2019-10-03] /app/pages/common/Modals/FeedbackModal/Feedback.js
- [Completed by @Infi-Knight (🔨 Refactor, 🧠 Overmind | common/Modals/FeedbackModal/index.js #2776)] /app/pages/common/Modals/FeedbackModal/index.js
- [Completed by @alanhoskins (Refactored app/pages/common/Modals/ForkServerModal #2774)] /app/pages/common/Modals/ForkServerModal/index.js
- [PR by @Avi98 (🔨 Refactor, 🧠 Overmind Hactoberfest | Refactor /app/pages/common/Modals/index.js #2902)] /app/pages/common/Modals/index.js
- [PR by @ftonato (🔨 Refactor, 🧠 Overmind, Hacktoberfest - /app/pages/common/Modals/LiveSessionEnded/index.js: convert to tsx and uses overmind #2810)] /app/pages/common/Modals/LiveSessionEnded/index.js
- [Completed by @MihirGH (🔨 Refactored, 🧠 Overmind, Hacktober | Refactor MoveSandboxFolderModal to use overmind #2751)] /app/pages/common/Modals/MoveSandboxFolderModal/index.js
- [PR by @NileshPatel17 (Refactored | Overmind Hacktober | /app/pages/common/Modals/NetlifyLogs/index.js #2727) and @ganes1410 (Refactor /app/pages/common/Modals/NetlifyLogs/index.js to /app/pages/common/Modals/NetlifyLogs/index.tsx 🧠 Overmind | Hacktoberfest #2820)] /app/pages/common/Modals/NetlifyLogs/index.js
- [Completed by @hasparus (🔨 Refactored 🧠 Overmind Hacktober | app/.../PickSandboxModal #2752)] /app/pages/common/Modals/PickSandboxModal/index.js
- [Completed by @sajadhsm (🔨 Refactor, 🧠 Overmind | /app/pages/common/Modals/PreferencesModal/Appearance/index.js #2806)] /app/pages/common/Modals/PreferencesModal/Appearance/index.js
- [PR by @sowmiya (/app/pages/common/Modals/PreferencesModal/Badges/index.js 🔨 Refactor 🧠 Overmind Hacktoberfest #2760)] /app/pages/common/Modals/PreferencesModal/Badges/index.js
- [Completed by @NileshPatel17
(@2759)] /app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier/index.js - [PR by @zplusp (@2841)] /app/pages/common/Modals/PreferencesModal/EditorPageSettings/EditorSettings/index.js
- [PR by @sajadhsm
(🔨 Refactor, 🧠 Overmind | Modals/PreferencesModal/EditorPageSettings/PreviewSettings/index.js #2835)] /app/pages/common/Modals/PreferencesModal/EditorPageSettings/PreviewSettings/index.js - [PR by @22PoojaGaur ( 🔨 Refactor, 🧠 Overmind and hacktoberfest | changes done for app/pages/common/Modals/PreferencesModal/Experiments/index.tsx #2918)] /app/pages/common/Modals/PreferencesModal/Experiments/index.tsx
- [PR by @hetpatel33 (🔨Refactored 🧠 Overmind Hacktober | /app/pages/common/Modals/PreferencesModal/index.js : refactor to replace Cerebral with Overmind #2746)] /app/pages/common/Modals/PreferencesModal/index.js
- [PR by @stackyism (🔨 Refactored 🧠 Overmind Hacktober | PaymentInfo/index.tsx: replaces Cerebral with Overmind & converts class to FC with hooks #2666)] /app/pages/common/Modals/PreferencesModal/PaymentInfo/index.tsx
- [PR by @hetpatel33 (🔨Refactored 🧠 Overmind Hacktober | /app/pages/common/Modals/PRModal/index.js : refactor to replace Cerebral with Overmind #2755)] /app/pages/common/Modals/PRModal/index.js
- [Completed by @MihirGH (🔨 Refactored, 🧠 Overmind, Hacktober | Refactor SearchDependenciesModal which now uses useOvermind #2747)] /app/pages/common/Modals/SearchDependenciesModal/index.js
- [Completed by @MihirGH (🔨 Refactored, 🧠 Overmind, Hacktober | Refactor SelectSandboxModal which now uses useOvermind #2743)] /app/pages/common/Modals/SelectSandboxModal/index.js
- [Claimed by @ganes1410 2019-10-16] /app/pages/common/Modals/ShareModal/index.js
- [Completed by @christineoo (Refactors app/src/app/pages/common/Modals/StorageManagementModal/index.js (#2621) #2808)] /app/pages/common/Modals/StorageManagementModal/index.js
- [Claimed by @jyash97 2019-10-03] /app/pages/common/Navigation/index.tsx
- [Claimed by @sheriallis 2019-10-14] /app/pages/Curator/index.js
- [Claimed by @lakhansamani 2019-10-05] /app/pages/Dashboard/Content/CreateNewSandbox/index.js
- [Claimed by @Antonio-Cabrero 2019-10-05] /app/pages/Dashboard/Content/CreateNewSandbox/NewSandboxModal/NewSandboxModal.tsx
- [PR by @br1anchen (🔨 Refactor, 🧠 Overmind, Hactoberfest | packages/app/src/app/pages/Dashboard/Content/DragLayer/SelectedSandboxItems #2863)] /app/pages/Dashboard/Content/DragLayer/SelectedSandboxItems/index.js
- [Claimed by @br1anchen 2019-10-19] /app/pages/Dashboard/Content/routes/PathedSandboxes/Navigation/NavigationLink.js
- [PR by @yevhenorlov (🔨 Refactor, 🧠 Overmind Hactoberfest | Refactor /app/pages/Dashboard/Content/routes/RecentSandboxes/index.js to use Overmind, Typescript, and Apollo hooks #2893)] /app/pages/Dashboard/Content/routes/RecentSandboxes/index.js
- [Completed by @yevhenorlov (🔨 Refactor, 🧠 Overmind Hactoberfest | Refactor /app/pages/Dashboard/Content/routes/TeamView/AddTeamMember/index.js to use Overmind, Typescript, and Apollo hooks #2906)] /app/pages/Dashboard/Content/routes/TeamView/AddTeamMember/index.js
- [Completed by @sakthivel-tw (🔨 Refactored 🧠 Overmind Hacktober | /app/pages/Dashboard/Content/Sandboxes/Filters/FilterOptions/index.tsx : refactor to replace Cerebral with Overmind #2650)] /app/pages/Dashboard/Content/Sandboxes/Filters/FilterOptions/index.tsx
- [Claimed by @yeion7 2019-10-04] /app/pages/Dashboard/Content/Sandboxes/Filters/SortOptions/index.js
- /app/pages/Dashboard/Content/SandboxGrid/index.js
- [PR by @armujahid (🔨 Refactor(/app/pages/Dashboard/index): replace Cerebral with 🧠 Overmind #2833)] /app/pages/Dashboard/index.js
- [PR by @lusan (refactored /app/src/app/pages/Dashboard/Sidebar/index.tsx dashboard sandbox index to overmind #2880)] /app/pages/Dashboard/Sidebar/index.js
- [PR by @sakthivel-tw (🔨 Refactored 🧠 Overmind Hacktober | /app/pages/Dashboard/Sidebar/TemplateItem/TemplateItem.tsx : refactor to remove Cerebral #2737)] /app/pages/Dashboard/Sidebar/TemplateItem/TemplateItem.tsx
- [PR by @sajadhsm (🔨 Refactor /app/pages/Dashboard/Sidebar/TrashItem/index.js (Remove Cerebral) #2859)] /app/pages/Dashboard/Sidebar/TrashItem/index.js
- [PR by @nobioma1 (🔨Refactor /app/pages/GitHub/index.js #2657)] /app/pages/GitHub/index.js
- [Completed by @chinmay17 (🔨 Refactored 🧠 Overmind Hacktober | app/pages/index.tsx : refactor to replace Cerebral with Overmind #2630)] /app/pages/index.tsx
- [PR by @jyotiarora2610 (refactored live index #2879)] /app/pages/Live/index.js
- [Completed by @hetpatel33 (🔨Refactored 🧠 Overmind Hacktober | /app/pages/NewSandbox/index.js : refactor to replace Cerebral with Overmind #2748)] /app/pages/NewSandbox/index.js
- [PR by @NileshPatel17 (Refactored 🧠 Overmind Hacktober | patron/subscription: /app/pages/Patron/PricingModal/PricingChoice/ChangeSubscription/index.ts #2654)] /app/pages/Patron/PricingModal/PricingChoice/ChangeSubscription/index.tsx
- [Completed by @malwilley (🔨 Refactored 🧠 Overmind Hacktober | /app/pages/Profile/index.js #2729)] /app/pages/Profile/index.js
- [PR by @ganes1410 (Refactor /app/pages/Profile/Sandboxes/index.js to /app/pages/Profile/Sandboxes/index.tsx 🔨 Refactor 🧠 Overmind Hacktoberfest #2765)] /app/pages/Profile/Sandboxes/index.js
- [PR by @ganes1410 (Refactor /app/pages/Profile/Showcase/index.js to /app/pages/Profile/Showcase/index.tsx 🔨 Refactor 🧠 Overmind Hacktoberfest #2766)] /app/pages/Profile/Showcase/index.js
-
[Closed by @christianalfoni] /app/pages/Sandbox/Editor/Content/index.js - [PR by @chinmay17 (🔨 Refactored 🧠 Overmind : /editor/content/preview/index to replace Cerebral with Overmind #2638)] /app/pages/Sandbox/Editor/Content/Preview/index.tsx
- [PR by @lusan (refactored content editor tabs packages/app/src/app/pages/Sandbox/Editor/Content/Tabs/index.tsx #2881)] /app/pages/Sandbox/Editor/Content/Tabs/index.js
- [Completed by @chinmay17 (🔨 Refactored 🧠 Overmind Hacktober /pages/Sandbox/Editor/Header/CollectionInfo/index.js converted TS and uses Overmind #2639)] /app/pages/Sandbox/Editor/Header/CollectionInfo/index.js
- [Completed by @chinmay17 (🔨 Refactored 🧠 Overmind Hacktober | /Sandbox/Editor/Header/Header.tsx : refactor to replace Cerebral with Overmind #2644)] /app/pages/Sandbox/Editor/Header/Header.tsx
- [Completed by @Gobinath-Manokaran (🔨 Refactor, 🧠 Overmind Hactoberfest | Refactor /app/pages/Sandbox/Editor/Header/index.tsx to use Overmind #2865)] /app/pages/Sandbox/Editor/Header/index.tsx
- /app/pages/Sandbox/Editor/Header/SandboxName/SandboxName.tsx
- /app/pages/Sandbox/Editor/index.js
- [Completed by @yevhenorlov (🔨 Refactor, 🧠 Overmind Hactoberfest | Refactor /app/pages/Sandbox/Editor/Workspace/Chat/index.js to use Overmind and Typescript #2910)] /app/pages/Sandbox/Editor/Workspace/Chat/index.js
- /app/pages/Sandbox/Editor/Workspace/Dependencies/AddVersion/index.js
- [Claimed by @silltho 2019-10-06] /app/pages/Sandbox/Editor/Workspace/Dependencies/index.js
- [PR by @neochaochaos (🔨 Refactor, 🧠 Overmind Hactoberfest | Refactor /app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/DirectoryChildren/index.js to use Overmind #2885)] /app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/DirectoryChildren/index.js
- [PR by @neochaochaos (🔨 Refactor, 🧠 Overmind Hactoberfest | Refactor /app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/DirectoryChildren/ModuleEntry.js to use Overmind #2885 #2887)] /app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/DirectoryChildren/ModuleEntry.js
- [Completed by @malwilley (🔨 Refactored 🧠 Overmind Hacktober | /app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/index.js #2787)] /app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/index.js
- [Claimed by @ivandevp 2019-10-14] /app/pages/Sandbox/Editor/Workspace/Files/index.js
- [Completed by @sajadhsm (🔨 Refactor, 🧠 Overmind | /app/pages/Sandbox/Editor/Workspace/items/ConfigurationFiles/index.js #2826)] /app/pages/Sandbox/Editor/Workspace/items/ConfigurationFiles/index.js
- [PR by @stackyism
(🔨 Refactored 🧠 Overmind Hacktober | VisitSiteButton.tsx : refactor to replace Cerebral with Overmind #2728)] /app/pages/Sandbox/Editor/Workspace/items/Deployment/Netlify/SiteInfo/Actions/VisitSiteButton/VisitSiteButton.tsx - [Completed by @stackyism
(🔨 Refactored 🧠 Overmind Hacktober | /app/pages/Sandbox/Editor/Workspace/items/Deployment/Netlify/SiteInfo/SiteInfo.tsx : replace Cerebral with Overmind & fixes NetlifySite id type #2738)] /app/pages/Sandbox/Editor/Workspace/items/Deployment/Netlify/SiteInfo/SiteInfo.tsx - [Completed by @hetpatel33 (🔨 Refactored 🧠 Overmind Hacktober | Editor/Workspace/items/Deployment/Zeit/Deploys/Actions/AliasDeploymentButton/AliasDeploymentButton.tsx : refactor to replace Cerebral with Overmind #2742) /app/pages/Sandbox/Editor/Workspace/items/Deployment/Zeit/Deploys/Actions/AliasDeploymentButton/AliasDeploymentButton.tsx
- [Completed by @stackyism (🔨 Refactored 🧠 Overmind Hacktober | /Sandbox/Editor/Workspace/items/Live/index.js : refactor to replace Cerebral with Overmind #2663)] /app/pages/Sandbox/Editor/Workspace/items/Live/index.js
- [Claimed by @lusan 2019-10-15] /app/pages/Sandbox/Editor/Workspace/items/Live/LiveInfo.js
- [PR by @deinakings (🔨 Refactored 🧠 Overmind Hacktober | Refactor app/pages/Sandbox/Editor/Workspace/items/Server/EnvVars/index.js to use Overmind #2818)] /app/pages/Sandbox/Editor/Workspace/items/Server/EnvVars/index.js
- [PR by @fullstackzach (🔨 Refactor, 🧠 Overmind, refactored OpenedTabs to use Overmind #2769) /app/pages/Sandbox/Editor/Workspace/OpenedTabs/index.js
- [Completed by @Gobinath-Manokaran (🔨 Refactor, 🧠 Overmind Hactoberfest | Refactor /app/pages/Sandbox/Editor/Workspace/Project/Keywords.tsx to use interface instead of types #2867)] /app/pages/Sandbox/Editor/Workspace/Project/Keywords.tsx
- [Claimed by @sheriallis and @kalaivanan-muthusamy 2019-10-13]
/app/pages/Sandbox/Editor/Workspace/Project/Project.tsx - [PR by @milap1296
(🔨 Refactored, 🧠 Overmind, Hacktober | Refactor SandboxConfig to use overmind #2757)] /app/pages/Sandbox/Editor/Workspace/Project/SandboxConfig/SandboxConfig.tsx - [Claimed by @lusan 2019-10-15] /app/pages/Sandbox/Editor/Workspace/Project/SandboxConfig/TemplateConfig.tsx
- [PR by @lusan (refactored sandbox index packages/app/src/app/pages/Sandbox/index.tsx is using Overmind #2874)] /app/pages/Sandbox/index.js
- [PR by @jyotiarora2610 (QuickActions refactoring app/src/app/pages/Sandbox/QuickActions/QuickActions.tsx #2817)] /app/pages/Sandbox/QuickActions/index.js
- [Completed by @NileshPatel17 (Refactored 🧠 Overmind Hacktober | /app/pages/Sandbox/SignOutNoticeModal/index.js : refactor to replace Cerebral with Overmind #2655)] /app/pages/Sandbox/SignOutNoticeModal/index.js
- [Completed by @NabeelahY (🔨 Refactored 🧠 Overmind Hacktober | /app/pages/Sandbox/ZenModeIntroductionModal/index.js #2669)] /app/pages/Sandbox/ZenModeIntroductionModal/index.js
- [Completed by @armujahid (refactor: /app/pages/Search/index.js 🔨 Refactor, 🧠 Overmind #2780)] /app/pages/Search/index.js
Best Practices and Style Guide
We've been working on a set of coding guidelines that we're applying across the project to increase readability and consistency. While not hard rules, we'd ask that you stick to these a close as possible. Since these are mostly stylistic choices, they're unlikely to cause anything to break if not followed, but we may ask you to fix a few if we feel it's important.
- 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.tsfile handling all exports to be consumed by outside components - Prefer
interfaceovertypefor typing Props - In general, prop interfaces should follow a IComponentNameProps naming scheme, though this is largely stylistic
- Prefer
const SomeComponent: React.FC<ISomeComponentProps> = ({ . . . }) => { }overconst SomeComponent = ({ . . . }: ISomeComponentProps) => { }to avoid needing to define common React component props - For styled components, Inline types are fine where their footprint is small, ie:
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.tsfile 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.gqlandmutations.gqlto 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.tsfile 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
csstagged 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.
In general, our component file structure looks like this:
./ ParentComponent
./ ChildComponent
- index.ts
- ChildComponent.tsx
- elements.ts
- SomeOtherChildComponent.tsx
- index.ts
- ParentComponent.tsx
- elements.ts
- types.ts
- queries.gql
- mutations.gql
Simple components (those without any styles, few types, and no grapql) live in single named files like SomeOtherChildComponent.tsx, while others live in their own directories with folder names that match the main component's name, using index.ts to define all exports to be exposed to all outside consumers up the tree and files such as elements.ts to handle concerns like component styling, shared type definitions, graphql queries/mutations, etc.
Many of our existing components just live in their own directory and are defined in the index.js file there. If you encounter one of these, it's best to split it up according the the rules defined in the style guide. If it's a simple component, you can just rename the file to the component's name and move it to the parent directory, getting rid of the folder it's in entirely.
If you're confused by any of these, just try your best and we'll point out any changes we'd like you to make when we review your PR! Don't be afraid to as us questions too!
Other Quick Wins
So while Overmind is the main focus of our current refactor, we're also looking to convert more of the code base over to Typescript and React Hooks. If you'd like to try and refactor any of our JavaScript files or convert a class component, you're more than welcome to do so! We don't have a convenient list of files that need to be refactored for those, but it shouldn't be too hard to find.
In general we could always use contributions like bug fixes and better documentation, so if you spot an issue you'd like to try and fix or something in our docs has a typo or isn't clear enough, please feel free to submit a PR for those too!
Thanks and Happy Hacking!
Lastly, we'd like to extend our sincerest thanks to our community for all the feedback and support you give us! The entire CodeSandbox team is driven by your enthusiasm and we're always on the lookout for new ways to collaborate together and build new features to address all the awesome use-cases you come up with for our app. Thanks so much for your time and effort!
