-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(designer-ui): Ensure
isAdvanced: false
tokens are shown if far …
…down in a list (#4064) * Move token picker section options filter to a helper fn * Fix bug where later options would not be visible * Add tests for `hasAdvanced`
- Loading branch information
1 parent
b0d825d
commit 89ddb0b
Showing
3 changed files
with
140 additions
and
25 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
libs/designer-ui/src/lib/tokenpicker/tokenpickersection/__test__/tokenpickerhelpers.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import type { OutputToken } from '../..'; | ||
import { getReducedTokenList, hasAdvanced } from '../tokenpickerhelpers'; | ||
|
||
describe('ui/tokenPicker/tokenPickerSection helpers', () => { | ||
describe('getReducedTokenList', () => { | ||
it('should return a list of tokens with the advanced tokens filtered out', () => { | ||
const tokens: OutputToken[] = [ | ||
{ isAdvanced: false, value: 'Value 1' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 2' } as OutputToken, | ||
{ isAdvanced: false, value: 'Value 3' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 4' } as OutputToken, | ||
]; | ||
const options = { hasSearchQuery: false, maxRowsShown: 2, showAllOptions: false }; | ||
|
||
const result = getReducedTokenList(tokens, options); | ||
|
||
expect(result).toEqual([ | ||
{ isAdvanced: false, value: 'Value 1' }, | ||
{ isAdvanced: false, value: 'Value 3' }, | ||
]); | ||
}); | ||
|
||
it('should return a list of tokens with the advanced tokens filtered out and the max rows shown respected', () => { | ||
const tokens: OutputToken[] = [ | ||
{ isAdvanced: false, value: 'Value 1' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 2' } as OutputToken, | ||
{ isAdvanced: false, value: 'Value 3' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 4' } as OutputToken, | ||
]; | ||
const options = { hasSearchQuery: false, maxRowsShown: 1, showAllOptions: false }; | ||
|
||
const result = getReducedTokenList(tokens, options); | ||
|
||
expect(result).toEqual([{ isAdvanced: false, value: 'Value 1' }]); | ||
}); | ||
|
||
it('should return a list of tokens with the search query presence respected', () => { | ||
const tokens: OutputToken[] = [ | ||
{ isAdvanced: false, value: 'Value 1' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 2' } as OutputToken, | ||
{ isAdvanced: false, value: 'Value 3' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 4' } as OutputToken, | ||
]; | ||
const options = { hasSearchQuery: true, maxRowsShown: 2, showAllOptions: false }; | ||
|
||
const result = getReducedTokenList(tokens, options); | ||
|
||
expect(result).toEqual([ | ||
{ isAdvanced: false, value: 'Value 1' }, | ||
{ isAdvanced: true, value: 'Value 2' }, | ||
]); | ||
}); | ||
|
||
it('should return a list of tokens with the "no more options" field respected', () => { | ||
const tokens: OutputToken[] = [ | ||
{ isAdvanced: false, value: 'Value 1' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 2' } as OutputToken, | ||
{ isAdvanced: false, value: 'Value 3' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 4' } as OutputToken, | ||
]; | ||
const options = { hasSearchQuery: false, maxRowsShown: 1, showAllOptions: true }; | ||
|
||
const result = getReducedTokenList(tokens, options); | ||
|
||
expect(result).toEqual([ | ||
{ isAdvanced: false, value: 'Value 1' }, | ||
{ isAdvanced: true, value: 'Value 2' }, | ||
{ isAdvanced: false, value: 'Value 3' }, | ||
{ isAdvanced: true, value: 'Value 4' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('hasAdvanced', () => { | ||
it('should return true if any of the tokens are advanced', () => { | ||
const tokens: OutputToken[] = [ | ||
{ isAdvanced: false, value: 'Value 1' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 2' } as OutputToken, | ||
{ isAdvanced: false, value: 'Value 3' } as OutputToken, | ||
{ isAdvanced: true, value: 'Value 4' } as OutputToken, | ||
]; | ||
|
||
const result = hasAdvanced(tokens); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
|
||
it('should return false if none of the tokens are advanced', () => { | ||
const tokens: OutputToken[] = [ | ||
{ isAdvanced: false, value: 'Value 1' } as OutputToken, | ||
{ isAdvanced: false, value: 'Value 2' } as OutputToken, | ||
{ isAdvanced: false, value: 'Value 3' } as OutputToken, | ||
{ isAdvanced: false, value: 'Value 4' } as OutputToken, | ||
]; | ||
|
||
const result = hasAdvanced(tokens); | ||
|
||
expect(result).toEqual(false); | ||
}); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
libs/designer-ui/src/lib/tokenpicker/tokenpickersection/tokenpickerhelpers.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,19 @@ | ||
import type { OutputToken } from '..'; | ||
|
||
export const getReducedTokenList = ( | ||
tokens: OutputToken[], | ||
options: { hasSearchQuery: boolean; maxRowsShown: number; showAllOptions: boolean } | ||
): OutputToken[] => { | ||
const { hasSearchQuery, maxRowsShown, showAllOptions } = options; | ||
|
||
let filteredTokens = tokens.filter((token) => !token.isAdvanced || showAllOptions || hasSearchQuery); | ||
if (!showAllOptions) { | ||
filteredTokens = filteredTokens.slice(0, maxRowsShown); | ||
} | ||
|
||
return filteredTokens; | ||
}; | ||
|
||
export const hasAdvanced = (tokens: OutputToken[]): boolean => { | ||
return tokens.some((token) => token.isAdvanced); | ||
}; |
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