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:
EYHN
2025-05-28 14:40:31 +00:00
parent acf92aa3da
commit 6e190b9703

View File

@@ -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 {