From 2e132bf16ae78ad666c7e8576d2b3b8c73048f3a Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:02:21 +0530 Subject: [PATCH] Nc fix: add missing formula docs and link (#7987) * fix(nc-gui): show view in docs btn from formula suggestion modal only if docs link is present * fix(nocodb-sdk): add docs link form `REGEX_MATCH` formula * docs: datetime routines * docs: add missing links * fix(nc-gui): AI pr review suggestion * docs: pr ai review changes * docs: formula record id --------- Co-authored-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- .../smartsheet/column/FormulaOptions.vue | 2 +- .../060.formula/040.date-functions.md | 76 ++++++++++++++++++- .../060.formula/060.generic-functions.md | 24 ++++++ packages/nocodb-sdk/src/lib/formulaHelpers.ts | 18 ++++- 4 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 packages/noco-docs/docs/070.fields/040.field-types/060.formula/060.generic-functions.md diff --git a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue index 89279b59c5..8aadae7b7e 100644 --- a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue @@ -332,7 +332,7 @@ onMounted(() => {
- + View in Docs diff --git a/packages/noco-docs/docs/070.fields/040.field-types/060.formula/040.date-functions.md b/packages/noco-docs/docs/070.fields/040.field-types/060.formula/040.date-functions.md index 9385ad06e1..2b2ce80388 100644 --- a/packages/noco-docs/docs/070.fields/040.field-types/060.formula/040.date-functions.md +++ b/packages/noco-docs/docs/070.fields/040.field-types/060.formula/040.date-functions.md @@ -22,7 +22,7 @@ DATETIME_DIFF("2022/10/14", "2022/10/15", "seconds") => -86400 ``` #### Remark -This function compares two dates and returns the difference in the specified unit. Positive integers indicate that second date is in the past compared to first, and vice versa for negative values. +This function compares two dates and returns the difference in the specified unit. Positive integers indicate that the second date is in the past compared to the first, and vice versa for negative values. --- @@ -94,6 +94,80 @@ Returns the day of the week as an integer between 0 and 6 (inclusive), with Mond --- +## DATESTR +The DATESTR function converts a date or datetime field into a string in "YYYY-MM-DD" format. + +#### Syntax +```plaintext +DATESTR(date | datetime) +``` + +#### Sample +```plaintext +DATESTR('2022-03-14') => 2022-03-14 +DATESTR('2022-03-14 12:00:00') => 2022-03-14 +``` + +#### Remark +This function converts a date or datetime field into a string in "YYYY-MM-DD" format, ignoring the time part. + +--- + +## DAY +The DAY function returns the day of the month as an integer. + +#### Syntax +```plaintext +DAY(date | datetime) +``` + +#### Sample +```plaintext +DAY('2022-03-14') => 14 +DAY('2022-03-14 12:00:00') => 14 +``` + +#### Remark +This function returns the day of the month as an integer between 1 and 31 (inclusive). + +--- + +## MONTH +The MONTH function returns the month of the year as an integer. + +#### Syntax +```plaintext +MONTH(date | datetime) +``` + +#### Sample +```plaintext +MONTH('2022-03-14') => 3 +MONTH('2022-03-14 12:00:00') => 3 +``` + +#### Remark +This function returns the month of the year as an integer between 1 and 12 (inclusive). + +--- + +## HOUR +The HOUR function returns the hour of the day as an integer. + +#### Syntax +```plaintext +HOUR(datetime) +``` + +#### Sample +```plaintext +HOUR('2022-03-14 12:00:00') => 12 +``` + +#### Remark +This function returns the hour of the day as an integer between 0 and 23 (inclusive). + +--- ## Related Articles - [Numeric and Logical Operators](015.operators.md) diff --git a/packages/noco-docs/docs/070.fields/040.field-types/060.formula/060.generic-functions.md b/packages/noco-docs/docs/070.fields/040.field-types/060.formula/060.generic-functions.md new file mode 100644 index 0000000000..be520a837e --- /dev/null +++ b/packages/noco-docs/docs/070.fields/040.field-types/060.formula/060.generic-functions.md @@ -0,0 +1,24 @@ +--- +title: 'Generic Functions' +description: 'This article explains system functions & miscellaneous functions that can be used in formula fields.' +tags: ['Fields', 'Field types', 'Formula'] +keywords: ['Fields', 'Field types', 'Formula', 'Create formula field', 'System functions', 'Miscellaneous functions'] +--- + +# System Functions + +## RECORD_ID + +The `RECORD_ID` function returns the unique identifier of the record. + +#### Syntax +```plaintext +RECORD_ID() +``` + +#### Sample +```plaintext +RECORD_ID() => 1 +``` + +--- diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.ts index 097d3db4fd..b250531a06 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.ts @@ -282,6 +282,8 @@ interface FormulaMeta { export const formulas: Record = { AVG: { + docsUrl: + 'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#avg', validation: { args: { min: 1, @@ -296,10 +298,10 @@ export const formulas: Record = { 'AVG({column1}, {column2}, {column3})', ], returnType: FormulaDataTypes.NUMERIC, - docsUrl: - 'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#avg', }, ADD: { + docsUrl: + 'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#add', validation: { args: { min: 1, @@ -314,8 +316,6 @@ export const formulas: Record = { 'ADD({column1}, {column2}, {column3})', ], returnType: FormulaDataTypes.NUMERIC, - docsUrl: - 'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#add', }, DATEADD: { docsUrl: @@ -376,6 +376,8 @@ export const formulas: Record = { returnType: FormulaDataTypes.DATE, }, DATESTR: { + docsUrl: + 'https://docs.nocodb.com/fields/field-types/formula/date-functions#datestr', validation: { args: { rqd: 1, @@ -387,6 +389,8 @@ export const formulas: Record = { returnType: FormulaDataTypes.STRING, }, DAY: { + docsUrl: + 'https://docs.nocodb.com/fields/field-types/formula/date-functions#day', validation: { args: { rqd: 1, @@ -398,6 +402,8 @@ export const formulas: Record = { returnType: FormulaDataTypes.STRING, }, MONTH: { + docsUrl: + 'https://docs.nocodb.com/fields/field-types/formula/date-functions#month', validation: { args: { rqd: 1, @@ -409,6 +415,8 @@ export const formulas: Record = { returnType: FormulaDataTypes.STRING, }, HOUR: { + docsUrl: + 'https://docs.nocodb.com/fields/field-types/formula/date-functions#hour', validation: { args: { rqd: 1, @@ -1171,6 +1179,8 @@ export const formulas: Record = { syntax: 'REGEX_MATCH(string, regex)', examples: ['REGEX_MATCH({title}, "abc.*")'], returnType: FormulaDataTypes.NUMERIC, + docsUrl: + 'https://docs.nocodb.com/fields/field-types/formula/string-functions#regex_match', }, REGEX_EXTRACT: {