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:
parent
4b355bdb08
commit
17167e982a
12 changed files with 13 additions and 22 deletions
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 });
|
||||
|
|
|
@ -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[] = [
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue