This project was bootstrapped with Create React App and uses Craco to add a configuration layer for CRA. For this porject, we use Typescript, a strongly typed programming language that builds on JavaScript. Typescript helps in better documentation of the code and communication between developers.
This project uses npm
. For installation you will need to install node
and npm
, if you don't already have it. node
and npm
can be installed from here.
To install the project, sinply clone the the repo and them run npm install
in the project folder. You can use terminal on Mac and Command Prompt on Windows.
Run the terminal or command prompt and then run the following
git clone https://github.com/UNDP-Data/SDG-Accelerator.git
cd SDG-Accelerator
npm install
To start the project locally, you can run npm run start
in the project folder in terminal or command prompt.
This is run the app in 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.
This project uses ESLint integrated with prettier, which verifies and formats your code so you don't have to do it manually. You should have your editor set up to display lint errors and automatically fix those which it is possible to fix. See http://eslint.org/docs/user-guide/integrations.
This project is build in Visual Studio Code, therefore the project is already set up to work with. Install it from here and then install this eslint plugin and you should be good to go.
We use SiteGround for deployment. To get access to SiteGround contact Naledi Hollbruegge (naledi.hollbruegge@undp.org) or Gayan Peiris (gayan.peiris@undp.org).
The development workflow should be roughly as follows:
- Make changes locally (see Local Development)
- Commit to a non-main branch. Use git-flow branch naming like
feature/add-filters
orfix/zooming
- Push it to github
- In github, make a Pull Request for branch you created to meger the changes to main
- Merge All the changes to main
This help create a good documentation of all the changes, fixes done to the code and also help in version control.
The deployment workflow should be roughly as follow:
- Make changes locally (see Local Development) or pull the final version you want to deploy from github (see Installation)
- Test it locally on your system to make sure everything is working properly
- Use
npm run build
to build the react app in the build folder - Rename the folder (if you like) and then upload the folder to SiteGround in the
public_html
folder - Change the
src
of thescript
tag in theindex.html
from/static/js/main.js
to/<FOLDER_NAME>/static/js/main.js
, if you don't do thisindex.html
will try to look for the js file atwww.data.undp.org/static/js/main.js
(which is not the right location) instead ofwww.data.undp.org/<FOLDER_NAME>/static/js/main.js
- You should be able to see the visualization in your browser using the URL
www.data.undp.org/<FOLDER_NAME>
Steps to integrating the visualization in the wordpress page is as follow:
- To integrate the visualization in the a wordpress page first login to wordpress. To get access to the Wordpress Admin Panel contact Naledi Hollbruegge (naledi.hollbruegge@undp.org) or Mustafa Saifee (mustafa.saifee@undp.org)
- Edit the page you want to add the visualization to using Elementor
- Add an HTML element where you want to add the visualization
- In the HTML code use (here make sure that the elemnent in which the react app is rendering the visualization is present as div). In the below example and in the code, the react-app is renders in a and HTML element with parameter
data-bucket-embed
; therefore in the HTML code thediv
element has the parameterdata-bucket-embed
. (You can also use a uniqueid
to render the element and use that to render the visualization)<script defer src="https://data.undp.org/<VIZ_FOLDER_NAME>/static/js/main.js"></script> <div id="root" data-bucket-embed></div>
- You should then see the visualization in previews. (If there is some problem do check the data file is linked correctly as WP might re-route it)
- Once you are happy with the changes just publish the page and you should see it online
- Header: For the top part of all the pages.
- CurrentGaps: Page for Current SDG Gaps.
- Priorities: Page for Acceleration Opportunities.
- Interlinkages: Page for Taget Interlinkages.
- FutureScenarios: Pages for Future Scenario.
Craco is used to add a cofiguration layer for CRA. The primary function is to stop the build
to have optimized chunks of the built script. This make the using the script in the Wordpress easier. The configuration file for Craco is placed in the root folder and called craco.config.js
npm run build
: Executescraco build
and builds the app without chunking the main js script file.npm run start
: Executescraco start
and start the local server for local deployment.npm install
: Installs all the dependencies.
Packages/Library Used
- React: React is used as MVC framework.
- React-Router-Dom: For routing.
- CRACO: Craco is used to configure different scripts (See Available Scripts for more details)
- styled-components: Utilises tagged template literals and the power of CSS, allows to write actual CSS code to style the components in JS/TS.
- Various D3 Libraries: Various D3 libraries are used for visualizations, adding interaction and reading the csv data file.
- antd: Is used as a UI library.
- lodash: This is used for manipulating and iterating arrays and objects.