Use existing utils
This commit is contained in:
parent
b7ce306e6a
commit
6f2d279f0e
|
@ -76,13 +76,15 @@ export const getSequentialName = <T extends any>(
|
|||
{
|
||||
getName,
|
||||
numberFirstItem,
|
||||
separator = "",
|
||||
}: {
|
||||
getName?: (item: T) => string
|
||||
numberFirstItem?: boolean
|
||||
separator?: string
|
||||
} = {}
|
||||
) => {
|
||||
if (!prefix?.length) {
|
||||
return null
|
||||
return ""
|
||||
}
|
||||
const trimmedPrefix = prefix.trim()
|
||||
const firstName = numberFirstItem ? `${prefix}1` : trimmedPrefix
|
||||
|
@ -107,5 +109,5 @@ export const getSequentialName = <T extends any>(
|
|||
max = num
|
||||
}
|
||||
})
|
||||
return max === 0 ? firstName : `${prefix}${max + 1}`
|
||||
return max === 0 ? firstName : `${prefix}${separator}${max + 1}`
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import {
|
|||
Table,
|
||||
} from "@budibase/types"
|
||||
import { utils } from "@budibase/shared-core"
|
||||
import { getSequentialName } from "@/helpers/duplicate"
|
||||
|
||||
interface Component extends ComponentType {
|
||||
_id: string
|
||||
|
@ -467,15 +468,14 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
|||
return null
|
||||
}
|
||||
|
||||
let componentName = `New ${definition.friendlyName || definition.name}`
|
||||
const $screenComponents = get(screenComponents)
|
||||
|
||||
const sameNameCount = $screenComponents.filter(c =>
|
||||
new RegExp(`^${componentName}( \\d*)?$`).test(c._instanceName)
|
||||
).length
|
||||
if (sameNameCount) {
|
||||
componentName = `${componentName} ${sameNameCount + 1}`
|
||||
}
|
||||
const componentName = getSequentialName(
|
||||
get(screenComponents),
|
||||
`New ${definition.friendlyName || definition.name}`,
|
||||
{
|
||||
getName: c => c._instanceName,
|
||||
separator: " ",
|
||||
}
|
||||
)
|
||||
|
||||
// Generate basic component structure
|
||||
let instance: Component = {
|
||||
|
|
Loading…
Reference in New Issue