From ff6ad5e3e17f15dec10f5cc46eab1bb2c7b6576d Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 22 Jan 2024 07:33:58 +0000 Subject: [PATCH] fix: kanban column order correction --- packages/nocodb/src/models/Column.ts | 77 ++++++++++++++++------------ packages/nocodb/src/models/View.ts | 24 +++++++++ 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/packages/nocodb/src/models/Column.ts b/packages/nocodb/src/models/Column.ts index 3e82cb6da8..869a776905 100644 --- a/packages/nocodb/src/models/Column.ts +++ b/packages/nocodb/src/models/Column.ts @@ -1354,39 +1354,50 @@ export default class Column implements ColumnType { source_id: param.source_id, fk_model_id: param.fk_model_id, }; - extractedColumnMetas.push( - extractProps(colWithId as any, [ - 'id', - 'fk_model_id', - 'column_name', - 'title', - 'uidt', - 'dt', - 'np', - 'ns', - 'clen', - 'cop', - 'pk', - 'rqd', - 'un', - 'ct', - 'ai', - 'unique', - 'cdf', - 'cc', - 'csn', - 'dtx', - 'dtxp', - 'dtxs', - 'au', - 'pv', - 'order', - 'base_id', - 'source_id', - 'system', - 'meta', - ]), - ); + + const insertObj = extractProps(colWithId as any, [ + 'id', + 'fk_model_id', + 'column_name', + 'title', + 'uidt', + 'dt', + 'np', + 'ns', + 'clen', + 'cop', + 'pk', + 'rqd', + 'un', + 'ct', + 'ai', + 'unique', + 'cdf', + 'cc', + 'csn', + 'dtx', + 'dtxp', + 'dtxs', + 'au', + 'pv', + 'order', + 'base_id', + 'source_id', + 'system', + 'meta', + ]); + + if (column.meta && typeof column.meta === 'object') { + insertObj.meta = JSON.stringify(column.meta); + } + + if (column.validate) { + if (typeof column.validate === 'string') + insertObj.validate = column.validate; + else insertObj.validate = JSON.stringify(column.validate); + } + extractedColumnMetas.push(insertObj); + columns.push(colWithId); } diff --git a/packages/nocodb/src/models/View.ts b/packages/nocodb/src/models/View.ts index 32c50f19b0..9ebbcb37ca 100644 --- a/packages/nocodb/src/models/View.ts +++ b/packages/nocodb/src/models/View.ts @@ -1609,6 +1609,30 @@ export default class View implements ViewType { columns = await Column.list({ fk_model_id: view.fk_model_id }); } + // todo: avoid duplicate code + if (view.type === ViewTypes.KANBAN && !copyFromView) { + // sort by display value & attachment first, then by singleLineText & Number + // so that later we can handle control `show` easily + columns.sort((a, b) => { + const displayValueOrder = +b.pv - +a.pv; + const attachmentOrder = + +(b.uidt === UITypes.Attachment) - +(a.uidt === UITypes.Attachment); + const singleLineTextOrder = + +(b.uidt === UITypes.SingleLineText) - + +(a.uidt === UITypes.SingleLineText); + const numberOrder = + +(b.uidt === UITypes.Number) - +(a.uidt === UITypes.Number); + const defaultOrder = b.order - a.order; + return ( + displayValueOrder || + attachmentOrder || + singleLineTextOrder || + numberOrder || + defaultOrder + ); + }); + } + let order = 1; let galleryShowLimit = 0; let kanbanShowLimit = 0;