π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
add record template outside
Ramesh Mane524f7ed28954
diff --git a/packages/nc-gui/components/smartsheet/expanded-form/presentors/Fields/ColumnList.vue b/packages/nc-gui/components/smartsheet/expanded-form/presentors/Fields/ColumnList.vueindex 5300b0f6b6..4437b28dfe 100644--- a/packages/nc-gui/components/smartsheet/expanded-form/presentors/Fields/ColumnList.vue+++ b/packages/nc-gui/components/smartsheet/expanded-form/presentors/Fields/ColumnList.vue@@ -1,5 +1,5 @@<script setup lang="ts">-import { type ColumnType, PermissionEntity, PermissionKey, isLinksOrLTAR, isVirtualCol } from 'nocodb-sdk'+import { type ColumnType, type LinkToAnotherRecordType, type TableType, PermissionEntity, PermissionKey, isLinksOrLTAR, isVirtualCol } from 'nocodb-sdk'const props = defineProps<{fields: ColumnType[]@@ -17,12 +17,69 @@ const isPublic = inject(IsPublicInj, ref(false))const meta = inject(MetaInj, ref())+const isTemplateMode = inject(IsTemplateModeInj, ref(false))+const { isUIAllowed } = useRoles()const { isMobileMode } = useGlobal()+const { getMeta } = useMetas()++const { open: openExpandedFormDetached } = useExpandedFormDetached()+const readOnly = computed(() => !isUIAllowed('dataEdit') || isPublic.value || isSqlView.value)+const addBlueprintForColumn = async (col: ColumnType) => {+ const colOptions = col.colOptions as LinkToAnotherRecordType+ const relatedTableId = colOptions?.fk_related_model_id+ const baseId = meta.value?.base_id+ if (!relatedTableId || !baseId) return++ try {+ const relatedMeta = (await getMeta(baseId, relatedTableId)) as TableType+ if (!relatedMeta) return++ openExpandedFormDetached({+ isOpen: true,+ row: { row: {}, oldRow: {}, rowMeta: { new: true } },+ meta: relatedMeta,+ loadRow: false,+ useMetaFields: true,+ blueprintMode: true,+ newRecordSubmitBtnText: 'Save Blueprint',+ newRecordHeader: `New ${relatedMeta.title} (Blueprint)`,+ createdRecord: (record: Record<string, any>) => {+ const blueprint = { ...record, _isBlueprint: true }+ // Ensure ltarState structure exists+ if (!_row.value.rowMeta) _row.value.rowMeta = {}+ if (!_row.value.rowMeta.ltarState) _row.value.rowMeta.ltarState = {}++ if (isHm(col) || isMm(col)) {+ if (!_row.value.rowMeta.ltarState[col.title!]) {+ _row.value.rowMeta.ltarState[col.title!] = []+ }+ _row.value.rowMeta.ltarState[col.title!].push(blueprint)+ } else {+ // BT or OO β single linked record+ _row.value.rowMeta.ltarState[col.title!] = blueprint+ }+ },+ })+ } catch (e) {+ console.error('Failed to open blueprint form:', e)+ }+}++const getRelatedTableName = (col: ColumnType): string => {+ const colOptions = col.colOptions as LinkToAnotherRecordType+ const relatedTableId = colOptions?.fk_related_model_id+ const baseId = meta.value?.base_id+ if (!relatedTableId || !baseId) return 'Sub Record'+ const { getMetaByKey } = useMetas()+ const relatedMeta = getMetaByKey(baseId, relatedTableId)+ return relatedMeta?.title || 'Sub Record'+}+const showCol = (col: ColumnType) => {return props.showColCallback?.(col) || !isVirtualCol(col) || !isNew.value || isLinksOrLTAR(col)}@@ -164,6 +221,30 @@ const isSyncedColumn = (column: ColumnType) => meta.value?.synced && column?.rea/></div></div>++ <!-- Add Blueprint button below LTAR fields in template mode -->+ <div+ v-if="isTemplateMode && isLinksOrLTAR(col) && !readOnly"+ class="flex items-center"+ :class="{+ 'flex-row <lg:pl-0': !props.forceVerticalMode,+ 'pl-0': props.forceVerticalMode,+ }"+ >+ <div+ v-if="!props.forceVerticalMode"+ class="flex-none w-45 <lg:hidden sm:mx-2"+ />+ <NcTooltip placement="bottom">+ <template #title>Define a new record that will be created and linked each time this template is used</template>+ <NcButton type="secondary" size="xs" class="!mt-1" @click.stop="addBlueprintForColumn(col)">+ <div class="flex items-center gap-1">+ <GeneralIcon icon="plus" class="h-3.5 w-3.5" />+ <span>Add {{ getRelatedTableName(col) }} Template</span>+ </div>+ </NcButton>+ </NcTooltip>+ </div></div></template>diff --git a/packages/nc-gui/components/virtual-cell/components/ItemChip.vue b/packages/nc-gui/components/virtual-cell/components/ItemChip.vueindex a1e9cc126b..633f05e375 100644--- a/packages/nc-gui/components/virtual-cell/components/ItemChip.vue+++ b/packages/nc-gui/components/virtual-cell/components/ItemChip.vue@@ -21,7 +21,9 @@ const emit = defineEmits(['unlink'])const { item, value, column, readonly: readonlyProp } = toRefs(props)-const { relatedTableMeta, externalBaseUserRoles } = useLTARStoreOrThrow()!+const { relatedTableMeta, externalBaseUserRoles, row: parentRow } = useLTARStoreOrThrow()!++const injectedColumn = inject(ColumnInj, ref())const { isUIAllowed } = useRoles()@@ -43,15 +45,58 @@ const reloadTrigger = inject(ReloadRowDataHookInj, createEventHook())const reloadViewDataTrigger = inject(ReloadViewDataHookInj, createEventHook())+const isBlueprint = computed(() => !!item.value?._isBlueprint)+const isClickDisabled = computed(() => {return (!active.value && !isExpandedForm.value) || isPublic.value || isForm.value || readonlyProp.value})const { open } = useExpandedFormDetached()+function openBlueprintEditor() {+ if (isClickDisabled.value) return++ // Clone the blueprint data (exclude internal flags for the form)+ const { _isBlueprint, ...blueprintData } = item.value++ open({+ isOpen: true,+ row: { row: { ...blueprintData }, oldRow: {}, rowMeta: { new: true } },+ meta: relatedTableMeta.value,+ loadRow: false,+ useMetaFields: true,+ blueprintMode: true,+ newRecordSubmitBtnText: 'Save Blueprint',+ newRecordHeader: `Edit ${relatedTableMeta.value?.title} (Blueprint)`,+ createdRecord: (record: Record<string, any>) => {+ const updatedBlueprint = { ...record, _isBlueprint: true }+ const colTitle = injectedColumn.value?.title+ if (!colTitle || !parentRow.value?.rowMeta?.ltarState) return++ const ltarState = parentRow.value.rowMeta.ltarState+ if (Array.isArray(ltarState[colTitle])) {+ // Find and replace the old blueprint in the array+ const idx = ltarState[colTitle].indexOf(item.value)+ if (idx !== -1) {+ ltarState[colTitle].splice(idx, 1, updatedBlueprint)+ }+ } else {+ // BT/OO β single value, just replace+ ltarState[colTitle] = updatedBlueprint+ }+ },+ })+}+function openExpandedForm() {if (isClickDisabled.value) return+ // Blueprint records open in blueprint editor instead+ if (isBlueprint.value) {+ openBlueprintEditor()+ return+ }+const rowId = extractPkFromRow(item.value, relatedTableMeta.value.columns as ColumnType[])if (!rowId) return@@ -113,7 +158,9 @@ export default {:class="{'px-1 rounded-full flex-1': !isAttachment(column),'border-nc-border-gray-medium rounded border-1 blue-chip':- border && ![UITypes.Attachment, UITypes.MultiSelect, UITypes.SingleSelect].includes(column.uidt),+ !isBlueprint && border && ![UITypes.Attachment, UITypes.MultiSelect, UITypes.SingleSelect].includes(column.uidt),+ 'rounded border-1 border-dashed blueprint-chip':+ isBlueprint && border && ![UITypes.Attachment, UITypes.MultiSelect, UITypes.SingleSelect].includes(column.uidt),}"><LazySmartsheetCell@@ -222,5 +269,17 @@ export default {@apply !block text-ellipsis;}}++ .blueprint-chip {+ @apply !bg-nc-bg-gray-extralight !border-nc-border-gray-medium px-2 py-[3px] rounded-lg;+ &,+ & * {+ @apply !text-nc-content-gray-muted !bg-nc-bg-gray-extralight;+ }++ :deep(.clamped-text) {+ @apply !block text-ellipsis;+ }+ }}</style>diff --git a/packages/nc-gui/components/virtual-cell/components/LinkedItems.vue b/packages/nc-gui/components/virtual-cell/components/LinkedItems.vueindex ff1e64a250..27738c10b5 100644--- a/packages/nc-gui/components/virtual-cell/components/LinkedItems.vue+++ b/packages/nc-gui/components/virtual-cell/components/LinkedItems.vue@@ -575,19 +575,6 @@ const handleKeyDown = (e: KeyboardEvent) => {{{ isMobileMode ? $t('title.linkMore') : $t('title.linkMoreRecords') }}</div></NcButton>- <NcTooltip v-if="isTemplateMode && isLinkedTableAccessible">- <template #title>Define a new record that will be created and linked each time this template is used</template>- <NcButton- 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" /> Add Blueprint- </div>- </NcButton>- </NcTooltip></div><template v-if="!isNew && childrenList?.pageInfo && +childrenList.pageInfo.totalRows! > childrenListPagination.size"><div class="flex justify-center items-center">diff --git a/packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue b/packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vueindex 17c4efaec6..17b8c625c3 100644--- a/packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue+++ b/packages/nc-gui/components/virtual-cell/components/UnLinkedItems.vue@@ -559,19 +559,6 @@ const handleKeyDown = (e: KeyboardEvent) => {</NcButton></template></PermissionsTooltip>- <NcTooltip v-if="isTemplateMode && isLinkedTableAccessible">- <template #title>Define a new record that will be created and linked each time this template is used</template>- <NcButton- 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" /> Add Blueprint- </div>- </NcButton>- </NcTooltip></div><templatev-if="