mirror of
https://github.com/beekeeper-studio/beekeeper-studio.git
synced 2026-03-13 10:12:54 +08:00
refactor: use pluralize library for folder deletion error messages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Entity, Column, OneToMany, ManyToOne, JoinColumn, BeforeRemove } from 'typeorm'
|
||||
import { ApplicationEntity } from './application_entity'
|
||||
import { SavedConnection } from './saved_connection'
|
||||
import pluralize from 'pluralize'
|
||||
|
||||
@Entity({ name: 'connection_folder' })
|
||||
export class ConnectionFolder extends ApplicationEntity {
|
||||
@@ -32,7 +33,7 @@ export class ConnectionFolder extends ApplicationEntity {
|
||||
async preventRemoveIfNotEmpty(): Promise<void> {
|
||||
const count = await SavedConnection.countBy({ connectionFolderId: this.id })
|
||||
if (count > 0) {
|
||||
throw new Error(`Cannot delete folder "${this.name}" — move or remove its ${count} connection${count === 1 ? '' : 's'} first.`)
|
||||
throw new Error(`Cannot delete folder "${this.name}" — move or remove its ${pluralize('connection', count, true)} first.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Entity, Column, OneToMany, ManyToOne, JoinColumn, BeforeRemove } from 'typeorm'
|
||||
import { ApplicationEntity } from './application_entity'
|
||||
import { FavoriteQuery } from './favorite_query'
|
||||
import pluralize from 'pluralize'
|
||||
|
||||
@Entity({ name: 'query_folder' })
|
||||
export class QueryFolder extends ApplicationEntity {
|
||||
@@ -32,7 +33,7 @@ export class QueryFolder extends ApplicationEntity {
|
||||
async preventRemoveIfNotEmpty(): Promise<void> {
|
||||
const count = await FavoriteQuery.countBy({ queryFolderId: this.id })
|
||||
if (count > 0) {
|
||||
throw new Error(`Cannot delete folder "${this.name}" — move or remove its ${count} quer${count === 1 ? 'y' : 'ies'} first.`)
|
||||
throw new Error(`Cannot delete folder "${this.name}" — move or remove its ${pluralize('query', count, true)} first.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import _ from 'lodash'
|
||||
import pluralize from 'pluralize'
|
||||
import { IConnectionFolder } from "@/common/interfaces/IQueryFolder";
|
||||
import { DataState, DataStore, mutationsFor } from "@/store/modules/data/DataModuleBase";
|
||||
import { safely } from "@/store/modules/data/StoreHelpers";
|
||||
@@ -42,7 +43,7 @@ export const LocalConnectionFolderModule: DataStore<IConnectionFolder, State> =
|
||||
async remove(context, folder) {
|
||||
const items = await Vue.prototype.$util.send('appdb/saved/find', { options: { where: { connectionFolderId: folder.id } } })
|
||||
if (items.length > 0) {
|
||||
throw new Error(`Cannot delete "${folder.name}" — move or remove its ${items.length} connection${items.length === 1 ? '' : 's'} first.`)
|
||||
throw new Error(`Cannot delete "${folder.name}" — move or remove its ${pluralize('connection', items.length, true)} first.`)
|
||||
}
|
||||
await Vue.prototype.$util.send('appdb/connectionFolder/remove', { obj: folder })
|
||||
context.commit('remove', folder)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import _ from 'lodash'
|
||||
import pluralize from 'pluralize'
|
||||
import { IQueryFolder } from "@/common/interfaces/IQueryFolder";
|
||||
import { DataState, DataStore, mutationsFor } from "@/store/modules/data/DataModuleBase";
|
||||
import { safely } from "@/store/modules/data/StoreHelpers";
|
||||
@@ -42,7 +43,7 @@ export const LocalQueryFolderModule: DataStore<IQueryFolder, State> = {
|
||||
async remove(context, folder) {
|
||||
const items = await Vue.prototype.$util.send('appdb/query/find', { options: { where: { queryFolderId: folder.id } } })
|
||||
if (items.length > 0) {
|
||||
throw new Error(`Cannot delete "${folder.name}" — move or remove its ${items.length} quer${items.length === 1 ? 'y' : 'ies'} first.`)
|
||||
throw new Error(`Cannot delete "${folder.name}" — move or remove its ${pluralize('query', items.length, true)} first.`)
|
||||
}
|
||||
await Vue.prototype.$util.send('appdb/queryFolder/remove', { obj: folder })
|
||||
context.commit('remove', folder)
|
||||
|
||||
Reference in New Issue
Block a user