Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug select few annotations in one item navigate to another item breaks #511

Open
wants to merge 5 commits into
base: main-variants
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/components/annotations/variants/VariantsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import VariantsTopBar from "@/components/annotations/variants/VariantsTopBar.vue";
import VariantsList from "@/components/annotations/variants/VariantsList.vue";
import { getItemColorBasedOnIndex } from '@/utils/color';
import {useAnnotationsStore} from "@/stores/annotations";
import {computed, onBeforeUnmount, watch} from "vue";
import {useContentsStore} from "@/stores/contents";
Expand All @@ -13,8 +12,6 @@ import { getVariantAnnotations } from '@/utils/annotations'
const annotationStore = useAnnotationsStore();
const contentsStore = useContentsStore();

allocateWitnessColorInVariantItem()

const annotations = computed<Annotation[]>(() => annotationStore.annotations);
const activeContentUrl = computed<string>(() => contentsStore.activeContentUrl);

Expand Down Expand Up @@ -88,18 +85,6 @@ const unsubscribe = TextEventBus.on('click', ({ target }) => {

onBeforeUnmount(() => unsubscribe())


function allocateWitnessColorInVariantItem() {
const colors = {}
if (!annotationStore.witnesses) return
if (annotationStore.witnesses.length === 0) return;

annotationStore.witnesses.forEach((witness, i) => {
colors[witness.idno] = getItemColorBasedOnIndex(i)
})
annotationStore.setVariantItemsColors(colors)
}

</script>

<template>
Expand Down
12 changes: 10 additions & 2 deletions src/stores/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {useConfigStore} from '@/stores/config';
import TextEventBus from '@/utils/TextEventBus';

import { getVariantAnnotations } from '@/utils/annotations'
import { allocateWitnessColorInVariantItem } from '@/utils/variants';


export const useAnnotationsStore = defineStore('annotations', () => {
Expand Down Expand Up @@ -176,7 +177,9 @@ export const useAnnotationsStore = defineStore('annotations', () => {
const annotationLoaded = ({ items, refs }) => {
annotations.value = items
witnesses.value = refs

preprocessVariants()
allocateWitnessColorInVariantItem()

updateAnnotationLoading(false)
};
Expand Down Expand Up @@ -215,9 +218,14 @@ export const useAnnotationsStore = defineStore('annotations', () => {
annotationStore.setActiveAnnotations(activeAnnotationsList)

const selector = AnnotationUtils.generateTargetSelector(removeAnnotation);
if (selector) {
const textEl = document.querySelector('#text-content')
const target = textEl.querySelector(selector)


// when target is null -> we switched to another item - we don't continue and change the level of highlight of the text
if (target) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!target) return ...But we have to come back here after the release.

if (AnnotationUtils.isVariant(removeAnnotation)) {
if (AnnotationUtils.getCurrentLevel(document.querySelector(selector)) > 0
if (AnnotationUtils.getCurrentLevel(target) > 0
&& Object.keys(activeAnnotations.value).findIndex(key => {
const sel = AnnotationUtils.generateTargetSelector(activeAnnotations.value[key])
return sel === selector
Expand Down
15 changes: 15 additions & 0 deletions src/utils/variants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useAnnotationsStore } from "@/stores/annotations";
import { getItemColorBasedOnIndex } from '@/utils/color';


export function allocateWitnessColorInVariantItem() {
const annotationStore = useAnnotationsStore()
const colors = {}
if (!annotationStore.witnesses) return
if (annotationStore.witnesses.length === 0) return;

annotationStore.witnesses.forEach((witness, i) => {
colors[witness.idno] = getItemColorBasedOnIndex(i)
})
annotationStore.setVariantItemsColors(colors)
}
43 changes: 43 additions & 0 deletions tests/cypress/e2e/variants.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,49 @@ const selectors = {
.should("have.length", 11)
});

it('Should switch from an item with no variants to another one with variants and show the list correctly', () => {
cy
.visit('/ahiqar-arabic-karshuni-local.html?tido=m20_i0_p0.0-1.0-2.0-3.2')
.wait(500)
.reload()
.wait(500)
.visit('/ahiqar-arabic-karshuni-local.html?tido=m20_i1_p0.0-1.0-2.0-3.2')
.wait(500)
.get(selectors.list)
.children()
.should('have.length', 11)
/*
this test passes locally, but fails in the github pi
cy
.visit('/ahiqar-arabic-karshuni-local.html?tido=m20_i0_p0.0-1.0-2.0-3.2')
.reload()
.get('.header') // go to next item
.find('button')
.contains('Next Sheet')
.click()
cy.get(selectors.list)
.children()
.should('have.length', 11)
*/

})

it('Should show the new list of annotations when first selecting a few annotations and then switching the item', () => {
cy
.get(selectors.list)
.children()
.eq(0)
.click()
.next()
.click()
.get(selectors.panel1)
.find('ul[role="tree"]')
.find('ul[role="group"]')
.find('div').contains('182b')
.click()
.checkNoAnnotationsAvailable()
})

it('select (unselect) a variant item', () => {
// should select a variant item and add its witness after the highlighted text + the highlighted text should become light blue
cy
Expand Down
Loading