Generate hsl for EventType label

This commit is contained in:
2022-07-24 21:54:12 +00:00
parent 4b4c1d5a1d
commit fa6e949805

View File

@@ -5,6 +5,29 @@ const EventTypes: CollectionConfig = {
access: {
read: () => true,
},
hooks: {
afterRead: [
({ doc }) => {
const hashCode = (str) => {
let hash = 0;
for (let i = 0; i < str.length; i++)
hash = str.charCodeAt(i) + ((hash << 5) - hash);
return hash;
};
const pickColour = (str) => {
return `hsl(${hashCode(str) % 360}, 100%, 50%)`;
};
doc.backgroundColour = pickColour(doc.name);
return doc;
}
]
},
admin: {
useAsTitle: 'name'
},