Skip to content

niolabs/ui-scaffold-pkchooser

Repository files navigation

nio UI Scaffold with PK Chooser

The easiest way to create a nio-powered UI is to start with our UI scaffold. It gets you up and running in minutes.

What’s in the box

If you’re at all familiar with React, this simple example covers most of what you need to know to get started.

Hello world (what time is it?)

Follow these steps to create a simple UI that can publish to, subscribe to, and display the output of your nio services.

  1. In your terminal, clone the UI scaffold, enter the directory, and install dependencies.

    git clone https://github.com/niolabs/ui-scaffold-pkchooser.git my-project
    cd my-project
    npm i -s
    
  2. In the root of the project, rename config.js.example to config.js.

  3. Start the project.

    npm start
    
  4. Visit the project at https://0.0.0.0:3000.

    • The development web server uses a self-signed certificate, and you may see a warning about the site being insecure. In your local development environment, it is safe to click "Advanced" > "proceed to site anyway."

You’ll see a simple UI with a clock that updates every second.

What’s actually happening?

  • The PubkeeperContext (providers > pubkeeper.js) uses React's Context API to asyncronously connect to the Pubkeeper server and continually ingest data into the PubkeeperProvider Context Object.
    • It creates a Brewer that publishes the time to the topic “ui_scaffold.example_brew” every second.
    • It creates a Pubkeeper Patron that subscribes to “ui_scaffold.example_brew” topic.
    • The Patron receives the data, and delivers it to the handler writeDataToOutput, which sets the local state variable providerData equal to an object containing time (a js Date object), and timeHistory (an array of all previous times received).
  • The Homepage uses the PubkeeperContext.Consumer to render the providerData.time value to the React Clock component from the nio UI Kit, which then renders itself based on the inbound time.
  • Page 2 uses the PubkeeperContext.Consumer to render the providerData.timeHistory array into a textbox.

Sure, you could have just had the timer set the local state variable, but then you wouldn’t have become such an expert at using Pubkeeper.

Using a static Pubkeeper Server

Once your system is created and you're ready to move the UI into the public domain, you'll want to remove the Pubkeeper Server chooser and replace it with your system's production Pubkeeper details.

  1. Get your Pubkeeper hostname and token from your nio-managed cloud-instance:

    1. Open the nio System Designer in a browser: https://designer.n.io/.
    2. Select your system in the left-hand navigation.
    3. Click the edit button in the contextual toolbar to open its configuration.
  2. Open config.js

    1. Set PK_HOST to your hostname value.
    2. Set PK_JWT to your token value.
    3. Set WS_HOST to your hostname value, but swap the word 'pubkeeper' for 'websocket'.
      1. e.g.- if your hostname is aaaaa.pubkeeper.nio.works, use aaaaa.websocket.nio.works.

Open config.js, change staticPubkeeper to true, and enter your pubkeeper server details below. As well, we'd appreciate it if you removed the webAuth section from the auth0 section.

Using your own Auth0 account for authentication

If you'd still like to use auth0 for webauth, you can create a free auth0 account here

Once you have an auth0 account, create a new application, copy your credentials, open config.js, and update the webAuth section appropriately.

What’s next?

The output of any service that shares the same Pubkeeper host and token that you configured above can be consumed by your UI. All you need to do is update the patron’s topic (or add new patrons!), register a handler, and render the data.

The nio UI Kit at https://uikit.niolabs.com is full of components for layout, charts, etc. that can be pulled into any React project that accommodates scss (we use webpack).

Of course, if React isn’t your thing, the Pubkeeper browser client can be used on any site that supports JavaScript:

npm i -s @pubkeeper/browser-client

Apache 2.0 License

Copyright 2017-2019 n.io innovation, LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published