Skip to content

Commit

Permalink
fix(updateProperties): getFieldMask ignore gridProperties (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathRobin authored Aug 31, 2024
1 parent cfee339 commit f874bfe
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import * as _ from './lodash';

export function getFieldMask(obj: Record<string, unknown>) {
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) {
Expand Down
65 changes: 65 additions & 0 deletions src/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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);
})
});
});

0 comments on commit f874bfe

Please sign in to comment.