-
Notifications
You must be signed in to change notification settings - Fork 78
Standalone React and Headless Rails applications #6287
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c5dc21a to
b5c9690
Compare
3a3125e to
d270e32
Compare
3aca1c3 to
9e0489e
Compare
Relevant means if there are >1 enrolled courses or not in CoursesIndex. If in CoursesIndex and there are no enrolled courses, do not show the Courses button.
0d1feca to
9263d5d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Enhancement
Feature
JavaScript
Pull requests that update JavaScript code
Ruby
Pull requests that update Ruby code
Technical Story
UI
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR splits Coursemology into two apps: a standalone React app and headless Rails app. Both apps are independent of each other and must be bootstrapped on different processes. The default HTML entry point to the app is now the standalone React app.
Note
At this stage, we cannot afford to make the Rails app API-only. Cookies (and cookie-based sessions), CSRF protection, and more are not available by default in an API-only Rails app. Manual extensions and tests will need to be done to go API-only.
Development changes
lvh.meto access the app. This enables multi-tenancy on local environments.Run
host lvh.meon your Terminal to bindlocalhostand127.0.0.1tolvh.me. Then, access the React app onlvh.me:8080and the Rails app onlvh.me:5000(or your set ports). You can now develop on other instances, e.g.,nushigh.lvh.me.It proxies requests with
?format=jsonand rewrites theOriginheader to please CORS. See thedevServerkey onwebpack.dev.jsfor more information.Bootstrap both React and Rails app on separate processes. This also makes it way easier to use Byebug since Foreman cannot show standard inputs.
Existing Capybara tests still work, and can be updated or extended if needed as we discover edge cases or bug fixes. But new tests should be written with Playwright.
yarn build:testnow setsBABEL_ENVto something else thanproduction.This is done to ensure
data-testidattributes are not removed during webpack's production build..envinclientif you haven't already. Then add this entry for reCAPTCHA.This is the same testing key as the one in the Rails app. If the site key in Rails app changes, make sure you update this too.
Important
We'd probably need to rewrite our Getting Started guide at some point. Maybe sometime after we set up our repo for the Go server.
Note
Playwright tests currently live in
tests/tests. The idea is to have ALL end-to-end tests undertests. Then we can havetests/playwrightandtests/capybara, for example, and bootstrap them with appropriatescriptsintests/package.json. I'm not sure if we can strip out Capybara tests from the Rails app, though.We're going to move some files and folders around once we start writing some Go codes, anyway. So, I envision the root of the repo will have folders like:
client,api-v1,api-v2,tests, and any other environments/configs/CI files. We can have one script (maybepackage.json) containing all the configs (environment variables, ports, etc.) at the root of the project.CircleCI pipeline changes
build_clientjob to build and cache client.test_playwrightjob for Playwright tests.build_client,test_playwright,jslint, andjstestnow use CircleCI's Node convenience image.jslintandjstestnow don't build client since it's unnecessary.vendor/recorderjs/node_modules.i18ntoi18n_enandi18n_zh.i18n_enis now required for merging tomaster.testis nowtest_rspec.lintis nowfactorybot_lint.Note
After this PR is merged, we need to remove
ci/circleci: testandci/circleci: lintfrommaster's branch protection settings. Until then, ignore the pending results forlintandtestin below status checks.Notable changes
Webpack injects the bundled JavaScript scripts with
HtmlWebpackPlugin.index.tsxnow immediately binds ReactDOM on script load.Sign in, Sign out, Forgot password, Reset password, and Resend confirmation email pages.
These pages are code-split. The contents of these pages are rendered in Markdown. There's a new component,
MarkdownPage.UnauthenticatedAppandAuthenticatedApp.They are code-split.
ScribingViewComponentnow lazy loads itsfabric- andreact-color-dependent children.They are code-split.
CssBaseline.Some components and pages that were using bare HTML elements, e.g.,
h4,span, etc., were converted to their appropriate counterparts withTypography.NotificationPopuptoasts' styles are now standardised./when authenticated now routes to a dashboard page: list of courses with and sorted by last accessed times.If the user has only one course, it will automatically redirect to that course. If the user has no courses, it will automatically redirect to
/courses.sessionstore that stores i18n config and authentication state.This is intended to be extended further in the future to include authentication details, permissions, actual session IDs, etc., if needed.
Before making any non-GET requests, it will request a fresh CSRF token and cache it if not already, expired, or invalid. It will continue requesting GET to
/csrf_tokenuntil the non-GET request gets through, for a maximum of 3 times.CanCan::AccessDenied403 to the Sign In and Forbidden pages./attemptURLs.This way, there's no need for manually GET-ting to
/attemptand redirect programmatically. This also allows users to Open Link in New Tab on these buttons.ErrorBoundarynow also prints out the rawErrorstack.lib/server-context.js.There's no need to infer Rails controller name in React. I18n config and CSRF token are managed by
I18nProviderand the base Axios client, respectively.lib/axios.js.Pagenow renders aFragmentto reduce extradivnesting.PopupMenuButtonnow supports asecondarytitle/component.Accordionnow supports a customiconcomponent.expect_forbiddenmatcher.login_asandlogoutperformers (supersedes Warden's).devDependencies.SearchFields.onKeyDownfunction is not invocable inTextFields.UserEmailSubscriptionspage.CoursesIndexnot opening New Course dialog when?new=truewhen loading.For full changelog, refer to the commit history.
Deployment changes
/static/*,/*, and?format=jsonto rewrite them to the static files,/index.html, and the Rails server, respectively.