From 273ecb42cee051f17f12601fa66d16c2ee29fae2 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Fri, 3 Nov 2023 12:22:28 +0500 Subject: [PATCH] UBER-1143: additional skill parsing, increase timeout for filter (#3933) Signed-off-by: Vyacheslav Tumanov --- .../src/components/CreateCandidate.svelte | 50 ++++++++++++++++++- .../src/components/SkillsView.svelte | 2 +- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/plugins/recruit-resources/src/components/CreateCandidate.svelte b/plugins/recruit-resources/src/components/CreateCandidate.svelte index 36d5580cd5..277c2ed0e2 100644 --- a/plugins/recruit-resources/src/components/CreateCandidate.svelte +++ b/plugins/recruit-resources/src/components/CreateCandidate.svelte @@ -346,9 +346,55 @@ const categoriesMap = toIdMap(categories) const newSkills: TagReference[] = [] - + const formattedSkills = (doc.skills.map((s) => s.toLowerCase()) ?? []).filter( + (skill) => !namedElements.has(skill) + ) + const refactoredSkills = [] + if (formattedSkills.length > 0) { + const existingTags = Array.from(namedElements.keys()).filter((x) => x.length > 2) + const regex = /\S+(?:[-+]\S+)+/g + const regexForEmpty = /^((?![a-zA-Zа-яА-Я]).)*$/g + for (let sk of formattedSkills) { + sk = sk.toLowerCase() + const toReplace = [...new Set([...existingTags, ...refactoredSkills])] + .filter((s) => sk.includes(s)) + .sort((a, b) => b.length - a.length) + if (toReplace.length > 0) { + for (const replacing of toReplace) { + if (namedElements.has(replacing)) { + refactoredSkills.push(replacing) + sk = sk.replace(replacing, '').trim() + } + } + } + if (sk.includes(' ')) { + const skSplit = sk.split(' ') + for (const spl of skSplit) { + const fixedTitle = regex.test(spl) ? spl.replaceAll(/[+-]/g, '') : spl + if (namedElements.has(fixedTitle)) { + refactoredSkills.push(fixedTitle) + sk = sk.replace(spl, '').trim() + } + if ([...doc.skills, ...refactoredSkills].includes(fixedTitle)) { + sk = sk.replace(spl, '').trim() + } + } + } + if (regex.test(sk)) { + const fixedTitle = sk.replaceAll(/[+-]/g, '') + if (namedElements.has(fixedTitle)) { + refactoredSkills.push(fixedTitle) + sk = '' + } + } + if (!regexForEmpty.test(sk) && !refactoredSkills.includes(sk)) { + refactoredSkills.push(sk) + } + } + } + const skillsToAdd = [...new Set([...doc.skills.map((s) => s.toLowerCase()), ...refactoredSkills])] // Create missing tag elemnts - for (const s of doc.skills ?? []) { + for (const s of skillsToAdd) { const title = s.trim().toLowerCase() let e = namedElements.get(title) if (e === undefined && shouldCreateNewSkills) { diff --git a/plugins/recruit-resources/src/components/SkillsView.svelte b/plugins/recruit-resources/src/components/SkillsView.svelte index 47aad43519..e20057a0cc 100644 --- a/plugins/recruit-resources/src/components/SkillsView.svelte +++ b/plugins/recruit-resources/src/components/SkillsView.svelte @@ -28,7 +28,7 @@ loc.path[3] = 'talents' loc.path.length = 4 navigate(loc) - setTimeout(() => setFilterTag(tag), 50) + setTimeout(() => setFilterTag(tag), 200) }