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) {
|
if (collection.id === id) {
|
||||||
this.rootYDoc.transact(() => {
|
this.rootYDoc.transact(() => {
|
||||||
yArray.delete(collectionIndex, 1);
|
yArray.delete(collectionIndex, 1);
|
||||||
|
const migratedCollectionInfo = this.migrateCollectionInfo(collection);
|
||||||
yArray.insert(collectionIndex, [
|
yArray.insert(collectionIndex, [
|
||||||
{
|
{
|
||||||
id: collection.id,
|
id: collection.id,
|
||||||
name: info.name ?? collection.name,
|
name: info.name ?? migratedCollectionInfo.name,
|
||||||
rules: info.rules ?? collection.rules,
|
rules: info.rules ?? migratedCollectionInfo.rules,
|
||||||
allowList: info.allowList ?? collection.allowList,
|
allowList: info.allowList ?? migratedCollectionInfo.allowList,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
@@ -183,7 +184,7 @@ export class CollectionStore extends Store {
|
|||||||
migrateCollectionInfo(
|
migrateCollectionInfo(
|
||||||
legacyCollectionInfo: LegacyCollectionInfo
|
legacyCollectionInfo: LegacyCollectionInfo
|
||||||
): CollectionInfo {
|
): CollectionInfo {
|
||||||
if ('rules' in legacyCollectionInfo) {
|
if ('rules' in legacyCollectionInfo && legacyCollectionInfo.rules) {
|
||||||
return legacyCollectionInfo as CollectionInfo;
|
return legacyCollectionInfo as CollectionInfo;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user