Git Product home page Git Product logo

create-react-viya-app's Introduction

create-react-restaf-viya-app

create-react-app from Facebook is a very popular cli for jump starting developing react apps.One of its key features is the Hot Module Replacement which recompiles and updates the display as the code is being updated.

Additionally when developing Viya apps the code needs to access SAS Viya using the REST APIs.

This extension of create-react-app is designed to help developer's building react apps using restaf library and its companions:

  1. restaf
  2. restaflib
  3. restaf-server

create-react-restaf-viya

There is a fully functional demo in the demo directory of this repository. It uses material-ui as the primary UI framework.

Key Assumption

The application is authenticated using authorization_code flow.

App Creation

npx create-react-viya-app react-appname --webapp webapp-name  --title webapp-title --script scriptTags-file

Only the react-appname is required. The optional parameters are:

  • webapp -- this is the user-friendly application name. Defaults to viyademo

  • title -- The text for the title tag in index.html. Defaults to SAS/Viya Application

  • script -- a file which has some HTML script tags to be inserted into index.html - defaults is a comment line

Configuration

Set the following in the .env file:

  • CLIENTID -- the default value is viyademo
  • CLIENTSECRET -- the default value is secret
  • VIYA_SERVER -- no defaults

Some defaults:

  1. The app server runs on localhost:5000/viyademo
  2. The clientid redirect is http://localhost:5000/viyademo
  3. The create-react-app server runs on its standard port(3000)

For more detailed configuration ioptions see See https://github.com/sassoftware/restaf-server/wiki

Development mode

Run this command to have HMR enabled

cd to-the-app-directory
yarn dev

Application mode

Run this command( no HMR)

cd to-the-app-directory
yarn build
yarn app

Then use the created app just as you would any app created with create-react-app

React Context - AppContext

By default a react context named AppContext is created.

To access the data code something like this:

import React,{useContext} from 'react';
import AppContext from '../providers/AppContext';

let appContext = useContext(AppContext);

let {store, appOptions} = appContext;

let {appenv, logonPayload} = appOptions;

The store is the restaf store object that you will use to make the API calls.

Requiring restaf and restaflib in your application

These two libraries are part of the installed dependencies. To access them in your react components do these as follows:

let restaf = require('@sassoftware/restaf/dist/restaf.js');
let restaflib = require('@sassoftware/restaflib/dist/restaflib.js');

or

import * as restaf from '@sassoftware/restaf/dist/restaf.js';
import * as restaflib from import * as restaf from '@sassoftware/restaf/dist/restaflib.js';

In all probablity you will not refer directly to restaf in your code. You will use the store object in the AppContext(see above). This value is set as part of the application setup.

create-react-viya-app's People

Contributors

devakumaraswamy avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.