fix(editor): view recorded in storage may not exist (#9788)

fix: BS-2415
This commit is contained in:
zzj3720
2025-01-20 05:36:42 +00:00
parent 1a18aeb22e
commit 66b6fd8b74
5 changed files with 25 additions and 13 deletions
@@ -473,7 +473,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
return duplicateView(this._model, id);
}
viewDataGet(viewId: string): DataViewDataType {
viewDataGet(viewId: string): DataViewDataType | undefined {
return this.viewDataList$.value.find(data => data.id === viewId)!;
}
@@ -499,8 +499,11 @@ export class DatabaseBlockDataSource extends DataSourceBase {
return view;
}
viewMetaGetById(viewId: string): ViewMeta {
viewMetaGetById(viewId: string): ViewMeta | undefined {
const view = this.viewDataGet(viewId);
if (!view) {
return;
}
return this.viewMetaGet(view.mode);
}
}
@@ -333,7 +333,12 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent<DatabaseBloc
this._dataSource = new DatabaseBlockDataSource(this.model);
this._dataSource.contextSet(HostContextKey, this.host);
const id = currentViewStorage.getCurrentView(this.model.id);
if (id) {
if (id && this.dataSource.viewManager.viewGet(id)) {
console.log(
'set current view',
id,
this._dataSource.viewManager.viewGet(id)
);
this.dataSource.viewManager.setCurrentView(id);
}
}