Skip to content

Commit

Permalink
Merge pull request #425 from konfuzio-ai/12831-remove-label-sets-endp…
Browse files Browse the repository at this point in the history
…oint

Refactor showing empty label sets in list by using document endpoint
  • Loading branch information
PedroDinis authored Nov 6, 2024
2 parents 526f6a3 + a7fa256 commit c0bd765
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 84 deletions.
7 changes: 4 additions & 3 deletions src/components/DocumentAnnotations/ChooseLabelSetModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ export default {
data() {
return {
show: true,
labels: [],
};
},
computed: {
...mapGetters("project", ["labelSetsFilteredForAnnotationSetCreation"]),
...mapGetters("document", ["numberOfLabelSetGroup"]),
...mapGetters("document", [
"numberOfLabelSetGroup",
"labelSetsFilteredForAnnotationSetCreation",
]),
},
methods: {
submit(labelSet) {
Expand Down
35 changes: 0 additions & 35 deletions src/components/DocumentAnnotations/DocumentAnnotations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,12 @@
<LoadingAnnotations />
</div>
</div>

<!-- When there's no annotation sets but show label sets for annotation creation-->
<div
v-else-if="
getAnnotationsFiltered.annotationSets.length === 0 &&
labelSets &&
labelSets.length > 0 &&
!isSearchingAnnotationList
"
class="empty-annotation-sets"
>
<div class="annotation-set-list">
<div
v-for="labelSet in labelSets"
:key="labelSet.id"
class="annotation-set-group"
>
<div class="label-set-header">
<div class="label-set-name">
{{ `${labelSet.name}` }}
</div>
</div>

<div v-if="labelSet.labels.length > 0">
<div v-for="label in labelSet.labels" :key="label.id">
<div class="labels">
<DocumentLabel :label="label" :label-set="labelSet" />
</div>
</div>
</div>
</div>
</div>
</div>
<div
v-else-if="
getAnnotationsFiltered.annotationSets.length === 0 &&
!isSearchingAnnotationList &&
(!labelSets || labelSets.length === 0)
"
class="empty-annotation-sets"
>
<EmptyState />
</div>
Expand Down Expand Up @@ -236,7 +202,6 @@ export default {
"selectedDocument",
"splittingSuggestions",
]),
...mapState("project", ["labelSets"]),
...mapGetters("document", [
"numberOfAnnotationSetGroup",
"getAnnotationsFiltered",
Expand Down
11 changes: 10 additions & 1 deletion src/components/DocumentPage/NewAnnotation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,21 @@ export default {
});
},
chooseLabelSet(labelSet) {
// check if there's already a new entry for that label set to be created
const existsIndex = this.setsList.findIndex((set) => {
return set.id === null && set.label_set.id === labelSet.id;
});
const newSet = {
label_set: labelSet,
labels: labelSet.labels,
id: null,
};
this.setsList.push(newSet);
if (existsIndex >= 0) {
this.setsList[existsIndex] = newSet;
} else {
this.setsList.push(newSet);
}
this.selectedSet = newSet;
},
openAnnotationSetCreation() {
Expand Down
55 changes: 36 additions & 19 deletions src/store/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,17 @@ const getters = {
let processedLabels = [];

annotationSets.forEach((annotationSet) => {
if (annotationSet.id) {
labels = [];
annotationSet.labels.forEach((label) => {
const labelAnnotations = [];
labels = [];
annotationSet.labels.forEach((label) => {
const labelAnnotations = [];

// add annotations to the document array
labelAnnotations.push(...label.annotations);
labels.push({ ...label, annotations: labelAnnotations });
processedLabels.push(label);
annotations.push(...labelAnnotations);
});
processedAnnotationSets.push({ ...annotationSet, labels });
}
// add annotations to the document array
labelAnnotations.push(...label.annotations);
labels.push({ ...label, annotations: labelAnnotations });
processedLabels.push(label);
annotations.push(...labelAnnotations);
});
processedAnnotationSets.push({ ...annotationSet, labels });
});
return {
annotationSets: processedAnnotationSets,
Expand Down Expand Up @@ -523,20 +521,43 @@ const getters = {
orderedAnnotationSets.sort((a, b) => {
return a.id - b.id || a.label_set.name.localeCompare(b.label_set.name);
});
orderedAnnotationSets.map((annotationSetTemp) => {
orderedAnnotationSets.forEach((annotationSetTemp) => {
if (
annotationSetTemp.label_set.id === labelSet.id &&
annotationSetTemp.label_set.name === labelSet.name
) {
found = true;
index++;
// check if annotation set exists, otherwise it will be new
if (annotationSetTemp.id) {
index++;
}
}
});
return found ? `${index + 1}` : "";
return found ? (index === 0 ? "" : `${index + 1}`) : "";
}
return "";
},

/**
* Gets label sets for an annotation set creation
*/
labelSetsFilteredForAnnotationSetCreation: (state) => {
let returnLabelSets = [];
if (state.annotationSets) {
state.annotationSets.forEach((annotationSet) => {
if (
annotationSet.id == null ||
annotationSet.label_set.has_multiple_annotation_sets
) {
const labelSet = { ...annotationSet.label_set };
labelSet.labels = [...annotationSet.labels];
returnLabelSets.push(labelSet);
}
});
}
return returnLabelSets;
},

/**
* Get label with annotations filtered if the label supports multiple or not
*/
Expand Down Expand Up @@ -1071,10 +1092,6 @@ const actions = {
if (!state.publicView) {
await dispatch("fetchMissingAnnotations");

await dispatch("project/fetchLabelSets", null, {
root: true,
});

await dispatch("project/fetchCurrentUser", null, {
root: true,
});
Expand Down
26 changes: 0 additions & 26 deletions src/store/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,6 @@ const state = {
showAnnotationTranslations: false,
};

const getters = {
/**
* Gets label sets for an annotation set creation
*/
labelSetsFilteredForAnnotationSetCreation: (state, _, rootState) => {
let returnLabels = [];
if (state.labelSets) {
returnLabels = state.labelSets.filter((labelSet) => {
// check if label set has multiple and if not, if there's already an annotation set created
if (!labelSet.has_multiple_annotation_sets) {
const existingAnnotationSet = rootState.document.annotationSets.find(
(annSet) => {
return annSet.label_set.id === labelSet.id;
}
);
return !existingAnnotationSet;
} else {
return true;
}
});
}
return returnLabels;
},
};

const actions = {
setProjectId: ({ commit }, projectId) => {
commit("SET_PROJECT_ID", projectId);
Expand Down Expand Up @@ -131,5 +106,4 @@ export default {
state,
actions,
mutations,
getters,
};

0 comments on commit c0bd765

Please sign in to comment.