From f874bfec709d2b214cf5453d9136d71faa0d4c3a Mon Sep 17 00:00:00 2001 From: Mathieu KIM ROBIN Date: Sun, 1 Sep 2024 00:34:31 +0300 Subject: [PATCH] fix(updateProperties): getFieldMask ignore gridProperties (#674) --- src/lib/utils.ts | 11 ++++++- src/test/utils.test.ts | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/test/utils.test.ts diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 36ef4e61..8aaccd35 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,7 +1,16 @@ import * as _ from './lodash'; export function getFieldMask(obj: Record) { - return Object.keys(obj).join(','); + let fromGrid = ''; + let fromRoot = Object.keys(obj).filter((key) => key !== 'gridProperties').join(','); + + if (obj.gridProperties) { + fromGrid = Object.keys(obj.gridProperties).map(key => `gridProperties.${key}`).join(','); + if (fromGrid.length && fromRoot.length) { + fromGrid = `${fromGrid},` + } + } + return fromGrid + fromRoot; } export function columnToLetter(column: number) { diff --git a/src/test/utils.test.ts b/src/test/utils.test.ts new file mode 100644 index 00000000..0e4349c1 --- /dev/null +++ b/src/test/utils.test.ts @@ -0,0 +1,65 @@ +import {getFieldMask} from "../lib/utils"; + +describe('utils', () => { + describe('getFieldMask', () => { + const cases = [ + ['tabColor', { + tabColor: { + red: 0, + green: 1, + blue: 2, + }, + }], + ['hidden,tabColor', { + hidden: false, + tabColor: { + red: 0, + green: 1, + blue: 2, + }, + }], + ['hidden,tabColor', { + hidden: false, + gridProperties: {}, + tabColor: { + red: 0, + green: 1, + blue: 2, + }, + }], + ['gridProperties.colCount,hidden,tabColor', { + hidden: false, + gridProperties: { + colCount: 78, + }, + tabColor: { + red: 0, + green: 1, + blue: 2, + }, + }], + ['gridProperties.colCount,gridProperties.rowCount,hidden,tabColor', { + hidden: false, + gridProperties: { + colCount: 78, + rowCount: 14, + }, + tabColor: { + red: 0, + green: 1, + blue: 2, + }, + }], + ['gridProperties.colCount,gridProperties.rowCount', { + gridProperties: { + colCount: 78, + rowCount: 14, + }, + }], + ]; + + test.each(cases)('%s', (expected, from) => { + expect(getFieldMask(from)).toBe(expected); + }) + }); +}); \ No newline at end of file