2.4.0 • Published 10 months ago

@edx/studio-frontend v2.4.0

Weekly downloads
1,473
License
AGPL-3.0
Repository
github
Last release
10 months ago

studio-frontend

codecov Build Status npm npm semantic-release

This repo is in the process of being deprecated [DEPR]: studio-frontend repo

All code changes should be made in the course-authoring repo.

React front end for edX Studio

For an introduction to what this repo is and how it fits into the rest of the edX platform, read Studio-frontend: Developing Frontend Separate from edX Platform.

Development

Requirements:

To install and run locally:

$ git clone git@github.com:edx/studio-frontend.git
$ cd studio-frontend
$ make up

You can append -detached to the make up command to run Docker in the background.

To install a new node package in the repo (assumes container is running):

$ make shell
$ npm install <package> --save-dev
$ exit
$ git add package.json

To make changes to the Docker image locally, modify the Dockerfile as needed and run:

$ docker build -t edxops/studio-frontend:latest .

Webpack will serve pages in development mode at http://localhost:18011.

The following pages are served in the development:

PageURL
Assetshttp://localhost:18011/assets.html
Accessibility Policyhttp://localhost:18011/accessibilityPolicy.html
Edit Image Modalhttp://localhost:18011/editImageModal.html

Notes:

The development server will run regardless of whether devstack is running along side it. If devstack is not running, requests to the studio API will fail. You can start up the devstack at any time by following the instructions in the devstack repository, and the development server will then be able to communicate with the studio container. API requests will return the following statuses, given your current setup:

Studio Running?Logged in?API return
Non/a504
YesNo404
YesYes, non-staff account403
YesYes, staff account200

Development Inside Devstack Studio

To load studio-frontend components from the webpack-dev-server inside your studio instance running in Devstack:

  1. In your devstack edx-platform folder, create cms/envs/private.py if it does not exist already.
  2. Add STUDIO_FRONTEND_CONTAINER_URL = 'http://localhost:18011' to cms/envs/private.py.
  3. Restart your Studio container: make cms-restart-container.

Pages in Studio that have studio-frontend components should now request assets from your studio-frontend docker container's webpack-dev-server. If you make a change to a file that webpack is watching, the Studio page should hot-reload or auto-reload to reflect the changes.

Testing the Production Build Inside Devstack Studio

The Webpack development build of studio-frontend is optimized for speeding up developement, but sometimes it is necessary to make sure that the production build works just like the development build. This is especially important when making changes to the Webpack configs.

Sandboxes use the production webpack build (see section below), but they also take a long time to provision. You can more quickly test the production build in your local docker devstack by following these steps:

  1. If you have a cms/envs/private.py file in your devstack edx-platform folder, then make sure the line STUDIO_FRONTEND_CONTAINER_URL = 'http://localhost:18011' is commented out.
  2. Reload your Studio server: make cms-restart-container.
  3. Run the production build of studio-frontend by running make shell and then npm run build inside the docker container.
  4. Copy the production files over to your devstack Studio's static assets folder by running this make command on your host machine in the studio-frontend folder: make copy-dist.
  5. Run Studio's static asset pipeline: make cms-static.

Your devstack Studio should now be using the production studio-frontend files built by your local checkout.

Testing in studio-frontend

Where do test files go?

If you are developing a component and you are adding new js or jsx test files, the test files would go in the same location as the file. This makes it easier to track and test. For example, if you are developing a component AssetsSearch in src/components/ you would name the test file after the component name AssetsSearch.test.jsx. Similarly, if you are adding a file parseDateTime.jsx in the src/utils/ place the test file at same location with the name parseDateTime.test.jsx.

How to run tests locally

To run the whole suite of tests, you can run npm run test inside the docker container shell.

make shell
npm run test

If you want to run a particular test file only, you can run npm run test -t <path>. You can also add ".only" to any "it" or "describe" block in a particular test file to only run that particular test. For example, it.only to run only that test or describe.only to run only the tests in that describe block.

How to debug locally running tests

To debug tests running locally, first open the Node debugger:

