Generate hsl for EventType label
This commit is contained in:
@@ -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'
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user