From b0249e6964662dc8d1135455257c1f97d492ed19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bueno=2C=20Jo=C3=A3o?= <3846247+jbbn@users.noreply.github.com> Date: Wed, 12 Oct 2022 21:31:00 -0300 Subject: [PATCH] fix(ng-gui): find unique neighbours Find unique neighbours on formula paths, therefore avoiding "circular reference" incorrect error validation while editing formula columns. closes #4024 --- .../components/smartsheet/column/FormulaOptions.vue | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue index 09d06566ca..a4c48f74b8 100644 --- a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue @@ -252,11 +252,15 @@ function validateAgainstMeta(parsedTree: any, errors = new Set(), typeErrors = n const formulaPaths = columns.value .filter((c: Record) => c.id !== column.value?.id && c.uidt === UITypes.Formula) .reduce((res: Record[], c: Record) => { - // in `formula`, get all the target neighbours + // in `formula`, get all the (unique) target neighbours // i.e. all column id (e.g. cl_xxxxxxxxxxxxxx) with formula type - const neighbours = (c.colOptions.formula.match(/cl_\w{14}/g) || []).filter( - (colId: string) => columns.value.filter((col: ColumnType) => col.id === colId && col.uidt === UITypes.Formula).length, - ) + const neighbours = [ + ...new Set( + (c.colOptions.formula.match(/cl_\w{14}/g) || []).filter( + (colId: string) => columns.value.filter((col: ColumnType) => col.id === colId && col.uidt === UITypes.Formula).length, + ), + ), + ] if (neighbours.length > 0) { // e.g. formula column 1 -> [formula column 2, formula column3] res.push({ [c.id]: neighbours })