Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change button style and add delete confirmation modal for filter rules #170

Merged
merged 5 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ui/public/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,11 @@
"type_ip_l": "IP address",
"type_cidr_l": "CIDR network",
"create_bypass_rule_for": "Create bypass rule for {value}",
"bypass_rule_is_going_to_be_deleted": "Bypass rule for {value} is going to be deleted...",
"delete_bypass_rule_for": "Delete bypass rule for {value}",
"bypass_rule_already_exists": "This bypass rule already exists",
"placeholder_bypass_rule": "E.g. {value}"
"placeholder_bypass_rule": "E.g. {value}",
"delete_filter_rule": "Delete bypass rule",
"delete_rule_confirm": "Delete rule {name}?"
},
"settings_mailboxes": {
"title": "Mailboxes settings",
Expand Down
111 changes: 45 additions & 66 deletions ui/src/views/FilterBypassRules.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@
<cv-data-table-cell>
<div class="justify-flex-end">
<NsButton
kind="danger"
kind="tertiary"
:icon="TrashCan20"
size="small"
@click="willDeleteBypassRule(row)"
@click="showDeleteRuleModal(row)"
>{{ $t("common.delete") }}
</NsButton>
</div>
Expand All @@ -146,6 +146,34 @@
@hide="hideCreateBypassRuleModal"
@reloadBypassRules="listBypassRules"
/>
<!-- delete filter rule modal -->
<NsDangerDeleteModal
:isShown="isShownDeleteRuleModal"
:name="currentRule.value"
:title="$t('filter_bypass_rules.delete_filter_rule')"
:warning="core.$t('common.please_read_carefully')"
:description="
$t('filter_bypass_rules.delete_rule_confirm', {
name: currentRule ? currentRule.value : '',
})
"
:typeToConfirm="
core.$t('common.type_to_confirm', {
name: currentRule ? currentRule.value : '',
})
"
:isErrorShown="!!error.removeBypassRule"
:errorTitle="$t('action.remove-bypass-rule')"
:errorDescription="error.removeBypassRule"
@hide="hideDeleteRuleModal"
@confirmDelete="removeBypassRule(currentRule)"
>
<template slot="explanation">
<p class="mg-top-sm">
{{ core.$t("common.this_action_is_not_reversible") }}
</p>
</template>
</NsDangerDeleteModal>
</div>
</template>

Expand Down Expand Up @@ -180,6 +208,12 @@ export default {
q: {
page: "filterBypassRules",
},
isShownDeleteRuleModal: false,
currentRule: {
direction: "",
value: "",
type: "",
},
urlCheckInterval: null,
tablePage: [],
tableColumns: ["direction", "value", "type"],
Expand Down Expand Up @@ -217,6 +251,13 @@ export default {
this.listBypassRules();
},
methods: {
showDeleteRuleModal(rule) {
this.currentRule = rule;
this.isShownDeleteRuleModal = true;
},
hideDeleteRuleModal() {
this.isShownDeleteRuleModal = false;
},
goToFilter() {
this.goToAppPage(this.instanceName, "filter");
},
Expand All @@ -226,67 +267,6 @@ export default {
hideCreateBypassRuleModal() {
this.isShownCreateBypassRuleModal = false;
},
willDeleteBypassRule(rule) {
const notification = {
id: this.getUuid(),
title: this.$t(
"filter_bypass_rules.bypass_rule_is_going_to_be_deleted",
{
value: rule.value,
}
),
type: "info",
toastTimeout: this.DELETE_DELAY - 1000,
actionLabel: this.core.$t("common.cancel"),
action: {
type: "callback",
callback: this.cancelDeleteBypassRule.bind(null, rule),
},
};
this.createNotificationForApp(notification);

const timeout = setTimeout(() => {
// remove notification from drawer
this.deleteNotificationForApp(notification.id);

// delete timeout
this.deleteBypassRuleTimeout = this.deleteBypassRuleTimeout.filter(
(el) => el.name !== rule.value
);

// call api to remove address
this.removeBypassRule(rule);
}, this.DELETE_DELAY);

this.deleteBypassRuleTimeout.push({
name: rule.value,
timeout,
notification,
});

// remove bypass rule from table
this.rules = this.rules.filter((r) => r.value !== rule.value);
},
cancelDeleteBypassRule(rule) {
const timeoutFound = this.deleteBypassRuleTimeout.find(
(el) => el.name === rule.value
);

if (timeoutFound) {
clearTimeout(timeoutFound.timeout);

// remove notification from drawer
this.deleteNotificationForApp(timeoutFound.notification.id);

// delete timeout
this.deleteBypassRuleTimeout = this.deleteBypassRuleTimeout.filter(
(el) => el.name !== rule.value
);
}

// reload bypass rules
this.listBypassRules();
},
async listBypassRules() {
this.loading.listBypassRules = true;
this.error.listBypassRules = "";
Expand Down Expand Up @@ -386,9 +366,8 @@ export default {
},
removeBypassRuleCompleted() {
this.loading.removeBypassRule = false;

// reload addresses
this.$emit("reloadBypassRules");
this.hideDeleteRuleModal();
this.listBypassRules();
},
},
};
Expand Down
Loading