Friday, December 24, 2021

Guidewire Jutro DataTable Usage (ver 4.1.1)

Jutro DataTable component is a major UI element when creating jutro pages, DataTable includes build-in pagination, searching, editing and no-data function, understanding how to use and configure jutro DataTable with metadata.json5 is very important.

1. Data source

DataTable metadata json5 definition has a data property, which accepts an array of item. Datatable's column is based on the item's attribute name. If you need to implement your own customized filter function, you can create a function to filter the data first and then feed the filtered data to the Datatable' data property.


2. search/filter 

For Jutro datatable, search and filter means the same. 

ShowSearch property controls whether to show a search input textbox on top of the datatable. If showSearch is set to true, then you can also specify a string on "filterPlaceholder" property to set a placehold text on the search input field. 

By default, when a search text is changed by user, the search criteria will check all records' all columns to get the matched records. However, you can customize the search behavior by specify DataTable's onFilter property to a custom function, and this function will be called whenever user changes the input of search input textbox field. A sample code is shown below:

      {

        "id": "myDataTable",

        "type": "container",

        "component": "DataTable",

        "componentProps": {

          "noDataText": {

            "id": "datatable.nodatatext",

            "defaultMessage": "No data found ...."

          },

          "expandOnRowClick": false,

          "defaultPageSize": 10,

          "pageSizeOptions": [

            10

          ],

          "filterPlaceholder": "",

          "rowIdPath": "publicID",

          "showSearch": true,

          "filterPlaceholder":"Search name, state, or population",

          "headerMultiline": true,

          "onFilter": "filterRow"

        },

    const filterTable = (filterValue) => {

        const filterNumber = parseInt(filterValue, 0);

        return (row) => {

            return row.claimNumber === filterValue;

        };

    };

  const resolvers = {

        resolveCallbackMap: {

            filterRow: filterTable

        }

    };


3. pagination

Pagination is supported by DataTable as build-in feature. The related settings include:

defaultPageSize : 10

pageSizeOptions : [10, 25]

showPagination: true


4. handle row click

When user clicks on a row, a custom callback function can be set to onClickRow property to handle the click, the input parameter is the row clicked.

  {

        "id": "ClaimSummary",

        "type": "container",

        "component": "DataTable",

        "componentProps": {

          "onRowClick": "onClickRow",

          "selectOnRowClick": true

        },

    resolveCallbackMap: {

            filterRow: filterTable,

            onClickRow: onClickRow

    }

    const onClickRow = (row) => {

        console.log(row);

    };


5. defaultSorted

Set datatable's default column for sorting


6. columnsConfigurable

true or false. Decide whether to show the three-bar button on right side of search bar for configuring columns.


7. Table column

Columns in DataTable are defined as an array under datatable's content property. Each column object's component property specify the column type, for example, DisplayColumn. The column object has below properties

header: specifying the header text

path: specify which datatable date object's field is for this column.

sortable: whether to show and support sort on this column

renderCell: specify a callback method to render the cell, the callback function has parameter of row item and row index

Tuesday, December 7, 2021

Guidewire Jutro notes

1. How to get all available properties for a component

Just opening project's framework/packages/components/widgets/folder, and then open the specific component you want to check.


2. Component settings in metadata definition

For object's component settings in metadata json5 file, it will first try to match the jutro component with the same name. If no match found, then it will match the html build-in element. For example, 

"component": "button"

will map to jutro button component, instead of html button element. But

"component": "label"

will map to html label element.


3. Content setting

The jutro framework will do its best to put the content into the mapped html element, for example, button will show the content string as its text. div will just show the content between the open and close tag. 


4. Add custom page/component

To add a new custom page, first create the page component and metadata json5 file. 

Then import the component in app.js file and also add the component into componentMap object.

In app.routes.metadata.json5, add a new path to load the page component for the specific route url path.

Actually this is the same change when running the below generate page command:

jutro-cli generate page


5. Enable guidewiree jutro capability buildin page

In addition to import the page component into app.js and componentMap, as well as updating the app.routes.metadata.json5, you also need to update config.json5's capabilitiesConfig section to set the capability's value to true. Otherwise the page/component jsx file will not be loaded.


6. Dynamic update UI with override in renderContentFromMetadata

When defining UI content with Metadata json5 format, all the values are hardcoded in json5 files. In order to dynamically change the values (for example, set element visible property based on server side response), the jsx file can set override parameter in renderContentFromMetadata method. For example, the below code sets claim element's visible property based on the return value of isClaimVisible()

       Claim: {
            data: claimDataTable,
            visible: isClaimVisible(),
}
Note, the method will only be called once when the UI is rendered from metadata, once the rendering is finished, even if the function returns a different value, it will not be called again automatically.
In order to be sure UI will reflect the underling data change, in the data change handler function, it should call useState() method to notify react to refresh the UI, so the metadata will be evaluated again. 
Basically, values set in override parameter is same as other react component properties, and they are read only when passed to child component for initialization. 

7. Difference between to and href for Link component
When href attribute is set for Link component, it will cause to reload the page on that url, which will download the full index.html and js files.
When to attribute is set for Link component, it will stay in the current html page, and only reload the component based on app.js router configuration. So it is much fast and user friendly.

Guidewire jutro metadata json5 object types

When defining objects in Jutro with metadata json 5 schema, there are 5 types available. Since there are only 5 types, so the exact html tag type of the object depends on both object's type and component setting, and Jutro will make the best guess based on those information.  

1. Elements

This type is for static object that do not offer a user input, like label or badge. Element type object does not have content property. 

2. Container

Container object contains array of elements, other containers, fields, iterables. Container object always has a content property to define its content.

3. Field

Field object is used to describe user input elements. Field type usually do not have content property, but have a label property depending on its component setting.

4. Action

Action object is used to describe interactive or action components. For button component, its content property sets the button text.

5. Iterables

Iterable type mainly used with Accordion, tabset and table to show repeated items. It also has build-in support for empty content.

6. layout

layout type is used for setting the elements layout.


Monday, December 6, 2021

Guidewire Jutro metadata: how to set property to json5 component

1. Set component prop in metadata json5 file

When creating component using Guidewire Jutro metadata json5 format, for simple element, for example, label component of element type, the label text is set by "content" attribute, and other attributes are set by componentProp attribute as below:

 {

        id: 'myLabel',

        type: 'element',

        component: 'label',

        content: 'mylabel name',

        componentProps: {

          for: 'myfor',

        },

        selfLayout: {

          component: 'div',

          componentProps: {

              someattr: 'mycustattr',

          },

        },

      },


This indicates jutro (4.1.1)  just puts whatever componentProps settings into the element's html without validation whether the attributes actually exist or not.

Note the selfLayout node defined in the metadata creates a new wrapping element for the current element. if the node is deleted, then <div someattr='mycustattr'> element will also be deleted.


2. Set component in jsx with override and resolver

In many cases, we need to set component properties dynamically in jsx files for example, set the callback method for button element. This can be done by passing resolver parameter in jsx's renderContentFromMetadata method. For example, if metadata sets button's callback to a string, the string needs to map to a method defined in jsx file as below

      {

        id: 'btnFileCLaim',

        component: 'button',

        type: 'element',

        content: 'button name',

        componentProps: {

          size: 'small',

          type: 'primary',

          onClick: 'clickme',

        },

      },


in component jsx file:

const MyTestComponent = () => {

  const onclickme = () => {
    console.log('button clicked');
  };

  const override = {
  };

  const resolvers = {
     resolveClassNameMap: styles,
     resolveCallbackMap: {
      clickme: onclickme,
    }
 };

 return renderContentFromMetadata(uiMetadata.viewClaimList, override, resolvers);
};

export default MyTestComponent;


When overriding property values, the id is used as key, and there is no need to specify componentProps. For example, in above sample, the below code can be used to override the button's label and type property

const MyTestComponent = () => {

    const onclickme = () => {
        console.log('button clicked');
    };

    const override = {
        codelessCardTitle: {
            content: 'myoverridecontent',
        },
        btnFileCLaim: {
            content: 'mybuttonoverridename',
            type: 'secondary',
        },
    };

    const resolvers = {
        resolveClassNameMap: styles,
        resolveCallbackMap: {
            clickme: onclickme,
        }
    };

    return renderContentFromMetadata(uiMetadata.viewClaimList, override, resolvers);
};