From 39e28851158887e0e8bea0cb4919cf2d49073dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Lesage?= <tlesage@teklia.com> Date: Thu, 21 Mar 2024 16:11:03 +0100 Subject: [PATCH] Wreck the entity link display --- src/api/entity.ts | 5 +- src/components/Element/DetailsPanel.vue | 7 --- src/components/Entity/Links.vue | 80 ------------------------- src/helpers/entity.ts | 4 +- src/stores/entity.ts | 19 +----- src/types/entity.ts | 17 ------ src/views/Entity/Details.vue | 60 ------------------- tests/unit/stores/entity.spec.js | 21 +------ 8 files changed, 7 insertions(+), 206 deletions(-) delete mode 100644 src/components/Entity/Links.vue diff --git a/src/api/entity.ts b/src/api/entity.ts index 8752e479a..8eaebd209 100644 --- a/src/api/entity.ts +++ b/src/api/entity.ts @@ -1,7 +1,7 @@ import axios from 'axios' import { PageNumberPaginationParameters, unique } from '.' import { ElementTiny, PageNumberPagination, UUID } from '@/types' -import { Entity, EntityLight, EntityLink, EntityType, TranscriptionEntity } from '@/types/entity' +import { Entity, EntityLight, EntityType, TranscriptionEntity } from '@/types/entity' // Retrieve an entity export const retrieveEntity = unique(async (id: UUID): Promise<Entity> => (await axios.get(`/entity/${id}/`)).data) @@ -14,9 +14,6 @@ export interface CorpusEntitiesListParameters extends PageNumberPaginationParame // List entities in a corpus export const listCorpusEntities = unique(async (id: UUID, params: CorpusEntitiesListParameters = {}): Promise<PageNumberPagination<EntityLight>> => (await axios.get(`/corpus/${id}/entities/`, { params })).data) -// List all links for an element -export const listElementLinks = unique(async (id: UUID): Promise<PageNumberPagination<EntityLink>> => (await axios.get(`/element/${id}/links/`)).data) - // List all elements linked to an entity export const listEntityElements = unique(async (id: UUID, params: PageNumberPaginationParameters = {}): Promise<PageNumberPagination<ElementTiny>> => (await axios.get(`/entity/${id}/elements/`, { params })).data) diff --git a/src/components/Element/DetailsPanel.vue b/src/components/Element/DetailsPanel.vue index 18afad1c4..298ed3740 100644 --- a/src/components/Element/DetailsPanel.vue +++ b/src/components/Element/DetailsPanel.vue @@ -66,11 +66,6 @@ <DropdownContent id="datasets" title="Datasets"> <ElementDatasets :corpus-id="corpusId" :element="element" /> </DropdownContent> - - <EntityLinks - :element-id="element.id" - v-if="elementType.folder === false" - /> </template> </div> </template> @@ -91,7 +86,6 @@ import { useElementsStore } from '@/stores' import DropdownContent from '@/components/DropdownContent.vue' import MLClassSelect from '@/components/MLClassSelect.vue' -import EntityLinks from '@/components/Entity/Links.vue' import Classifications from '@/components/Element/Classifications' import ElementMetadata from '@/components/Element/Metadata' import OrientationPanel from '@/components/Element/OrientationPanel.vue' @@ -108,7 +102,6 @@ export default defineComponent({ Classifications, DropdownContent, ElementMetadata, - EntityLinks, MLClassSelect, OrientationPanel, TranscriptionCreationForm, diff --git a/src/components/Entity/Links.vue b/src/components/Entity/Links.vue deleted file mode 100644 index 82b8a86b8..000000000 --- a/src/components/Entity/Links.vue +++ /dev/null @@ -1,80 +0,0 @@ -<template> - <div v-if="allLinks && allLinks.length"> - <DropdownContent id="entity-roles" title="Roles"> - <nav class="panel"> - <p class="panel-heading"> - {{ allLinks.length }} role{{ allLinks.length > 1 ? 's' : '' }} - </p> - <a v-for="link in allLinks" :key="link.id" class="panel-block"> - <span class="metadata-content"> - <router-link :to="{ name: 'entity-details', params: { id: link.parent.id } }"> - {{ link.parent.name }} - </router-link> - </span> - <span class="metadata-content">{{ link.role.parent_name }} - {{ link.role.child_name }}</span> - <span class="metadata-content"> - <router-link :to="{ name: 'entity-details', params: { id: link.child.id } }"> - {{ link.child.name }} - </router-link> - </span> - </a> - </nav> - </DropdownContent> - <hr /> - </div> -</template> - -<script lang="ts"> -import { PropType, defineComponent } from 'vue' -import { mapState, mapActions } from 'pinia' -import DropdownContent from '@/components/DropdownContent.vue' -import { useEntityStore } from '@/stores' -import { UUID } from '@/types' -import { EntityLink } from '@/types/entity' - -export default defineComponent({ - props: { - elementId: { - type: String as PropType<UUID>, - required: true - } - }, - components: { - DropdownContent - }, - computed: { - ...mapState(useEntityStore, ['links']), - allLinks (): EntityLink[] | null { - if (this.links) return this.links.results - return null - } - }, - methods: { - ...mapActions(useEntityStore, ['listLinks']) - }, - watch: { - elementId: { - immediate: true, - handler (id) { - this.listLinks(id) - } - } - } -}) -</script> - -<style scoped> -.metadata { - margin-bottom: 1em; -} -.content, .content pre { - margin-bottom: 0; -} -.panel-block { - justify-content: space-between; - cursor: default; -} -.metadata-content { - flex: 1; -} -</style> diff --git a/src/helpers/entity.ts b/src/helpers/entity.ts index b4517dab0..8c963818c 100644 --- a/src/helpers/entity.ts +++ b/src/helpers/entity.ts @@ -1,6 +1,8 @@ import { EntityLight, TranscriptionEntity } from '@/types/entity' import { orderBy } from 'lodash' +export type TranscriptionEntityLight = Omit<TranscriptionEntity, 'worker_run' | 'worker_version_id' | 'confidence'> + export interface Token { offset: number, text: string, @@ -9,8 +11,6 @@ export interface Token { overflow?: boolean } -export type TranscriptionEntityLight = Omit<TranscriptionEntity, 'worker_run' | 'worker_version_id' | 'confidence'> - /** * Parse TranscriptionEntitys to place them on a transcription text using a series of Token components. * @param text Transcription text to place the entities on. diff --git a/src/stores/entity.ts b/src/stores/entity.ts index dfe5d6897..a3b88fb64 100644 --- a/src/stores/entity.ts +++ b/src/stores/entity.ts @@ -1,9 +1,9 @@ import { ElementTiny, PageNumberPagination, UUID } from '@/types' import { defineStore } from 'pinia' import { useNotificationStore } from './notification' -import { CorpusEntitiesListParameters, PageNumberPaginationParameters, listCorpusEntities, listElementLinks, listEntityElements, listTranscriptionEntities, retrieveEntity } from '@/api' +import { CorpusEntitiesListParameters, PageNumberPaginationParameters, listCorpusEntities, listEntityElements, listTranscriptionEntities, retrieveEntity } from '@/api' import { errorParser } from '@/helpers' -import { Entity, EntityLight, EntityLink, TranscriptionEntity } from '@/types/entity' +import { Entity, EntityLight, TranscriptionEntity } from '@/types/entity' export interface EntityTranscriptionResults extends PageNumberPagination<TranscriptionEntity> { loaded: number @@ -18,10 +18,6 @@ interface State { * A page of entities retrieved for the entity list page */ entities: PageNumberPagination<EntityLight> | null, - /** - * A page of entity links found in an element - */ - links: PageNumberPagination<EntityLink> | null, /** * A page of elements related to an entity */ @@ -39,7 +35,6 @@ export const useEntityStore = defineStore('entity', { state: (): State => ({ entity: null, entities: null, - links: null, elements: null, inTranscription: {} }), @@ -57,14 +52,6 @@ export const useEntityStore = defineStore('entity', { } }, - async listLinks (id: UUID) { - try { - this.links = await listElementLinks(id) - } catch (err) { - useNotificationStore().notify({ type: 'error', text: errorParser(err) }) - } - }, - async listElements (id: UUID, params: PageNumberPaginationParameters) { try { this.elements = await listEntityElements(id, params) @@ -93,4 +80,4 @@ export const useEntityStore = defineStore('entity', { } } } -}) \ No newline at end of file +}) diff --git a/src/types/entity.ts b/src/types/entity.ts index c2a7b38f9..a6902e058 100644 --- a/src/types/entity.ts +++ b/src/types/entity.ts @@ -14,14 +14,6 @@ export interface EntityType { color: string } -export interface EntityRole { - id: UUID - parent_name: string - child_name: string - parent_type_id: UUID - child_type_id: UUID -} - export interface EntityLight { id: UUID name: string @@ -32,17 +24,8 @@ export interface EntityLight { worker_run: WorkerRunSummary | null } -export interface EntityLink { - id: UUID - parent: EntityLight - child: EntityLight - role: EntityRole -} - export interface Entity extends EntityLight { corpus: CorpusLight - children: EntityLink[] - parents: EntityLink[] } export interface TranscriptionEntity { diff --git a/src/views/Entity/Details.vue b/src/views/Entity/Details.vue index 095062c04..31b961804 100644 --- a/src/views/Entity/Details.vue +++ b/src/views/Entity/Details.vue @@ -45,66 +45,6 @@ <div class="notification is-warning" v-else> No details available. </div> - <hr /> - - <h2 class="title is-4">{{ entity.children.length !== 0 ? entity.children.length : '' }} Parents</h2> - <table class="table" v-if="entity.children.length !== 0"> - <thead> - <th>Parent name</th> - <th>Parent role</th> - <th></th> - <th>Child role</th> - </thead> - <tbody> - <tr v-for="child in entity.children" :key="child.id"> - <td> - <router-link :to="{ name: 'entity-details', params: { id: child.parent.id } }">{{ child.parent.name }}</router-link> - </td> - <td> - <span class="tag" :style="entityStyle(child.parent.type)">{{ child.role.parent_name }}</span> - </td> - <td> - <i class="icon-arrow-right"></i> - </td> - <td> - <span class="tag" :style="entityStyle(child.child.type)">{{ child.role.child_name }}</span> - </td> - </tr> - </tbody> - </table> - <div class="notification is-warning" v-else> - No parents available. - </div> - <hr /> - - <h2 class="title is-4"> {{ entity.parents.length !== 0 ? entity.parents.length : '' }} Children</h2> - <table class="table" v-if="entity.parents.length !== 0"> - <thead> - <th>Child name</th> - <th>Parent role</th> - <th></th> - <th>Child role</th> - </thead> - <tbody> - <tr v-for="parent in entity.parents" :key="parent.id"> - <td> - <router-link :to="{ name: 'entity-details', params: { id: parent.child.id } }">{{ parent.child.name }}</router-link> - </td> - <td> - <span class="tag" :style="entityStyle(parent.parent.type)">{{ parent.role.parent_name }}</span> - </td> - <td> - <i class="icon-arrow-right"></i> - </td> - <td> - <span class="tag" :style="entityStyle(parent.child.type)">{{ parent.role.child_name }}</span> - </td> - </tr> - </tbody> - </table> - <div class="notification is-warning" v-else> - No children available. - </div> </div> </div> diff --git a/tests/unit/stores/entity.spec.js b/tests/unit/stores/entity.spec.js index 05bcef1b1..f6e1c9a72 100644 --- a/tests/unit/stores/entity.spec.js +++ b/tests/unit/stores/entity.spec.js @@ -2,7 +2,7 @@ import { assert } from 'chai' import axios from 'axios' import { FakeAxios, assertRejects, setUpTestPinia, actionsCompletedPlugin } from '../testhelpers' import { useEntityStore, useNotificationStore } from '@/stores' -import { elementSample, entitiesSample, entitySample, linksSample, entitiesInTranscriptionSample } from '../samples' +import { elementSample, entitiesSample, entitySample, entitiesInTranscriptionSample } from '../samples' describe('entity', () => { describe('actions', () => { @@ -62,25 +62,6 @@ describe('entity', () => { }) }) - describe('listLinks', () => { - it('lists links', async () => { - mock.onGet('/element/elementid/links/').reply(200, linksSample) - await store.listLinks('elementid') - assert.deepStrictEqual(store.links, linksSample) - }) - - it('handles errors', async () => { - mock.onGet('/element/elementid/links/').reply(400, 'no') - await store.listLinks('elementid') - assert.deepStrictEqual(store.links, null) - assert.deepStrictEqual(notificationStore.notifications, [{ - id: 0, - type: 'error', - text: 'no' - }]) - }) - }) - describe('listElements', () => { it('lists elements related to an entity', async () => { mock.onGet('/entity/entityid/elements/').reply(200, elementSample) -- GitLab