diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 36ef4e6..8aaccd3 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 0000000..0e4349c --- /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