Skip to content

Commit

Permalink
Ignore empty column changes (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
namoscato committed May 24, 2022
1 parent 2dd1ab5 commit 67be333
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
17 changes: 11 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ import {columnPermissionsViewFromTableChanges} from '..'
import {emptyTablePermissionsChanges} from '../..'

describe('columnPermissionsViewFromTableChanges', () => {
test('no permission changes', () => {
expect(
columnPermissionsViewFromTableChanges(emptyTablePermissionsChanges())
).toStrictEqual(null)
})

test('no column changes', () => {
expect(
columnPermissionsViewFromTableChanges({
...emptyTablePermissionsChanges(),
select_permissions: {
added: [],
modified: [
{
role: 'user',
columns: []
}
],
deleted: []
}
})
).toStrictEqual(null)
})

test('add computed column', () => {
expect(
columnPermissionsViewFromTableChanges({
Expand Down
13 changes: 9 additions & 4 deletions src/diff/tables/permissions/columns/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ import {assertNeverChangeType, iconFromChangeType} from '../../utils'

import {isEqual} from 'lodash'

/**
* Iterate through `tablePermissions` per role and operation that include column changes.
*/
export function* columnChangeIterator(
tablePermissions: TablePermissionsChanges
): Generator<ColumnPermissionChange> {
for (const permission of TablePermissions) {
for (const changeType of ChangeTypes) {
for (const {role, columns} of tablePermissions[permission][changeType]) {
yield {
permission,
role,
columns
if (true === columns || columns.length) {
yield {
permission,
role,
columns
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/diff/tables/permissions/columns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function columnPermissionsViewFromTableChanges(
for (const {type} of columns) {
columnChangeTypes.add(type)
}
} else if (columns) {
} else {
columnChangeCount.isLowerBound = true
columnChangeTypes.add('modified')
}
Expand Down

0 comments on commit 67be333

Please sign in to comment.