-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
173 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,9 @@ | |
{ | ||
"props": true, | ||
"ignorePropertyModificationsFor": [ | ||
"state" | ||
"state", | ||
"acc", | ||
"accumulator" | ||
] | ||
} | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
frontend/src/components/common/NewTable/utils/__test__/updateSortingState.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import compact from 'lib/functions/compact'; | ||
|
||
describe('compact', () => { | ||
it('should remove falsey values from the array', () => { | ||
const input = [0, 1, false, 2, '', 3, null, undefined, 4, NaN, 5]; | ||
const expected = [1, 2, 3, 4, 5]; | ||
expect(compact(input)).toEqual(expected); | ||
}); | ||
|
||
it('should return an empty array if all values are falsey', () => { | ||
const input = [0, false, '', null, undefined, NaN]; | ||
const expected: number[] = []; | ||
expect(compact(input)).toEqual(expected); | ||
}); | ||
|
||
it('should return a new array with only truthy values preserved', () => { | ||
const input = [1, 'hello', true, [], { a: 1 }, 42]; | ||
const expected = [1, 'hello', true, [], { a: 1 }, 42]; | ||
expect(compact(input)).toEqual(expected); | ||
}); | ||
|
||
it('should preserve non-falsey values in their original order', () => { | ||
const input = [1, null, 2, undefined, 3, false, 4]; | ||
const expected = [1, 2, 3, 4]; | ||
expect(compact(input)).toEqual(expected); | ||
}); | ||
|
||
it('should not modify the original array', () => { | ||
const input = [0, 1, 2, false, '', null, undefined, NaN]; | ||
const inputCopy = [...input]; | ||
compact(input); | ||
expect(input).toEqual(inputCopy); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import groupBy from 'lib/functions/groupBy'; | ||
|
||
describe('groupBy', () => { | ||
it('should group objects in the array by the specified key', () => { | ||
const input = [ | ||
{ id: 1, name: 'John' }, | ||
{ id: 2, name: 'Jane' }, | ||
{ id: 3, name: 'Doe' }, | ||
{ id: 4, name: 'John' }, | ||
]; | ||
|
||
const result = groupBy(input, 'name'); | ||
|
||
expect(result).toEqual({ | ||
John: [ | ||
{ id: 1, name: 'John' }, | ||
{ id: 4, name: 'John' }, | ||
], | ||
Jane: [{ id: 2, name: 'Jane' }], | ||
Doe: [{ id: 3, name: 'Doe' }], | ||
}); | ||
}); | ||
|
||
it('should return an empty object when the input array is empty', () => { | ||
const result = groupBy([], 'name'); | ||
|
||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should handle objects with undefined values for the specified key', () => { | ||
const input = [ | ||
{ id: 1, name: 'John' }, | ||
{ id: 2, name: undefined }, | ||
{ id: 3, name: 'Doe' }, | ||
{ id: 4 }, | ||
]; | ||
|
||
const result = groupBy(input, 'name'); | ||
|
||
expect(result).toEqual({ | ||
John: [{ id: 1, name: 'John' }], | ||
Doe: [{ id: 3, name: 'Doe' }], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @description | ||
* Creates an array with all falsey values removed. The values false, null, 0, "", undefined, and NaN are | ||
* falsey. | ||
* | ||
* @param array The array to compact. | ||
* @return Returns the new array of filtered values. | ||
*/ | ||
export default function compact<T>( | ||
array: Array<T | null | undefined | false | '' | 0> | ||
): T[] { | ||
return array.filter(Boolean) as T[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export default function groupBy<T extends object>( | ||
collections: T[], | ||
key: string | ||
) { | ||
return collections.reduce<Record<string, [T, ...T[]]>>((acc, curr) => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const groupByKey = key in curr ? curr[key] : null; | ||
|
||
if (typeof groupByKey !== 'string' && typeof groupByKey !== 'number') { | ||
return acc; | ||
} | ||
|
||
if (acc[groupByKey]) { | ||
acc[groupByKey].push(curr); | ||
return acc; | ||
} | ||
|
||
acc[groupByKey] = [curr]; | ||
return acc; | ||
}, {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.