Settings
It’s possible to define a settings window for your integration app where users can customize the integration flow.
To define the settings window, you need to implement the getConfiguration method in your integration configuration file.
configuration.projectIntegration.getConfiguration = ( projectId, crowdinClient, integrationCredentials) => { return [ // Configuration Options ]}You can also specify whether to auto-reload the integration settings when the user changes them:
configuration.projectIntegration.reloadOnConfigSave = true;Configuration Options
Section titled “Configuration Options”The configuration options are defined as an array of objects. Each object represents a single configuration option.
{ label: 'GENERAL'}Label HTML
Section titled “Label HTML”{ labelHtml: 'This is <b>labelHtml</b> <i>example</i>'}Checkbox
Section titled “Checkbox”{ key: 'flag', label: 'Checkbox', type: 'checkbox'}Text input
Section titled “Text input”{ key: 'text', label: 'Text input', type: 'text'}Select
Section titled “Select”{ key: 'option', label: 'Select', type: 'select', defaultValue: '12', isSearchable: true, isMulti: true, options: [ { value: '12', label: 'Option' } ]}Configuration options:
isSearchable- Allow to search for option(s), default isfalse.isMulti- Allow to select multiple options, default isfalse.
Textarea
Section titled “Textarea”{ key: 'textarea', label: 'Textarea', type: 'textarea'}Notice
Section titled “Notice”{ key: 'alert', type: 'notice', noticeType: 'info', noIcon: false, label: 'Some message title'}Help Text
Section titled “Help Text”You can add a help text to any field by using the helpText or helpTextHtml property:
{ key: 'text', label: 'Text input', type: 'text', helpText: 'Help text', helpTextHtml: 'Help text <b>HTML</b>'}Field Dependencies
Section titled “Field Dependencies”It’s possible to show or hide fields based on the value of another field. To define field dependencies, you need to use the dependencySettings property.
For example, to show the field only if the flag field is checked:
{ key: 'text', label: 'Text input', type: 'text', dependencySettings: JSON.stringify([ { '#flag': { type: 'equal', value: true } } ]),}Examples
Section titled “Examples”- Alias of empty type:
'empty', 'blank' - Alias of not empty type:
'!empty', 'notEmpty', 'not-empty', 'notempty' - Alias of equal type:
'equal', '=', '==', '===' - Alias of not equal type:
'!equal', '!=', '!==', '!===', 'notEqual', 'not-equal', 'notequal'
Show field if dependsOn field value is empty
Section titled “Show field if dependsOn field value is empty”JSON.stringify([ { 'input[name=test]': { type: 'empty' } } ])Show field if dependsOn field value is equal to given value
Section titled “Show field if dependsOn field value is equal to given value”JSON.stringify([ { 'input[name=test]': { type: 'equal', value: 'lorem' } } ])JSON.stringify([ { 'input[name=test]': { type: 'equal', value: ['lorem', 'ipsum'] } } ])normalizeSettings Function
Section titled “normalizeSettings Function”This method allows you to modify saved integration settings without needing to migrate the database. You can change existing settings, such as altering field types or adjusting values based on other parameters.
configuration.projectIntegration = { getConfiguration: (projectId, crowdinClient, integrationCredentials) => { return [ /* { key: 'publish', label: 'Set Publish Status', type: 'checkbox', }, */ { key: 'publishStatus', label: 'Set Publish Status', type: 'select', defaultValue: 'draft', options: [ { value: 'draft', label: 'Draft', }, { value: 'publish', label: 'Publish', }, { value: 'match', label: 'Match Source', }, ], } ]; }, normalizeSettings: ({ appSettings, apiCredentials, client }) => { if (appSettings?.publish === true) { appSettings.publishStatus = 'publish'; } return appSettings; },};Validate settings
Section titled “Validate settings”You can validate settings before they are saved by implementing the validateSettings method in your projectIntegration configuration. This method allows you to check if the provided settings are valid and return appropriate error messages.
configuration.projectIntegration.validateSettings = ({ client, credentials, appSettings }) => { const errors = {};
if (appSettings.string_keys) { const keys = appSettings.string_keys.split(',').map(key => key.trim()); const hasInvalidKey = keys.some(key => /\s/.test(key));
if (hasInvalidKey) { errors.string_keys = 'String keys cannot contain spaces. Example of valid keys: postBody,body,html,title,foobar'; } }
// Return validation errors as key-value pairs where key is the field name and value is the error message return Object.keys(errors).length ? errors : null;};