Skip to content

Frontend Development Environment

Luis Neves edited this page Aug 30, 2019 · 26 revisions

Prerequisites

Node and npm have to be installed:

zypper in nodejs8 

http://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_Leap_15.0/

npm install -g yarn
npm install -g webpack
npm install -g flow-bin@0.93.0
yarn install

Frontend Server - faster development cycle - frontend proxy server - yarn proxy

Frontend proxy server that will serve all the local javascript files and proxy the rest for a chosen backend server.

cd web/html/src
yarn proxy --server "https://server.tf.local"           (Don't forget about the https://)

Frontend Server - React hot reload

React hot reload allows us to see our react changes without refreshing the whole page. For that to work we need to have our "yarn proxy" running and make sure the entry point of the react page we are working on has the hot reloading enabled. You can find an example here: https://github.com/uyuni-project/uyuni/blob/master/web/html/src/manager/content-management/create-project/create-project.js#L59

Just be aware that this mode doesn't work for all the changes as the components aren't remounted again. If you have new code inside constructor/lifecycle methods, you might need to reload the full page.

React style guide of reusable components

We use storybooks to document our React reusable components. This can be useful either to find which components can be reused while implementing a new feature or to understand the impact of changing a component. The development of the react reusable components ideally should be styleguide first.

Instructions to run the styleguide (this assumes you have the frontend proxy server running):

cd web/html/src
yarn run storybook

After this all the files "<component_name<.stories.js" will be loaded as documentation inside the styleguide. You can consult the official docs storybooks for more information.

New dependency

All the frontend dependencies are tracked inside the module "susemanager-frontend/susemanager-nodejs-sdk-devel". Inside OBS these are the only dependencies that will be available.

To add a new dependency run the command

yarn add <depency_name>
or
yarn add --dev <depency_name> (if it's only a development/build dependency)

After running this command run "yarn build" on web/html/src, add a new entry to the file "susemanager-frontend/susemanager-nodejs-sdk-devel/susemanager-nodejs-sdk-devel.changes" and commit all the generated files

How to add a new react page

All the routes exported on the files 'manager/<folder_name>/index.js' will be automatically registered as react pages entries. Check the file content-management/index.js for an example. Don't forget to restart webpack after these changes.

Folders Structure

For the sake of organization, each new react page should be inside their own new folder. A good structure for a new React page would be:

src/manager/dashboard/dashboard.js
src/manager/dashboard/dashboard.renderer.js

The file dashboard.renderer.js will provide a global function to render the page, which can be called from anywhere.

For an example take a look in the virtualization guest feature.

Bear in mind if this new react page is expected to grow a lot, instead of creating multiple react child pages, you could consider the creation of a Mini SPA react app adding client routing with "react-router"

yarn.lock conflicts - What should I do

Conflicts on this file can be hard to solve manually. I suggest to solve it like this:

  • solve conflicts with theirs
  • run yarn add again with the new dependencies you added

Linting

cd $PROJECT_ROOT/web/html/src
yarn lint
Clone this wiki locally