1.9.19 • Published 3 months ago

flow-component-model v1.9.19

Weekly downloads
84
License
MIT
Repository
github
Last release
3 months ago

This library will allow you to create Flow custom components which richer functionality, these are given direct access to read and write the entire state not just the state and data source attached to them in the designer.

You can implement a component which functions as an entire Flow page or as a component on a page but which isn't restriced to what it can read/write.

THIS ONLY WORKS WITH THE LEGACY PLAYER!

Overview

The package contains three basic classes you can use to create components and 3 helper classes: -

FlowComponent

This is designed to function as a component that replaces a standard component on a page. You will be using the component's datasource to draw list data and its state to get the current value and set the new value. The FlowComponent will not automatically call getValues() on load.

FlowPage

This is an extension of the FlowComponent auto-loads every value defined in your tenant which is used by your Flow. The FlowPage will automatically call getValues() on load.

FlowChart

This is an extension of the FlowComponent but adds the features of google charts allowing you to create a chart by simply setting the axis names and specifying which model data columns represent them.

It's a very thin wrapper, anything in the options is simply passed through to the charts engine underneath.

Define your chart options in the constructor().

constructor(props: any) {
        super(props);
        this.chartType = eFlowChartType.PieChart;
        this.columnNames = ['Team Role', 'Count',{type: 'string', role: 'tooltip'}, { role: 'style' }];
        //this.propertyNames = [new FlowChartColumnDefinition('driver', eContentType.ContentString), new FlowChartColumnDefinition('percent', eContentType.ContentNumber), new FlowChartColumnDefinition('percent', eContentType.ContentString)];
        this.options = {
            width: this.model.width || 600,
            height: this.model.height || 600,
            colors: ['#1338b0', '#c95b12','#828181','#e0ac58','#e0ac58'],
            title: this.model.label || 'Opportunities By Role',
            chartArea: {width: '100%', height: '85%'},
            legend: { position: 'bottom', maxLines: 10 },
            is3D: true,
            pieSliceText: 'value',
            hAxis: {
                fontSize: 4,
                title: 'Role',
            },
            vAxis: {
                title: 'Count',
            },
        };

    }

For more complex data you can override the buildData() method.

We are adding arrays of column data to match the columnNames array in the constructor

buildData(dataTable: any[]) {
        if (this.model.dataSource) {
            dataTable.push(
                [
                    col1,
                    col2,
                    col3,
                    '' ...
                ]
            );
        }
        
    } 

To manipulate the data for formatting, override the manipulateDataTable() method.

manipulateDataTable(google: any, dataTable: any) {
        let formatter = new (google as any).visualization.NumberFormat({prefix: '$ '});
        formatter.format(dataTable,1)
    }

FlowMessageBox & FlowDialogBox & FlowContextMenu

Depricated.

Please use FCMKit instead.

https://github.com/MarkWattsBoomi/FCMKit

Features

FlowPage, FlowComponent & FlowChart give you access directly to: -

Model

contentType: string;
dataSource: FlowObjectDataArray;
developerName: string;
enabled: boolean;
height: number;
helpInfo: string;
hintInfo: string;
joinUri: string;
label: string;
maxSize: number;
multiSelect: boolean;
readOnly: boolean;
required: boolean;
size: number;
validationMessage: string;
visible: boolean;
width: number;
displayColumns: FlowDisplayColumn[];

State

The state value is retrieved and updated using the getStateValue() & setStateValue() methods

Outcomes

Any outcomes at a page level or specifically set as "Display With" the page component.
Outcomes is an object with the outcomes keyed on the developer name.
An outcome can be triggered using the triggerOutcome() method;
    if(this.outcomes["outcomeName"]) {
        await this.triggerOutcome("outcomeName");
    }

User

An object containing the details of the current authenticated user if any.

Fields

An object with all the fields defined in the Flow keyed on their developer name.
Reload fields with the LoadValue() or LoadValues() methods and set them with the updateValues() method.

There's an asynchronous helper to get specific fields directly from Flow.  It retuirns the object and also stores it into the Fields object.
    const fld: FlowField = await this.loadValue(fieldName);

Attributes

An object with all the component's attributes keyed on their developer name.

There's a helper methof to get an attribute if it exists and return it or the default value if not
    attributeValue: String = this.getAttribute("attributeName",[optional default value]);

Basic Values

Various other basic values are provided: -
TenantId: string;
StateId: string;
FlowKey: string;
ComponentId: string;
ParentId: string;
IsDesignTime: boolean;
LoadingState: eLoadingState;

Getting started

Create a new empty folder. Run "npm init" and answer the prompts, Run "npm install -s flow-component-model@latest" Run "npm rebuild"

Create a new component tsx file and set your class to extend one of the library's base class: -

import * as React from 'react';
import { FlowComponent } from 'flow-component-model';
declare const manywho: any;

