Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

nested record creation

Ramesh Manef725427f3eae
diff --git a/packages/nc-gui/components/smartsheet/expanded-form/Detached.vue b/packages/nc-gui/components/smartsheet/expanded-form/Detached.vue
index 95a11a18c1..9d14b8e84b 100644
--- a/packages/nc-gui/components/smartsheet/expanded-form/Detached.vue
+++ b/packages/nc-gui/components/smartsheet/expanded-form/Detached.vue
@@ -21,6 +21,7 @@ const shouldClose = (isVisible: boolean, i: number) => {
:skip-reload="state.skipReload"
:template-mode="state.templateMode"
:template-name="state.templateName"
+ :blueprint-mode="state.blueprintMode"
:new-record-submit-btn-text="state.newRecordSubmitBtnText"
:new-record-header="state.newRecordHeader"
@update:model-value="shouldClose($event, i)"
diff --git a/packages/nc-gui/components/smartsheet/expanded-form/index.vue b/packages/nc-gui/components/smartsheet/expanded-form/index.vue
index 5a56cbe77e..d861caed35 100644
--- a/packages/nc-gui/components/smartsheet/expanded-form/index.vue
+++ b/packages/nc-gui/components/smartsheet/expanded-form/index.vue
@@ -23,6 +23,7 @@ interface Props {
newRecordSubmitBtnText?: string
templateMode?: boolean
templateName?: string
+ blueprintMode?: boolean
expandForm?: (row: Row) => void
maintainDefaultViewOrder?: boolean
allowNullFieldIds?: string[]
@@ -111,6 +112,8 @@ const isPublic = inject(IsPublicInj, ref(false))
provide(MetaInj, activeMeta)
+provide(IsTemplateModeInj, computed(() => !!props.templateMode || !!props.blueprintMode))
+
// override cell event hook to avoid unexpected behavior at form fields
// issue happens when opening expanded form from cell (LTAR/Links)
provide(CanvasSelectCellInj, undefined)
@@ -264,8 +267,8 @@ const isLTARChanged = computed(() => {
})
const isSaveRecordBtnDisabled = computed(() => {
- // In template mode, always allow saving (even empty template)
- if (props.templateMode) return false
+ // In template/blueprint mode, always allow saving (even empty)
+ if (props.templateMode || props.blueprintMode) return false
return changedColumns.value.size === 0 && !isUnsavedFormExist.value && !isLTARChanged.value
})
@@ -328,6 +331,18 @@ const save = async () => {
return
}
+ // Blueprint mode: emit row data as a blueprint (used for LTAR "link a new record" inside templates)
+ if (props.blueprintMode) {
+ isUnsavedFormExist.value = false
+ isExpanded.value = false
+ emits('createdRecord', {
+ ..._row.value.row,
+ _isBlueprint: true,
+ })
+ isSaving.value = false
+ return
+ }
+
let kanbanClbk
if (activeView.value?.type === ViewTypes.KANBAN) {
kanbanClbk = (row: any, isNewRow: boolean) => {
@@ -564,8 +579,8 @@ useActiveKeydownListener(
e.stopPropagation()
- // In template mode, use the save() function which handles template logic
- if (props.templateMode) {
+ // In template/blueprint mode, use the save() function which handles template/blueprint logic
+ if (props.templateMode || props.blueprintMode) {
await save()
return
}
@@ -808,8 +823,8 @@ function onTouchEnd() {
const showSendRecordModal = ref(false)
const visibleMoreOptions = computed(() => {
- // In template mode, hide all extra options
- if (props.templateMode) {
+ // In template/blueprint mode, hide all extra options
+ if (props.templateMode || props.blueprintMode) {
return {
reloadRecord: false,
copyRecordUrl: false,
@@ -854,7 +869,7 @@ export default {
:closable="false"
:footer="null"
:visible="isExpanded"
- :width="templateMode ? 'min(65vw,700px)' : commentsDrawer && isUIAllowed('commentList', baseRoles) ? 'min(80vw,1280px)' : 'min(70vw,768px)'"
+ :width="(templateMode || blueprintMode) ? 'min(65vw,700px)' : commentsDrawer && isUIAllowed('commentList', baseRoles) ? 'min(80vw,1280px)' : 'min(70vw,768px)'"
class="nc-drawer-expanded-form"
:size="isMobileMode ? 'medium' : 'small'"
v-bind="modalProps"
@@ -970,7 +985,7 @@ export default {
</div>
</div>
</div>
- <div v-if="!templateMode" class="ml-auto">
+ <div v-if="!templateMode && !blueprintMode" class="ml-auto">
<SmartsheetExpandedFormViewModeSelector v-model="activeViewMode" :view="view" class="nc-expanded-form-mode-switch" />
</div>
<div v-else class="ml-auto" />
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/components/AddNewRowMenu.vue b/packages/nc-gui/components/smartsheet/grid/canvas/components/AddNewRowMenu.vue
index f25fe1447d..ab34a98211 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/components/AddNewRowMenu.vue
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/components/AddNewRowMenu.vue
@@ -1,4 +1,5 @@
<script setup lang="ts">
+import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk'
import { ViewTypes } from 'nocodb-sdk'
const props = withDefaults(
@@ -47,15 +48,70 @@ const parseTemplateData = (tmpl: any): { fields: Record<string, any>; ltarState:
}
}
+const resolveBlueprintsInLtarState = async (ltarState: Record<string, any>): Promise<Record<string, any>> => {
+ if (!base.value?.id || !meta.value?.columns) return ltarState
+
+ const resolvedState: Record<string, any> = {}
+
+ for (const [colTitle, linkedData] of Object.entries(ltarState)) {
+ const column = meta.value.columns.find((c: ColumnType) => c.title === colTitle)
+ if (!column) {
+ resolvedState[colTitle] = linkedData
+ continue
+ }
+
+ const colOptions = column.colOptions as LinkToAnotherRecordType
+ const relatedTableId = colOptions?.fk_related_model_id
+
+ if (!relatedTableId) {
+ resolvedState[colTitle] = linkedData
+ continue
+ }
+
+ if (Array.isArray(linkedData)) {
+ const resolvedItems = []
+ for (const item of linkedData) {
+ if (item?._isBlueprint) {
+ const { _isBlueprint, ...recordData } = item
+ try {
+ const created = await $api.dbTableRow.create('noco', base.value.id, relatedTableId, recordData)
+ resolvedItems.push(created)
+ } catch (e: any) {
+ console.error(`Failed to create blueprint record in table ${relatedTableId}:`, e)
+ }
+ } else {
+ resolvedItems.push(item)
+ }
+ }
+ resolvedState[colTitle] = resolvedItems
+ } else if (linkedData?._isBlueprint) {
+ const { _isBlueprint, ...recordData } = linkedData
+ try {
+ const created = await $api.dbTableRow.create('noco', base.value.id, relatedTableId, recordData)
+ resolvedState[colTitle] = created
+ } catch (e: any) {
+ console.error(`Failed to create blueprint record in table ${relatedTableId}:`, e)
+ }
+ } else {
+ resolvedState[colTitle] = linkedData
+ }
+ }
+
+ return resolvedState
+}
+
const handleUseTemplate = async (tmpl: any) => {
if (!base.value?.id || !meta.value?.id || !tmpl?.id) return
try {
const { fields, ltarState } = parseTemplateData(tmpl)
+ // Resolve any blueprint records β€” create real records in linked tables first
+ const resolvedLtarState = await resolveBlueprintsInLtarState(ltarState)
+
// Create record via standard row creation API (handles LTAR/Links natively)
await $api.dbTableRow.create('noco', base.value.id, meta.value.id, {
...fields,
- ...ltarState,
+ ...resolvedLtarState,
})
// Increment template usage count
diff --git a/packages/nc-gui/components/smartsheet/toolbar/RecordTemplatesButton.vue b/packages/nc-gui/components/smartsheet/toolbar/RecordTemplatesButton.vue
index 87ddd0a998..ced9f4b366 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/RecordTemplatesButton.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/RecordTemplatesButton.vue
@@ -1,6 +1,6 @@
<script setup lang="ts">
import dayjs from 'dayjs'
-import type { TableType } from 'nocodb-sdk'
+import type { ColumnType, LinkToAnotherRecordType, TableType } from 'nocodb-sdk'
import type { NcTableColumnProps } from '../../../lib/types'
interface TemplateType {
@@ -271,15 +271,75 @@ const onDeleteConfirm = async () => {
}
}
+const resolveBlueprintsInLtarState = async (ltarState: Record<string, any>): Promise<Record<string, any>> => {
+ if (!base.value?.id || !meta.value?.columns) return ltarState
+
+ const resolvedState: Record<string, any> = {}
+
+ for (const [colTitle, linkedData] of Object.entries(ltarState)) {
+ // Find the LTAR column by title to get the related table ID
+ const column = meta.value.columns.find((c: ColumnType) => c.title === colTitle)
+ if (!column) {
+ resolvedState[colTitle] = linkedData
+ continue
+ }
+
+ const colOptions = column.colOptions as LinkToAnotherRecordType
+ const relatedTableId = colOptions?.fk_related_model_id
+
+ if (!relatedTableId) {
+ resolvedState[colTitle] = linkedData
+ continue
+ }
+
+ if (Array.isArray(linkedData)) {
+ // HM or MM β€” array of linked records
+ const resolvedItems = []
+ for (const item of linkedData) {
+ if (item?._isBlueprint) {
+ // Create a real record in the linked table from blueprint data
+ const { _isBlueprint, ...recordData } = item
+ try {
+ const created = await $api.dbTableRow.create('noco', base.value.id, relatedTableId, recordData)
+ resolvedItems.push(created)
+ } catch (e: any) {
+ console.error(`Failed to create blueprint record in table ${relatedTableId}:`, e)
+ // Skip failed blueprints but continue with others
+ }
+ } else {
+ resolvedItems.push(item)
+ }
+ }
+ resolvedState[colTitle] = resolvedItems
+ } else if (linkedData?._isBlueprint) {
+ // BT or OO β€” single linked record
+ const { _isBlueprint, ...recordData } = linkedData
+ try {
+ const created = await $api.dbTableRow.create('noco', base.value.id, relatedTableId, recordData)
+ resolvedState[colTitle] = created
+ } catch (e: any) {
+ console.error(`Failed to create blueprint record in table ${relatedTableId}:`, e)
+ }
+ } else {
+ resolvedState[colTitle] = linkedData
+ }
+ }
+
+ return resolvedState
+}
+
const handleUseTemplate = async (tmpl: TemplateType) => {
if (!tmpl.id || !base.value?.id || !meta.value?.id) return
try {
const { fields, ltarState } = parseTemplateData(tmpl)
+ // Resolve any blueprint records β€” create real records in linked tables first
+ const resolvedLtarState = await resolveBlueprintsInLtarState(ltarState)
+
// Create record via standard row creation API (handles LTAR/Links natively)
await $api.dbTableRow.create('noco', base.value.id, meta.value.id, {
...fields,
- ...ltarState,
+ ...resolvedLtarState,
})
// Increment template usage count
diff --git a/packages/nc-gui/components/virtual-cell/components/LinkedItems.vue b/packages/nc-gui/components/virtual-cell/components/LinkedItems.vue
index eaf4f5bcf3..f5cc4b385b 100644
--- a/packages/nc-gui/components/virtual-cell/components/LinkedItems.vue
+++ b/packages/nc-gui/components/virtual-cell/components/LinkedItems.vue
@@ -25,10 +25,14 @@ const isForm = inject(IsFormInj, ref(false))
const isPublic = inject(IsPublicInj, ref(false))
+const isTemplateMode = inject(IsTemplateModeInj, ref(false))
+
const isExpandedFormCloseAfterSave = ref(false)
const isNewRecord = ref(false)
+const isBlueprintMode = ref(false)
+
const injectedColumn = inject(ColumnInj, ref())
const readOnly = inject(ReadonlyInj, ref(false))
@@ -168,6 +172,17 @@ const addNewRecord = () => {
expandedFormDlg.value = true
isExpandedFormCloseAfterSave.value = true
isNewRecord.value = true
+ isBlueprintMode.value = false
+}
+
+const addNewBlueprintRecord = () => {
+ if (!isLinkedTableAccessible.value) return
+
+ expandedFormRow.value = {}
+ expandedFormDlg.value = true
+ isExpandedFormCloseAfterSave.value = true
+ isNewRecord.value = true
+ isBlueprintMode.value = true
}
const reloadViewDataListener = withLoading((params) => {
@@ -184,6 +199,16 @@ onBeforeUnmount(() => {
})
const onCreatedRecord = async (record: any) => {
+ // Blueprint mode: store the record data as a blueprint in ltarState (no real record created)
+ if (isBlueprintMode.value) {
+ const blueprint = { ...record, _isBlueprint: true }
+ await addLTARRef(blueprint, injectedColumn?.value as ColumnType)
+ loadChildrenList(false, state.value)
+ isBlueprintMode.value = false
+ isNewRecord.value = false
+ return
+ }
+
reloadTrigger?.trigger({
shouldShowLoading: false,
})
@@ -549,6 +574,17 @@ const handleKeyDown = (e: KeyboardEvent) => {
{{ isMobileMode ? $t('title.linkMore') : $t('title.linkMoreRecords') }}
</div>
</NcButton>
+ <NcButton
+ v-if="isTemplateMode && isLinkedTableAccessible"
+ size="small"
+ class="!hover:(bg-nc-bg-default text-nc-content-brand) !h-7 !text-small"
+ type="secondary"
+ @click="addNewBlueprintRecord"
+ >
+ <div class="flex items-center gap-1">
+ <MdiPlus v-if="!isMobileMode" class="h-4 w-4" /> Link a New Record
+ </div>
+ </NcButton>
</div>
<template v-if="!isNew && childrenList?.pageInfo && +childrenList.pageInfo.totalRows! > childrenListPagination.size">
<div class="flex justify-center items-center">
@@ -567,16 +603,9 @@ const handleKeyDown = (e: KeyboardEvent) => {
<LazySmartsheetExpandedForm
v-if="expandedFormRow && expandedFormDlg"
v-model="expandedFormDlg"
- :load-row="!isPublic"
+ :load-row="!isPublic && !isBlueprintMode"
:close-after-save="isExpandedFormCloseAfterSave"
:meta="relatedTableMeta"
- :new-record-header="
- isExpandedFormCloseAfterSave
- ? $t('activity.tableNameCreateNewRecord', {
- tableName: relatedTableMeta?.title,
- })
- : undefined
- "
:row="{
row: expandedFormRow,
oldRow: expandedFormRow,
@@ -591,7 +620,9 @@ const handleKeyDown = (e: KeyboardEvent) => {
use-meta-fields
skip-reload
maintain-default-view-order
- :new-record-submit-btn-text="!isNewRecord ? undefined : 'Create & Link'"
+ :blueprint-mode="isBlueprintMode"
+ :new-record-submit-btn-text="!isNewRecord ? undefined : isBlueprintMode ? 'Save Blueprint' : 'Create & Link'"
+ :new-record-header="isBlueprintMode ? `New ${relatedTableMeta?.title} (Blueprint)` : isExpandedFormCloseAfterSave ? $t('activity.tableNameCreateNewRecord', { tableName: relatedTableMeta?.title }) : undefined"
@created-record="onCreatedRecord"
@deleted-record="onDeletedRecord"
/>
diff --git a/packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue b/packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue
index 0779408ccd..99404da083 100644
--- a/packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue
+++ b/packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue
@@ -60,10 +60,14 @@ const { showRecordPlanLimitExceededModal } = useEeConfig()
const isPublic = inject(IsPublicInj, ref(false))
+const isTemplateMode = inject(IsTemplateModeInj, ref(false))
+
const isExpandedFormCloseAfterSave = ref(false)
const isNewRecord = ref(false)
+const isBlueprintMode = ref(false)
+
isChildrenExcludedLoading.value = true
const isForm = inject(IsFormInj, ref(false))
@@ -234,9 +238,30 @@ const addNewRecord = () => {
expandedFormDlg.value = true
isExpandedFormCloseAfterSave.value = true
isNewRecord.value = true
+ isBlueprintMode.value = false
+}
+
+const addNewBlueprintRecord = () => {
+ if (!isLinkedTableAccessible.value) return
+
+ expandedFormRow.value = {}
+ expandedFormDlg.value = true
+ isExpandedFormCloseAfterSave.value = true
+ isNewRecord.value = true
+ isBlueprintMode.value = true
}
const onCreatedRecord = (record: any) => {
+ // Blueprint mode: store the record data as a blueprint in ltarState (no real record created)
+ if (isBlueprintMode.value) {
+ const blueprint = { ...record, _isBlueprint: true }
+ addLTARRef(blueprint, injectedColumn?.value as ColumnType)
+ isBlueprintMode.value = false
+ isNewRecord.value = false
+ vModel.value = false
+ return
+ }
+
addLTARRef(record, injectedColumn?.value as ColumnType)
reloadTrigger?.trigger({
@@ -531,6 +556,17 @@ const handleKeyDown = (e: KeyboardEvent) => {
</NcButton>
</template>
</PermissionsTooltip>
+ <NcButton
+ v-if="isTemplateMode && isLinkedTableAccessible"
+ size="small"
+ class="!hover:(bg-nc-bg-default text-nc-content-brand) !h-7 !text-small"
+ type="secondary"
+ @click="addNewBlueprintRecord"
+ >
+ <div class="flex items-center gap-1">
+ <MdiPlus v-if="!isMobileMode" class="h-4 w-4" /> Link a New Record
+ </div>
+ </NcButton>
</div>
<template
v-if="
@@ -561,16 +597,10 @@ const handleKeyDown = (e: KeyboardEvent) => {
<LazySmartsheetExpandedForm
v-if="expandedFormDlg"
v-model="expandedFormDlg"
- :load-row="!isPublic"
+ :load-row="!isPublic && !isBlueprintMode"
:close-after-save="isExpandedFormCloseAfterSave"
:meta="relatedTableMeta"
- :new-record-header="
- isExpandedFormCloseAfterSave
- ? $t('activity.tableNameCreateNewRecord', {
- tableName: relatedTableMeta?.title,
- })
- : undefined
- "
+ :new-record-header="isBlueprintMode ? `New ${relatedTableMeta?.title} (Blueprint)` : isExpandedFormCloseAfterSave ? $t('activity.tableNameCreateNewRecord', { tableName: relatedTableMeta?.title }) : undefined"
:row="{
row: expandedFormRow,
oldRow: {},
@@ -582,10 +612,11 @@ const handleKeyDown = (e: KeyboardEvent) => {
}"
:row-id="extractPkFromRow(expandedFormRow, relatedTableMeta.columns as ColumnType[])"
:state="newRowState"
+ :blueprint-mode="isBlueprintMode"
use-meta-fields
maintain-default-view-order
skip-reload
- :new-record-submit-btn-text="!isNewRecord ? undefined : 'Create & Link'"
+ :new-record-submit-btn-text="!isNewRecord ? undefined : isBlueprintMode ? 'Save Blueprint' : 'Create & Link'"
@deleted-record="onDeletedRecord"
@created-record="onCreatedRecord"
/>
diff --git a/packages/nc-gui/composables/useExpandedFormDetached/index.ts b/packages/nc-gui/composables/useExpandedFormDetached/index.ts
index 12de41b030..6bf25f3800 100644
--- a/packages/nc-gui/composables/useExpandedFormDetached/index.ts
+++ b/packages/nc-gui/composables/useExpandedFormDetached/index.ts
@@ -15,6 +15,7 @@ export interface UseExpandedFormDetachedProps {
'skipReload'?: boolean
'templateMode'?: boolean
'templateName'?: string
+ 'blueprintMode'?: boolean
'newRecordSubmitBtnText'?: string
'newRecordHeader'?: string
'createdRecord'?: (row: Row['row']) => void
diff --git a/packages/nc-gui/context/index.ts b/packages/nc-gui/context/index.ts
index 7074cab1e0..4d44806ba4 100644
--- a/packages/nc-gui/context/index.ts
+++ b/packages/nc-gui/context/index.ts
@@ -150,6 +150,8 @@ export const ExtensionConfigInj: InjectionKey<Ref<ExtensionConfigInjType> | Comp
export const IsOrgBillingInj: InjectionKey<Ref<boolean>> = Symbol('is-org-billing-injection')
+export const IsTemplateModeInj: InjectionKey<Ref<boolean>> = Symbol('is-template-mode-injection')
+
export const WorkflowVariableInj: InjectionKey<{
selectedNodeId: Ref<string | null>
getAvailableVariablesFlat: (nodeId: string) => any[]