From 47f090c060a52f544fd77351f702f863bfc4963c Mon Sep 17 00:00:00 2001 From: Andrew Simachev Date: Fri, 10 Jan 2025 16:26:35 +0100 Subject: [PATCH 1/2] JS-6162: Remove relation links --- src/ts/component/block/dataview.tsx | 2 +- src/ts/lib/dataview.ts | 2 +- src/ts/lib/relation.ts | 4 ++-- src/ts/store/detail.ts | 4 ++++ src/ts/store/record.ts | 31 +++++++++++++++++++++++++---- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/ts/component/block/dataview.tsx b/src/ts/component/block/dataview.tsx index ec5253f6a9..b4845c893b 100644 --- a/src/ts/component/block/dataview.tsx +++ b/src/ts/component/block/dataview.tsx @@ -1212,7 +1212,7 @@ const BlockDataview = observer(class BlockDataview extends React.Component keys.includes(it.relationKey)); }; diff --git a/src/ts/lib/dataview.ts b/src/ts/lib/dataview.ts index 5c7d788865..790428c0d7 100644 --- a/src/ts/lib/dataview.ts +++ b/src/ts/lib/dataview.ts @@ -12,7 +12,7 @@ class Dataview { const order: any = {}; - let relations = U.Common.objectCopy(S.Record.getObjectRelations(rootId, blockId)).filter(it => it); + let relations = U.Common.objectCopy(S.Record.getDataviewRelations(rootId, blockId)).filter(it => it); let o = 0; if (!config.debug.hiddenObject) { diff --git a/src/ts/lib/relation.ts b/src/ts/lib/relation.ts index 3db37df76f..8ce6cc9cbe 100644 --- a/src/ts/lib/relation.ts +++ b/src/ts/lib/relation.ts @@ -428,7 +428,7 @@ class Relation { public getCoverOptions (rootId: string, blockId: string) { const formats = [ I.RelationType.File ]; - const options: any[] = U.Common.objectCopy(S.Record.getObjectRelations(rootId, blockId)).filter(it => { + const options: any[] = U.Common.objectCopy(S.Record.getDataviewRelations(rootId, blockId)).filter(it => { if (it.isInstalled && (it.relationKey == 'picture')) { return true; }; @@ -460,7 +460,7 @@ class Relation { }; }; - let options: any[] = S.Record.getObjectRelations(rootId, blockId).filter((it: any) => { + let options: any[] = S.Record.getDataviewRelations(rootId, blockId).filter((it: any) => { return it.isInstalled && formats.includes(it.format) && !it.isHidden; }); diff --git a/src/ts/store/detail.ts b/src/ts/store/detail.ts index 8d37594956..be3087443c 100644 --- a/src/ts/store/detail.ts +++ b/src/ts/store/detail.ts @@ -167,6 +167,10 @@ class DetailStore { return this.mapper(object, skipLayoutFormat); }; + public getKeys (rootId: string, id: string): string[] { + return (this.map.get(rootId)?.get(id) || []).map(it => it.relationKey); + }; + /** Mutates object provided and also returns a new object. Sets defaults. * This Function contains domain logic which should be encapsulated in a model */ public mapper (object: any, skipLayoutFormat?: I.ObjectLayout[]): any { diff --git a/src/ts/store/record.ts b/src/ts/store/record.ts index 521d71e51f..60002ad0a3 100644 --- a/src/ts/store/record.ts +++ b/src/ts/store/record.ts @@ -1,5 +1,5 @@ import { observable, action, set, intercept, makeObservable } from 'mobx'; -import { S, I, M, U, J, Dataview } from 'Lib'; +import { S, I, M, U, J, Dataview, Relation } from 'Lib'; enum KeyMapType { Relation = 'relation', @@ -104,7 +104,7 @@ class RecordStore { relationListDelete (rootId: string, blockId: string, keys: string[]) { const key = this.getId(rootId, blockId); - const relations = this.getObjectRelations(rootId, blockId).filter(it => !keys.includes(it.relationKey)); + const relations = this.getDataviewRelations(rootId, blockId).filter(it => !keys.includes(it.relationKey)); this.relationMap.set(key, relations.map(it => ({ relationKey: it.relationKey, format: it.format }))); }; @@ -312,8 +312,21 @@ class RecordStore { return (this.relationMap.get(this.getId(rootId, blockId)) || []).map(it => it.relationKey); }; - getObjectRelations (rootId: string, blockId: string): any[] { - return this.getObjectRelationKeys(rootId, blockId).map(it => this.getRelationByKey(it)).filter(it => it); + getObjectRelations (rootId: string, typeId: string): any[] { + const type = S.Record.getTypeById(typeId); + const recommended = Relation.getArrayValue(type?.recommendedRelations); + const typeRelations = recommended.map(it => this.getRelationById(it)).filter(it => it); + const objectRelations = S.Detail.getKeys(rootId, rootId).map(it => this.getRelationByKey(it)).filter(it => it && !recommended.includes(it.id)); + + return this.checkHiddenObjects(typeRelations.concat(objectRelations)); + }; + + getDataviewRelationKeys (rootId: string, blockId: string): any[] { + return (this.relationMap.get(this.getId(rootId, blockId)) || []).map(it => it.relationKey); + }; + + getDataviewRelations (rootId: string, blockId: string): any[] { + return this.getDataviewRelationKeys(rootId, blockId).map(it => this.getRelationByKey(it)).filter(it => it); }; getRelationByKey (relationKey: string): any { @@ -382,6 +395,16 @@ class RecordStore { return [ rootId, blockId, groupId ].join('-'); }; + checkHiddenObjects (records: any[]): any[] { + const isHidden = S.Common.config.debug.hiddenObject; + + if (!Array.isArray(records)) { + return []; + }; + + return records.filter(it => isHidden ? true : !it.isHidden); + }; + }; export const Record: RecordStore = new RecordStore(); \ No newline at end of file From 6b5ab4a4c95ad2b9676f559a8c8c577f8a13d195 Mon Sep 17 00:00:00 2001 From: Andrew Simachev Date: Fri, 10 Jan 2025 19:17:42 +0100 Subject: [PATCH 2/2] remove relationLinks mapping --- src/ts/lib/api/dispatcher.ts | 3 +-- src/ts/lib/api/mapper.ts | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ts/lib/api/dispatcher.ts b/src/ts/lib/api/dispatcher.ts index 5e41834bfb..8081a65fa3 100644 --- a/src/ts/lib/api/dispatcher.ts +++ b/src/ts/lib/api/dispatcher.ts @@ -1136,7 +1136,7 @@ class Dispatcher { }; onObjectView (rootId: string, traceId: string, objectView: any) { - const { details, restrictions, relationLinks, participants } = objectView; + const { details, restrictions, participants } = objectView; const root = objectView.blocks.find(it => it.id == rootId); const structure: any[] = []; const contextId = [ rootId, traceId ].filter(it => it).join('-'); @@ -1147,7 +1147,6 @@ class Dispatcher { analytics.removeContext(); }; - S.Record.relationsSet(contextId, rootId, relationLinks); S.Detail.set(contextId, details); S.Block.restrictionsSet(contextId, restrictions); S.Block.participantsSet(contextId, participants); diff --git a/src/ts/lib/api/mapper.ts b/src/ts/lib/api/mapper.ts index d317d9f70c..5dd173a4e1 100644 --- a/src/ts/lib/api/mapper.ts +++ b/src/ts/lib/api/mapper.ts @@ -415,7 +415,6 @@ export const Mapper = { rootId: obj.getRootid(), blocks: (obj.getBlocksList() || []).map(Mapper.From.Block), details: (obj.getDetailsList() || []).map(Mapper.From.Details), - relationLinks: (obj.getRelationlinksList() || []).map(Mapper.From.RelationLink), restrictions: Mapper.From.Restrictions(obj.getRestrictions()), participants: (obj.getBlockparticipantsList() || []).map(it => ({ blockId: it.getBlockid(),