fix(core): fix migrate filter list error (#13022)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved error handling for collection filter migrations, reducing the
chance of failures affecting filter lists.
* **New Features**
* Expanded support for filter conditions on the "Tags" field, including
options like "is empty," "is not empty," "contains all," and more.
* **Enhancements**
* Improved handling of "Is Favourited" and "Is Public" filters for more
consistent results.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
EYHN
2025-07-04 14:12:21 +08:00
committed by GitHub
parent 5a49d5cd24
commit f961d9986f

View File

@@ -191,7 +191,9 @@ export class CollectionStore extends Store {
id: legacyCollectionInfo.id, id: legacyCollectionInfo.id,
name: legacyCollectionInfo.name, name: legacyCollectionInfo.name,
rules: { rules: {
filters: this.migrateFilterList(legacyCollectionInfo.filterList), filters: legacyCollectionInfo.filterList
? this.migrateFilterList(legacyCollectionInfo.filterList)
: [],
}, },
allowList: legacyCollectionInfo.allowList, allowList: legacyCollectionInfo.allowList,
}; };
@@ -200,6 +202,7 @@ export class CollectionStore extends Store {
migrateFilterList( migrateFilterList(
filterList: LegacyCollectionInfo['filterList'] filterList: LegacyCollectionInfo['filterList']
): FilterParams[] { ): FilterParams[] {
try {
return filterList.map(filter => { return filterList.map(filter => {
const leftValue = filter.left.name; const leftValue = filter.left.name;
const method = filter.funcName; const method = filter.funcName;
@@ -266,7 +269,10 @@ export class CollectionStore extends Store {
method: 'include-any-of', method: 'include-any-of',
value: arg0.join(','), value: arg0.join(','),
}; };
} else if (method === 'does not contains all' && Array.isArray(arg0)) { } else if (
method === 'does not contains all' &&
Array.isArray(arg0)
) {
return { return {
type: 'system', type: 'system',
key: 'tags', key: 'tags',
@@ -299,5 +305,9 @@ export class CollectionStore extends Store {
method: 'unknown', method: 'unknown',
}; };
}); });
} catch (err) {
console.error('Failed to migrate filter list', err);
return [];
}
} }
} }