Skip to content

Commit

Permalink
feat: add bypass toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
devmiguelangel committed Jun 11, 2024
1 parent 43958ca commit 3eb4970
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
26 changes: 21 additions & 5 deletions src/components/computed-properties.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
:fields="fields"
:items="current"
filter-key="name"
disable-key="byPass"
:inline-edit="false"
:data-test-actions="{
tableBox: { 'data-cy': 'calcs-table' },
Expand All @@ -30,13 +31,15 @@
@item-delete="deleteProperty"
@add-page="displayFormProperty"
>
<template #options>
<template #options="{ item }">
<button
v-b-tooltip="{ customClass: 'bypass-btn-tooltip' }"
title="Unbypass Calc"
:title="item.byPass ? 'Unbypass Calc' : 'Bypass Calc'"
class="btn"
@click="toggleBypass(item.id)"
>
<i class="fas fa-sign-in-alt"></i>
<i v-show="!item.byPass" class="fas fa-sign-out-alt"></i>
<i v-show="item.byPass" class="fas fa-sign-in-alt"></i>
</button>
<div class="sortable-item-vr"></div>
</template>
Expand Down Expand Up @@ -238,9 +241,14 @@ export default {
this.value.forEach((item) => {
this.numberItem++;
item.id = this.numberItem;
if (!Object.hasOwn(item, 'byPass')) {
item.byPass = false;
}
});
this.current = this.value;
}
},
},
created() {
Validator.register(
Expand Down Expand Up @@ -314,6 +322,13 @@ export default {
this.focusFirstCalculatedPropertiesError();
}
},
toggleBypass(itemId) {
this.current = this.current.map((item) =>
item.id === itemId ? { ...item, byPass: !item.byPass } : item,
);
this.$emit("input", this.current);
},
saveProperty() {
if (this.add.id === 0) {
this.numberItem++;
Expand All @@ -322,7 +337,8 @@ export default {
property: this.add.property,
name: this.add.name,
formula: this.add.formula,
type: this.add.type
type: this.add.type,
byPass: false,
});
} else {
this.current.forEach((item) => {
Expand Down
6 changes: 4 additions & 2 deletions src/components/sortable/Sortable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
:items="items"
:filtered-items="filteredItems"
:inline-edit="inlineEdit"
:disable-key="disableKey"
:data-test-actions="dataTestActions"
@ordered="$emit('ordered', $event)"
@item-edit="$emit('item-edit', $event)"
@item-delete="$emit('item-delete', $event)"
>
<template #options>
<slot name="options"></slot>
<template #options="{ item }">
<slot name="options" :item="item"></slot>
</template>
</SortableList>
</div>
Expand All @@ -52,6 +53,7 @@ export default {
fields: { type: Array, required: true },
items: { type: Array, required: true },
filterKey: { type: String, required: true },
disableKey: { type: String, default: null },
inlineEdit: { type: Boolean, default: true },
dataTestActions: {
type: Object,
Expand Down
12 changes: 10 additions & 2 deletions src/components/sortable/sortableList/SortableList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
:data-order="item.order"
:data-test="`item-${item.order}`"
:title="item.name"
class="sortable-list-tr sortable-item"
:class="[
'sortable-list-tr',
'sortable-item',
{ 'sortable-item-disabled': isDisabled(item) },
]"
draggable="true"
@dragstart="(event) => dragStart(event, item.order)"
@dragenter="(event) => dragEnter(event, item.order)"
Expand Down Expand Up @@ -69,7 +73,7 @@
<i class="fas fa-edit"></i>
</button>
<div class="sortable-item-vr"></div>
<slot name="options"></slot>
<slot name="options" :item="item"></slot>
<button
class="btn"
title="Delete"
Expand All @@ -93,6 +97,7 @@ export default {
items: { type: Array, required: true },
filteredItems: { type: Array, required: true },
inlineEdit: { type: Boolean, default: true },
disableKey: { type: String, default: null },
dataTestActions: { type: Object, required: true },
},
data() {
Expand Down Expand Up @@ -223,6 +228,9 @@ export default {
dragOver(event) {
event.preventDefault();
},
isDisabled(item) {
return this.disableKey ? item[this.disableKey] : false;
},
},
}
</script>
Expand Down
4 changes: 4 additions & 0 deletions src/components/sortable/sortableList/sortableList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ $border-color: #cdddee;
margin: 9px 0;
border-right: 1px solid $border-color;
}

&-disabled > .sortable-item-prop {
color: rgba(85, 98, 113, 0.5);
}
}
}

Expand Down

0 comments on commit 3eb4970

Please sign in to comment.