Skip to content

Commit 5b5dbb9

Browse files
authored
refactor(wikibase-schema-editor): harmonize qualifiers and references editors (#130)
1 parent c77ffbb commit 5b5dbb9

20 files changed

Lines changed: 761 additions & 991 deletions

frontend/.eslintrc-auto-import.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"ProjectFile": true,
4242
"PropType": true,
4343
"PropertyReference": true,
44+
"PropertyValueEditorActions": true,
45+
"PropertyValueEditorOptions": true,
46+
"PropertyValueEditorState": true,
4447
"PropertyValueMap": true,
4548
"Ref": true,
4649
"ReferenceSchemaMapping": true,
@@ -53,6 +56,7 @@
5356
"Slot": true,
5457
"Slots": true,
5558
"StatementRank": true,
59+
"StatementSchema": true,
5660
"StatementSchemaMapping": true,
5761
"TermsSchemaMapping": true,
5862
"TransformationFunction": true,
@@ -321,6 +325,8 @@
321325
"useProjectListStore": true,
322326
"useProjectStore": true,
323327
"usePropertySelection": true,
328+
"usePropertyValueDisplay": true,
329+
"usePropertyValueEditor": true,
324330
"useRafFn": true,
325331
"useRefHistory": true,
326332
"useReferenceValueMapping": true,

frontend/auto-imports.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ declare global {
259259
const useProjectListStore: typeof import('./src/features/project-management/stores/project-list.store')['useProjectListStore']
260260
const useProjectStore: typeof import('./src/features/project-management/stores/project.store')['useProjectStore']
261261
const usePropertySelection: typeof import('./src/features/wikibase-schema/composables/usePropertySelection')['usePropertySelection']
262+
const usePropertyValueDisplay: typeof import('./src/features/wikibase-schema/composables/usePropertyValueDisplay')['usePropertyValueDisplay']
263+
const usePropertyValueEditor: typeof import('./src/features/wikibase-schema/composables/usePropertyValueEditor')['usePropertyValueEditor']
262264
const useRafFn: typeof import('@vueuse/core')['useRafFn']
263265
const useRefHistory: typeof import('@vueuse/core')['useRefHistory']
264266
const useReferenceValueMapping: typeof import('./src/features/wikibase-schema/composables/useReferenceValueMapping')['useReferenceValueMapping']
@@ -373,6 +375,9 @@ declare global {
373375
export type { ProjectColumn } from './src/features/data-processing/composables/useColumnGeneration'
374376
import('./src/features/data-processing/composables/useColumnGeneration')
375377
// @ts-ignore
378+
export type { PropertyValueEditorState, PropertyValueEditorActions, PropertyValueEditorOptions } from './src/features/wikibase-schema/composables/usePropertyValueEditor'
379+
import('./src/features/wikibase-schema/composables/usePropertyValueEditor')
380+
// @ts-ignore
376381
export type { SchemaRequest } from './src/features/wikibase-schema/composables/useSchemaApi'
377382
import('./src/features/wikibase-schema/composables/useSchemaApi')
378383
// @ts-ignore
@@ -394,7 +399,7 @@ declare global {
394399
export type { ProjectFile, FileSelectEvent, FileRemoveEvent, ApiClient } from './src/shared/types/index'
395400
import('./src/shared/types/index')
396401
// @ts-ignore
397-
export type { ValidationErrorType, ValidationErrorCode, ValidationError, ValidationResult, ValidationContext, WikibaseSchemaMapping, TransformationFunction, TransformationParameter, ColumnInfo } from './src/shared/types/wikibase-schema'
402+
export type { ValidationErrorType, ValidationErrorCode, ValidationError, ValidationResult, ValidationContext, WikibaseSchemaMapping, TransformationFunction, TransformationParameter, StatementSchema, ColumnInfo } from './src/shared/types/wikibase-schema'
398403
import('./src/shared/types/wikibase-schema')
399404
}
400405

@@ -656,6 +661,8 @@ declare module 'vue' {
656661
readonly useProjectListStore: UnwrapRef<typeof import('./src/features/project-management/stores/project-list.store')['useProjectListStore']>
657662
readonly useProjectStore: UnwrapRef<typeof import('./src/features/project-management/stores/project.store')['useProjectStore']>
658663
readonly usePropertySelection: UnwrapRef<typeof import('./src/features/wikibase-schema/composables/usePropertySelection')['usePropertySelection']>
664+
readonly usePropertyValueDisplay: UnwrapRef<typeof import('./src/features/wikibase-schema/composables/usePropertyValueDisplay')['usePropertyValueDisplay']>
665+
readonly usePropertyValueEditor: UnwrapRef<typeof import('./src/features/wikibase-schema/composables/usePropertyValueEditor')['usePropertyValueEditor']>
659666
readonly useRafFn: UnwrapRef<typeof import('@vueuse/core')['useRafFn']>
660667
readonly useRefHistory: UnwrapRef<typeof import('@vueuse/core')['useRefHistory']>
661668
readonly useReferenceValueMapping: UnwrapRef<typeof import('./src/features/wikibase-schema/composables/useReferenceValueMapping')['useReferenceValueMapping']>

frontend/components.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {}
99
declare module 'vue' {
1010
export interface GlobalComponents {
1111
AutoComplete: typeof import('primevue/autocomplete')['default']
12+
BasePropertyValueEditor: typeof import('./src/features/wikibase-schema/components/BasePropertyValueEditor.vue')['default']
1213
Button: typeof import('primevue/button')['default']
1314
Card: typeof import('primevue/card')['default']
1415
Chip: typeof import('primevue/chip')['default']
@@ -31,8 +32,11 @@ declare module 'vue' {
3132
ProgressSpinner: typeof import('primevue/progressspinner')['default']
3233
ProjectView: typeof import('./src/features/project-management/pages/ProjectView.vue')['default']
3334
PropertySelector: typeof import('./src/features/wikibase-schema/components/PropertySelector.vue')['default']
35+
PropertyValueItem: typeof import('./src/features/wikibase-schema/components/PropertyValueItem.vue')['default']
36+
PropertyValueList: typeof import('./src/features/wikibase-schema/components/PropertyValueList.vue')['default']
3437
PropertyValueMappingEditor: typeof import('./src/features/wikibase-schema/components/PropertyValueMappingEditor.vue')['default']
3538
QualifiersEditor: typeof import('./src/features/wikibase-schema/components/QualifiersEditor.vue')['default']
39+
ReferenceContainer: typeof import('./src/features/wikibase-schema/components/ReferenceContainer.vue')['default']
3640
ReferencesEditor: typeof import('./src/features/wikibase-schema/components/ReferencesEditor.vue')['default']
3741
RouterLink: typeof import('vue-router')['RouterLink']
3842
RouterView: typeof import('vue-router')['RouterView']
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<script setup lang="ts" generic="T">
2+
// Props
3+
interface Props<T> {
4+
items: T[]
5+
title: string
6+
singularLabel: string
7+
pluralLabel: string
8+
addButtonLabel: string
9+
addButtonTestId?: string
10+
emptyMessage: string
11+
headerIcon?: string
12+
emptyIcon?: string
13+
getItemKey?: (item: T, index: number) => string
14+
showEditor?: boolean
15+
currentItem?: T
16+
isEditing?: boolean
17+
}
18+
19+
withDefaults(defineProps<Props<T>>(), {
20+
addButtonTestId: 'add-item-button',
21+
headerIcon: 'pi pi-list',
22+
emptyIcon: 'pi pi-inbox',
23+
getItemKey: (_, index) => `item-${index}`,
24+
showEditor: false,
25+
currentItem: undefined,
26+
isEditing: false,
27+
})
28+
29+
// Emits
30+
interface Emits<T> {
31+
add: []
32+
edit: [index: number]
33+
remove: [index: number]
34+
save: [item: T]
35+
cancel: []
36+
}
37+
38+
const emit = defineEmits<Emits<T>>()
39+
40+
// Event handlers
41+
const handleAdd = () => {
42+
emit('add')
43+
}
44+
45+
const handleEdit = (index: number) => {
46+
emit('edit', index)
47+
}
48+
49+
const handleRemove = (index: number) => {
50+
emit('remove', index)
51+
}
52+
53+
const handleSave = (item: T) => {
54+
emit('save', item)
55+
}
56+
57+
const handleCancel = () => {
58+
emit('cancel')
59+
}
60+
</script>
61+
62+
<template>
63+
<div class="space-y-4">
64+
<!-- Header with Add Button -->
65+
<PropertyValueList
66+
:items="items"
67+
:title="title"
68+
:singular-label="singularLabel"
69+
:plural-label="pluralLabel"
70+
:add-button-label="addButtonLabel"
71+
:add-button-test-id="addButtonTestId"
72+
:empty-message="emptyMessage"
73+
:header-icon="headerIcon"
74+
:empty-icon="emptyIcon"
75+
:get-item-key="getItemKey"
76+
@add="handleAdd"
77+
@edit="handleEdit"
78+
@remove="handleRemove"
79+
>
80+
<template #item="{ item, index, onEdit, onRemove }">
81+
<slot
82+
name="item"
83+
:item="item"
84+
:index="index"
85+
:on-edit="onEdit"
86+
:on-remove="onRemove"
87+
/>
88+
</template>
89+
</PropertyValueList>
90+
91+
<!-- Single Item Editor -->
92+
<slot
93+
v-if="showEditor"
94+
name="editor"
95+
:current-item="currentItem"
96+
:is-editing="isEditing"
97+
:on-save="handleSave"
98+
:on-cancel="handleCancel"
99+
/>
100+
</div>
101+
</template>

0 commit comments

Comments
 (0)