Skip to content

Commit

Permalink
Fix addition of new option in select field if there are no existing o…
Browse files Browse the repository at this point in the history
  • Loading branch information
ijreilly authored Aug 23, 2024
1 parent 4c5fc23 commit 981f311
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
6 changes: 5 additions & 1 deletion packages/twenty-ui/src/theme/utils/getNextThemeColor.ts
Original file line number Diff line number Diff line change
@@ -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,
);
Expand Down

0 comments on commit 981f311

Please sign in to comment.