Skip to content
Snippets Groups Projects
user avatar
Johanna Szepanski authored
e0a37024
History

CE deploy & monitor web UI

This project is meant to be the web User Interface for the CE deploy & monitor tool. The project is written in ReactJS.

Developing environment

  • NodeJS and npm
  • Docker (if want to run backend locally for test purposes)
  • IDE for JavaScript developement (e.g. Visual Studio Code)
  • Credentials from ESS Artifactory, with permission to the ics-npm registry

(For developing purposes it is suggested to use Node Version Manager [NVM] which makes easy to change between different Node versions).

Required versions

  • Node: v20+
  • npm: v6.10+

Local development setup

Installing Dependencies

This project includes private dependencies from Artifactory, so additional configuration is required.

  1. Create an .npmrc file based on the example provided in this registry, substituting your email and base64 credentials.
  2. Install dependencies with npm ci.

Note, we lock dependency versions with package-lock.json; please install dependencies with npm ci (not npm install) to avoid overwriting the package-lock.

Updating the API Files

This project uses @rtk-query/codegen-openapi to auto-generate the deploy api from its OpenAPI spec. To generate the spec:

  1. Run npm run generate-api to update the api file; see openapi-config.json for path information.
  2. Commit the changed file.

Note: default path to api spec is localhost. To generate a new spec BE must run locally. It is possible to change path to any other swagger environment, but it is preferred to use locally running backend.

Proxying to Existing Backends

For being able to run the backend, and frontend application on the same machine (locally) a proxy has been set in the project! If you don't want to run the backend server, and frontend on the same machine, or have different settings, please adjust the vite.config.ts at the following line: target: "http://localhost:8080"

External configuration

All necessary configuration is stored in a config file in the public folder, called config.js. The config file has to be included in the index.html file! The following values can be set in the file:

Environment variable Description
SERVER_ADDRESS The backend server base URL (host:port) (if backend server is running natively on the same host as the UI then the value has to be empty, and proxy has to be set!)
API_BASE_ENDPOINT The context path of the application's REST API (e.g. /api/spec)
SUPPORT_URL The URL for where to ask for more support (i.e. service desk)
TOKEN_RENEW_INTERVAL Time interval to renew JWT auth token (in milliseconds)
NAMING_ADDRESS Naming service base URL (used for IOC name Naming reference feature)
NETBOX_ADDRESS Netbox service base URL (used for IOC name Naming reference feature)
ENVIRONMENT_TITLE Adds a (sub)text to the HTLM title, and also for the appBar header. Supposed to show information to the user which environment they are using. The default value is empty. Optional field!

Refering to a value in the JS source code is: window.field-name (e.g. window.SERVER_ADDRESS).

Setting Environment Variables

Environment variables are stored in .env files. Precedency of environment variable files are (files on the left have more priority than files on the right):

  • npm start: .env.development.local, .env.local, .env.development, .env
  • npm run build: .env.production.local, .env.local, .env.production, .env

All environment variables start with REACT_APP_ prefix.

Useful links to start developing in ReactJS

This project was bootstrapped with Create React App.

Available Scripts

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

ESLint & Prettier

Linting can be checked, and to some extent auto fixed by running following scripts:

npm run lint

will run npx eslint src which will run eslint on all files in the src directory and write out the results of the check in your console.

npm run lint:fix

will run npm run lint -- --fix which will run eslint on all files in the src directory and fix what can be auto fixed and write out the rest of the results of the check, of what could not be auto fixed, in your console.

npm run prettier

will run npx prettier src --check which will run prettier on all files in the src directory and write out which files would be changed in your console.

npm run prettier:fix

will run npm run prettier -- --write which will run prettier on all files in the src directory and write out which files have be changed in your console.

npm run format

will run npm run prettier:fix && npm run lint:fix which will run lint:fix and the prettier:fix scripts mentioned above.

Pre-Commit

Installation

You will need to install pre-commit first locally on you machine, the install it in you project, instructions on how to do this you can find here: https://pre-commit.com/#install

By running pre-commit run --all-files pre-commit will run both eslint and prettier on all files in src, much like the scripts from the package.json

End-to-end testing with Cypress

For end-to-end testing we user Cypress, tests are written in gherkin syntax. To run Cypress tests, you have to

  • run the backend server
  • run the frontend code

Details: https://github.com/TheBrainFamily/cypress-cucumber-preprocessor

Then to open Cypress dialog window enter:

npx cypress open

To run Cypress tests from command line (without the test-dialog), enter

npx cypress run

Building

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

Learn More

You can learn more in the vite documentation.

To learn React, check out the React documentation.