mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
fix(core): migrate collection info before update it (#12617)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved reliability when updating collection information, ensuring data is correctly migrated and validated before saving changes. This prevents issues with incomplete or invalid collection data. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -164,12 +164,13 @@ export class CollectionStore extends Store {
|
||||
if (collection.id === id) {
|
||||
this.rootYDoc.transact(() => {
|
||||
yArray.delete(collectionIndex, 1);
|
||||
const migratedCollectionInfo = this.migrateCollectionInfo(collection);
|
||||
yArray.insert(collectionIndex, [
|
||||
{
|
||||
id: collection.id,
|
||||
name: info.name ?? collection.name,
|
||||
rules: info.rules ?? collection.rules,
|
||||
allowList: info.allowList ?? collection.allowList,
|
||||
name: info.name ?? migratedCollectionInfo.name,
|
||||
rules: info.rules ?? migratedCollectionInfo.rules,
|
||||
allowList: info.allowList ?? migratedCollectionInfo.allowList,
|
||||
},
|
||||
]);
|
||||
});
|
||||
@@ -183,7 +184,7 @@ export class CollectionStore extends Store {
|
||||
migrateCollectionInfo(
|
||||
legacyCollectionInfo: LegacyCollectionInfo
|
||||
): CollectionInfo {
|
||||
if ('rules' in legacyCollectionInfo) {
|
||||
if ('rules' in legacyCollectionInfo && legacyCollectionInfo.rules) {
|
||||
return legacyCollectionInfo as CollectionInfo;
|
||||
}
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user