Skip to content

Commit ba4d07a

Browse files
committed
show in search after remove
1 parent 39d82c0 commit ba4d07a

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@rollup/plugin-commonjs": "^18.0.0",
1717
"@shoelace-style/localize": "^3.2.1",
1818
"@shoelace-style/shoelace": "~2.18.0",
19+
"@solancer/two-way-map": "^1.0.4",
1920
"@tailwindcss/container-queries": "^0.1.1",
2021
"@tanstack/lit-virtual": "^3.13.12",
2122
"@tanstack/virtual-core": "^3.13.12",

frontend/src/features/collections/collections-add.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { localized, msg } from "@lit/localize";
22
import { Task, TaskStatus } from "@lit/task";
33
import type { SlInput, SlMenuItem } from "@shoelace-style/shoelace";
4+
import { TwoWayMap } from "@solancer/two-way-map";
45
import Fuse from "fuse.js";
56
import { html, nothing } from "lit";
67
import { customElement, property, query, state } from "lit/decorators.js";
@@ -62,8 +63,8 @@ export class CollectionsAdd extends BtrixElement {
6263
@query("btrix-combobox")
6364
private readonly combobox?: Combobox | null;
6465

65-
// Map collection names to ID for filtering fuzzy search
66-
private readonly collectionNames = new Map<string, string>();
66+
// Map collection names to ID for managing search options
67+
private readonly nameSearchMap = new TwoWayMap<string, string>();
6768

6869
private get collectionIds() {
6970
return this.collections.map(({ id }) => id);
@@ -137,13 +138,20 @@ export class CollectionsAdd extends BtrixElement {
137138
const { item } = e.detail;
138139
139140
if (item.name) {
140-
this.collectionNames.set(item.name, item.id);
141+
this.nameSearchMap.set(item.name, item.id);
141142
}
142143
}}
143144
@btrix-remove=${(e: BtrixRemoveLinkedCollectionEvent) => {
144145
const { id } = e.detail.item;
145146
146147
this.removeCollection(id);
148+
149+
// Remove from search mapping
150+
const name = this.nameSearchMap.getByValue(id);
151+
152+
if (name) {
153+
this.nameSearchMap.delete(name);
154+
}
147155
}}
148156
></btrix-linked-collections>
149157
</div>
@@ -174,7 +182,7 @@ export class CollectionsAdd extends BtrixElement {
174182
this.collections = [...this.collections, coll];
175183
void this.dispatchChange();
176184
177-
this.collectionNames.set(coll.name, coll.id);
185+
this.nameSearchMap.set(coll.name, coll.id);
178186
179187
if (this.input) {
180188
this.input.value = "";
@@ -238,7 +246,7 @@ export class CollectionsAdd extends BtrixElement {
238246
const results = fuse
239247
?.search(this.searchByValue)
240248
// Filter out items that have been selected
241-
.filter(({ item }) => !this.collectionNames.get(item))
249+
.filter(({ item }) => !this.nameSearchMap.get(item))
242250
// Show first few results
243251
.slice(0, 5);
244252

frontend/yarn.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)