Skip to content
Snippets Groups Projects
Commit 39e28851 authored by Theo Lesage's avatar Theo Lesage
Browse files

Wreck the entity link display

parent 32e5ecbf
No related branches found
No related tags found
1 merge request!1655Wreck the entity link display
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)
......
......@@ -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,
......
<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>
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.
......
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
})
......@@ -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 {
......
......@@ -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>
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment