-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Plugin: Allow setting feature flags via cli args (#984)
Co-authored-by: Levente Balogh <[email protected]>
- Loading branch information
1 parent
0517626
commit 268ff00
Showing
6 changed files
with
110 additions
and
10 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
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
58 changes: 58 additions & 0 deletions
58
packages/create-plugin/src/utils/tests/utils.helpers.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { partitionArr } from '../utils.helpers.js'; | ||
|
||
describe('partitionArr', () => { | ||
it('should partition an array of numbers based on a predicate', () => { | ||
const arr = [1, 2, 3, 4, 5, 6]; | ||
const isEven = (num: number) => num % 2 === 0; | ||
const result = partitionArr(arr, isEven); | ||
expect(result).toEqual([ | ||
[2, 4, 6], | ||
[1, 3, 5], | ||
]); | ||
}); | ||
|
||
it('should partition an array of strings based on a predicate', () => { | ||
const arr = ['apple', 'banana', 'cherry', 'date']; | ||
const startsWithA = (str: string) => str[0] === 'a'; | ||
const result = partitionArr(arr, startsWithA); | ||
expect(result).toEqual([['apple'], ['banana', 'cherry', 'date']]); | ||
}); | ||
|
||
it('should return two empty arrays if the input array is empty', () => { | ||
const arr: number[] = []; | ||
const isEven = (num: number) => num % 2 === 0; | ||
const result = partitionArr(arr, isEven); | ||
expect(result).toEqual([[], []]); | ||
}); | ||
|
||
it('should place all items in the first partition if all match the predicate', () => { | ||
const arr = [2, 4, 6, 8]; | ||
const isEven = (num: number) => num % 2 === 0; | ||
const result = partitionArr(arr, isEven); | ||
expect(result).toEqual([[2, 4, 6, 8], []]); | ||
}); | ||
|
||
it('should place all items in the second partition if none match the predicate', () => { | ||
const arr = [1, 3, 5, 7]; | ||
const isEven = (num: number) => num % 2 === 0; | ||
const result = partitionArr(arr, isEven); | ||
expect(result).toEqual([[], [1, 3, 5, 7]]); | ||
}); | ||
|
||
it('should work with a complex object array and predicate', () => { | ||
const arr = [ | ||
{ name: 'Alice', age: 25 }, | ||
{ name: 'Bob', age: 30 }, | ||
{ name: 'Charlie', age: 35 }, | ||
]; | ||
const isUnder30 = (person: { name: string; age: number }) => person.age < 30; | ||
const result = partitionArr(arr, isUnder30); | ||
expect(result).toEqual([ | ||
[{ name: 'Alice', age: 25 }], | ||
[ | ||
{ name: 'Bob', age: 30 }, | ||
{ name: 'Charlie', age: 35 }, | ||
], | ||
]); | ||
}); | ||
}); |
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,3 @@ | ||
export function partitionArr<T>(arr: T[], pred: (item: T) => boolean): [T[], T[]] { | ||
return arr.reduce<[T[], T[]]>((acc, i) => (acc[pred(i) ? 0 : 1].push(i), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
{ | ||
"features": { | ||
{{#if bundleGrafanaUI}} | ||
"bundleGrafanaUI": true{{/if}} | ||
{{#if useReactRouterV6}} | ||
"useReactRouterV6": true{{/if}} | ||
"bundleGrafanaUI": {{ bundleGrafanaUI }}, | ||
"useReactRouterV6": {{ useReactRouterV6 }} | ||
} | ||
} |