Refresh tag selector when a tag's type changes between views
Some checks failed
CI / Detect changes (push) Has been cancelled
CI / Utilities Tests (push) Has been cancelled
CI / Build, Upload (push) Has been cancelled
CI / Test () (push) Has been cancelled
CI / Test (macOS NFS) (push) Has been cancelled
CI / Test (Windows arm64) (push) Has been cancelled
CI / Test (Windows x64) (push) Has been cancelled

Switching to a view that has the same tags but with different types
(manual vs. automatic) kept the previous list, so with "Show Automatic"
off a tag could show or hide incorrectly.
This commit is contained in:
Dan Stillman 2026-09-30 11:45:36 -04:00
parent d8382c5c11
commit 15f6a81181
2 changed files with 35 additions and 2 deletions

View file

@ -416,10 +416,10 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent {
// If tags haven't changed, return previous array without sorting again
if (this.state.tags.length == tags.length) {
let prevTags = new Set(this.state.tags.map(tag => tag.tag));
let prevTags = new Set(this.state.tags.map(tag => tag.type + ':' + tag.tag));
let same = true;
for (let tag of tags) {
if (!prevTags.has(tag.tag)) {
if (!prevTags.has(tag.type + ':' + tag.tag)) {
same = false;
break;
}

View file

@ -127,6 +127,39 @@ describe("Tag Selector", function () {
}
});
it("should hide a tag that's only automatic in the new view when automatic tags are hidden", async function () {
var collection1 = await createDataObject('collection');
var collection2 = await createDataObject('collection');
var item1 = createUnsavedDataObject('item', { collections: [collection1.id] });
item1.setTags(["A", "B"]);
var item2 = createUnsavedDataObject('item', { collections: [collection2.id] });
item2.setTags([{ tag: "A", type: 1 }, "B"]);
await Zotero.DB.executeTransaction(async function () {
await item1.save();
await item2.save();
});
tagSelector.toggleShowAutomatic(false);
try {
await select(win, collection1);
await waitForCallback(() => getRegularTags().length == 2);
var spy = sinon.spy(tagSelector, 'onItemViewChanged');
try {
await select(win, collection2);
await waitForCallback(() => spy.called);
await spy.lastCall.returnValue;
}
finally {
spy.restore();
}
assert.sameMembers(getRegularTags(), ['B']);
}
finally {
tagSelector.toggleShowAutomatic(true);
}
});
it("should show tags from annotations for attachments in scope", async function () {
var collection = await createDataObject('collection');
await select(win, collection);