export {
DialobComposer, // React component for Dialob Composer
createDialobComposerReducer, // Function that creates Composer's Redux reducer
createDialobComposerMiddleware, // Function that creates Composer's Redux middleware
DEFAULT_ITEM_CONFIG, // Default item editor configuration
DEFAULT_ITEMTYPE_CONFIG, // Default item type configuration
DEFAULT_VALUESET_PROPS, // Default valueset extra property configuration
Item, // Base class for item editor React components
SimpleField, // "Simple field"-type dialob component editor
Group, // "Group"-type dialob component editor
connectItem, // Function that connects React component to Composer's Redux store
ItemMenu,
DialobActions, // Action API for modifying Dialob form
PropEditors, // React components for built-in item prop types
MarkdownEditor // Markdown editor component with preview
};
Connect Composer's Redux reducer and middleware to your application store
const reducers = {
dialobComposer: createDialobComposerReducer()
};
const reducer = combineReducers(reducers);
const store = createStore(reducer, applyMiddleware(...createDialobComposerMiddleware()));
Embed react component
<DialobComposer formId={FORM_ID} configuration={DIALOB_COMPOSER_CONFIG}/>
const DIALOB_COMPOSER_CONFIG = {
transport: {
csrf: {
headerName: window.COMPOSER_CONFIG.csrfHeader,
token: window.COMPOSER_CONFIG.csrf
},
apiUrl: window.COMPOSER_CONFIG.backend_api_url,
previewUrl: window.COMPOSER_CONFIG.filling_app_url,
tenantId: window.COMPOSER_CONFIG.tenantId,
},
documentationUrl: '',
itemEditors: DEFAULT_ITEM_CONFIG,
itemTypes: DEFAULT_ITEMTYPE_CONFIG,
valueSetProps: CUSTOM_VALUESET_PROPS,
postAddItem: (dispatch, action, lastItem) => {},
closeHandler : () => {}
};
- transport - Transport configuration, CSRF header, token etc.
- apiUrl - URL for Dialob backend service API
- previewUrl - (Optional) URL for Dialob Filling preview application. If omitted, "Preview" feature is disabled.
/<sessionId>
is appended to the URL for preview. - itemEditors - Configuration for item editors
- documentationUrl - (Optional) URL for user guide documentaion, defaults to
https://docs.dialob.io/
- itemTypes - Configuration for item types
- valueSetProps - (Optional) configuration for custom properties for valueset entries
- postAddItem - (Optional) callback function that gets called after a new item gets added to a form. Arguments:
dispatch
- Redux dispatch for dispatching additional actions into composer state,action
- The Redux action that was used for creating the item,lastItem
- The item that was added (including ID). Use this, for example, to create addtitional form structure depending on the created item, communicate to other parts of application etc. - closeHandler - JS function that is called when toolbar
X
button is clicked.
For exmaple: src/defaults/itemTypes.js
Item type configuration corresponds to "Add new" item creation menu structure and also defines available item types including their configuration
DEFAULT_ITEMTYPE_CONFIG = {
categories: [
{
title: 'Structure',
type: 'structure',
items: [
{
title: 'Group',
optionEditors: [
{name: 'Additional option', editor: GenericOptionEditor}
],
propEditors: {
columns: {
component: PropEditors.InputProp,
props: {
type: 'number',
min: 1,
max: 20
}
}
},
config: {
type: 'group',
props: {
columns: 1
}
}
},
{
title: 'Multi-choice',
convertible: ['list'],
propEditors: {
display: {
component: PropEditors.ChoiceProp,
props: {
options: [
{key: 'dropdown', label: 'Dropdown'},
{key: 'button', label: 'Button'},
{key: 'checkbox', label: 'Checkbox'}
]
}
}
},
config: {
type: 'multichoice',
props: {
display: 'dropdown',
}
}
}
]
},
// ....
]
},
// ....
]
}
categories
defines top-level categories, category object contains following attributes:Title
Label used in UItype
Category type, allowed values:structure
,input
,output
- These are used to limit certain categories of items to be added into form depending on conditionsitems
Array of item configurations within this category. Item objects contain following attributestitle
Label used in UIconvertible
(Optional) Array of item type identifiers into which this item can be converted. Entries are first matched byview
attribute, if not found then bytype
. If omitted, item can't be converted to other types.optionEditors
(Optional) Array of additional pages for item options dialog. Array of objects:{name: 'Title of page', editor: OptionEditorComponent}
(see below)propEditors
(Optional) if custom property editors are configured for item. If prop editor is not defined, it will be fallen back to plain text. Editor configuration is set of objects having prop name as a key:component
: React component to use for editing the propprops
: (Optional) Additional properties for the editing component. (see below)
config
: Snippet of Dialob form item configuration (See Dialob Form API). Any predefined structure is supported. only mandatory attribute istype
. Item's default ID will be based onview
attribute falling back totype
Note! props
Are item specific properties that are available at filling time
Built in editors:
-
PropEditors.InputProp
- Plain input component, supports HTML<input>
attributes as props for defining input type etc. -
PropEditors.ChoiceProp
- Dropdown selection list,options
prop having an array of{key: '', label: ''},
entries, wherekey
is value stored in prop andlabel
is text displayed in UI. -
PropEditors.BoolProp
- Boolean switch. -
PropEditors.MultiChoiceProp
- Dropdown selection list, allows multiple selections (Array of string value).options
prop as inChoiceProp
,allowAdditions
true/false -- Allow adding arbitrary strings to list.
Custom editing component template
const CustomProp = ({ onChange, value, name, item, ...props }) => {
// onChange(value) - callback function for setting the prop's value
// value - current value of the prop
// name - prop name
// item - item data for current item. (Immutable.Map)
// props - additional editor component props passed on from configuration
// Return react component here that renders UI for prop editor
return (<Input onChange={(e) => onChange(e.target.value)} value={value || ''} {...props} />);
};
Custom item option dialog page component template
const OptionEditorComponent = ({item}) => {
// item - item data for current item. (Immutable.Map)
// Return react compinent here that renders UI for option dialog page
}
For example: src/defaults/itemConfig.js
Item editor configuration defines which kind of item editing components are used in which conditions.
WIP
This is for controlling additional metadata properties for value set entries that are stored with form data, but not communicated to filling side.
For example: src/defaults/valueSetProps.js
export const DEFAULT_VALUESET_PROPS = [
{
title: 'Custom attribute',
name: 'attr',
editor: GenericValueSetPropEditor
}
];
title
Title shown in table column headerattr
attribute nameeditor
React component for editing the value
Valueset entry metadata prop editor React component template
const CustomValueSetProp = ({ onChange, value }) => {
// onChange(value) - callback function for setting the prop's value
// value - current value of the prop
// Return react component here that renders UI for prop editor
};