Skip to content

Commit

Permalink
chore: rework button state
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Jul 21, 2023
1 parent 35e799f commit 53d53f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
5 changes: 3 additions & 2 deletions assets/css/bpmn-js-bpmnlint.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@
color: #444;
}

.bjsl-button svg {
margin-top: -1px;
.bjsl-button .icon {
margin-right: 10px;
width: 15px;
height: 15px;
}

.bjsl-button-success {
Expand Down
34 changes: 29 additions & 5 deletions lib/Linting.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,34 @@ Linting.prototype._clearIssues = function() {
this._clearOverlays();
};

Linting.prototype._setButtonState = function(state, errors, warnings, infos) {
Linting.prototype._setButtonState = function(issues) {
var {
errors,
warnings,
infos
} = issues;

var button = this._button;

var state = (errors && 'error') || (warnings && 'warning') || 'success';

var icon = stateToIcon[state];
var label = this._translate(
(errors || warnings)
? '{errors} Errors, {warnings} Warnings'
: 'Toggle Linting',
{
errors: String(errors),
warnings: String(warnings),
infos: String(infos),
}
);

var html = icon + '<span>' + this._translate('{errors} Errors, {warnings} Warnings', { errors: errors.toString(), warnings: warnings.toString() }) + '</span>';
var html = `
<span class="icon">${icon}</span>
<span>${ label }</span>`;

state = this.isActive() ? state : 'inactive';

[
'error',
Expand Down Expand Up @@ -548,9 +570,11 @@ Linting.prototype._updateButton = function() {
});
}

var state = (errors && 'error') || (warnings && 'warning') || 'success';

this._setButtonState(state, errors, warnings, infos);
this._setButtonState({
errors,
warnings,
infos
});
};

Linting.prototype._createButton = function() {
Expand Down
10 changes: 4 additions & 6 deletions test/spec/LintingSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,8 @@ describe('linting', function() {
toggleLinting(modeler, function() {

// then
const buttonSpan = el.querySelector('button.bjsl-button.bjsl-button-error span');
expect(buttonSpan).to.exist;
expect(buttonSpan.innerText).to.equal('8 Errors, 2 Warnings');
const buttonText = el.querySelector('button.bjsl-button.bjsl-button-error').textContent;
expect(buttonText.trim()).to.equal('8 Errors, 2 Warnings');

done();
});
Expand Down Expand Up @@ -825,9 +824,8 @@ describe('i18n', function() {
expect(button).to.exist;
expect(button.title).to.equal('Перемкнути перевірку');

const buttonTextSpan = button.querySelector('span');
expect(buttonTextSpan).to.exist;
expect(buttonTextSpan.innerText).to.equal('16 помилок, 0 попередженнь');
const buttonText = button.textContent;
expect(buttonText.trim()).to.equal('16 помилок, 0 попередженнь');

const endEventRequiredMessage = el.querySelector('a[data-rule="end-event-required"]');
expect(endEventRequiredMessage).to.exist;
Expand Down

0 comments on commit 53d53f4

Please sign in to comment.