Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-6162: Remove relation links #1148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ts/component/block/dataview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ const BlockDataview = observer(class BlockDataview extends React.Component<Props
return [];
};

const keys = S.Record.getObjectRelationKeys(rootId, block.id);
const keys = S.Record.getDataviewRelationKeys(rootId, block.id);
return view.getVisibleRelations().filter(it => keys.includes(it.relationKey));
};

Expand Down
3 changes: 1 addition & 2 deletions src/ts/lib/api/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('-');
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/ts/lib/api/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/ts/lib/dataview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/ts/lib/relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
});

Expand Down
4 changes: 4 additions & 0 deletions src/ts/store/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 27 additions & 4 deletions src/ts/store/record.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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 })));
};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Loading