Add score color logic and evaluation migration
- Introduced `getScoreColors` function to dynamically set badge colors based on skill scores for better visual feedback. - Updated HomePage to display skill evaluation percentages with corresponding colors. - Implemented `migrateEvaluation` function to ensure existing evaluations are updated with new skill categories, enhancing data integrity. - Refactored data loading in `loadSkillCategories` and `loadTeams` to fetch from API endpoints, improving flexibility and maintainability.
This commit is contained in:
@@ -16,6 +16,40 @@ import {
|
||||
} from "@/lib/evaluation-utils";
|
||||
import { loadSkillCategories, loadTeams } from "@/lib/data-loader";
|
||||
|
||||
// Fonction pour migrer une évaluation existante avec de nouvelles catégories
|
||||
function migrateEvaluation(
|
||||
evaluation: UserEvaluation,
|
||||
allCategories: SkillCategory[]
|
||||
): UserEvaluation {
|
||||
const existingCategoryNames = evaluation.evaluations.map((e) => e.category);
|
||||
const missingCategories = allCategories.filter(
|
||||
(cat) => !existingCategoryNames.includes(cat.category)
|
||||
);
|
||||
|
||||
if (missingCategories.length === 0) {
|
||||
return evaluation; // Pas de migration nécessaire
|
||||
}
|
||||
|
||||
console.log(
|
||||
"🔄 Migrating evaluation with new categories:",
|
||||
missingCategories.map((c) => c.category)
|
||||
);
|
||||
|
||||
const newCategoryEvaluations: CategoryEvaluation[] = missingCategories.map(
|
||||
(category) => ({
|
||||
category: category.category,
|
||||
skills: [],
|
||||
selectedSkillIds: [],
|
||||
})
|
||||
);
|
||||
|
||||
return {
|
||||
...evaluation,
|
||||
evaluations: [...evaluation.evaluations, ...newCategoryEvaluations],
|
||||
lastUpdated: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
export function useEvaluation() {
|
||||
const [userEvaluation, setUserEvaluation] = useState<UserEvaluation | null>(
|
||||
null
|
||||
@@ -39,7 +73,10 @@ export function useEvaluation() {
|
||||
// Try to load existing evaluation
|
||||
const saved = loadUserEvaluation();
|
||||
if (saved) {
|
||||
setUserEvaluation(saved);
|
||||
// Migrate evaluation to include new categories if needed
|
||||
const migratedEvaluation = migrateEvaluation(saved, categories);
|
||||
setUserEvaluation(migratedEvaluation);
|
||||
saveUserEvaluation(migratedEvaluation); // Save the migrated version
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize data:", error);
|
||||
|
||||
Reference in New Issue
Block a user