Skip to content

Commit

Permalink
fix(uip-setting): pr fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sisha0 committed Apr 30, 2021
1 parent 0925496 commit 25a3e65
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/settings/setting/bool-setting/bool-setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import ArrayUtils from '../../../utils/array-utils/array-utils';

export class UIPBoolSetting extends UIPSetting {
public static is = 'uip-bool-setting';
public static inconsistentState = {
message: '(inconsistent)',
class: 'inconsistency-marker'
};

@attr({defaultValue: ''}) public label: string;
@attr({defaultValue: ''}) public value: string;
Expand Down Expand Up @@ -49,7 +53,8 @@ export class UIPBoolSetting extends UIPSetting {
const attrValues = model.getAttribute(this.target, this.attribute);

if (this.mode === 'replace') {
if ((attrValues[0] === null || attrValues[0] === this.value) && attrValues.every(val => attrValues[0] === val)) {
if ((attrValues[0] === null || attrValues[0] === this.value) &&
attrValues.every(val => attrValues[0] === val)) {
this.setValue(attrValues[0]);
} else {
this.setInconsistency();
Expand Down Expand Up @@ -79,17 +84,16 @@ export class UIPBoolSetting extends UIPSetting {
this.$field.checked = value !== null;
}

this.querySelector('.inconsistency-marker')?.remove();
this.querySelector(`.${UIPBoolSetting.inconsistentState.class}`)?.remove();
}

// TODO: implement inconsistency state for boolean setting
protected setInconsistency(): void {
this.$field.checked = false;
this.querySelector('.inconsistency-marker')?.remove();
this.querySelector(`.${UIPBoolSetting.inconsistentState.class}`)?.remove();

const inconsistencyMarker = document.createElement('span');
inconsistencyMarker.classList.add('inconsistency-marker');
inconsistencyMarker.innerText = '(inconsistent)';
inconsistencyMarker.classList.add(UIPBoolSetting.inconsistentState.class);
inconsistencyMarker.innerText = UIPBoolSetting.inconsistentState.message;

this.appendChild(inconsistencyMarker);
}
Expand Down
2 changes: 1 addition & 1 deletion src/settings/setting/select-setting/select-setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {generateUId} from '@exadel/esl/modules/esl-utils/misc/uid';

export class UIPSelectSetting extends UIPSetting {
public static is = 'uip-select-setting';
static inconsistentState = {
public static inconsistentState = {
value: 'inconsistent',
text: 'Inconsistent value'
};
Expand Down
3 changes: 2 additions & 1 deletion src/settings/setting/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export abstract class UIPSetting extends ESLBaseElement {
}

public applyTo(model: UIPStateModel): void {
this.isValid() ? model.setAttribute(this.target, this.attribute, this.getDisplayedValue()) : this.setInconsistency();
this.isValid() ? model.setAttribute(this.target, this.attribute, this.getDisplayedValue()) :
this.setInconsistency();
}

public updateFrom(model: UIPStateModel): void {
Expand Down
6 changes: 1 addition & 5 deletions src/utils/array-utils/array-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export default class ArrayUtils {
}

static remove<T>(array: T[], element: T): T[] {
const arr = [...array];
const elementIndex = arr.indexOf(element);
elementIndex !== -1 && arr.splice(elementIndex, 1);

return arr;
return array.filter(el => el !== element);
}
}

0 comments on commit 25a3e65

Please sign in to comment.