Browse Source

feat: add links option with LTAR and in edit

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5848/head
Pranav C 1 year ago
parent
commit
8f5ac4af88
  1. 8
      packages/nc-gui/components/smartsheet/column/EditOrAdd.vue
  2. 46
      packages/nc-gui/components/smartsheet/column/LinkOptions.vue
  3. 6
      packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue
  4. 22
      packages/nocodb/src/helpers/columnHelpers.ts
  5. 3
      packages/nocodb/src/services/columns.service.ts

8
packages/nc-gui/components/smartsheet/column/EditOrAdd.vue

@ -58,7 +58,7 @@ const advancedDbOptions = ref(false)
const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber]
const onlyNameUpdateOnEditColumns = [UITypes.LinkToAnotherRecord, UITypes.Lookup, UITypes.Rollup]
const onlyNameUpdateOnEditColumns = [UITypes.LinkToAnotherRecord, UITypes.Lookup, UITypes.Rollup, UITypes.Links]
const geoDataToggleCondition = (t: { name: UITypes }) => {
return betaFeatureToggleState.show ? betaFeatureToggleState.show : !t.name.includes(UITypes.GeoData)
@ -209,7 +209,11 @@ useEventListener('keydown', (e: KeyboardEvent) => {
<LazySmartsheetColumnDateTimeOptions v-if="formState.uidt === UITypes.DateTime" v-model:value="formState" />
<LazySmartsheetColumnRollupOptions v-if="formState.uidt === UITypes.Rollup" v-model:value="formState" />
<LazySmartsheetColumnLinkedToAnotherRecordOptions
v-if="!isEdit && (formState.uidt === UITypes.LinkToAnotherRecord || formState.uidt === UITypes.Links)"
v-if="!isEdit && (formState.uidt === UITypes.LinkToAnotherRecord)"
v-model:value="formState"
/>
<LazySmartsheetColumnLinkOptions
v-if="formState.uidt === UITypes.Links"
v-model:value="formState"
/>
<LazySmartsheetColumnSpecificDBTypeOptions v-if="formState.uidt === UITypes.SpecificDBType" />

46
packages/nc-gui/components/smartsheet/column/LinkOptions.vue

@ -0,0 +1,46 @@
<script setup lang="ts">
import { useGlobal, useVModel } from '#imports'
const props = defineProps<{
value: any
}>()
const emit = defineEmits(['update:value'])
const vModel = useVModel(props, 'value', emit)
const validators = {}
const { setAdditionalValidations, validateInfos } = useColumnCreateStoreOrThrow()
const { appInfo } = useGlobal()
const searchValue = ref<string>('')
setAdditionalValidations({
...validators,
})
// set default valueO
vModel.value.meta = {
singular: '',
plural: '',
...vModel.value.meta,
}
</script>
<template>
<a-row class="my-2" gutter="8">
<a-col :span="12">
<a-form-item v-bind="validateInfos['meta.singular']" label="Singular Label">
<a-input v-model:value="vModel.meta.singular" class="!w-full nc-link-singular" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item v-bind="validateInfos['meta.plural']" label="Plural Label">
<a-input v-model:value="vModel.meta.plural" class="!w-full nc-link-plural" />
</a-form-item>
</a-col>
</a-row>
</template>

6
packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue

@ -85,6 +85,12 @@ const filterOption = (value: string, option: { key: string }) => option.key.toLo
</a-select-option>
</a-select>
</a-form-item>
<LazySmartsheetColumnLinkOptions
v-model:value="vModel"
/>
</div>
<template v-if="!isXcdbBase">
<div

22
packages/nocodb/src/helpers/columnHelpers.ts

@ -1,9 +1,11 @@
import { customAlphabet } from 'nanoid';
import { UITypes } from 'nocodb-sdk';
import { GridViewColumn, RollupColumn } from '../models'
import { pluralize, singularize } from 'inflection';
import { GridViewColumn } from '../models';
import Column from '../models/Column';
import { getUniqueColumnAliasName } from '../helpers/getUniqueName';
import validateParams from '../helpers/validateParams';
import type { RollupColumn } from '../models';
import type {
BoolType,
ColumnReqType,
@ -31,6 +33,7 @@ export async function createHmAndBtColumn(
fkColName?: string,
virtual: BoolType = false,
isSystemCol = false,
columnMeta = null
) {
// save bt column
{
@ -79,6 +82,7 @@ export async function createHmAndBtColumn(
if (!isSystemCol)
await populateRollupForLTAR({
column: col,
columnMeta
});
}
}
@ -213,9 +217,13 @@ export const generateFkName = (parent: TableType, child: TableType) => {
return constraintName;
};
export async function populateRollupForLTAR({ column }: { column: Column }) {
export async function populateRollupForLTAR({
column,
columnMeta
}: {
column: Column;
columnMeta: any;
}) {
const model = await column.getModel();
const views = await model.getViews();
@ -227,6 +235,11 @@ export async function populateRollupForLTAR({ column }: { column: Column }) {
const pkId =
relatedModel.primaryKey?.id || (await relatedModel.getColumns())[0]?.id;
const meta = {
plural: columnMeta?.plural || pluralize(relatedModel.title),
singular: columnMeta?.singular || singularize(relatedModel.title),
};
await Column.insert<RollupColumn>({
uidt: UITypes.Links,
title: getUniqueColumnAliasName(
@ -237,6 +250,7 @@ export async function populateRollupForLTAR({ column }: { column: Column }) {
fk_model_id: model.id,
rollup_function: 'count',
fk_relation_column_id: column.id,
meta,
});
const viewCol = await GridViewColumn.list(views[0].id).then((cols) =>

3
packages/nocodb/src/services/columns.service.ts

@ -1647,6 +1647,7 @@ export class ColumnsService {
(param.column as LinkToAnotherColumnReqType).title,
foreignKeyName,
(param.column as LinkToAnotherColumnReqType).virtual,
param.column['meta']
);
} else if ((param.column as LinkToAnotherColumnReqType).type === 'mm') {
const aTn = `${param.project?.prefix ?? ''}_nc_m2m_${randomID()}`;
@ -1808,9 +1809,11 @@ export class ColumnsService {
await populateRollupForLTAR({
column: col1,
columnMeta: param.column['meta']
});
await populateRollupForLTAR({
column: col2,
columnMeta: param.column['meta']
});
// todo: create index for virtual relations as well

Loading…
Cancel
Save