1) navigate to chrome://inspect in your browser 2) choose "Open dedicated DevTools for Node" (it will open in a new window) 3) check that the default network configuration in the "Connection" tab is 127.0.0.1:9229 (i.e. port 9229 on localhost)

Next, after adding a debugger; statement above the test code you'd like to debug, use these commands inside the studio-frontend repo:

make shell
node --inspect=0.0.0.0 node_modules/.bin/jest --runInBand

The node debugger should grab focus as soon as your first breakpoint is hit. You can specify individual test files by appending -- path/to/yourTestFile.test.jsx to the end of the node command.

Testing a Branch on a Sandbox

It is a good practice to test out any major changes to studio-frontend in a sandbox since it is much closer to a production environment than devstack. Once you have a branch of studio-frontend up for review:

  1. Create a new branch in edx-platform off master.
  2. Edit the package.json in that branch so that it will install studio-frontend from your branch in review:

    "@edx/studio-frontend": "edx/studio-frontend#your-branch-name",
  3. Commit the change and push your edx-platform branch.

  4. Follow this document on provisioning a sandbox using your edx-platform branch.

The sandbox should automatically pull the studio-frontend branch, run the production webpack build, and then install the dist files into its static assets during provisioning.

Releases

This all happens automagically on merges to master, hooray! There are just a few things to keep in mind:

What is the latest version?

Check github, npm, or the npm badge at the top of this README. package.json no longer contains the correct version (on Github), as it creates an odd loop of "something merged to master, run semantic-release" -> "semantic-release modified package.json, better check that in and make a PR" -> "a PR merged to master, run semantic-release", etc. This is the default behavior for semantic-release.

Commit message linting

In order for semantic-release to determine which release type (major/minor/patch) to make, commits must be formatted as specified by these Angular conventions. TravisBuddy will let you know if anything is wrong before you merge your PR. It can be difficult at first, but eventually you get used to it and the added value of automatic releases is well worth it, in our opinions.

A note on merge messages

