Skip to content
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
7 changes: 6 additions & 1 deletion vueManager/src/components/DeliveriesGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const toast = useToast()
const confirm = useConfirm()
const { _ } = useLexicon()

const CONFIRM_GROUP = 'settings-deliveries'

// Bulk selection
const {
selectedItems,
Expand All @@ -49,6 +51,7 @@ const {
confirmBulkDelete,
} = useSelection({
entityName: 'delivery',
confirmGroup: CONFIRM_GROUP,
deleteBulk: async ids => {
await request.delete('/api/mgr/deliveries/bulk', { ids })
},
Expand Down Expand Up @@ -343,6 +346,7 @@ async function saveDelivery() {
*/
function deleteDelivery(delivery) {
confirm.require({
group: CONFIRM_GROUP,
message: _('delivery_delete_confirm_message').replace('{name}', delivery.name),
header: _('confirm_delete'),
icon: 'pi pi-exclamation-triangle',
Expand Down Expand Up @@ -422,7 +426,7 @@ onMounted(async () => {
<template>
<div class="deliveries-grid">
<Toast />
<ConfirmDialog append-to="self" />
<ConfirmDialog :group="CONFIRM_GROUP" append-to="self" />

<Card>
<template #title>
Expand Down Expand Up @@ -559,6 +563,7 @@ onMounted(async () => {
<ActionsColumn
:data="delivery"
:actions="getActionsConfig(column)"
:confirm-group="CONFIRM_GROUP"
grid-id="deliveries"
@edit="editDelivery"
@delete="deleteDelivery"
Expand Down
7 changes: 6 additions & 1 deletion vueManager/src/components/LinksGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const toast = useToast()
const confirm = useConfirm()
const { _ } = useLexicon()

const CONFIRM_GROUP = 'settings-links'

// Bulk selection
const {
selectedItems,
Expand All @@ -35,6 +37,7 @@ const {
confirmBulkDelete,
} = useSelection({
entityName: 'link',
confirmGroup: CONFIRM_GROUP,
deleteBulk: async ids => {
await request.delete('/api/mgr/links/bulk', { ids })
},
Expand Down Expand Up @@ -147,6 +150,7 @@ async function saveLink() {
*/
function deleteLink(link) {
confirm.require({
group: CONFIRM_GROUP,
message: _('link_delete_confirm_message').replace('{name}', link.name),
header: _('confirm_delete'),
icon: 'pi pi-exclamation-triangle',
Expand Down Expand Up @@ -211,7 +215,7 @@ onMounted(() => {
<template>
<div class="links-grid">
<Toast />
<ConfirmDialog append-to="self" />
<ConfirmDialog :group="CONFIRM_GROUP" append-to="self" />

<Card>
<template #title>
Expand Down Expand Up @@ -300,6 +304,7 @@ onMounted(() => {
<ActionsColumn
:data="data"
:actions="getActionsConfig()"
:confirm-group="CONFIRM_GROUP"
grid-id="links"
@edit="openEdit"
@delete="deleteLink"
Expand Down
6 changes: 5 additions & 1 deletion vueManager/src/components/OptionGroupsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const toast = useToast()
const confirm = useConfirm()
const { _ } = useLexicon()

const CONFIRM_GROUP = 'settings-option-groups'

const searchQuery = ref('')

const {
Expand Down Expand Up @@ -134,6 +136,7 @@ function confirmDelete(group) {
: _('ms3_option_group_delete_confirm')

confirm.require({
group: CONFIRM_GROUP,
message: detail,
header: _('ms3_option_group_delete_header'),
icon: 'pi pi-exclamation-triangle',
Expand Down Expand Up @@ -171,6 +174,7 @@ function confirmBulkDelete() {
const ids = [...selectedIds.value]
if (!ids.length) return
confirm.require({
group: CONFIRM_GROUP,
message: _('ms3_option_group_bulk_delete_confirm').replace('{count}', String(ids.length)),
header: _('ms3_option_group_delete_header'),
icon: 'pi pi-exclamation-triangle',
Expand Down Expand Up @@ -212,7 +216,7 @@ onMounted(() => {
<template>
<div class="ms3-option-groups">
<Toast />
<ConfirmDialog />
<ConfirmDialog :group="CONFIRM_GROUP" />

<Card>
<template #content>
Expand Down
6 changes: 5 additions & 1 deletion vueManager/src/components/OptionsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const toast = useToast()
const confirm = useConfirm()
const { _ } = useLexicon()

const CONFIRM_GROUP = 'settings-options'

// Grid state
const options = ref([])
const totalRecords = ref(0)
Expand Down Expand Up @@ -237,6 +239,7 @@ function buildProperties() {

function confirmDelete(row) {
confirm.require({
group: CONFIRM_GROUP,
message:
_('ms3_option_remove_confirm') ||
`Удалить опцию «${row.caption || row.key}»? Значения у товаров будут удалены.`,
Expand Down Expand Up @@ -264,6 +267,7 @@ function confirmBulkDelete() {
if (selectedRows.value.length === 0) return
const ids = selectedRows.value.map(r => r.id)
confirm.require({
group: CONFIRM_GROUP,
message:
_('ms3_options_remove_confirm') ||
`Удалить выбранные опции (${ids.length})? Значения у товаров будут удалены.`,
Expand Down Expand Up @@ -342,7 +346,7 @@ onBeforeUnmount(() => {
<template>
<div class="options-grid-app">
<Toast />
<ConfirmDialog />
<ConfirmDialog :group="CONFIRM_GROUP" />

<div class="options-grid-layout">
<!-- Category filter tree (left pane) -->
Expand Down
7 changes: 6 additions & 1 deletion vueManager/src/components/PaymentsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const toast = useToast()
const confirm = useConfirm()
const { _ } = useLexicon()

const CONFIRM_GROUP = 'settings-payments'

// Bulk selection
const {
selectedItems,
Expand All @@ -47,6 +49,7 @@ const {
confirmBulkDelete,
} = useSelection({
entityName: 'payment',
confirmGroup: CONFIRM_GROUP,
deleteBulk: async ids => {
await request.delete('/api/mgr/payments/bulk', { ids })
},
Expand Down Expand Up @@ -311,6 +314,7 @@ async function savePayment() {
*/
function deletePayment(payment) {
confirm.require({
group: CONFIRM_GROUP,
message: _('payment_delete_confirm_message').replace('{name}', payment.name),
header: _('confirm_delete'),
icon: 'pi pi-exclamation-triangle',
Expand Down Expand Up @@ -390,7 +394,7 @@ onMounted(async () => {
<template>
<div class="payments-grid">
<Toast />
<ConfirmDialog append-to="self" />
<ConfirmDialog :group="CONFIRM_GROUP" append-to="self" />

<Card>
<template #title>
Expand Down Expand Up @@ -527,6 +531,7 @@ onMounted(async () => {
<ActionsColumn
:data="payment"
:actions="getActionsConfig(column)"
:confirm-group="CONFIRM_GROUP"
grid-id="payments"
@edit="editPayment"
@delete="deletePayment"
Expand Down
7 changes: 6 additions & 1 deletion vueManager/src/components/StatusesGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const toast = useToast()
const confirm = useConfirm()
const { _ } = useLexicon()

const CONFIRM_GROUP = 'settings-statuses'

// Bulk selection
const {
selectedItems,
Expand All @@ -35,6 +37,7 @@ const {
confirmBulkDelete,
} = useSelection({
entityName: 'status',
confirmGroup: CONFIRM_GROUP,
deleteBulk: async ids => {
await request.delete('/api/mgr/statuses/bulk', { ids })
},
Expand Down Expand Up @@ -153,6 +156,7 @@ async function saveStatus() {
*/
function deleteStatus(status) {
confirm.require({
group: CONFIRM_GROUP,
message: _('status_delete_confirm_message').replace('{name}', status.name),
header: _('confirm_delete'),
icon: 'pi pi-exclamation-triangle',
Expand Down Expand Up @@ -249,7 +253,7 @@ onMounted(() => {
<template>
<div class="statuses-grid">
<Toast />
<ConfirmDialog append-to="self" />
<ConfirmDialog :group="CONFIRM_GROUP" append-to="self" />

<Card>
<template #title>
Expand Down Expand Up @@ -371,6 +375,7 @@ onMounted(() => {
<ActionsColumn
:data="status"
:actions="getActionsConfig()"
:confirm-group="CONFIRM_GROUP"
grid-id="statuses"
@edit="openEdit"
@delete="deleteStatus"
Expand Down
7 changes: 6 additions & 1 deletion vueManager/src/components/VendorsGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const toast = useToast()
const confirm = useConfirm()
const { _ } = useLexicon()

const CONFIRM_GROUP = 'settings-vendors'

// Bulk selection
const {
selectedItems,
Expand All @@ -43,6 +45,7 @@ const {
confirmBulkDelete,
} = useSelection({
entityName: 'vendor',
confirmGroup: CONFIRM_GROUP,
deleteBulk: async ids => {
await request.delete('/api/mgr/vendors/bulk', { ids })
},
Expand Down Expand Up @@ -310,6 +313,7 @@ async function saveVendor() {
*/
function deleteVendor(vendor) {
confirm.require({
group: CONFIRM_GROUP,
message: _('vendor_delete_confirm_message').replace('{name}', vendor.name),
header: _('confirm_delete'),
icon: 'pi pi-exclamation-triangle',
Expand Down Expand Up @@ -481,7 +485,7 @@ onMounted(async () => {
<template>
<div class="vendors-grid">
<Toast />
<ConfirmDialog append-to="self" />
<ConfirmDialog :group="CONFIRM_GROUP" append-to="self" />

<Card>
<template #title>
Expand Down Expand Up @@ -604,6 +608,7 @@ onMounted(async () => {
<ActionsColumn
:data="vendor"
:actions="getActionsConfig(column)"
:confirm-group="CONFIRM_GROUP"
grid-id="vendors"
@edit="editVendor"
@delete="deleteVendor"
Expand Down
52 changes: 52 additions & 0 deletions vueManager/tests/settingsConfirmGroups.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'

const srcRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'src', 'components')

const GRIDS = [
['OptionsGrid.vue', 'settings-options'],
['OptionGroupsGrid.vue', 'settings-option-groups'],
['DeliveriesGrid.vue', 'settings-deliveries'],
['PaymentsGrid.vue', 'settings-payments'],
['StatusesGrid.vue', 'settings-statuses'],
['VendorsGrid.vue', 'settings-vendors'],
['LinksGrid.vue', 'settings-links'],
]

function read(name) {
return fs.readFileSync(path.join(srcRoot, name), 'utf8')
}

test('settings tab grids isolate ConfirmDialog with unique groups (#548)', () => {
const groups = GRIDS.map(([, group]) => group)
assert.equal(new Set(groups).size, groups.length, 'CONFIRM_GROUP values must be unique')

for (const [file, expectedGroup] of GRIDS) {
const text = read(file)
assert.match(
text,
new RegExp(`const CONFIRM_GROUP = '${expectedGroup}'`),
`${file} must declare CONFIRM_GROUP = '${expectedGroup}'`
)

assert.match(text, /<ConfirmDialog[^>]*:group="CONFIRM_GROUP"/, `${file} ConfirmDialog must bind :group`)

const requireAt = [...text.matchAll(/confirm\.require\s*\(/g)]
assert.ok(requireAt.length > 0, `${file} must have confirm.require`)
for (const match of requireAt) {
const snippet = text.slice(match.index, match.index + 400)
assert.match(snippet, /\bgroup:\s*CONFIRM_GROUP/, `${file} confirm.require must pass group: CONFIRM_GROUP`)
}

if (text.includes('<ActionsColumn')) {
assert.match(text, /:confirm-group="CONFIRM_GROUP"/, `${file} ActionsColumn must pass confirm-group`)
}

if (/\bconfirmBulkDelete\b[\s\S]{0,200}=\s*useSelection\(/.test(text)) {
assert.match(text, /confirmGroup:\s*CONFIRM_GROUP/, `${file} useSelection must pass confirmGroup`)
}
}
})