Add counter
This commit is contained in:
parent
4ea8b60b3b
commit
b7ce306e6a
|
@ -20,6 +20,7 @@ import {
|
||||||
previewStore,
|
previewStore,
|
||||||
tables,
|
tables,
|
||||||
componentTreeNodesStore,
|
componentTreeNodesStore,
|
||||||
|
screenComponents,
|
||||||
} from "@/stores/builder"
|
} from "@/stores/builder"
|
||||||
import { buildFormSchema, getSchemaForDatasource } from "@/dataBinding"
|
import { buildFormSchema, getSchemaForDatasource } from "@/dataBinding"
|
||||||
import {
|
import {
|
||||||
|
@ -467,6 +468,14 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let componentName = `New ${definition.friendlyName || definition.name}`
|
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}`
|
||||||
|
}
|
||||||
|
|
||||||
// Generate basic component structure
|
// Generate basic component structure
|
||||||
let instance: Component = {
|
let instance: Component = {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import { userStore, userSelectedResourceMap, isOnlyUser } from "./users.js"
|
||||||
import { deploymentStore } from "./deployments.js"
|
import { deploymentStore } from "./deployments.js"
|
||||||
import { contextMenuStore } from "./contextMenu.js"
|
import { contextMenuStore } from "./contextMenu.js"
|
||||||
import { snippets } from "./snippets"
|
import { snippets } from "./snippets"
|
||||||
import { screenComponentErrors } from "./screenComponent"
|
import { screenComponents, screenComponentErrors } from "./screenComponent"
|
||||||
|
|
||||||
// Backend
|
// Backend
|
||||||
import { tables } from "./tables"
|
import { tables } from "./tables"
|
||||||
|
@ -68,6 +68,7 @@ export {
|
||||||
snippets,
|
snippets,
|
||||||
rowActions,
|
rowActions,
|
||||||
appPublished,
|
appPublished,
|
||||||
|
screenComponents,
|
||||||
screenComponentErrors,
|
screenComponentErrors,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,12 @@ import { tables } from "./tables"
|
||||||
import { selectedScreen } from "./screens"
|
import { selectedScreen } from "./screens"
|
||||||
import { viewsV2 } from "./viewsV2"
|
import { viewsV2 } from "./viewsV2"
|
||||||
import { findComponentsBySettingsType } from "@/helpers/screen"
|
import { findComponentsBySettingsType } from "@/helpers/screen"
|
||||||
import { UIDatasourceType, Screen } from "@budibase/types"
|
import { UIDatasourceType, Screen, Component } from "@budibase/types"
|
||||||
import { queries } from "./queries"
|
import { queries } from "./queries"
|
||||||
import { views } from "./views"
|
import { views } from "./views"
|
||||||
import { bindings, featureFlag } from "@/helpers"
|
import { bindings, featureFlag } from "@/helpers"
|
||||||
import { getBindableProperties } from "@/dataBinding"
|
import { getBindableProperties } from "@/dataBinding"
|
||||||
|
import { findAllComponents } from "@/helpers/components"
|
||||||
|
|
||||||
function reduceBy<TItem extends {}, TKey extends keyof TItem>(
|
function reduceBy<TItem extends {}, TKey extends keyof TItem>(
|
||||||
key: TKey,
|
key: TKey,
|
||||||
|
@ -111,3 +112,16 @@ export const screenComponentErrors = derived(
|
||||||
return getInvalidDatasources($selectedScreen, datasources)
|
return getInvalidDatasources($selectedScreen, datasources)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const screenComponents = derived(
|
||||||
|
[selectedScreen],
|
||||||
|
([$selectedScreen]) => {
|
||||||
|
if (!$selectedScreen) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const allComponents = findAllComponents(
|
||||||
|
$selectedScreen.props
|
||||||
|
) as Component[]
|
||||||
|
return allComponents
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue