Skip to content
Ivan Arrizabalaga Getino edited this page Sep 14, 2016 · 4 revisions

Goal

The main goal of this app is to serve a shortcut to deal with datasets in a quicker manner.

It is a react (https://facebook.github.io/react/) based app

React quick tips

React is NOT a full MVVM framework (like angularjs), it is supposed to deal with just the VIEWS (there could be a much longer discussion in this point but this is the official claim).

In order to deal with the views react proposal is dealing with Components (like angular2, jsf, taglibs) aggregated one on top another.

Recommended tutorial (https://scotch.io/tutorials/learning-react-getting-started-and-concepts)

SPECS, LIFECYCLE & STATE

The render method is the only required spec for creating a component, but there are several lifecycle methods & specs we can use that are mighty helpful when you actually want your component to do anything.

LIFECYCLE METHODS

  • componentWillMount – Invoked once, on both client & server before rendering occurs.
  • componentDidMount – Invoked once, only on the client, after rendering occurs.
  • shouldComponentUpdate – Return value determines whether component should update.
  • componentWillUnmount – Invoked prior to unmounting component.

SPECS

  • getInitialState – Return value is the initial value for state.
  • getDefaultProps – Sets fallback props values if props aren’t supplied.
  • mixins – An array of objects, used to extend the current component’s functionality.

STATE

Every component has a state object and a props object. State is set using the setState method. Calling setState triggers UI updates and is the bread and butter of React’s interactivity. If we want to set an initial state before any interaction occurs we can use the getInitialState method.

#Structure Our app so far follows this hierarchy of components

App
  HeaderBar
  <!-- Floating action button -->
  ListActionBar
  SinglePanelLayout
    MainContent
      <!--Search field -->
      SearchBox
      Pagination
      LoadingStatus
      <!-- List of datasets -->
      DataTable

#i18N In order to translate strings you must consider:

  1. i18N is a utility packed with d2, it is configured in the app.js where the properties files are loaded.
  2. Those property files are loaded dinamically from the d2 boostrap function (init), thus the webpack.config.js and the package.json have been modified copy and serve those files under the i18n folder.
  3. Any component with Translate mixin gets a getTranslation function that it is the only you must use in order to translate your strings. That mixin assumes your component can access to context.d2 so your root component cannot add that mixin.

#Useful links

  • d2: d2 js library that wraps every dhis2 endpoint to ease js development.
  • d2-ui: a set of ui components (based on material-ui project ) that should be reused to build dhis2 apps.
Clone this wiki locally