Frontend SDK
What is it?
This Frontend SDK is used for building custom components and workflow steps for use in Dais UI Builder. If you are not familiar with Dais UI Builder, it is recommended that you familiarize yourself with the product first. Dais UI Builder provides hooks to allow custom components or workflow steps to be written for project-specific needs if the stock functionality does not suffice. This repo acts as a starting point to develop, publish and use your components and workflow steps within Dais UI Builder.
To make your life easier we've automated some parts of it.
Prerequisites
- node (
12.22.7). - Artifactory access to
dais-npm-trial-virtual. - Dais developer key (i.e https://creator.gamma.bcg.com).
How do you use it?
There are four main cases you may want to achieve. Please find your case below and follow the instructions.
Main Topics
- Creating a new Dais component/workflow step - building component / workflow step from scratch or by using some 3rd party library.
- Creating a Dais component from a component artifact - connecting existing component artifact with Dais.
- Taking over a component/workflow step - continuing work after someone or on another machine.
- Publishing component/workflow step to Dais.
- Test your component/workflow step - write unit tests for your components to make sure they work correctly in any use case.
- Preview component with storybook - useful during development, allows to see how component behaves but doesn't provide connector functionality.
Additional Topics
- My credentials have changed - run takeover command to generate new credential files.
Creating a Custom Component/Workflow Step from Scratch
So, you want to create completely fresh component / workflow step to use in Dais UI Builder? This option also works in cases you'd like to use a 3rd party library as the basis of the component / workflow step, i.e., HighCharts Bar Chart.
Type: npm run wizard:init
You will be asked to answer couple questions and then you're ready to roll.
Here's the list of questions:
Setup information:
- Artifactory email.
- Artifactory API key.
- Dais project URL you may answer with full url or just domain, it's better to provide full name as it will extract project ID so you don't have to answer Q5).
- Dais Developer Key.
- Project ID (depends on the answer on Q3).
- Package name.
- Package version.
Component information:
- Do you want to load sample components? if you want to see some reference components select Y.
- Component name.
- Is this existing component answer N here.
- Do you want to add another component if you have more components answer Y.
Workflow information:
- Do you want to load sample workflows? if you want to see some reference workflow select Y.
- Workflow name.
Now in src/components/chosen_name you'll have three files:
- Connector - this is used to actually connect component to Dais, it consists of 3 sections (each section is documented inside and contains links with API docs):
- Definition - contains properties how your component is seen in Dais
- Schema - properties that associate to props that component receive
- Register - it joins definition and schema into one
- Index - React component
- name.stories - Storybook stories of your component
And in src/workflows/chosen_name you'll have one file:
- Index.ts - contains connector and workflow function. What's connector? See: 8 lines above.
To preview component, see: Preview component with storybook
Best "preview" option for workflow steps is to write test for it: Testing code
To publish connector / workflow step to dais see: Publishing component to Dais
Using an Existing Component
So, you already have some component (not built in Dais) that you'd like to use it in Dais UI Builder?
Type: npm run wizard:init
Answer couple questions and you're ready to roll.
Here's the list of questions:
Setup information:
- Artifactory email
- Artifactory API key
- Dais project URL you may answer with full url or just domain, it's better to provide full name as it will extract project ID so you don't have to answer Q5)
- Dais Developer Key
- Project ID (depends on the answer on Q3)
- Package name
- Package version
Component information:
- Component name.
- Is this existing component answer Y here.
- Where can I find your component artifact provide relative path to where you're putting your component artifact..
- Do you want to add another component.
Now in src/components/chosen_name you'll have one file:
- Connector - this is used to actually connect component to Dais, it consists of 3 sections (each section is documented inside and contains links with API docs)
- Definition - contains properties how your component is seen in Dais.
- Schema - properties that associate to props that component receive.
- Register - it joins definition and schema into one.
And you should copy artifact to the position you've provided in Component information point 3.
To preview component, see: Preview component with storybook
To publish it to dais see: Publishing component to Dais
Working on a Component Created by Someone Else
(Setting up an existing repo again)
So, your taking over after someone? Or you're continuing work on a new machine? Or maybe some of your credentials have changed?
If your credentials have changed start with npm run wizard:clean - this will remove old credentials.
Type: npm run wizard:init
Answer a couple of questions and you're ready to roll. The wizard will prepare the environment, so you'll be able to work with this project. Here's the list of questions:
Setup information:
- Artifactory email.
- Artifactory API key.
- Dais project URL you may answer with full url or just domain, it's better to provide full name as it will extract project ID so you don't have to answer Q5).
- Dais Developer Key.
- Project ID (depends on the answer on Q3).
Publishing your Component to Dais
So, you've finished your work on the component and it's ready to go. Next step is to see it working in Dais UI Builder. To do this,
Type npm run publish
This will build your component (create publishable artifact) and then it will publish your component. In the console output you'll get Object looking similar to this (filled with your specific information):
{
"name": "component-template-kw",
"type": "modular",
"common": false,
"version": "2.0.0"
}
You will also receive url to which you should go to paste it, i.e.:
https://creator.thesimulationgroup.com/app/xxhx0oy3iry7/admin/projectsetups\
At this page you should localize 'packages' key and put this code inside the array. Hit save and look for your component in your project.
Testing
- Tests are written in jest + react-testing-library.
- Default test provided for your component checks if component returns expected text.
- Default test provided for your workflow checks if handler simply returns a passed object.
- To start tests, first look into your component folder, find the *.test.tsx file and run
npm run testit will start test suite in watch mode, so any change you make will be automatically tested.
Don't know Jest? Find out more here: jest website
Don't know React testing library? Find out more here: react testing library website
Preview with Storybook
Default test provided for your component is simply rendering the component without any properties.
To spin up storybook, look into your component folder, find the *.stories.tsx and run npm run preview it will start storybook and display stories you've just found.
Don't know storybook? Find out more here: storybook website