From 463fbb99b1f48f11e28a06946886c9764843e7c3 Mon Sep 17 00:00:00 2001 From: Erwan Rouchet <rouchet@teklia.com> Date: Wed, 20 Mar 2024 15:27:01 +0100 Subject: [PATCH] Update TypeScript definitions for elements --- src/api/entity.ts | 4 ++-- src/api/image.ts | 4 ++-- src/stores/entity.ts | 4 ++-- src/stores/image.ts | 6 +++--- src/types/index.ts | 26 ++++++++++++-------------- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/api/entity.ts b/src/api/entity.ts index 05adc810a..8752e479a 100644 --- a/src/api/entity.ts +++ b/src/api/entity.ts @@ -1,6 +1,6 @@ import axios from 'axios' import { PageNumberPaginationParameters, unique } from '.' -import { ElementSlim, PageNumberPagination, UUID } from '@/types' +import { ElementTiny, PageNumberPagination, UUID } from '@/types' import { Entity, EntityLight, EntityLink, EntityType, TranscriptionEntity } from '@/types/entity' // Retrieve an entity @@ -18,7 +18,7 @@ export const listCorpusEntities = unique(async (id: UUID, params: CorpusEntities 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<ElementSlim>> => (await axios.get(`/entity/${id}/elements/`, { params })).data) +export const listEntityElements = unique(async (id: UUID, params: PageNumberPaginationParameters = {}): Promise<PageNumberPagination<ElementTiny>> => (await axios.get(`/entity/${id}/elements/`, { params })).data) interface TranscriptionEntityListParameters extends PageNumberPaginationParameters { entity_worker_run?: UUID | false diff --git a/src/api/image.ts b/src/api/image.ts index 9c58df7b5..9c7cc0615 100644 --- a/src/api/image.ts +++ b/src/api/image.ts @@ -1,5 +1,5 @@ import axios from 'axios' -import { PageNumberPagination, ElementSlim, Image, UUID } from '@/types' +import { PageNumberPagination, ElementTiny, Image, UUID } from '@/types' import { PageNumberPaginationParameters, unique } from '.' /** @@ -29,6 +29,6 @@ export interface ImageElementsParameters extends PageNumberPaginationParameters * List all elements on an image. */ export const listImageElements = unique( - async ({ id, ...params }: ImageElementsParameters): Promise<PageNumberPagination<ElementSlim>> => + async ({ id, ...params }: ImageElementsParameters): Promise<PageNumberPagination<ElementTiny>> => (await axios.get(`/image/${id}/elements/`, { params })).data ) diff --git a/src/stores/entity.ts b/src/stores/entity.ts index 917b0de9f..dfe5d6897 100644 --- a/src/stores/entity.ts +++ b/src/stores/entity.ts @@ -1,4 +1,4 @@ -import { ElementSlim, PageNumberPagination, UUID } from '@/types' +import { ElementTiny, PageNumberPagination, UUID } from '@/types' import { defineStore } from 'pinia' import { useNotificationStore } from './notification' import { CorpusEntitiesListParameters, PageNumberPaginationParameters, listCorpusEntities, listElementLinks, listEntityElements, listTranscriptionEntities, retrieveEntity } from '@/api' @@ -25,7 +25,7 @@ interface State { /** * A page of elements related to an entity */ - elements: PageNumberPagination<ElementSlim> | null, + elements: PageNumberPagination<ElementTiny> | null, /** * Entities per transcription, with pagination status * { [transcription ID]: { count, results, loaded } } diff --git a/src/stores/image.ts b/src/stores/image.ts index a5ee2bab9..f250dbbea 100644 --- a/src/stores/image.ts +++ b/src/stores/image.ts @@ -1,10 +1,10 @@ import { defineStore } from 'pinia' import { listImageElements, ImageElementsParameters } from '@/api' import { errorParser } from '@/helpers' -import { ElementSlim, PageNumberPagination, UUID } from '@/types' +import { ElementTiny, PageNumberPagination, UUID } from '@/types' import { useNotificationStore } from '.' -export interface ImageElements extends PageNumberPagination<ElementSlim> { +export interface ImageElements extends PageNumberPagination<ElementTiny> { imageId: UUID } @@ -27,7 +27,7 @@ export const useImageStore = defineStore('image', { notificationStore.notify({ type: 'error', text: errorParser(err) }) } }, - setElements (imageId: UUID, data: PageNumberPagination<ElementSlim>) { + setElements (imageId: UUID, data: PageNumberPagination<ElementTiny>) { this.elements = { ...data, imageId diff --git a/src/types/index.ts b/src/types/index.ts index 36926bd76..a744af9c3 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -147,23 +147,21 @@ export interface ElementTiny extends Required<Pick<ElementBase, 'id' | 'type' | corpus: CorpusLight } -export interface ElementSlim extends ElementTiny { +export interface Element extends ElementTiny { + created: string + creator: string | null + rights: Right[] + metadata_count: number + classifications: Classification[] + worker_version: UUID | null + worker_run: WorkerRunSummary | null + confidence: number | null /** * URL of the element's thumbnail, on which a PUT request can be made to upload a new thumbnail. - * The URL will only be available if the element's type is a folder type and the user is admin or internal. + * The URL will only be available if the element's type is a folder type + * and the user is a corpus admin, or a corpus contributor and the element's creator. */ - thumbnail_put_url?: string | null -} - -export interface Element extends ElementSlim { - created: string, - creator: string | null, - rights: Right[], - metadata_count: number, - classifications: Classification[], - worker_version: UUID | null, - worker_run: WorkerRunSummary | null, - confidence: number | null + thumbnail_put_url: string | null } export interface ElementList extends Required<Pick<ElementBase, 'id' | 'type' | 'name' | 'corpus' | 'thumbnail_url' | 'zone' | 'rotation_angle' | 'mirrored' | 'created' | 'classes' | 'metadata' | 'has_children'>> {} -- GitLab