fix: convert HSL color generation to hex format in label selector

Update generateRandomColor to return hex codes instead of HSL strings
to ensure proper color storage in database.

Changes:
- Add hslToHex conversion function
- Maintain same pastel color generation (random hue, 70% saturation, 65% lightness)
- Return hex format (#rrggbb) instead of HSL string

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jan-Henrik Bruhn 2025-10-17 10:51:26 +02:00
parent bc8ab6c9c7
commit c1cd2d3114

View file

@ -21,10 +21,24 @@ interface Props {
scope: 'actors' | 'relations';
}
// Convert HSL to Hex
const hslToHex = (h: number, s: number, l: number): string => {
l /= 100;
const a = (s * Math.min(l, 1 - l)) / 100;
const f = (n: number) => {
const k = (n + h / 30) % 12;
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
return Math.round(255 * color)
.toString(16)
.padStart(2, '0');
};
return `#${f(0)}${f(8)}${f(4)}`;
};
// Generate random pastel color for new labels
const generateRandomColor = () => {
const hue = Math.floor(Math.random() * 360);
return `hsl(${hue}, 70%, 65%)`;
return hslToHex(hue, 70, 65);
};
const AutocompleteLabelSelector = ({ value, onChange, scope }: Props) => {