This project contains a simple UI written in ReactJs that can be used to demonstrate how to start a Camunda Process Instance and how to view User Tasks.
See the camunda-demo-starter
project to quickly start a fully functional Camunda 7 or 8 demo environment that includes this project.
This project is a Spring Boot Java Application that runs a ReactJs web application. This makes it possible to take advantage of Spring Security and other Spring goodies.
Clone this project (the camunda-demo-ui
project) to your local machine
git clone https://github.com/camunda-consulting/camunda-demo-ui
The camunda-demo-ui
directory contains the relevant files for this project.
Once you have the code, use maven to compile both the ReactJs App and Spring Boot
cd camunda-demo-ui mvn clean spring-boot:run
Note
|
The app will be available on port 8080 |
http://localhost:8080
The Maven build will perform the following:
-
Install the correct versions of NPM and Node
-
Create the node_modules directory with the necessary dependencies
-
Use Webpack to build/transpile the JSX files into a bundle.js javascript file
-
Copy
bundle.js
intosrc/main/resources/static/built
-
Build the Spring Boot Application that uses Thymeleaf to serve the ReactJS UI
-
Thymeleaf is a spring project for UI templating. It looks in the
src/main/resources/templates
directory for a.html
file to serve. -
A Spring Controller is configured to serve the HTML on a specific context path. See the controller
src/main/java/com/camunda/poc/starter/controller/ui/UiApplicationController.java
This project relies on the camunda-data-api
project to provide a backend api where the React app gets data.
In the .env file in the project home directory change the environment variables to match the spring-boot server context for the data-api.
Note
|
The connection to the demo data api is configured in .env |
DATA_API=http://127.0.0.1:9000/api
Warning
|
CORS is disabled by default with SimpleSecurityFilter.java |
When demoing or distributing it makes sense to build this project with docker-compose. When you follow the "Quick Start" steps in the camunda-demo-starter project, the docker image is already built and deployed as a GitHub Package. But, if you are customizing this project, you can also run the docker-compose command like so:
docker-compose -f docker-compose.ui.yml up -d --build reactjs
Even though everything can be built using mvn
, it’s often convenient to use npm
and webpack
to run the ReactJs webapp so that it’s possible to update react javascript files and then refresh the browser to see the changes in real time.
-
Run or just build the spring-boot project with either command. This will install all node, npm and the dependencies
mvn clean spring-boot:run
or
mvn clean install -DskipTests
-
Start a node server process
npm run live
-
Start another terminal and start a
webpack
processnpm run watch
-
Confirm the
node
andwebpack
processes are up and running.-
Browse to http://localhost:3000/app.html and ensure that the form is displayed.
-
Make a change to
/src/main/js/reactjs/app.jsx
. Wait for webpack to build the newbundle.js
, then refresh the browser and make sure you see your changes.
-
-
The Javascript/JSX files of interest are in the
src/main/js
folder. -
The files in
src/main/js/reactjs/application/components
are reusable components. -
The files in
src/main/js/reactjs/application/usecase
are use case specific components -
The file
src/main/js/reactjs/application/app.jsx
is the entry point to the application.
This project is organized to make it easy to add new single page web apps. Each app can reuse shared components as needed. Create a new app in 3 steps:
-
Create a new "entrypoint" jsx file. Entry point components typically render a main React component into a html page. For example,
src/main/js/reactjs/application/login.jsx
mounts a<Login/>
react component. -
Update the
webpack.config.js
to produce a bundle js file for the entrypoint. For example, the following snippet tells webpack to transpilelogin.jsx
(and all of it’s transitive dependencies). The result will be a javascript file namedlogin.bundle.js
inside thesrc/main/resources/static/built
directory.
entry: {
...
login: path.resolve(__dirname, 'src/main/js/reactjs/application/login.jsx'),
...
},
-
Use the javascript file from an html file. For example,
src/main/resources/templates/login.html
simply includes thelogin.bundle.js
file like so:
<div id="react"></div>
<script src="built/login.bundle.js"></script>