Self Governance Design Pattern — Part 1 — Setting up UI

Revanth Kumar
3 min readOct 1, 2018

--

In the previous Post, I have introduced you to the Self Governance Design Pattern (SGDP). As promised this post will be about setting up the UI for development.

Unlike other design patterns where the parent gives data to the child to render, SGDP will be letting the child take care of fetching the data and let the parent inform the child about where can it find itself.

Note: It is assumed that you have already setup a react project. You can use any one of the boilerplate generators like create-react-app or nwb to name couple.

Step 1 — Setting up the Project Workspace.

This is purely developer specific, feel free to modify the structure since it has nothing to do with SGDP.

We will be building a Registration Page with 9 fields:

  1. First Name (Text Field)
  2. Middle Name (Text Field)
  3. Last Name (Text Field)
  4. Address (Text Area)
  5. Zip Code (Text Field)
  6. City (Text Field)
  7. State (Drop Down)
  8. Country (Drop Down)
  9. Phone Number with Country Code (Text Field)

Here is my workspace setup:

Workspace Structure

Views/RegistrationPage.js houses the view logic for the Registration Page.

Shared folder has the Self Governable / Sustainable components. We have 3 shared components Text Field, Phone Number Field and Drop Down Field (Text Area can be implemented using Text Field).

Step 2 — Laying out the User Interface

We will be using Office UI Fabric to build the UI and Components. Components themselves are mere wrappers of their counter parts from Office UI. In future articles we will be adding logic into Components to fetch and update data. For now they are dumb.

https://github.com/revanth0212/sgdp-part-1/blob/master/src/App/Shared/TextField.js
https://github.com/revanth0212/sgdp-part-1/blob/master/src/App/Shared/DropDownField.js
https://github.com/revanth0212/sgdp-part-1/blob/master/src/App/Shared/PhoneNumberField.js

Step 3 — Laying out the User Interface

We will be using Simple Grid for UI Layout.

Here is what we are trying to achieve. A very simple UI for registration:

Using Simple Grid, I have added Shared Components we created in Step 2 into Views/RegistrationPage.js:

https://github.com/revanth0212/sgdp-part-1/blob/master/src/App/Views/RegistrationPage.js

That’s it for this article. In the next article we will be talking about Data Flow and how to make Components fetch and update data themselves.

You check out the hosted application on codesandbox.

You can reach me at:

Email: revanth0212@gmail.com

Twitter: https://twitter.com/imre1th

LinkedIn: www.linkedin.com/in/revanth0212

Github: https://github.com/revanth0212

Peace \m/

--

--