Fixed CompendiumBrowser Class filter for Subclass view

This commit is contained in:
WBHarry 2026-05-03 12:14:04 +02:00
parent 2c6d813f25
commit e28d90fe71
2 changed files with 17 additions and 13 deletions

View file

@ -277,7 +277,7 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
(await foundry.applications.ux.TextEditor.implementation.enrichHTML(item.description)); (await foundry.applications.ux.TextEditor.implementation.enrichHTML(item.description));
} }
this.fieldFilter = this._createFieldFilter(); this.fieldFilter = await this._createFieldFilter();
if (this.presets?.filter) { if (this.presets?.filter) {
Object.entries(this.presets.filter).forEach(([k, v]) => { Object.entries(this.presets.filter).forEach(([k, v]) => {
@ -355,12 +355,12 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
); );
} }
_createFieldFilter() { async _createFieldFilter() {
const filters = ItemBrowser.getFolderConfig(this.selectedMenu.data, 'filters'); const filters = ItemBrowser.getFolderConfig(this.selectedMenu.data, 'filters');
filters.forEach(f => { for(const f of filters) {
if (typeof f.field === 'string') f.field = foundry.utils.getProperty(game, f.field); if (typeof f.field === 'string') f.field = foundry.utils.getProperty(game, f.field);
else if (typeof f.choices === 'function') { else if (typeof f.choices === 'function') {
f.choices = f.choices(this.items); f.choices = await f.choices(this.items);
} }
// Clear field label so template uses our custom label parameter // Clear field label so template uses our custom label parameter
@ -370,7 +370,8 @@ export class ItemBrowser extends HandlebarsApplicationMixin(ApplicationV2) {
f.name ??= f.key; f.name ??= f.key;
f.value = this.presets?.filter?.[f.name]?.value ?? null; f.value = this.presets?.filter?.[f.name]?.value ?? null;
}); }
return filters; return filters;
} }

View file

@ -393,15 +393,18 @@ export const typeConfig = {
], ],
filters: [ filters: [
{ {
key: 'system.linkedClass.uuid', key: 'system.linkedClass',
label: 'TYPES.Item.class', label: 'TYPES.Item.class',
choices: items => { choices: async items => {
const list = items const list = [];
.filter(item => item.system.linkedClass) for(const item of items.filter(item => item.system.linkedClass)) {
.map(item => ({ const linkedClass = await foundry.utils.fromUuid(item.system.linkedClass);
value: item.system.linkedClass.uuid, list.push({
label: item.system.linkedClass.name value: linkedClass.uuid,
})); label: linkedClass.name
});
}
return list.reduce((a, c) => { return list.reduce((a, c) => {
if (!a.find(i => i.value === c.value)) a.push(c); if (!a.find(i => i.value === c.value)) a.push(c);
return a; return a;