Skip to content

quickStart

Deva Kumar edited this page Oct 1, 2020 · 14 revisions

Quick Start tool for Building SAS Viya Applications


Key Feature


This Quick Start tool allows you to build new applications with minimal setup. Once you have setup your local development enviroment you can add new SAS Viya applications by adding react components. The key library for developing SAS Viya Applications is restaf.


Getting started


Do the 3 steps - Ready, Set and Go as described below

Ready

Setup the development environment as follows:

  1. Issue this command
npx @sassoftware/create-react-restaf-viya-app [directoryName] --webapp <you application name>  --use viya-app

Ex:
npx @sassoftware/create-react-resaf-viya-app myapp --webapp sales --use viya-app 

This will create a sub-directory called myapp and install a started application that is ready for execution once you complete the VIYA_SERVER related configurations.

Set

The required configurations are explained at this link.

The default clientId information that you will use are

  • Oauth flow: authorization_code
  • clientid: alldemos
  • secret: secret
  • redirect_uri: htttp://localhost:5000/your-webapp-name

Once the server setup is completed, complete the setup of your development environment:

  1. Set an environment variable as follows
set VIYA_SERVER=<your viya server: ex: http://myviyaserver.com>

Alternatively you can edit the .env file and add this information to it.

The last step is to build the default application.

yarn buildapp

Go

Now you are ready to run the default application.

Enter the following commands

yarn app

At this point you should visit http://localhost:5000/your-webapp. If webapp value is sales then visit

http://localhost:5000/sales

Default Applications

These are default applications that you can access from the hamburger menu in the banner.

  1. Run a casl program in Cas

  2. Run a SAS program in spre

  3. View the props these applications (and the new ones you will write) will have access to.

These are good examples for learning how to use restaf to make REST API calls to SAS Viya

The default applications usematerial-ui react components. Feel free to use any react component library you like.


Adding your own applications


It is a simple two step process.

  1. Step 1: Develop your main app component in the viewers directory. You can use any react library. By default this project installs @material-ui. But you can use any component library.

  2. Step 2: Edit appMenus.js and add your application as a menu item. The format of a menu in the array in appMenus.js is as follows:

Let us assume that your new component is called Mydemo.js

{
    component: 'MyDemo',
    props    : {
        text: 'My cool app',
        ... additional props as needed
    },
}

The component name must match the name of the component you created in step 1.

The text will appear as the selection in the menu displayed by Home.js

The props will be available in your component - see below on how you can access these.

Group 1 Props

Each application defined in this step will receive the following props

  1. All the prop that were passed to App.js in your index.js

  2. This list is enhanced with the following:

    • store -- restaf store object
    • host -- your current SAS Viya url
    • appName -- the name of your application

Group 2 props

The props provided in the menu defintion are available thru history as follows:

import { useLocation } from 'react-router-dom';
    <snip>
let location = useLocation();
let appProps = location.state;

appProps now has the props specified in the appMenu.js for this component

As an example the props for the "Browse Folders" menu item is defined in App.js as shown below

let m = {
    component: 'ViewList',
    props: {
        text: 'Browse Folders',
        service: 'folders',
        initialTab: 0,
        tabs: [
            { label: 'Summary', component: 'SummaryViewer' },
            { label: 'Viewer', component: 'DefaultViewer' },
        ],
    },
},

When you run the application your menu will appear on the home page. Selecting it will display your application.

Note: Everytime you change appMenus.js or add a new viewer you must restart the app with the commands below. But normal editing of existing application will do a hot replacement of the app.

To hide an application add this to your menu item (hide: true)

Recommendation: Clone one of the default examples and modify the code to suit your needs.

During development you should use the following command to have Hot Module Replacement enabled

yarn dev

To create production build issue the command

yarn buildapp

You can also run the application in docker(but first run yarn buildapp)

Run this command to create an image

yarn dkrbuild

Run this command to run the application

yarn dkrrun


Conclusion

That is all there is to adding new components.


Creating clientids


Most folks create clientid's using shell scripts run on the Viya server or using POSTMAN scripts. Here is a even simpler way. You must have admin privledges. The example below uses the default values for this repo. Feel free to change it to suite your needs.

Step 1: Issue this command in a shell on your local machine

npx @sassoftware/registerclient --host=your-viya-server-url

Example:

npx @sassoftware/registerclient --host=http://mytestserver.fbi.sashq-d.openstack.sas.com

Step 2: You will get a prompt on your shell. Enter "logon" as a command. You will be promoted for your userid and password

Step 3: After successful logon enter the following

add viyademo -t authorization_code -s secret -r http://localhost:8080/viyademo,https://localhost/viyademo

Step 4: Enter help to explore other features or enter exit to get out of the application


Other information


Key scripts

yarn dev

This will run the application in development mode with Hot Module Replacement enabled

yarn build

This will build the deployable version in the ./build directory and copy it to ./publish directory

yarn app

This will run the deployable version you created with yarn build

Standard create-react-app Scripts


In the project directory, you can run:

yarn start

Runs the app in the 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.

yarn test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

yarn build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

yarn eject

Note: this is a one-way operation. Once you eject, you can’t go back!

If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

yarn build fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

Clone this wiki locally