export default class MyCustomComponent extends FlowComponent {

}

manywho.component.register('WorkQueues', WorkQueues);

Your component will then inherit the properties and methods above: -

##Note: If you extend the FlowPage class then your component will automatically run getValues() when it mounts and will have populated all the available outcomes, attributes and fields.

Asynchronous

Most methods are implemented as async which allows the use of await this.methodName().

This includes the basic React componentDidMount which has been reworked to this signature: - async componentDidMount(): Promise

this means that if you are going to implement the componentDidMount then ensure you await the super implementation: -

async componentDidMount() {
    await super.componentDidMount();
    ....
}

Fields

fields can be accessed from this.fields and will contain a keyed array for you to access e.g.

this.fields.MyField or this.fields"MyField

this.fields.MyField.value will return the field's value. If the field is a simple string, number, boolean, content etc then value will be the string rpresentation of it. If the field is an object then that object will be returned and you as a FlowObjectData and you can access it's attributes and it's properties collection If the field is a List then a FlowObjectDataArray object will be returned which you can iterate over. FlowObjectDataArray.items() is a Arrya

Attributes

any attributes defined on your component are available via this.attributes which are keyed on the attribute name e.g.

this.attributes.MyAttribute is a FlowAttribute object with Name & Value properies.

this.getAttribute(attributeName, defaultValue) is a helper to simplify the process.

Outcomes

any outcomes attached to the component are available via this.outcomes which are keyed on the outcome name e.g.

this.outcomes.MyOutcome or this.outcomes"MyOutcome" is a FlowOutcome object.

Outcomes can be triggered calling this.triggerOutcome(outcomeName).

Flow Movement Events

When an outcome is triggered and Flow re-delivers the page, if your component wasn't destroyed because the same page is being displayed then your component will not know that its data might have changed.

To work around this an event manager has been implemented to notify your component.

There are 3 events for beforeSend, done & error

You need to attach a handler to get these events and to detach it when your component will unmount.

All 3 are optional.

async componentDidMount() {
    await super.componentDidMount();
    (manywho as any).eventManager.addDoneListener(this.flowMoved, this.componentId);
    (manywho as any).eventManager.addBeforeSendListener(this.flowMoved, this.componentId);
    (manywho as any).eventManager.addFailListener(this.flowMoved, this.componentId);
}

async flowMoved(xhr: XMLHttpRequest, request: any) {
    ... do whatever
}

async componentWillUnmount() {
    await super.componentWillUnmount();
    (manywho as any).eventManager.removeBeforeSendListener(this.componentId);
    (manywho as any).eventManager.removeDoneListener(this.componentId);
    (manywho as any).eventManager.removeFailListener(this.componentId);
}

Classes

A number of wrapper classes have been implemented to simplify interaction with various Flow objects: -

FlowObjectDataArray

Wrappers the Flow list construct with helpers for adding, removing and finding objects.

let myArray: FlowObjectDataArray = FlowObjectDataArray.newInstance([]);

FlowObjectData

Wrappers the objectData concept and provides helpers for creating & manipulating including adding properties.

let myObjData: FlowObjectData = new FlowObjectData(iObjectData); (pass in a generic Flow objectData); or let myObjData: FlowObjectData = FlowObjectData.newInstance("FlowTypeName");

FlowObjectDataProperty

A wrapper for working with FlowObjectData properties. let myObjData: FlowObjectData = FlowObjectData.newInstance("FlowTypeName"); myObjData.addProperty(FlowObjectDataProperty.newInstance("AttributeName",eContentType.contentString, "The value"));

FlowOutcome

A wrapper round the outcome object

FlowAttribute

A simple wrapper around the attribute concept.

FlowField

A wrapper for working with values in a flow. Can access any value in the flow's state.

let myField: await FlowField=this.loadValue("FlowValueName"); myField.value="NewValue"; await this.updateValue(myField);

FlowDisplayColumn

A wrapper to simplify the display columns in the model

Flow Chart

Basing your class on the FlowChart class simplifies creating custom charts.

This call already implements all the logic to redraw the chart after a move event in flow.

This is a very basic example: -

export default class MyChart extends FlowChart {
    constructor(props: any) {
        super(props);
        
        this.chartType="BARCHART";
        
        this.columnNames=['', 'Immediate', '<1 year', '1-5 years','>5 years','unable to quantify or not answered', { role: 'style' }];
        
        this.propertyNames=[new columnDefinition("paybackPeriod",eContentType.ContentString),new columnDefinition("percent",eContentType.ContentNumber)];
        
        this.options = {
            width: 1000,
            height: 130,
            colors:['#009688','#74ccbd','#cbf2ec','#f4f7b7','#edede8'],
            legend: { position: 'bottom', maxLines: 3, },
            bar: { groupheigh: '100%' },
            isStacked: 'true'
        };
    }

}
manywho.component.register('MyChart', MyChart);

