Skip to content

Commit

Permalink
Merge pull request #1091 from libris/feature/lxl-4504-catalogue-singl…
Browse files Browse the repository at this point in the history
…e-item

# Summary of changes
    * Add settings.extractableMappedTypes that specifies which types can be extracted and which type they should be converted to. That is, Item can be extracted to its own document and should then be converted to 'SingleItem. This is a bit clumsy but does the job for now.
    * When loading a record/document, other documents that should be inlined are moved from quoted to the main inspector data.
        * This is done for linked things in properties with category compositional (only hasComponent...).
            * TODO? Should be compositional + integral
        * Their ETags are fetched and stored for later use.
        * We count on embellish data to include the whole docs and don't fetch the doc data separately.
    * When saving, inlined documents are extracted and updated before the main document in separate requests.
    * Inlined records that should be deleted are deleted after the main doc is saved (this might fail...).
    * 81208b0 breaks out the id-pill used in the top right corner of entity-summary to its own component.
    * bcf023b contains the main changes.
    * The other commits just remove obsolete and dead code that I encountered.

# Not in scope

There is no way to move (link) a SingleItem to another holding record.
  • Loading branch information
olovy authored Aug 21, 2024
2 parents 58502bf + 6fbccd8 commit 1f34c0a
Show file tree
Hide file tree
Showing 20 changed files with 434 additions and 912 deletions.
3 changes: 3 additions & 0 deletions lxljs/vocab.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ export function getRecordType(mainEntityType, vocab, context) {
// Mostly added as to not throw an error while the data is being picked up.
return null;
}
if (isSubClassOf(mainEntityType, 'SingleItem', vocab, context)) {
return 'SingleItem';
}
if (isSubClassOf(mainEntityType, 'Item', vocab, context)) {
return 'Item';
}
Expand Down
2 changes: 1 addition & 1 deletion vue-client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ body {
}
}
}
input, textarea, img, select, .ItemEntity, .ItemLocal, .EntityAction, .ItemSibling, .icon, .icon i, li, i.fa, div {
input, textarea, img, select, .ItemEntity, .ItemLocal, .EntityAction, .icon, .icon i, li, i.fa, div {
&:focus {
.focus-mixin-border();
}
Expand Down
23 changes: 0 additions & 23 deletions vue-client/src/components/inspector/entity-adder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -383,29 +383,6 @@ export default {
addToHistory: true,
});
},
addSibling(obj) {
const linkObj = { '@id': `${this.inspector.data.record['@id']}#work` };
const workObj = obj;
workObj['@id'] = linkObj['@id'];
this.$store.dispatch('setInspectorStatusValue', {
property: 'lastAdded',
value: 'work',
});
this.$store.dispatch('updateInspectorData', {
changeList: [
{
path: `${this.path}`,
value: linkObj,
},
{
path: 'work',
value: workObj,
},
],
addToHistory: true,
});
},
addEmpty(typeId) {
this.hide();
const shortenedType = StringUtil.getCompactUri(typeId, this.resources.context);
Expand Down
79 changes: 14 additions & 65 deletions vue-client/src/components/inspector/field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import ItemLocal from './item-local.vue';
import ItemError from './item-error.vue';
import ItemVocab from './item-vocab.vue';
import ItemType from './item-type.vue';
import ItemSibling from './item-sibling.vue';
import ItemBoolean from './item-boolean.vue';
import ItemNumeric from './item-numeric.vue';
import ItemGrouped from './item-grouped.vue';
Expand Down Expand Up @@ -131,7 +130,6 @@ export default {
activeModal: false,
removeHover: false,
pasteHover: false,
foundChip: false,
removed: false,
uniqueIds: [],
};
Expand All @@ -141,7 +139,6 @@ export default {
'item-entity': ItemEntity,
'item-value': ItemValue,
'item-local': ItemLocal,
'item-sibling': ItemSibling,
'item-error': ItemError,
'item-vocab': ItemVocab,
'item-boolean': ItemBoolean,
Expand Down Expand Up @@ -269,7 +266,8 @@ export default {
this.resources.context,
this.resources.vocabClasses,
).map((item) => StringUtil.getCompactUri(item, this.resources.context));
return fetchedRange;
const unselectableTypes = Object.values(this.settings.extractableMappedTypes);
return fetchedRange.filter((t) => !unselectableTypes.includes(t));
},
allSearchTypes() {
if (this.allValuesFrom.length > 0) {
Expand Down Expand Up @@ -376,15 +374,6 @@ export default {
}
return `${this.parentPath}.${this.fieldKey}`;
},
isMarc() {
return this.fieldKey.startsWith('marc:');
},
isChild() {
if (this.parentPath !== 'mainEntity') {
return true;
}
return false;
},
isLangMapWithPartner() {
return this.isLangMap && this.hasProp;
},
Expand All @@ -399,12 +388,10 @@ export default {
);
},
isCompositional() {
if (this.keyAsVocabProperty && this.keyAsVocabProperty.hasOwnProperty('category')) {
if (this.keyAsVocabProperty.category['@id'] === 'https://id.kb.se/vocab/compositional') {
return true;
}
}
return false;
return VocabUtil.hasCategory(this.keyAsVocabProperty, 'compositional', this.resources);
},
isHistoryView() {
return this.diff !== null;
},
hasSingleValue() {
if (!isArray(this.fieldValue) || this.fieldValue.length === 1) {
Expand Down Expand Up @@ -560,15 +547,12 @@ export default {
if (this.fieldKey === '@type' || VocabUtil.getContextValue(this.fieldKey, '@type', this.resources.context) === '@vocab') {
return 'vocab';
}
if (this.isPlainObject(o) && (!this.isLinked(o) || this.isInlined(o))) {
return 'local';
}
if (this.isPlainObject(o) && this.isLinked(o)) {
return 'entity';
}
if (this.isPlainObject(o) && o.hasOwnProperty('@id') && this.isInGraph(o)) {
return 'sibling';
}
if (this.isPlainObject(o) && !this.isLinked(o)) {
return 'local';
}
if (this.range && this.range.length > 0 && this.range.every((r) => Object.keys(VocabUtil.XSD_NUMERIC_TYPES).includes(r))) {
return 'numeric';
}
Expand All @@ -584,21 +568,11 @@ export default {
if (typeof o === 'undefined') {
throw new Error('Cannot check link status of undefined object.');
}
if (o.hasOwnProperty('@id') && !o.hasOwnProperty('@type')) {
return true;
}
return false;
return o.hasOwnProperty('@id');
},
isInGraph(o) {
const data = this.inspector.data;
for (const point in data) {
if (data[point] !== null) {
if (data[point]['@id'] === o['@id']) {
return true;
}
}
}
return false;
isInlined(o) {
// FIXME
return this.isLinked(o) && Object.keys(o).length > 1 && this.isCompositional && !this.isHistoryView;
},
isEmbedded(o) {
const type = o['@type'];
Expand All @@ -607,13 +581,6 @@ export default {
}
return VocabUtil.isEmbedded(type, this.resources.vocab, this.settings);
},
isChip(item) {
if (this.getDatatype(item) === 'entity') {
this.foundChip = true;
return true;
}
return false;
},
highLightLastAdded() {
if (this.isLastAdded === true) {
if (this.fieldValue === null || (isArray(this.fieldValue) && this.fieldValue.length === 0)) {
Expand Down Expand Up @@ -948,7 +915,7 @@ export default {
:diff="diff"
:parent-path="path" />

<!-- Not linked, local child objects -->
<!-- Not linked, local child objects OR inlined linked objects-->
<item-local
:data-parent="path"
v-if="getDatatype(item) == 'local'"
Expand All @@ -967,24 +934,6 @@ export default {
:in-array="valueIsArray"
:diff="diff"
:should-expand="expandChildren || embellished" />

<item-sibling
v-if="getDatatype(item) == 'sibling'"
:id="item['@id']"
:is-locked="locked"
:field-key="fieldKey"
:entity-type="entityType"
:is-compositional="isCompositional"
:all-values-from="allValuesFrom"
:some-values-from="someValuesFrom"
:all-search-types="allSearchTypes"
:range="range"
:range-full="rangeFull"
:index="index"
:in-array="valueIsArray"
:diff="diff"
:should-expand="expandChildren || embellished"
:parent-path="path" />
</div>
<portal-target :name="`typeSelect-${path}`" />
</div>
Expand Down
10 changes: 5 additions & 5 deletions vue-client/src/components/inspector/item-entity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export default {
isCardWithData() {
return this.isCard && this.focusData && Object.keys(this.focusData).length > 1;
},
isHistoryView() {
return this.diff != null;
},
},
watch: {
'inspector.event'(val) {
Expand Down Expand Up @@ -128,17 +131,14 @@ export default {
removeFocus() {
this.focused = false;
},
isHistoryView() {
return this.diff != null;
},
},
components: {
Menu,
PreviewCard,
ReverseRelations,
},
created() {
if (this.$store.state.settings.defaultExpandedProperties.includes(this.fieldKey)) {
if (this.$store.state.settings.defaultExpandedProperties.includes(this.fieldKey) && !this.isHistoryView) {
this.expand();
}
},
Expand All @@ -151,7 +151,7 @@ export default {
}
}).catch((error) => console.error(error));
}
if (this.isExpanded && !this.isHistoryView()) {
if (this.isExpanded && !this.isHistoryView) {
this.expand();
}
if (this.isNewlyAdded) {
Expand Down
Loading

0 comments on commit 1f34c0a

Please sign in to comment.