1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00

JS-4316: dbStore.getRecords refactoring

This commit is contained in:
Andrew Simachev 2024-04-09 15:33:38 +02:00
parent 4b355bdb08
commit 17167e982a
No known key found for this signature in database
GPG key ID: 49A163D0D14E6FD8
12 changed files with 13 additions and 22 deletions

View file

@ -237,7 +237,7 @@ const Create = observer(class Create extends React.Component<I.PageComponent, St
};
getObjects (subId: string) {
return dbStore.getRecordIds(subId, '').map(id => detailStore.get(subId, id));
return dbStore.getRecords(subId);
};
getSpaces () {

View file

@ -261,9 +261,8 @@ const ViewCalendar = observer(class ViewCalendar extends React.Component<I.ViewC
getItems () {
const { getView } = this.props;
const view = getView();
const subId = this.getSubId();
return dbStore.getRecordIds(subId, '').map(id => detailStore.get(subId, id, [ view.groupRelationKey ]));
return dbStore.getRecords(this.getSubId(), [ view.groupRelationKey ]);
};
resize () {

View file

@ -187,8 +187,7 @@ const ListObject = observer(class ListObject extends React.Component<Props> {
};
getItems () {
const { subId } = this.props;
return dbStore.getRecordIds(subId, '').map(id => detailStore.get(subId, id, this.getKeys()));
return dbStore.getRecords(this.props.subId, this.getKeys());
};
getKeys () {

View file

@ -403,7 +403,7 @@ const ListObjectManager = observer(class ListObjectManager extends React.Compone
getItems () {
const { subId, rowLength } = this.props;
const ret: any[] = [];
const records = dbStore.getRecordIds(subId, '').map(id => detailStore.get(subId, id));
const records = dbStore.getRecords(subId);
let row = { children: [] };
let n = 0;

View file

@ -117,8 +117,7 @@ const MenuCalendarDay = observer(class MenuCalendarDay extends React.Component<I
const { data } = param;
const { rootId, block, getView, d, m, y } = data;
const view = getView();
const subId = dbStore.getSubId(rootId, block.id);
const items = dbStore.getRecordIds(subId, '').map(id => detailStore.get(subId, id, [ view.groupRelationKey ]));
const items = dbStore.getRecords(dbStore.getSubId(rootId, block.id), [ view.groupRelationKey ]);
const current = [ d, m, y ].join('-');
return items.filter(it => UtilDate.date('j-n-Y', it[view.groupRelationKey]) == current);

View file

@ -234,8 +234,7 @@ const MenuTemplateList = observer(class MenuTemplateList extends React.Component
const { param } = this.props;
const { data } = param;
const { noAdd, typeId } = data;
const subId = this.getSubId();
const items = dbStore.getRecordIds(subId, '').map(id => detailStore.get(subId, id));
const items = dbStore.getRecords(this.getSubId());
const isAllowed = UtilObject.isAllowedTemplate(typeId);
items.unshift({ id: Constant.templateId.blank });

View file

@ -527,7 +527,7 @@ const PageMainStore = observer(class PageMainStore extends React.Component<I.Pag
getItems () {
const { loading } = this.state;
const records = dbStore.getRecordIds(Constant.subId.store, '').map(id => detailStore.get(Constant.subId.store, id));
const records = dbStore.getRecords(Constant.subId.store);
const limit = this.getLimit();
let ret: any[] = [

View file

@ -155,7 +155,7 @@ const PageMainType = observer(class PageMainType extends React.Component<I.PageC
<ListObjectPreview
key="listTemplate"
ref={ref => this.refListPreview = ref}
getItems={() => dbStore.getRecordIds(subIdTemplate, '').map(id => detailStore.get(subIdTemplate, id, []))}
getItems={() => dbStore.getRecords(subIdTemplate, [])}
canAdd={allowedTemplate}
onAdd={this.onTemplateAdd}
onMenu={allowedTemplate ? (e: any, item: any) => this.onMenu(item) : null}

View file

@ -71,7 +71,7 @@ const PopupSettingsPageSpacesList = observer(class PopupSettingsPageSpacesList e
const subId = Constant.subId.space;
const sortStatuses = [ I.ParticipantStatus.Joining, I.ParticipantStatus.Active, I.ParticipantStatus.Removing ];
const sortPermissions = [ I.ParticipantPermissions.Owner, I.ParticipantPermissions.Writer, I.ParticipantPermissions.Reader ];
const items = dbStore.getRecordIds(subId, '').map(id => detailStore.get(subId, id));
const items = dbStore.getRecords(subId);
return items.filter(it => !it.isAccountDeleted && it.isLocalOk).map(it => {
const participant = UtilSpace.getMyParticipant(it.targetSpaceId);

View file

@ -287,9 +287,7 @@ const WidgetTree = observer(class WidgetTree extends React.Component<I.WidgetCom
// return the child nodes details for the given subId
getChildNodesDetails (nodeId: string): I.WidgetTreeDetails[] {
const subId = this.getSubId(nodeId);
return dbStore.getRecordIds(subId, '').map(id => this.mapper(detailStore.get(subId, id, [ 'id', 'layout', 'links' ], true)));
return dbStore.getRecords(this.getSubId(nodeId), [ 'id', 'layout', 'links' ], true).map(it => this.mapper(it));
};
mapper (item) {

View file

@ -87,14 +87,11 @@ class UtilSpace {
};
getSpaceviewBySpaceId (id: string) {
const subId = Constant.subId.space;
return dbStore.getRecordIds(subId, '').map(id => detailStore.get(subId, id)).find(it => it.targetSpaceId == id);
return dbStore.getRecords(Constant.subId.space).find(it => it.targetSpaceId == id);
};
getParticipantsList (statuses: I.ParticipantStatus[]) {
const subId = Constant.subId.participant;
return dbStore.getRecordIds(subId, '').map(id => detailStore.get(subId, id)).filter(it => statuses.includes(it.status));
return dbStore.getRecords(Constant.subId.participant).filter(it => statuses.includes(it.status));
};
getParticipantId (spaceId: string, accountId: string) {

View file

@ -352,7 +352,7 @@ class DbStore {
return this.recordMap.get(this.getId(rootId, blockId)) || [];
};
getRecords (subId: string, keys?: string[]): any[] {
getRecords (subId: string, keys?: string[], forceKeys?: boolean): any[] {
return this.getRecordIds(subId, '').map(id => detailStore.get(subId, id, keys));
};