Browse Source

Merge pull request #7281 from nocodb/nc-fix/formula-revamp

Nc fix/formula revamp
pull/7285/head
Raju Udava 11 months ago committed by GitHub
parent
commit
9f3b2f13dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      packages/nc-gui/components/smartsheet/column/EditOrAdd.vue
  2. 190
      packages/nc-gui/components/smartsheet/column/FormulaOptions.vue
  3. 254
      packages/nocodb-sdk/src/lib/formulaHelpers.ts

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

@ -81,6 +81,10 @@ const columnToValidate = [UITypes.Email, UITypes.URL, UITypes.PhoneNumber]
const onlyNameUpdateOnEditColumns = [UITypes.LinkToAnotherRecord, UITypes.Lookup, UITypes.Rollup, UITypes.Links] const onlyNameUpdateOnEditColumns = [UITypes.LinkToAnotherRecord, UITypes.Lookup, UITypes.Rollup, UITypes.Links]
// To close column type dropdown on escape and
// close modal only when the type popup is close
const isColumnTypeOpen = ref(false)
const geoDataToggleCondition = (t: { name: UITypes }) => { const geoDataToggleCondition = (t: { name: UITypes }) => {
if (!appInfo.value.ee) return true if (!appInfo.value.ee) return true
@ -199,6 +203,8 @@ onMounted(() => {
}) })
const handleEscape = (event: KeyboardEvent): void => { const handleEscape = (event: KeyboardEvent): void => {
if (isColumnTypeOpen.value) return
if (event.key === 'Escape') emit('cancel') if (event.key === 'Escape') emit('cancel')
} }
@ -206,6 +212,16 @@ const isFieldsTab = computed(() => {
return openedViewsTab.value === 'field' return openedViewsTab.value === 'field'
}) })
const onDropdownChange = (value: boolean) => {
if (value) {
isColumnTypeOpen.value = value
} else {
setTimeout(() => {
isColumnTypeOpen.value = value
}, 300)
}
}
if (props.fromTableExplorer) { if (props.fromTableExplorer) {
watch( watch(
formState, formState,
@ -224,7 +240,7 @@ if (props.fromTableExplorer) {
'bg-white': !props.fromTableExplorer, 'bg-white': !props.fromTableExplorer,
'w-[400px]': !props.embedMode, 'w-[400px]': !props.embedMode,
'!w-146': isTextArea(formState) && formState.meta?.richMode, '!w-146': isTextArea(formState) && formState.meta?.richMode,
'!w-[600px]': formState.uidt === UITypes.Formula && !props.embedMode, '!w-116 overflow-visible': formState.uidt === UITypes.Formula && !props.embedMode,
'!w-[500px]': formState.uidt === UITypes.Attachment && !props.embedMode && !appInfo.ee, '!w-[500px]': formState.uidt === UITypes.Attachment && !props.embedMode && !appInfo.ee,
'shadow-lg border-1 border-gray-200 shadow-gray-300 rounded-xl p-6': !embedMode, 'shadow-lg border-1 border-gray-200 shadow-gray-300 rounded-xl p-6': !embedMode,
}" }"
@ -275,6 +291,7 @@ if (props.fromTableExplorer) {
class="nc-column-type-input !rounded" class="nc-column-type-input !rounded"
:disabled="isKanban || readOnly" :disabled="isKanban || readOnly"
dropdown-class-name="nc-dropdown-column-type border-1 !rounded-md border-gray-200" dropdown-class-name="nc-dropdown-column-type border-1 !rounded-md border-gray-200"
@dropdown-visible-change="onDropdownChange"
@change="onUidtOrIdTypeChange" @change="onUidtOrIdTypeChange"
@dblclick="showDeprecated = !showDeprecated" @dblclick="showDeprecated = !showDeprecated"
> >

190
packages/nc-gui/components/smartsheet/column/FormulaOptions.vue

@ -55,6 +55,8 @@ const supportedColumns = computed(
) )
const { getMeta } = useMetas() const { getMeta } = useMetas()
const suggestionPreviewed = ref<Record<any, string> | undefined>()
const validators = { const validators = {
formula_raw: [ formula_raw: [
{ {
@ -93,6 +95,8 @@ const formulaRef = ref()
const sugListRef = ref() const sugListRef = ref()
const variableListRef = ref<(typeof AntListItem)[]>([])
const sugOptionsRef = ref<(typeof AntListItem)[]>([]) const sugOptionsRef = ref<(typeof AntListItem)[]>([])
const wordToComplete = ref<string | undefined>('') const wordToComplete = ref<string | undefined>('')
@ -116,6 +120,7 @@ const suggestionsList = computed(() => {
description: formulas[fn].description, description: formulas[fn].description,
syntax: formulas[fn].syntax, syntax: formulas[fn].syntax,
examples: formulas[fn].examples, examples: formulas[fn].examples,
docsUrl: formulas[fn].docsUrl,
})), })),
...supportedColumns.value ...supportedColumns.value
.filter((c) => { .filter((c) => {
@ -149,6 +154,14 @@ const acTree = computed(() => {
return ref return ref
}) })
const suggestedFormulas = computed(() => {
return suggestion.value.filter((s) => s && s.type !== 'column')
})
const variableList = computed(() => {
return suggestion.value.filter((s) => s && s.type === 'column')
})
function isCurlyBracketBalanced() { function isCurlyBracketBalanced() {
// count number of opening curly brackets and closing curly brackets // count number of opening curly brackets and closing curly brackets
const cntCurlyBrackets = (formulaRef.value.$el.value.match(/\{|}/g) || []).reduce( const cntCurlyBrackets = (formulaRef.value.$el.value.match(/\{|}/g) || []).reduce(
@ -196,6 +209,11 @@ function handleInput() {
suggestion.value = acTree.value suggestion.value = acTree.value
.complete(wordToComplete.value) .complete(wordToComplete.value)
?.sort((x: Record<string, any>, y: Record<string, any>) => sortOrder[x.type] - sortOrder[y.type]) ?.sort((x: Record<string, any>, y: Record<string, any>) => sortOrder[x.type] - sortOrder[y.type])
if (suggestion.value.length > 0 && suggestion.value[0].type !== 'column') {
suggestionPreviewed.value = suggestion.value[0]
}
if (!isCurlyBracketBalanced()) { if (!isCurlyBracketBalanced()) {
suggestion.value = suggestion.value.filter((v) => v.type === 'column') suggestion.value = suggestion.value.filter((v) => v.type === 'column')
} }
@ -203,14 +221,21 @@ function handleInput() {
} }
function selectText() { function selectText() {
if (suggestion.value && selected.value > -1 && selected.value < suggestion.value.length) { if (suggestion.value && selected.value > -1 && selected.value < suggestionsList.value.length) {
appendText(suggestion.value[selected.value]) if (selected.value < suggestedFormulas.value.length) {
appendText(suggestedFormulas.value[selected.value])
} else {
appendText(variableList.value[selected.value + suggestedFormulas.value.length])
} }
}
selected.value = 0
} }
function suggestionListUp() { function suggestionListUp() {
if (suggestion.value) { if (suggestion.value) {
selected.value = --selected.value > -1 ? selected.value : suggestion.value.length - 1 selected.value = --selected.value > -1 ? selected.value : suggestion.value.length - 1
suggestionPreviewed.value = suggestedFormulas.value[selected.value]
scrollToSelectedOption() scrollToSelectedOption()
} }
} }
@ -218,6 +243,8 @@ function suggestionListUp() {
function suggestionListDown() { function suggestionListDown() {
if (suggestion.value) { if (suggestion.value) {
selected.value = ++selected.value % suggestion.value.length selected.value = ++selected.value % suggestion.value.length
suggestionPreviewed.value = suggestedFormulas.value[selected.value]
scrollToSelectedOption() scrollToSelectedOption()
} }
} }
@ -226,9 +253,9 @@ function scrollToSelectedOption() {
nextTick(() => { nextTick(() => {
if (sugOptionsRef.value[selected.value]) { if (sugOptionsRef.value[selected.value]) {
try { try {
sugListRef.value.$el.scrollTo({ sugOptionsRef.value[selected.value].$el.scrollIntoView({
top: sugOptionsRef.value[selected.value].$el.offsetTop, block: 'nearest',
behavior: 'smooth', inline: 'start',
}) })
} catch (e) {} } catch (e) {}
} }
@ -256,8 +283,52 @@ onMounted(() => {
</script> </script>
<template> <template>
<div class="formula-wrapper"> <div class="formula-wrapper relative">
<a-form-item v-bind="validateInfos.formula_raw" :label="$t('datatype.Formula')"> <div
v-if="suggestionPreviewed && suggestionPreviewed.type === 'function'"
class="absolute -left-91 w-84 top-0 bg-white z-10 pl-3 pt-3 border-1 shadow-md rounded-xl"
>
<div class="pr-3">
<div class="flex flex-row w-full justify-between pb-1 border-b-1">
<div class="flex items-center gap-x-1 font-semibold text-base">
<component :is="iconMap.function" class="text-lg" />
{{ suggestionPreviewed.text }}
</div>
<NcButton type="text" size="small" @click="suggestionPreviewed = undefined">
<GeneralIcon icon="close" />
</NcButton>
</div>
</div>
<div class="flex flex-col max-h-120 nc-scrollbar-md pr-2">
<div class="flex mt-3">{{ suggestionPreviewed.description }}</div>
<div class="text-gray-500 uppercase text-xs mt-3 mb-2">Syntax</div>
<div class="bg-white rounded-md py-1 px-2 border-1">{{ suggestionPreviewed.syntax }}</div>
<div class="text-gray-500 uppercase text-xs mt-3 mb-2">Examples</div>
<div
v-for="(example, index) of suggestionPreviewed.examples"
:key="example"
class="bg-gray-100 py-1 px-2"
:class="{
'border-t-1 border-gray-200': index !== 0,
'rounded-b-md': index === suggestionPreviewed.examples.length - 1 && suggestionPreviewed.examples.length !== 1,
'rounded-t-md': index === 0 && suggestionPreviewed.examples.length !== 1,
'rounded-md': suggestionPreviewed.examples.length === 1,
}"
>
{{ example }}
</div>
</div>
<div class="flex flex-row mt-1 mb-3 justify-end pr-3">
<a target="_blank" rel="noopener noreferrer" :href="suggestionPreviewed.docsUrl">
<NcButton type="text" class="!text-gray-400 !hover:text-gray-800 !text-xs"
>View in Docs
<GeneralIcon icon="openInNew" class="ml-1" />
</NcButton>
</a>
</div>
</div>
<a-form-item v-bind="validateInfos.formula_raw" class="!pb-1" :label="$t('datatype.Formula')">
<!-- <GeneralIcon <!-- <GeneralIcon
v-if="isEeUI" v-if="isEeUI"
icon="magic" icon="magic"
@ -268,7 +339,7 @@ onMounted(() => {
<a-textarea <a-textarea
ref="formulaRef" ref="formulaRef"
v-model:value="vModel.formula_raw" v-model:value="vModel.formula_raw"
class="mb-2 nc-formula-input" class="nc-formula-input !rounded-md !my-1"
@keydown.down.prevent="suggestionListDown" @keydown.down.prevent="suggestionListDown"
@keydown.up.prevent="suggestionListUp" @keydown.up.prevent="suggestionListUp"
@keydown.enter.prevent="selectText" @keydown.enter.prevent="selectText"
@ -276,26 +347,15 @@ onMounted(() => {
/> />
</a-form-item> </a-form-item>
<div class="text-gray-600 mt-2 mb-4 prose-sm"> <div ref="sugListRef" class="h-[250px] overflow-auto nc-scrollbar-md">
{{ <template v-if="suggestedFormulas.length > 0">
// As using {} in translation will be treated as placeholder, and this translation contain {} as part of th text <div class="rounded-t-lg border-1 bg-gray-50 px-3 py-1 uppercase text-gray-600 text-xs">Formulas</div>
$t('msg.formula.hintStart', {
placeholder1: '{}',
placeholder2: '{column_name}',
})
}}
<a
class="prose-sm"
href="https://docs.nocodb.com/setup-and-usages/formulas#available-formula-features"
target="_blank"
rel="noopener"
>
{{ $t('msg.formula.hintEnd') }}
</a>
</div>
<div class="h-[250px] overflow-auto scrollbar-thin-primary"> <a-list
<a-list ref="sugListRef" :data-source="suggestion" :locale="{ emptyText: $t('msg.formula.noSuggestedFormulaFound') }"> :data-source="suggestedFormulas"
:locale="{ emptyText: $t('msg.formula.noSuggestedFormulaFound') }"
class="border-1 border-t-0 rounded-b-lg !mb-4"
>
<template #renderItem="{ item, index }"> <template #renderItem="{ item, index }">
<a-list-item <a-list-item
:ref=" :ref="
@ -303,46 +363,74 @@ onMounted(() => {
sugOptionsRef[index] = el sugOptionsRef[index] = el
} }
" "
class="cursor-pointer" class="cursor-pointer !overflow-hidden hover:bg-gray-50"
:class="{
'!bg-gray-100': selected === index,
}"
@click.prevent.stop="appendText(item)" @click.prevent.stop="appendText(item)"
@mouseenter="suggestionPreviewed = item"
> >
<a-list-item-meta> <a-list-item-meta>
<template #title> <template #title>
<div class="flex"> <div class="flex items-center gap-x-1">
<a-col :span="6"> <component :is="iconMap.function" v-if="item.type === 'function'" class="text-lg" />
<span class="prose-sm text-gray-600">{{ item.text }}</span>
</a-col>
<a-col :span="18">
<div v-if="item.type === 'function'" class="text-xs text-gray-500">
{{ item.description }} <br /><br />
{{ $t('labels.syntax') }}: <br />
{{ item.syntax }} <br /><br />
{{ $t('labels.examples') }}: <br />
<div v-for="(example, idx) of item.examples" :key="idx"> <component :is="iconMap.calculator" v-if="item.type === 'op'" class="text-lg" />
<div>({{ idx + 1 }}): {{ example }}</div>
</div>
</div>
<div v-if="item.type === 'column'" class="float-right mr-5 -mt-2"> <component :is="item.icon" v-if="item.type === 'column'" class="text-lg" />
<a-badge-ribbon :text="item.uidt" color="gray" /> <span class="prose-sm text-gray-600">{{ item.text }}</span>
</div>
</a-col>
</div> </div>
</template> </template>
</a-list-item-meta>
</a-list-item>
</template>
</a-list>
</template>
<template #avatar> <template v-if="variableList.length > 0">
<component :is="iconMap.function" v-if="item.type === 'function'" class="text-lg" /> <div class="rounded-t-lg border-1 bg-gray-50 px-3 py-1 uppercase text-gray-600 text-xs">Fields</div>
<component :is="iconMap.calculator" v-if="item.type === 'op'" class="text-lg" /> <a-list
ref="variableListRef"
:data-source="variableList"
:locale="{ emptyText: $t('msg.formula.noSuggestedFormulaFound') }"
class="border-1 border-t-0 rounded-b-lg !overflow-hidden"
>
<template #renderItem="{ item, index }">
<a-list-item
:ref="
(el) => {
sugOptionsRef[index + suggestedFormulas.length] = el
}
"
:class="{
'!bg-gray-100': selected === index + suggestedFormulas.length,
}"
class="cursor-pointer hover:bg-gray-50"
@click.prevent.stop="appendText(item)"
>
<a-list-item-meta>
<template #title>
<div class="flex items-center gap-x-1">
<component :is="item.icon" class="text-lg" />
<component :is="item.icon" v-if="item.type === 'column'" class="text-lg" /> <span class="prose-sm text-gray-600">{{ item.text }}</span>
</div>
</template> </template>
</a-list-item-meta> </a-list-item-meta>
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
</template>
<div v-if="suggestion.length === 0">
<span class="text-gray-500">Empty</span>
</div>
</div> </div>
</div> </div>
</template> </template>
<style lang="scss" scoped>
:deep(.ant-list-item) {
@apply !pt-1.75 pb-0.75 !px-2;
}
</style>

254
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -275,6 +275,7 @@ interface FormulaMeta {
syntax?: string; syntax?: string;
examples?: string[]; examples?: string[];
returnType?: ((args: any[]) => FormulaDataTypes) | FormulaDataTypes; returnType?: ((args: any[]) => FormulaDataTypes) | FormulaDataTypes;
docsUrl?: string;
} }
export const formulas: Record<string, FormulaMeta> = { export const formulas: Record<string, FormulaMeta> = {
@ -293,6 +294,8 @@ export const formulas: Record<string, FormulaMeta> = {
'AVG({column1}, {column2}, {column3})', 'AVG({column1}, {column2}, {column3})',
], ],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#avg',
}, },
ADD: { ADD: {
validation: { validation: {
@ -309,8 +312,12 @@ export const formulas: Record<string, FormulaMeta> = {
'ADD({column1}, {column2}, {column3})', 'ADD({column1}, {column2}, {column3})',
], ],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#add',
}, },
DATEADD: { DATEADD: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#dateadd',
validation: { validation: {
args: { args: {
rqd: 3, rqd: 3,
@ -351,9 +358,9 @@ export const formulas: Record<string, FormulaMeta> = {
} }
}, },
}, },
description: 'Adds a "count" units to Datetime.', description: 'Adds "count" units to Datetime.',
syntax: syntax:
'DATEADD(date | datetime, value, ["day" | "week" | "month" | "year"])', 'DATEADD(date | datetime, count, ["day" | "week" | "month" | "year"])',
examples: [ examples: [
'DATEADD({column1}, 2, "day")', 'DATEADD({column1}, 2, "day")',
'DATEADD({column1}, -2, "day")', 'DATEADD({column1}, -2, "day")',
@ -372,7 +379,8 @@ export const formulas: Record<string, FormulaMeta> = {
rqd: 1, rqd: 1,
}, },
}, },
description: 'Formats a datetime into a string (YYYY-MM-DD)', syntax: 'DATESTR(date | datetime)',
description: 'Formats input field into a string in "YYYY-MM-DD" format',
examples: ['DATESTR({column1})'], examples: ['DATESTR({column1})'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
@ -382,7 +390,8 @@ export const formulas: Record<string, FormulaMeta> = {
rqd: 1, rqd: 1,
}, },
}, },
description: 'Extract day from a date(1-31)', syntax: 'DAY(date | datetime)',
description: 'Extract day from a date field (1-31)',
examples: ['DAY({column1})'], examples: ['DAY({column1})'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
@ -392,7 +401,8 @@ export const formulas: Record<string, FormulaMeta> = {
rqd: 1, rqd: 1,
}, },
}, },
description: 'Extract month from a date(1-12)', syntax: 'MONTH(date | datetime)',
description: 'Extract month from a date field (1-12)',
examples: ['MONTH({column1})'], examples: ['MONTH({column1})'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
@ -402,11 +412,15 @@ export const formulas: Record<string, FormulaMeta> = {
rqd: 1, rqd: 1,
}, },
}, },
description: 'Extract hour from a datetime(0-23)', syntax: 'DAY(time | datetime)',
description: 'Extract hour from a time field (0-23)',
examples: ['HOUR({column1})'], examples: ['HOUR({column1})'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
DATETIME_DIFF: { DATETIME_DIFF: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#datetime_diff',
validation: { validation: {
args: { args: {
min: 2, min: 2,
@ -469,7 +483,7 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Calculate the difference of two given date / datetime in specified units.', 'Calculate the difference of two given date / datetime fields in specified units.',
syntax: syntax:
'DATETIME_DIFF(date | datetime, date | datetime, ["milliseconds" | "ms" | "seconds" | "s" | "minutes" | "m" | "hours" | "h" | "days" | "d" | "weeks" | "w" | "months" | "M" | "quarters" | "Q" | "years" | "y"])', 'DATETIME_DIFF(date | datetime, date | datetime, ["milliseconds" | "ms" | "seconds" | "s" | "minutes" | "m" | "hours" | "h" | "days" | "d" | "weeks" | "w" | "months" | "M" | "quarters" | "Q" | "years" | "y"])',
examples: [ examples: [
@ -486,34 +500,43 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
AND: { AND: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/conditional-expressions#and',
validation: { validation: {
args: { args: {
min: 1, min: 1,
}, },
}, },
description: 'TRUE if all expr evaluate to TRUE', description: 'Result is TRUE if all conditions are met',
syntax: 'AND(expr1, [expr2, ...])', syntax: 'AND(expr1, [expr2, ...])',
examples: ['AND(5 > 2, 5 < 10) => 1', 'AND({column1} > 2, {column2} < 10)'], examples: ['AND(5 > 2, 5 < 10) => 1', 'AND({column1} > 2, {column2} < 10)'],
returnType: FormulaDataTypes.COND_EXP, returnType: FormulaDataTypes.COND_EXP,
}, },
OR: { OR: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/conditional-expressions#or',
validation: { validation: {
args: { args: {
min: 1, min: 1,
}, },
}, },
description: 'TRUE if at least one expr evaluates to TRUE', description: 'Result is TRUE if at least one condition is met',
syntax: 'OR(expr1, [expr2, ...])', syntax: 'OR(expr1, [expr2, ...])',
examples: ['OR(5 > 2, 5 < 10) => 1', 'OR({column1} > 2, {column2} < 10)'], examples: ['OR(5 > 2, 5 < 10) => 1', 'OR({column1} > 2, {column2} < 10)'],
returnType: FormulaDataTypes.COND_EXP, returnType: FormulaDataTypes.COND_EXP,
}, },
CONCAT: { CONCAT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#concat',
validation: { validation: {
args: { args: {
min: 1, min: 1,
}, },
}, },
description: 'Concatenated string of input parameters', description: 'Concatenate input parameters into a single string',
syntax: 'CONCAT(str1, [str2, ...])', syntax: 'CONCAT(str1, [str2, ...])',
examples: [ examples: [
'CONCAT("AA", "BB", "CC") => "AABBCC"', 'CONCAT("AA", "BB", "CC") => "AABBCC"',
@ -522,6 +545,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
TRIM: { TRIM: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#trim',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -537,91 +563,115 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
UPPER: { UPPER: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#upper',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
type: FormulaDataTypes.STRING, type: FormulaDataTypes.STRING,
}, },
}, },
description: 'Upper case converted string of input parameter', description: 'Converts the input parameter to an upper-case string.',
syntax: 'UPPER(str)', syntax: 'UPPER(str)',
examples: ['UPPER("nocodb") => "NOCODB"', 'UPPER({column1})'], examples: ['UPPER("nocodb") => "NOCODB"', 'UPPER({column1})'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
LOWER: { LOWER: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#lower',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
type: FormulaDataTypes.STRING, type: FormulaDataTypes.STRING,
}, },
}, },
description: 'Lower case converted string of input parameter', description: 'Converts the input parameter to an lower-case string.',
syntax: 'LOWER(str)', syntax: 'LOWER(str)',
examples: ['LOWER("NOCODB") => "nocodb"', 'LOWER({column1})'], examples: ['LOWER("NOCODB") => "nocodb"', 'LOWER({column1})'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
LEN: { LEN: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#len',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
type: FormulaDataTypes.STRING, type: FormulaDataTypes.STRING,
}, },
}, },
description: 'Input parameter character length', description: 'Calculate the character length of the input parameter.',
syntax: 'LEN(value)', syntax: 'LEN(value)',
examples: ['LEN("NocoDB") => 6', 'LEN({column1})'], examples: ['LEN("NocoDB") => 6', 'LEN({column1})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
MIN: { MIN: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#min',
validation: { validation: {
args: { args: {
min: 1, min: 1,
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: 'Minimum value amongst input parameters', description: 'Find the minimum value among the input parameters.',
syntax: 'MIN(value1, [value2, ...])', syntax: 'MIN(value1, [value2, ...])',
examples: ['MIN(1000, 2000) => 1000', 'MIN({column1}, {column2})'], examples: ['MIN(1000, 2000) => 1000', 'MIN({column1}, {column2})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
MAX: { MAX: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#max',
validation: { validation: {
args: { args: {
min: 1, min: 1,
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: 'Maximum value amongst input parameters', description: 'Find the maximum value among the input parameters.',
syntax: 'MAX(value1, [value2, ...])', syntax: 'MAX(value1, [value2, ...])',
examples: ['MAX(1000, 2000) => 2000', 'MAX({column1}, {column2})'], examples: ['MAX(1000, 2000) => 2000', 'MAX({column1}, {column2})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
CEILING: { CEILING: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#ceiling',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: 'Rounded next largest integer value of input parameter', description:
'Rounds the input parameter to the next largest integer value.',
syntax: 'CEILING(value)', syntax: 'CEILING(value)',
examples: ['CEILING(1.01) => 2', 'CEILING({column1})'], examples: ['CEILING(1.01) => 2', 'CEILING({column1})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
FLOOR: { FLOOR: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#floor',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: description: 'Round down the input parameter to the nearest integer.',
'Rounded largest integer less than or equal to input parameter',
syntax: 'FLOOR(value)', syntax: 'FLOOR(value)',
examples: ['FLOOR(3.1415) => 3', 'FLOOR({column1})'], examples: ['FLOOR(3.1415) => 3', 'FLOOR({column1})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
ROUND: { ROUND: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#round',
validation: { validation: {
args: { args: {
min: 1, min: 1,
@ -630,7 +680,7 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Rounded number to a specified number of decimal places or the nearest integer if not specified', 'Rounds the number to a specified decimal places or the nearest integer if precision is not specified',
syntax: 'ROUND(value, precision), ROUND(value)', syntax: 'ROUND(value, precision), ROUND(value)',
examples: [ examples: [
'ROUND(3.1415) => 3', 'ROUND(3.1415) => 3',
@ -640,18 +690,25 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
MOD: { MOD: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#mod',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: 'Remainder after integer division of input parameters', description:
'Calculate the remainder resulting from integer division of input parameters.',
syntax: 'MOD(value1, value2)', syntax: 'MOD(value1, value2)',
examples: ['MOD(1024, 1000) => 24', 'MOD({column}, 2)'], examples: ['MOD(1024, 1000) => 24', 'MOD({column}, 2)'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
REPEAT: { REPEAT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#repeat',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
@ -660,83 +717,105 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Specified copies of the input parameter string concatenated together', 'Concatenate the specified number of copies of the input parameter string.',
syntax: 'REPEAT(str, count)', syntax: 'REPEAT(str, count)',
examples: ['REPEAT("A", 5) => "AAAAA"', 'REPEAT({column}, 5)'], examples: ['REPEAT("A", 5) => "AAAAA"', 'REPEAT({column}, 5)'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
LOG: { LOG: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#log',
validation: { validation: {
args: { args: {
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: description:
'Logarithm of input parameter to the base (default = e) specified', 'Compute the logarithm of the input parameter to the specified base (default = e).',
syntax: 'LOG([base], value)', syntax: 'LOG([base], value)',
examples: ['LOG(2, 1024) => 10', 'LOG(2, {column1})'], examples: ['LOG(2, 1024) => 10', 'LOG(2, {column1})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
EXP: { EXP: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#exp',
validation: { validation: {
args: { args: {
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: 'Exponential value of input parameter (e ^ power)', description:
'Compute the exponential value of the input parameter (e raised to the power specified)',
syntax: 'EXP(power)', syntax: 'EXP(power)',
examples: ['EXP(1) => 2.718281828459045', 'EXP({column1})'], examples: ['EXP(1) => 2.718281828459045', 'EXP({column1})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
POWER: { POWER: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#power',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: 'base to the exponent power, as in base ^ exponent', description: 'Compute base raised to the exponent power.',
syntax: 'POWER(base, exponent)', syntax: 'POWER(base, exponent)',
examples: ['POWER(2, 10) => 1024', 'POWER({column1}, 10)'], examples: ['POWER(2, 10) => 1024', 'POWER({column1}, 10)'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
SQRT: { SQRT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#sqrt',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: 'Square root of the input parameter', description: 'Calculate the square root of the input parameter.',
syntax: 'SQRT(value)', syntax: 'SQRT(value)',
examples: ['SQRT(100) => 10', 'SQRT({column1})'], examples: ['SQRT(100) => 10', 'SQRT({column1})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
ABS: { ABS: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#abs',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: 'Absolute value of the input parameter', description: 'Obtain the absolute value of the input parameter.',
syntax: 'ABS(value)', syntax: 'ABS(value)',
examples: ['ABS({column1})'], examples: ['ABS({column1})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
NOW: { NOW: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#now',
validation: { validation: {
args: { args: {
rqd: 0, rqd: 0,
type: FormulaDataTypes.DATE, type: FormulaDataTypes.DATE,
}, },
}, },
description: 'Returns the current time and day', description: 'Retrieve the current time and day.',
syntax: 'NOW()', syntax: 'NOW()',
examples: ['NOW() => 2022-05-19 17:20:43'], examples: ['NOW() => 2022-05-19 17:20:43'],
returnType: FormulaDataTypes.DATE, returnType: FormulaDataTypes.DATE,
}, },
REPLACE: { REPLACE: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#replace',
validation: { validation: {
args: { args: {
rqd: 3, rqd: 3,
@ -744,8 +823,8 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'String, after replacing all occurrences of srchStr with rplcStr', 'Replace all occurrences of "searchStr" with "replaceStr" in the given string.',
syntax: 'REPLACE(str, srchStr, rplcStr)', syntax: 'REPLACE(str, searchStr, replaceStr)',
examples: [ examples: [
'REPLACE("AABBCC", "AA", "BB") => "BBBBCC"', 'REPLACE("AABBCC", "AA", "BB") => "BBBBCC"',
'REPLACE({column1}, {column2}, {column3})', 'REPLACE({column1}, {column2}, {column3})',
@ -753,14 +832,18 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
SEARCH: { SEARCH: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#search',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
type: FormulaDataTypes.STRING, type: FormulaDataTypes.STRING,
}, },
}, },
description: 'Index of srchStr specified if found, 0 otherwise', description:
syntax: 'SEARCH(str, srchStr)', 'Retrieve the index of the specified "searchStr" if found; otherwise, returns 0.',
syntax: 'SEARCH(str, searchStr)',
examples: [ examples: [
'SEARCH("HELLO WORLD", "WORLD") => 7', 'SEARCH("HELLO WORLD", "WORLD") => 7',
'SEARCH({column1}, "abc")', 'SEARCH({column1}, "abc")',
@ -768,42 +851,54 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
INT: { INT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#int',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
}, },
}, },
description: 'Integer value of input parameter', description: 'Obtain the integer value of the input parameter',
syntax: 'INT(value)', syntax: 'INT(value)',
examples: ['INT(3.1415) => 3', 'INT({column1})'], examples: ['INT(3.1415) => 3', 'INT({column1})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
RIGHT: { RIGHT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#right',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
type: FormulaDataTypes.STRING, type: FormulaDataTypes.STRING,
}, },
}, },
description: 'n characters from the end of input parameter', description: 'Retrieve the last n characters from the input string.',
syntax: 'RIGHT(str, n)', syntax: 'RIGHT(str, n)',
examples: ['RIGHT("HELLO WORLD", 5) => WORLD', 'RIGHT({column1}, 3)'], examples: ['RIGHT("HELLO WORLD", 5) => WORLD', 'RIGHT({column1}, 3)'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
LEFT: { LEFT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#left',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
type: FormulaDataTypes.STRING, type: FormulaDataTypes.STRING,
}, },
}, },
description: 'n characters from the beginning of input parameter', description: 'Retrieve the first n characters from the input string.',
syntax: 'LEFT(str, n)', syntax: 'LEFT(str, n)',
examples: ['LEFT({column1}, 2)', 'LEFT("ABCD", 2) => "AB"'], examples: ['LEFT({column1}, 2)', 'LEFT("ABCD", 2) => "AB"'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
SUBSTR: { SUBSTR: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#substr',
validation: { validation: {
args: { args: {
min: 2, min: 2,
@ -812,7 +907,7 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Substring of length n of input string from the postition specified', 'Extracts a substring of length "n" from the input string, starting from the specified position.',
syntax: ' SUBTR(str, position, [n])', syntax: ' SUBTR(str, position, [n])',
examples: [ examples: [
'SUBSTR("HELLO WORLD", 7) => WORLD', 'SUBSTR("HELLO WORLD", 7) => WORLD',
@ -822,26 +917,33 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
MID: { MID: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#mid',
validation: { validation: {
args: { args: {
rqd: 3, rqd: 3,
type: FormulaDataTypes.STRING, type: FormulaDataTypes.STRING,
}, },
}, },
description: 'Alias for SUBSTR', description: 'Extracts a substring; an alias for SUBSTR.',
syntax: 'MID(str, position, [count])', syntax: 'MID(str, position, [count])',
examples: ['MID("NocoDB", 3, 2) => "co"', 'MID({column1}, 3, 2)'], examples: ['MID("NocoDB", 3, 2) => "co"', 'MID({column1}, 3, 2)'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
IF: { IF: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/conditional-expressions#if',
validation: { validation: {
args: { args: {
min: 2, min: 2,
max: 3, max: 3,
}, },
}, },
description: 'SuccessCase if expr evaluates to TRUE, elseCase otherwise', description:
syntax: 'IF(expr, successCase, elseCase)', 'Evaluate successCase if the expression is TRUE, else the failureCase.',
syntax: 'IF(expr, successCase, failureCase)',
examples: [ examples: [
'IF(5 > 1, "YES", "NO") => "YES"', 'IF(5 > 1, "YES", "NO") => "YES"',
'IF({column} > 1, "YES", "NO")', 'IF({column} > 1, "YES", "NO")',
@ -871,6 +973,9 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
SWITCH: { SWITCH: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/conditional-expressions#switch',
validation: { validation: {
args: { args: {
min: 3, min: 3,
@ -879,7 +984,8 @@ export const formulas: Record<string, FormulaMeta> = {
// Todo: Add validation for switch // Todo: Add validation for switch
}, },
}, },
description: 'Switch case value based on expr output', description:
'Evaluate case value based on expression output; if no match is found, evaluate default case.',
syntax: 'SWITCH(expr, [pattern, value, ..., default])', syntax: 'SWITCH(expr, [pattern, value, ..., default])',
examples: [ examples: [
'SWITCH(1, 1, "One", 2, "Two", "N/A") => "One""', 'SWITCH(1, 1, "One", 2, "Two", "N/A") => "One""',
@ -913,18 +1019,25 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
URL: { URL: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#url',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
type: FormulaDataTypes.STRING, type: FormulaDataTypes.STRING,
}, },
}, },
description: 'Convert to a hyperlink if it is a valid URL', description:
'Verify and convert to a hyperlink if the input is a valid URL.',
syntax: 'URL(str)', syntax: 'URL(str)',
examples: ['URL("https://github.com/nocodb/nocodb")', 'URL({column1})'], examples: ['URL("https://github.com/nocodb/nocodb")', 'URL({column1})'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
WEEKDAY: { WEEKDAY: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#weekday',
validation: { validation: {
args: { args: {
min: 1, min: 1,
@ -970,7 +1083,7 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Returns the day of the week as an integer between 0 and 6 inclusive starting from Monday by default', 'Retrieve the day of the week as an integer (0-6), starting from Monday by default.',
syntax: 'WEEKDAY(date, [startDayOfWeek])', syntax: 'WEEKDAY(date, [startDayOfWeek])',
examples: ['WEEKDAY("2021-06-09")', 'WEEKDAY(NOW(), "sunday")'], examples: ['WEEKDAY("2021-06-09")', 'WEEKDAY(NOW(), "sunday")'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
@ -986,6 +1099,9 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'TRUE()', syntax: 'TRUE()',
examples: ['TRUE()'], examples: ['TRUE()'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
// TODO: Add docs url
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/logical-functions#true',
}, },
FALSE: { FALSE: {
@ -998,6 +1114,9 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'FALSE()', syntax: 'FALSE()',
examples: ['FALSE()'], examples: ['FALSE()'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
// TODO: Add docs url
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/logical-functions#false',
}, },
REGEX_MATCH: { REGEX_MATCH: {
@ -1008,7 +1127,7 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Returns 1 if the input text matches a regular expression or 0 if it does not.', 'Verifies whether the input text matches a regular expression, returning 1 for a match and 0 otherwise.',
syntax: 'REGEX_MATCH(string, regex)', syntax: 'REGEX_MATCH(string, regex)',
examples: ['REGEX_MATCH({title}, "abc.*")'], examples: ['REGEX_MATCH({title}, "abc.*")'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
@ -1021,10 +1140,13 @@ export const formulas: Record<string, FormulaMeta> = {
type: FormulaDataTypes.STRING, type: FormulaDataTypes.STRING,
}, },
}, },
description: 'Returns the first match of a regular expression in a string.', description:
'Retrieve the first match of a regular expression in a string.',
syntax: 'REGEX_EXTRACT(string, regex)', syntax: 'REGEX_EXTRACT(string, regex)',
examples: ['REGEX_EXTRACT({title}, "abc.*")'], examples: ['REGEX_EXTRACT({title}, "abc.*")'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#regex_extract',
}, },
REGEX_REPLACE: { REGEX_REPLACE: {
validation: { validation: {
@ -1034,10 +1156,12 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Replaces all matches of a regular expression in a string with a replacement string', 'Replace all occurrences of a regular expression in a string with a specified replacement string.',
syntax: 'REGEX_MATCH(string, regex, replacement)', syntax: 'REGEX_MATCH(string, regex, replacement)',
examples: ['REGEX_EXTRACT({title}, "abc.*", "abcd")'], examples: ['REGEX_EXTRACT({title}, "abc.*", "abcd")'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#regex_replace',
}, },
BLANK: { BLANK: {
validation: { validation: {
@ -1045,10 +1169,13 @@ export const formulas: Record<string, FormulaMeta> = {
rqd: 0, rqd: 0,
}, },
}, },
description: 'Returns a blank value(null)', description: 'Yields a null value.',
syntax: 'BLANK()', syntax: 'BLANK()',
examples: ['BLANK()'], examples: ['BLANK()'],
returnType: FormulaDataTypes.NULL, returnType: FormulaDataTypes.NULL,
// TODO: Add docs url
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/logical-functions#blank',
}, },
XOR: { XOR: {
validation: { validation: {
@ -1058,10 +1185,13 @@ export const formulas: Record<string, FormulaMeta> = {
// todo: validation for boolean // todo: validation for boolean
}, },
description: description:
'Returns true if an odd number of arguments are true, and false otherwise.', 'Verifies whether an odd number of arguments are true, returning true if so, and false otherwise.',
syntax: 'XOR(expression, [exp2, ...])', syntax: 'XOR(expression, [exp2, ...])',
examples: ['XOR(TRUE(), FALSE(), TRUE())'], examples: ['XOR(TRUE(), FALSE(), TRUE())'],
returnType: FormulaDataTypes.BOOLEAN, returnType: FormulaDataTypes.BOOLEAN,
// TODO: Add docs url
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/logical-functions#xor',
}, },
EVEN: { EVEN: {
validation: { validation: {
@ -1071,10 +1201,12 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Returns the nearest even integer that is greater than or equal to the specified value', 'Rounds up the specified value to the nearest even integer that is greater than or equal to the specified value',
syntax: 'EVEN(value)', syntax: 'EVEN(value)',
examples: ['EVEN({column})'], examples: ['EVEN({column})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#even',
}, },
ODD: { ODD: {
validation: { validation: {
@ -1084,10 +1216,12 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Returns the nearest odd integer that is greater than or equal to the specified value', 'Rounds up the specified value to the nearest odd integer that is greater than or equal to the specified value',
syntax: 'ODD(value)', syntax: 'ODD(value)',
examples: ['ODD({column})'], examples: ['ODD({column})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#odd',
}, },
RECORD_ID: { RECORD_ID: {
validation: { validation: {
@ -1095,7 +1229,7 @@ export const formulas: Record<string, FormulaMeta> = {
rqd: 0, rqd: 0,
}, },
}, },
description: 'Returns the record id of the current record', description: 'Retrieve the record ID of the current record.',
syntax: 'RECORD_ID()', syntax: 'RECORD_ID()',
examples: ['RECORD_ID()'], examples: ['RECORD_ID()'],
@ -1110,10 +1244,12 @@ export const formulas: Record<string, FormulaMeta> = {
min: 1, min: 1,
}, },
}, },
description: 'Counts the number of non-empty arguments', description: 'Counts non-empty arguments',
syntax: 'COUNTA(value1, [value2, ...])', syntax: 'COUNTA(value1, [value2, ...])',
examples: ['COUNTA({field1}, {field2})'], examples: ['COUNTA({field1}, {field2})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#counta',
}, },
COUNT: { COUNT: {
validation: { validation: {
@ -1121,10 +1257,12 @@ export const formulas: Record<string, FormulaMeta> = {
min: 1, min: 1,
}, },
}, },
description: 'Count the number of arguments that are numbers', description: 'Counts numerical arguments',
syntax: 'COUNT(value1, [value2, ...])', syntax: 'COUNT(value1, [value2, ...])',
examples: ['COUNT({field1}, {field2})'], examples: ['COUNT({field1}, {field2})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#count',
}, },
COUNTALL: { COUNTALL: {
validation: { validation: {
@ -1136,6 +1274,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'COUNTALL(value1, [value2, ...])', syntax: 'COUNTALL(value1, [value2, ...])',
examples: ['COUNTALL({field1}, {field2})'], examples: ['COUNTALL({field1}, {field2})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#countall',
}, },
ROUNDDOWN: { ROUNDDOWN: {
validation: { validation: {
@ -1146,10 +1286,12 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Round down the value after the decimal point to the number of decimal places given by "precision"(default is 0)', 'Rounds down the value after the decimal point to the specified number of decimal places given by "precision" (default is 0).',
syntax: 'ROUNDDOWN(value, [precision])', syntax: 'ROUNDDOWN(value, [precision])',
examples: ['ROUNDDOWN({field1})', 'ROUNDDOWN({field1}, 2)'], examples: ['ROUNDDOWN({field1})', 'ROUNDDOWN({field1}, 2)'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#rounddown',
}, },
ROUNDUP: { ROUNDUP: {
validation: { validation: {
@ -1160,10 +1302,12 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Round up the value after the decimal point to the number of decimal places given by "precision"(default is 0)', 'Rounds up the value after the decimal point to the specified number of decimal places given by "precision" (default is 0).',
syntax: 'ROUNDUP(value, [precision])', syntax: 'ROUNDUP(value, [precision])',
examples: ['ROUNDUP({field1})', 'ROUNDUP({field1}, 2)'], examples: ['ROUNDUP({field1})', 'ROUNDUP({field1}, 2)'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#roundup',
}, },
VALUE: { VALUE: {
validation: { validation: {
@ -1172,10 +1316,12 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
description: description:
'Extract the numeric value from a string, if `%` or `-` is present, it will handle it accordingly and return the numeric value', 'Extracts the numeric value from a string, handling % or - appropriately, and returns the resulting numeric value.',
syntax: 'VALUE(value)', syntax: 'VALUE(value)',
examples: ['VALUE({field})', 'VALUE("abc10000%")', 'VALUE("$10000")'], examples: ['VALUE({field})', 'VALUE("abc10000%")', 'VALUE("$10000")'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#value',
}, },
// Disabling these functions for now; these act as alias for CreatedAt & UpdatedAt fields; // Disabling these functions for now; these act as alias for CreatedAt & UpdatedAt fields;
// Issue: Error noticed if CreatedAt & UpdatedAt fields are removed from the table after creating these formulas // Issue: Error noticed if CreatedAt & UpdatedAt fields are removed from the table after creating these formulas

Loading…
Cancel
Save