Fix addition of new option in select field if there are no existing options (#6718)
Fixes [sentry](https://twenty-v7.sentry.io/issues/5745628875/?alert_rule_id=15135099&alert_type=issue¬ification_uuid=95108411-b431-4abd-bdd6-687c96a7353e&project=4507072563183616&referrer=discord)
This commit is contained in:
@ -11,7 +11,7 @@ export const generateNewSelectOption = (
|
||||
const newOptionLabel = generateNewSelectOptionLabel(options);
|
||||
|
||||
return {
|
||||
color: getNextThemeColor(options[options.length - 1].color),
|
||||
color: getNextThemeColor(options[options.length - 1]?.color),
|
||||
id: v4(),
|
||||
label: newOptionLabel,
|
||||
position: options.length,
|
||||
|
||||
@ -20,4 +20,9 @@ describe('getNextThemeColor', () => {
|
||||
|
||||
expect(getNextThemeColor(currentColor)).toBe(nextColor);
|
||||
});
|
||||
it('returns the first color when currentColorIsUndefined', () => {
|
||||
const firstColor: ThemeColor = MAIN_COLOR_NAMES[0];
|
||||
|
||||
expect(getNextThemeColor(undefined)).toBe(firstColor);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import { MAIN_COLOR_NAMES, ThemeColor } from '@ui/theme';
|
||||
import { isDefined } from '@ui/utilities';
|
||||
|
||||
export const getNextThemeColor = (currentColor: ThemeColor): ThemeColor => {
|
||||
export const getNextThemeColor = (currentColor?: ThemeColor): ThemeColor => {
|
||||
if (!isDefined(currentColor)) {
|
||||
return MAIN_COLOR_NAMES[0];
|
||||
}
|
||||
const currentColorIndex = MAIN_COLOR_NAMES.findIndex(
|
||||
(color) => color === currentColor,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user