mirror of https://github.com/nocodb/nocodb
braks
2 years ago
10 changed files with 217 additions and 197 deletions
@ -1,98 +1,53 @@
|
||||
import type { ColumnType } from 'nocodb-sdk' |
||||
import { SqlUiFactory, UITypes, isVirtualCol } from 'nocodb-sdk' |
||||
import type { ComputedRef, Ref } from 'vue' |
||||
import { computed, useProject } from '#imports' |
||||
import { computed, dataTypeLow, isBoolean, isPrimary, isString, isTextArea, useProject } from '#imports' |
||||
|
||||
export function useColumn(column: Ref<ColumnType | undefined>) { |
||||
const { project } = useProject() |
||||
|
||||
const uiDatatype: ComputedRef<UITypes> = computed(() => column.value?.uidt as UITypes) |
||||
const data = computed(() => { |
||||
if (!column.value) return null |
||||
|
||||
const abstractType = computed(() => { |
||||
// kludge: CY test hack; column.value is being received NULL during attach cell delete operation
|
||||
return (column.value && isVirtualCol(column.value)) || !column.value |
||||
? null |
||||
: SqlUiFactory.create( |
||||
project.value?.bases?.[0]?.type ? { client: project.value.bases[0].type } : { client: 'mysql2' }, |
||||
).getAbstractType(column.value) |
||||
}) |
||||
|
||||
const dataTypeLow = computed(() => column.value?.dt?.toLowerCase()) |
||||
const isBoolean = computed(() => abstractType.value === 'boolean') |
||||
const isString = computed(() => uiDatatype.value === UITypes.SingleLineText || abstractType.value === 'string') |
||||
const isTextArea = computed(() => uiDatatype.value === UITypes.LongText) |
||||
const isInt = computed(() => abstractType.value === 'integer') |
||||
const isFloat = computed(() => abstractType.value === 'float' || abstractType.value === UITypes.Number) |
||||
const isDate = computed(() => abstractType.value === 'date' || uiDatatype.value === UITypes.Date) |
||||
const isYear = computed(() => abstractType.value === 'year' || uiDatatype.value === UITypes.Year) |
||||
const isTime = computed(() => abstractType.value === 'time' || uiDatatype.value === UITypes.Time) |
||||
const isDateTime = computed(() => abstractType.value === 'datetime' || uiDatatype.value === UITypes.DateTime) |
||||
const isJSON = computed(() => uiDatatype.value === UITypes.JSON) |
||||
const isEnum = computed(() => uiDatatype.value === UITypes.SingleSelect) |
||||
const isSingleSelect = computed(() => uiDatatype.value === UITypes.SingleSelect) |
||||
const isSet = computed(() => uiDatatype.value === UITypes.MultiSelect) |
||||
const isMultiSelect = computed(() => uiDatatype.value === UITypes.MultiSelect) |
||||
const isURL = computed(() => uiDatatype.value === UITypes.URL) |
||||
const isEmail = computed(() => uiDatatype.value === UITypes.Email) |
||||
const isAttachment = computed(() => uiDatatype.value === UITypes.Attachment) |
||||
const isRating = computed(() => uiDatatype.value === UITypes.Rating) |
||||
const isCurrency = computed(() => uiDatatype.value === UITypes.Currency) |
||||
const isPhoneNumber = computed(() => uiDatatype.value === UITypes.PhoneNumber) |
||||
const isDecimal = computed(() => uiDatatype.value === UITypes.Decimal) |
||||
const isDuration = computed(() => uiDatatype.value === UITypes.Duration) |
||||
const isPercent = computed(() => uiDatatype.value === UITypes.Percent) |
||||
const isSpecificDBType = computed(() => uiDatatype.value === UITypes.SpecificDBType) |
||||
const isAutoSaved = computed(() => |
||||
[ |
||||
UITypes.SingleLineText, |
||||
UITypes.LongText, |
||||
UITypes.PhoneNumber, |
||||
UITypes.Email, |
||||
UITypes.URL, |
||||
UITypes.Number, |
||||
UITypes.Decimal, |
||||
UITypes.Percent, |
||||
UITypes.Count, |
||||
UITypes.AutoNumber, |
||||
UITypes.SpecificDBType, |
||||
UITypes.Geometry, |
||||
UITypes.Duration, |
||||
].includes(uiDatatype.value), |
||||
) |
||||
const isManualSaved = computed(() => [UITypes.Currency].includes(uiDatatype.value)) |
||||
const isPrimary = computed(() => column.value?.pv) |
||||
const isPrimaryKey = computed(() => !!column.value?.pk) |
||||
const abstractType = computed(() => { |
||||
// kludge: CY test hack; column.value is being received NULL during attach cell delete operation
|
||||
return (column.value && isVirtualCol(column.value)) || !column.value |
||||
? null |
||||
: SqlUiFactory.create( |
||||
project.value?.bases?.[0]?.type ? { client: project.value.bases[0].type } : { client: 'mysql2' }, |
||||
).getAbstractType(column.value) |
||||
}) |
||||
|
||||
return { |
||||
abstractType, |
||||
dataTypeLow, |
||||
isPrimary, |
||||
isBoolean, |
||||
isString, |
||||
isTextArea, |
||||
isInt, |
||||
isFloat, |
||||
isDate, |
||||
isYear, |
||||
isTime, |
||||
isDateTime, |
||||
isJSON, |
||||
isEnum, |
||||
isSet, |
||||
isURL, |
||||
isEmail, |
||||
isAttachment, |
||||
isRating, |
||||
isCurrency, |
||||
isDecimal, |
||||
isDuration, |
||||
isAutoSaved, |
||||
isManualSaved, |
||||
isSingleSelect, |
||||
isMultiSelect, |
||||
isPercent, |
||||
isPhoneNumber, |
||||
isSpecificDBType, |
||||
isPrimaryKey, |
||||
} |
||||
return { |
||||
abstractType, |
||||
dataTypeLow: dataTypeLow(column.value), |
||||
isPrimary: isPrimary(column.value), |
||||
isBoolean: isBoolean(abstractType.value), |
||||
isString: isString(column.value, abstractType.value), |
||||
isTextArea: isTextArea(column.value), |
||||
isInt, |
||||
isFloat, |
||||
isDate, |
||||
isYear, |
||||
isTime, |
||||
isDateTime, |
||||
isJSON, |
||||
isEnum, |
||||
isSet, |
||||
isURL, |
||||
isEmail, |
||||
isAttachment, |
||||
isRating, |
||||
isCurrency, |
||||
isDecimal, |
||||
isDuration, |
||||
isAutoSaved, |
||||
isManualSaved, |
||||
isSingleSelect, |
||||
isMultiSelect, |
||||
isPercent, |
||||
isPhoneNumber, |
||||
isSpecificDBType, |
||||
} |
||||
}) |
||||
} |
||||
|
@ -1,36 +1,24 @@
|
||||
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' |
||||
import { RelationTypes, UITypes } from 'nocodb-sdk' |
||||
import type { ColumnType } from 'nocodb-sdk' |
||||
import type { Ref } from 'vue' |
||||
import { computed } from '#imports' |
||||
import { computed, isBt, isCount, isFormula, isHm, isLookup, isMm, isRollup } from '#imports' |
||||
import HasMany from '~/components/virtual-cell/HasMany.vue' |
||||
import ManyToMany from '~/components/virtual-cell/ManyToMany.vue' |
||||
import BelongsTo from '~/components/virtual-cell/BelongsTo.vue' |
||||
import Lookup from '~/components/virtual-cell/Lookup.vue' |
||||
import Rollup from '~/components/virtual-cell/Rollup.vue' |
||||
import Formula from '~/components/virtual-cell/Formula.vue' |
||||
import Count from '~/components/virtual-cell/Count.vue' |
||||
|
||||
export function useVirtualCell(column: Ref<ColumnType | undefined>) { |
||||
const isHm = computed( |
||||
() => |
||||
column.value?.uidt === UITypes.LinkToAnotherRecord && |
||||
(<LinkToAnotherRecordType>column.value?.colOptions).type === RelationTypes.HAS_MANY, |
||||
) |
||||
const isMm = computed( |
||||
() => |
||||
column.value?.uidt === UITypes.LinkToAnotherRecord && |
||||
(<LinkToAnotherRecordType>column.value?.colOptions).type === RelationTypes.MANY_TO_MANY, |
||||
) |
||||
const isBt = computed( |
||||
() => |
||||
column.value?.uidt === UITypes.LinkToAnotherRecord && |
||||
(<LinkToAnotherRecordType>column.value?.colOptions).type === RelationTypes.BELONGS_TO, |
||||
) |
||||
const isLookup = computed(() => column.value?.uidt === UITypes.Lookup) |
||||
const isRollup = computed(() => column.value?.uidt === UITypes.Rollup) |
||||
const isFormula = computed(() => column.value?.uidt === UITypes.Formula) |
||||
const isCount = computed(() => column.value?.uidt === UITypes.Count) |
||||
return computed(() => { |
||||
if (!column.value) return null |
||||
|
||||
return { |
||||
isHm, |
||||
isMm, |
||||
isBt, |
||||
isLookup, |
||||
isRollup, |
||||
isFormula, |
||||
isCount, |
||||
} |
||||
if (isHm(column.value)) return HasMany |
||||
if (isMm(column.value)) return ManyToMany |
||||
if (isBt(column.value)) return BelongsTo |
||||
if (isLookup(column.value)) return Lookup |
||||
if (isRollup(column.value)) return Rollup |
||||
if (isFormula(column.value)) return Formula |
||||
if (isCount(column.value)) return Count |
||||
}) |
||||
} |
||||
|
@ -0,0 +1,59 @@
|
||||
import type { ColumnType, ProjectType } from 'nocodb-sdk' |
||||
import { SqlUiFactory, UITypes, isVirtualCol } from 'nocodb-sdk' |
||||
|
||||
export const abstractType = (column: ColumnType, project: ProjectType) => { |
||||
// kludge: CY test hack; column.value is being received NULL during attach cell delete operation
|
||||
return (column && isVirtualCol(column)) || !column |
||||
? null |
||||
: SqlUiFactory.create(project.bases?.[0]?.type ? { client: project.bases[0].type } : { client: 'mysql2' }).getAbstractType( |
||||
column, |
||||
) |
||||
} |
||||
|
||||
export const dataTypeLow = (column: ColumnType) => column.dt?.toLowerCase() |
||||
export const isBoolean = (abstractType: any) => abstractType === 'boolean' |
||||
export const isString = (column: ColumnType, abstractType: any) => |
||||
column.uidt === UITypes.SingleLineText || abstractType === 'string' |
||||
export const isTextArea = (column: ColumnType) => column.uidt === UITypes.LongText |
||||
export const isInt = (column: ColumnType, abstractType: any) => abstractType === 'integer' |
||||
export const isFloat = (column: ColumnType, abstractType: any) => abstractType === 'float' || abstractType === UITypes.Number |
||||
export const isDate = (column: ColumnType, abstractType: any) => abstractType === 'date' || column.uidt === UITypes.Date |
||||
export const isYear = (column: ColumnType, abstractType: any) => abstractType === 'year' || column.uidt === UITypes.Year |
||||
export const isTime = (column: ColumnType, abstractType: any) => abstractType === 'time' || column.uidt === UITypes.Time |
||||
export const isDateTime = (column: ColumnType, abstractType: any) => |
||||
abstractType === 'datetime' || column.uidt === UITypes.DateTime |
||||
export const isJSON = (column: ColumnType) => column.uidt === UITypes.JSON |
||||
export const isEnum = (column: ColumnType) => column.uidt === UITypes.SingleSelect |
||||
export const isSingleSelect = (column: ColumnType) => column.uidt === UITypes.SingleSelect |
||||
export const isSet = (column: ColumnType) => column.uidt === UITypes.MultiSelect |
||||
export const isMultiSelect = (column: ColumnType) => column.uidt === UITypes.MultiSelect |
||||
export const isURL = (column: ColumnType) => column.uidt === UITypes.URL |
||||
export const isEmail = (column: ColumnType) => column.uidt === UITypes.Email |
||||
export const isAttachment = (column: ColumnType) => column.uidt === UITypes.Attachment |
||||
export const isRating = (column: ColumnType) => column.uidt === UITypes.Rating |
||||
export const isCurrency = (column: ColumnType) => column.uidt === UITypes.Currency |
||||
export const isPhoneNumber = (column: ColumnType) => column.uidt === UITypes.PhoneNumber |
||||
export const isDecimal = (column: ColumnType) => column.uidt === UITypes.Decimal |
||||
export const isDuration = (column: ColumnType) => column.uidt === UITypes.Duration |
||||
export const isPercent = (column: ColumnType) => column.uidt === UITypes.Percent |
||||
export const isSpecificDBType = (column: ColumnType) => column.uidt === UITypes.SpecificDBType |
||||
export const isAutoSaved = (column: ColumnType) => |
||||
[ |
||||
UITypes.SingleLineText, |
||||
UITypes.LongText, |
||||
UITypes.PhoneNumber, |
||||
UITypes.Email, |
||||
UITypes.URL, |
||||
UITypes.Number, |
||||
UITypes.Decimal, |
||||
UITypes.Percent, |
||||
UITypes.Count, |
||||
UITypes.AutoNumber, |
||||
UITypes.SpecificDBType, |
||||
UITypes.Geometry, |
||||
].includes(column.uidt as UITypes) |
||||
|
||||
export const isManualSaved = (column: ColumnType) => |
||||
[UITypes.Currency, UITypes.Year, UITypes.Time, UITypes.Duration].includes(column.uidt as UITypes) |
||||
|
||||
export const isPrimary = (column: ColumnType) => column.pv |
@ -0,0 +1,16 @@
|
||||
import type { ColumnType, LinkToAnotherRecordType } from 'nocodb-sdk' |
||||
import { RelationTypes, UITypes } from 'nocodb-sdk' |
||||
|
||||
export const isHm = (column: ColumnType) => |
||||
column.uidt === UITypes.LinkToAnotherRecord && (<LinkToAnotherRecordType>column.colOptions).type === RelationTypes.HAS_MANY |
||||
|
||||
export const isMm = (column: ColumnType) => |
||||
column.uidt === UITypes.LinkToAnotherRecord && (<LinkToAnotherRecordType>column.colOptions).type === RelationTypes.MANY_TO_MANY |
||||
|
||||
export const isBt = (column: ColumnType) => |
||||
column.uidt === UITypes.LinkToAnotherRecord && (<LinkToAnotherRecordType>column.colOptions).type === RelationTypes.BELONGS_TO |
||||
|
||||
export const isLookup = (column: ColumnType) => column.uidt === UITypes.Lookup |
||||
export const isRollup = (column: ColumnType) => column.uidt === UITypes.Rollup |
||||
export const isFormula = (column: ColumnType) => column.uidt === UITypes.Formula |
||||
export const isCount = (column: ColumnType) => column.uidt === UITypes.Count |
Loading…
Reference in new issue