chartType

This controls the type of google chart shown

BARCHART, COLUMNCHART, GEOCHART, PIECHART, DONUTCHART

columnNames

Specify an array of axis names.

For stacked charts this will be the vertical axis then all the horizontal axis option names.

propertyNames

Allows you to specify which property names in the model object data correspond to each column name.

This is the default simple implementation when each model object data represents one item to be drawn on the chart.

If you need to work with more complex data then this can be ommitted and the buildData() method can be overwritten

options

Allows you to specify the chart options as defined in the google charts API.

This object is passed unmodified to the google charts api.

buildData

overriding this function allows you full control to build the chart data.

In this example we have the data spread across the first 3 items from the model, you can see that we drag the value of the "Percent" column from 1tems 0-2

buildData(dataTable: any[]) {
        if (this.model.dataSource)
        {
             dataTable.push(
                [
                    "",
                    parseInt(this.model.dataSource.items[0].properties["Percent"].value as string), 
                    parseInt(this.model.dataSource.items[1].properties["Percent"].value as string), 
                    parseInt(this.model.dataSource.items[2].properties["Percent"].value as string),
                    ""
                ]
            );
            
        }

Quick Start Template

Create a new folder to hold your project.

Grab the Template.zip file here and unzip it in your folder.

Open the folder in VS Code.

In a console run "npm install".

Run "npm run start" to execute the component in debug.

Run "npm run build" to compile the component into the build folder.

1.9.19

3 months ago

1.9.18

3 months ago

1.9.17

4 months ago

1.9.15

4 months ago

1.9.14

4 months ago

1.9.13

6 months ago

1.9.12

6 months ago

1.9.11

8 months ago

1.9.10

8 months ago

1.9.1

8 months ago

1.9.0

9 months ago

1.9.9

8 months ago

1.9.8

8 months ago

1.9.7

8 months ago

1.9.6

8 months ago

1.9.5

8 months ago

1.9.4

8 months ago

1.9.3

8 months ago

1.9.2

8 months ago

1.8.5

10 months ago

1.8.4

11 months ago

1.8.2

11 months ago

1.8.1

11 months ago

1.8.0

12 months ago

1.7.53

12 months ago

1.8.3

11 months ago

1.7.50

1 year ago

1.7.51

1 year ago

1.7.52

1 year ago

1.7.48

1 year ago

1.7.49

1 year ago

1.7.36

1 year ago

1.7.40

1 year ago

1.7.41

1 year ago

1.7.45

1 year ago

1.7.46

1 year ago

1.7.47

1 year ago

1.7.35

1 year ago

1.7.31

2 years ago

1.7.32

2 years ago

1.7.33

2 years ago

1.7.30

2 years ago

1.7.26

2 years ago

1.7.27

2 years ago

1.7.28

2 years ago

1.7.29

2 years ago

1.7.20

3 years ago

1.7.21

3 years ago

1.7.22

3 years ago

1.7.23

3 years ago

1.7.24

3 years ago

1.7.25

3 years ago

1.7.19

3 years ago

1.7.10

3 years ago

1.7.11

3 years ago

1.7.12

3 years ago

1.7.13

3 years ago

1.7.14

3 years ago

1.7.15

3 years ago

1.7.16

3 years ago

1.7.17

3 years ago

1.7.18

3 years ago

1.7.9

3 years ago

1.7.8

3 years ago

1.7.7

3 years ago

1.7.6

3 years ago

1.7.5

3 years ago

1.6.17

3 years ago

1.6.19

3 years ago

1.6.18

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.15

3 years ago

1.6.14

3 years ago

1.6.16

3 years ago

1.6.11

3 years ago

1.6.10

3 years ago

1.6.12

3 years ago

1.6.9

3 years ago

1.6.8

3 years ago

1.6.7

3 years ago

1.6.6

3 years ago

1.6.4

3 years ago

1.6.5

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.11

3 years ago

1.5.9

3 years ago

1.5.10

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.20

4 years ago

1.4.30

4 years ago

1.4.40

4 years ago

1.4.16

4 years ago

1.4.15

4 years ago

1.4.13

4 years ago

1.4.14

4 years ago

1.4.12

4 years ago

1.4.11

4 years ago

1.4.10

4 years ago

1.4.9

4 years ago

1.4.8

4 years ago

1.4.6

4 years ago

1.4.7

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.24

4 years ago

1.2.25

4 years ago

1.2.26

4 years ago

1.2.23

4 years ago

1.2.22

4 years ago

1.2.20

4 years ago

1.2.16

4 years ago

1.2.15

4 years ago

1.2.13

4 years ago

1.2.12

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.9

4 years ago

1.2.10

4 years ago

1.2.11

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago