Skip to content

Commit

Permalink
Merge pull request #92 from JJ-8/89-fix-tags-casing
Browse files Browse the repository at this point in the history
Force tags to be lowercase in the frontend during parsing
  • Loading branch information
JJ-8 authored Mar 24, 2024
2 parents 49791e1 + 80e463b commit 26eb22a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions front/src/components/Dialogs/TaskImportDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,29 +175,33 @@ export default defineComponent({
onPaste() {
void this.$nextTick(() => this.autoDetectParser());
},
normalizeTags(tags: string[]): string[] {
if (tags.length == 0) return [];
return Array.from(new Set(tags.map((t) => t.trim().toLowerCase())));
},
parseTasks(v: string): ParsedTask[] {
// Get list of task {title,category} from parse
const parsedTasks = this.currentParser.value.parse(v);
// Precompute a set of task to avoid N square operation
const hashTask = (title: string, tags: string[]): string =>
title +
tags
.map((t) => t.toLowerCase())
.sort()
.join('');
title + this.normalizeTags(tags).sort().join('');
const taskSet = new Set();
for (const task of this.ctf.tasks) {
taskSet.add(
hashTask(
task.title,
task.assignedTags.map((t) => t.tag)
this.normalizeTags(task.assignedTags.map((t) => t.tag))
)
);
}
// mark already existing tasks
return parsedTasks.map((task) => {
const hash = hashTask(task.title, task.tags);
return { ...task, keep: !taskSet.has(hash) };
return {
...task,
tags: this.normalizeTags(task.tags),
keep: !taskSet.has(hash),
};
});
},
computeTags(tags: { nodeId: number; tag: string }[]) {
Expand Down

0 comments on commit 26eb22a

Please sign in to comment.