Note that when you merge a PR to master (using a merge commit; we've disabled squash-n-merge), there are actually 2 commits that land on the master branch. The first is the one contained in your PR, which has been linted already. The other is the merge commit, which commitlint is smart enough to ignore due to these regexes. The point here is that you should not change the default Merge pull request <number> from <branch> message on your merge commit, or else the master build will fail and we won't get a deploy.

Updating Latest Docker Image in Docker Hub

If you are making changes to the Dockerfile or docker-compose.yml you may want to include them in the default docker container.

  1. Run make from-scratch
  2. Run docker tag edxops/studio-frontend:latest edxops/studio-frontend:latest
  3. Run docker push edxops/studio-frontend:latest
  4. Check that "Last Updated" was updated here: https://hub.docker.com/r/edxops/studio-frontend/tags/

Adding a new app

There's a bunch of boilerplate that needs to be created to set up a new studio-frontend app that can be independently embedded into a page in Studio. See the openedx-workshop branch, which demonstrates setting up a very basic HelloWorld app.

CSS

CSS in studio-frontend is a bit tricky. Because components are embedded in existing Studio pages, we have to isolate the CSS. This prevents Studio CSS affecting studio-frontend components and from studio-frontend CSS affecting the surrounding Studio page. However, there are a few key points to know about this:

  1. All studio-frontend styles are scoped to the .SFE-wrapper div.
    • In a way, this div acts like the <body> element for the embedded studio-frontend component.
    • If any elements from studio-frontend are placed outside of this div, then they will be unstyled (or only have Studio styles applied to them).
  2. Studio-frontend elements are fully reset using a browser default stylesheet. So, weird things will occasionally happen with the styling, because it is not a perfect process.
    • Use a browser dev tools style inspector to see what styles are being applied. Remove styles from default.css if you think they might be conflicting with other styling.
    • E.g. for some reason, ordered lists appear as unordered. We still have not figured that one out.
  3. Selectors that you write in studio-frontend .scss files will be prepended with a selector to the wrapper div during the Webpack build process (#root.SFE .SFE-wrapper). This is so that studio-frontend styles affect only the contents of the embedded studio-frontend component and so that they are specific enough that they override any Studio styling.
  4. The edx-bootstrap.scss file contains only the Bootstrap variables and mixin definitions. This file is safe to @import into individual component .scss files. It allows you to, for example, color an element using the primary color defined in the current Bootstrap theme with the $primary variable.
  5. Only import SFE.scss in JavaScript at the root of a studio-frontend app. This file contains all of the Bootstrap style definitions and the CSS reset. There is a lot of CSS in the file, so we only want to import it once per app.
  6. We currently have CSS modules enabled in the Webpack css-loader, but aren't really using the features of it. CSS modules allows you to rename classname selectors defined in the CSS to be more specific, but we currently have it configured to leave the names alone. We found it simpler to just reference Bootstrap classes with a plain string (e.g. "col-1" vs. styles['col-1']).
    • CSS modules helps avoid class name collision between different components on the same page. We haven't run into this issue with studio-frontend yet, but we might want to consider using it in the future once we do.
  7. Make sure the font-awesome CSS is imported in JavaScript in the app root index file.

Ideally, studio-frontend should not need these CSS hacks. In the future, studio-frontend should control the full HTML page instead of being embedded in a Studio page shell. That way, studio-frontend components would be free from legacy Studio styles and would not need to apply any resets.

Getting Help

If you need assistance with this repository please see our documentation for Getting Help for more information.

Issue Tracker

We use JIRA for our issue tracker, not GitHub Issues. Please see our documentation for tracking issues for more information on how to track issues that we will be able to respond to and track accurately. Thanks!

How to Contribute

Contributions are very welcome, but for legal reasons, you must submit a signed individual contributor's agreement before we can accept your contribution. See our CONTRIBUTING file for more information -- it also contains guidelines for how to maintain high code quality, which will make your contribution more likely to be accepted.

Reporting Security Issues

Please do not report security issues in public. Please email security@openedx.org.

2.4.0

10 months ago

2.3.0

1 year ago

2.2.0

1 year ago

2.1.3

1 year ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

3 years ago

1.19.0

3 years ago

1.19.1

3 years ago

1.18.1

3 years ago

1.18.2

3 years ago

1.18.0

3 years ago

1.17.0

4 years ago

1.16.23

4 years ago

1.16.22

4 years ago

1.16.21

4 years ago

1.16.20

5 years ago

1.16.19

5 years ago

1.16.17

6 years ago

1.16.16

6 years ago

1.16.15

6 years ago

1.16.14

6 years ago

1.16.13

6 years ago

1.16.12

6 years ago

1.16.11

6 years ago

1.16.10

6 years ago

1.16.9

6 years ago

1.16.8

6 years ago

1.16.7

6 years ago

1.16.6

6 years ago

1.16.5

6 years ago

1.16.4

6 years ago

1.16.3

6 years ago

1.16.2

6 years ago

1.16.1

6 years ago

1.16.0

6 years ago

1.15.0

6 years ago

1.14.1

6 years ago

1.14.0

6 years ago

1.13.1

6 years ago

1.13.0

6 years ago

1.12.1

6 years ago

1.12.0

6 years ago

1.11.1

6 years ago

1.11.0

6 years ago

1.10.8

6 years ago

1.10.7

6 years ago

1.10.6

6 years ago

1.10.5

6 years ago

1.10.4

6 years ago

1.10.3

6 years ago

1.10.2

6 years ago

1.10.1

6 years ago

1.10.0

7 years ago

1.9.13

7 years ago

1.9.12

7 years ago

1.9.11

7 years ago

1.9.10

7 years ago

1.9.9

7 years ago

1.9.8

7 years ago

1.9.7

7 years ago

1.9.6

7 years ago

1.9.5

7 years ago

1.9.4

7 years ago

1.8.0

7 years ago

1.7.3

7 years ago

1.7.2

7 years ago

1.7.1

7 years ago

1.7.0

7 years ago

1.6.3

7 years ago

1.6.2

7 years ago

1.6.1

7 years ago

1.5.0

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.9.0

7 years ago

0.8.7

7 years ago

0.8.6

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.7

7 years ago

0.6.6

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago