Skip to content

Commit

Permalink
feat(entry-field-description): make translate first parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Oct 5, 2020
1 parent b361381 commit 9755d04
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/factory/AutoSuggestTextBoxFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var autoSuggestTextBox = function(translate, options, defaultParameters) {
'</div>');

if (description) {
domQuery('.bpp-field-wrapper', resource.html).appendChild(entryFieldDescription(description, translate));
domQuery('.bpp-field-wrapper', resource.html).appendChild(entryFieldDescription(translate, description));
}

if (canBeShown) {
Expand Down
2 changes: 1 addition & 1 deletion lib/factory/CheckboxEntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var checkbox = function(translate, options, defaultParameters) {

// add description below checkbox entry field
if (description) {
resource.html.appendChild(entryFieldDescription(description, translate, { show: canBeHidden && 'isHidden' }));
resource.html.appendChild(entryFieldDescription(translate, description, { show: canBeHidden && 'isHidden' }));
}

resource.get = function(element) {
Expand Down
2 changes: 1 addition & 1 deletion lib/factory/ComboEntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var comboBox = function(translate, options) {

// add description below combo box entry field
if (description) {
comboBoxEntry.html.appendChild(entryFieldDescription(description, translate, { show: 'showCustomInput' }));
comboBoxEntry.html.appendChild(entryFieldDescription(translate, description, { show: 'showCustomInput' }));
}

return comboBoxEntry;
Expand Down
2 changes: 1 addition & 1 deletion lib/factory/EntryFieldDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var MAX_DESCRIPTION_LENGTH = 200;
* @param {object} [options]
* @param {string} [options.show] - name of callback to determine whether description is shown
*/
module.exports = function entryFieldDescription(description, translate, options) {
module.exports = function entryFieldDescription(translate, description, options) {
var show = options && options.show;

// we tokenize the description to extract text, HTML and markdown links
Expand Down
2 changes: 1 addition & 1 deletion lib/factory/LinkEntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function link(translate, options) {

// add description below link entry field
if (description) {
resource.html.appendChild(entryFieldDescription(description, translate, { show: 'showLink' }));
resource.html.appendChild(entryFieldDescription(translate, description, { show: 'showLink' }));
}

resource.handleClick = bind(handleClick, resource);
Expand Down
2 changes: 1 addition & 1 deletion lib/factory/SelectEntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var selectbox = function(translate, options, defaultParameters) {

// add description below select box entry field
if (description && typeof options.showCustomInput !== 'function') {
resource.html.appendChild(entryFieldDescription(description, translate, { show: canBeHidden && 'isHidden' }));
resource.html.appendChild(entryFieldDescription(translate, description, { show: canBeHidden && 'isHidden' }));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/factory/TableEntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = function(translate, options) {
'</div>');

if (description) {
html.appendChild(entryFieldDescription(description, translate, { show: 'showTable' }));
html.appendChild(entryFieldDescription(translate, description, { show: 'showTable' }));
}

var factory = {
Expand Down
2 changes: 1 addition & 1 deletion lib/factory/TextBoxEntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var textBox = function(translate, options, defaultParameters) {

// add description below text box entry field
if (description) {
resource.html.appendChild(entryFieldDescription(description, translate, { show: canBeShown && 'isShown' }));
resource.html.appendChild(entryFieldDescription(translate, description, { show: canBeShown && 'isShown' }));
}

if (canBeShown) {
Expand Down
2 changes: 1 addition & 1 deletion lib/factory/TextInputEntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var textField = function(translate, options, defaultParameters) {

// add description below text input entry field
if (description) {
resource.html.appendChild(entryFieldDescription(description, translate, { show: canBeHidden && 'isHidden' }));
resource.html.appendChild(entryFieldDescription(translate, description, { show: canBeHidden && 'isHidden' }));
}

resource[actionName] = actionMethod;
Expand Down
4 changes: 2 additions & 2 deletions lib/factory/ToggleSwitchEntryFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ var toggleSwitch = function(translate, options, defaultParameters) {
'</div>'));

if (descriptionOn) {
resource.html.appendChild(entryFieldDescription(descriptionOn, translate, { show: 'isOn' }));
resource.html.appendChild(entryFieldDescription(translate, descriptionOn, { show: 'isOn' }));
}

if (descriptionOff) {
resource.html.appendChild(entryFieldDescription(descriptionOff, translate, { show: 'isOff' }));
resource.html.appendChild(entryFieldDescription(translate, descriptionOff, { show: 'isOff' }));
}

resource.get = function(element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function getInputParameterEntries(element, bpmnFactory, options, translate) {
entries;

if (!params.length) {
var description = entryFieldDescription(translate('No variables defined.'), translate);
var description = entryFieldDescription(translate, translate('No variables defined.'));

return [{
id: idPrefix + 'input-parameter' + '-placeholder',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function getOutputParameterEntries(element, bpmnFactory, options, translate) {
entries;

if (!params.length) {
var description = entryFieldDescription(translate('No variables defined.'), translate);
var description = entryFieldDescription(translate, translate('No variables defined.'));

return [{
id: idPrefix + 'output-parameter' + '-placeholder',
Expand Down
4 changes: 2 additions & 2 deletions lib/provider/camunda/parts/implementation/ProcessVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = function(element, translate) {
byScope = groupByScope(withNames);

// (1) tab description entry
var description = entryFieldDescription(translate('Available process variables, identified in the diagram.'), translate);
var description = entryFieldDescription(translate, translate('Available process variables, identified in the diagram.'));

entries.push({
id: 'process-variables-description',
Expand All @@ -99,7 +99,7 @@ module.exports = function(element, translate) {

// (2) empty list placeholder
if (!withNames.length) {
var placeholder = entryFieldDescription(translate('No variables found.'), translate);
var placeholder = entryFieldDescription(translate, translate('No variables found.'));

entries.push({
id: 'process-variables-placeholder',
Expand Down
41 changes: 20 additions & 21 deletions test/spec/factory/EntryFieldDescriptionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('factory/EntryFieldDescription', function() {
it('should use provided callback name', function() {

// when
var html = EntryFieldDescription('desc', translate, { show: 'show' });
var html = EntryFieldDescription(translate, 'desc', { show: 'show' });

// then
expect(domAttr(html, 'data-show')).to.equal('show');
Expand All @@ -21,8 +21,8 @@ describe('factory/EntryFieldDescription', function() {
it('should not set "data-show" attribute if callback name is not present', function() {

// when
var html1 = EntryFieldDescription('desc', translate);
var html2 = EntryFieldDescription('desc', translate, { show: undefined });
var html1 = EntryFieldDescription(translate, 'desc');
var html2 = EntryFieldDescription(translate, 'desc', { show: undefined });

// then
expect(domAttr(html1, 'data-show')).not.to.exist;
Expand All @@ -36,7 +36,7 @@ describe('factory/EntryFieldDescription', function() {
it('should escape HTML', function() {

// when
var html = EntryFieldDescription('<html />', translate);
var html = EntryFieldDescription(translate, '<html />');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal('&lt;html /&gt;');
Expand All @@ -46,7 +46,7 @@ describe('factory/EntryFieldDescription', function() {
it('should preserve plain <a href>', function() {

// when
var html = EntryFieldDescription('Hallo <a href="http://foo">FOO</a> <a href="https://bar">BAR</a>!', translate);
var html = EntryFieldDescription(translate, 'Hallo <a href="http://foo">FOO</a> <a href="https://bar">BAR</a>!');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -58,7 +58,7 @@ describe('factory/EntryFieldDescription', function() {
it('should preserve query string in plain <a href>', function() {

// when
var html = EntryFieldDescription('Hallo <a href="http://foo?foo=bar&foo.bar[]=1">FOO</a>', translate);
var html = EntryFieldDescription(translate, 'Hallo <a href="http://foo?foo=bar&foo.bar[]=1">FOO</a>');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -70,7 +70,7 @@ describe('factory/EntryFieldDescription', function() {
it('should preserve <a> and <br/>', function() {

// when
var html = EntryFieldDescription(
var html = EntryFieldDescription(translate,
'<div>' +
'<a href="http://foo">' +
'<p>' +
Expand All @@ -79,8 +79,7 @@ describe('factory/EntryFieldDescription', function() {
'</a>' +
'<br />' +
'<a href="http://bar">BAR</a>' +
'</div>',
translate
'</div>'
);

// then
Expand All @@ -101,7 +100,7 @@ describe('factory/EntryFieldDescription', function() {
it('should handle markdown special chars in <a href>', function() {

// when
var html = EntryFieldDescription('Hallo <a href="http://foo?()[]">[]FOO</a>', translate);
var html = EntryFieldDescription(translate, 'Hallo <a href="http://foo?()[]">[]FOO</a>');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -113,7 +112,7 @@ describe('factory/EntryFieldDescription', function() {
it('should ignore custom <a href>', function() {

// when
var html = EntryFieldDescription('Hallo <a class="foo" href="http://foo">FOO</a>!', translate);
var html = EntryFieldDescription(translate, 'Hallo <a class="foo" href="http://foo">FOO</a>!');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -125,7 +124,7 @@ describe('factory/EntryFieldDescription', function() {
it('should ignore broken <a href>', function() {

// when
var html = EntryFieldDescription('Hallo <a href="http://foo>FOO</a>!', translate);
var html = EntryFieldDescription(translate, 'Hallo <a href="http://foo>FOO</a>!');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -137,7 +136,7 @@ describe('factory/EntryFieldDescription', function() {
it('should ignore non HTTP(S) protocol <a href>', function() {

// when
var html = EntryFieldDescription('Hallo <a href="javascript:foo()">FOO</a>!', translate);
var html = EntryFieldDescription(translate, 'Hallo <a href="javascript:foo()">FOO</a>!');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -149,7 +148,7 @@ describe('factory/EntryFieldDescription', function() {
it('should transform markdown link', function() {

// when
var html = EntryFieldDescription('Hallo [FOO](http://foo) [BAR](https://bar?a=1&b=10)!', translate);
var html = EntryFieldDescription(translate, 'Hallo [FOO](http://foo) [BAR](https://bar?a=1&b=10)!');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -161,7 +160,7 @@ describe('factory/EntryFieldDescription', function() {
it('should ignore broken markdown link', function() {

// when
var html = EntryFieldDescription('Hallo [FOO](http://foo', translate);
var html = EntryFieldDescription(translate, 'Hallo [FOO](http://foo');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -173,7 +172,7 @@ describe('factory/EntryFieldDescription', function() {
it('should transform HTML in markdown link', function() {

// when
var html = EntryFieldDescription('Hallo ["FOO" <div/>](http://foo)', translate);
var html = EntryFieldDescription(translate, 'Hallo ["FOO" <div/>](http://foo)');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -185,7 +184,7 @@ describe('factory/EntryFieldDescription', function() {
it('should preserve line breaks', function() {

// when
var html = EntryFieldDescription('Hello <br/> world', translate);
var html = EntryFieldDescription(translate, 'Hello <br/> world');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -197,7 +196,7 @@ describe('factory/EntryFieldDescription', function() {
it('should ignore whitespaces in br tag', function() {

// when
var html = EntryFieldDescription('Hello <br /> world', translate);
var html = EntryFieldDescription(translate, 'Hello <br /> world');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -209,7 +208,7 @@ describe('factory/EntryFieldDescription', function() {
it('should preserve line breaks within <a> text', function() {

// when
var html = EntryFieldDescription('<a href="https://test.com"> HELLO <br/> WORLD </a>', translate);
var html = EntryFieldDescription(translate, '<a href="https://test.com"> HELLO <br/> WORLD </a>');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -221,7 +220,7 @@ describe('factory/EntryFieldDescription', function() {
it('should not ignore <a> if br used within URL field', function() {

// when
var html = EntryFieldDescription('<a href="https://test<br />website.com"> HELLO <br/> WORLD </a>', translate);
var html = EntryFieldDescription(translate, '<a href="https://test<br />website.com"> HELLO <br/> WORLD </a>');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand All @@ -233,7 +232,7 @@ describe('factory/EntryFieldDescription', function() {
it('should handle special HTML chars in markdown link', function() {

// when
var html = EntryFieldDescription('Hallo [YOU](http://foo=<" []>)', translate);
var html = EntryFieldDescription(translate, 'Hallo [YOU](http://foo=<" []>)');

// then
expect(domQuery('.description__text', html).innerHTML).to.equal(
Expand Down

0 comments on commit 9755d04

Please sign in to comment.