@7365admin1/layer-common 4.97.1-staging.659 → 4.97.1-staging.660

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,7 +51,7 @@
51
51
  <v-list-item
52
52
  density="compact"
53
53
  class="switch-context__row"
54
- v-for="item in uniqueItems"
54
+ v-for="item in visibleItems"
55
55
  :key="item.value"
56
56
  @click="selectItem(item.value)"
57
57
  >
@@ -61,6 +61,14 @@
61
61
 
62
62
  {{ item.text }}
63
63
  </v-list-item>
64
+ <v-list-item
65
+ v-if="!visibleItems.length && searchTerm"
66
+ density="compact"
67
+ class="switch-context__row"
68
+ disabled
69
+ >
70
+ No match for "{{ search }}"
71
+ </v-list-item>
64
72
  </v-list>
65
73
 
66
74
  <!-- The two actions under the list. Seven applications hand-wrote this
@@ -213,8 +221,61 @@ const uniqueItems = computed(() => {
213
221
  });
214
222
  });
215
223
 
224
+ /**
225
+ * THE SEARCH, APPLIED ON SCREEN.
226
+ *
227
+ * Owner report, 2026-11-05 (Security app, Aigle Security): typing "aigle" in
228
+ * the site switcher still listed every site. The layouts DO send the term to
229
+ * `GET /api/customer-sites`, but that search is the Sites page's search - it
230
+ * also matches the CLIENT's name (`siteOrgName`), and for an organisation's own
231
+ * sites the client is the organisation itself. So "aigle" matched every Aigle
232
+ * site and the server answer was the whole list. The organisation search
233
+ * (`$text` on memberships) has the opposite flaw: whole words only, and it also
234
+ * matches the member's own name.
235
+ *
236
+ * The switcher's contract is "find the row by the name I can see", so the rows
237
+ * are filtered here by that name (case-insensitive, contains) - instantly, as
238
+ * the user types, and over whatever the caller hands back. The caller's server
239
+ * search still runs (it is how a list longer than one page is reached); its
240
+ * rows are merged with the last unfiltered list, so a partial word the server
241
+ * cannot match still finds a row that was already loaded.
242
+ */
243
+ const searchTerm = computed(() =>
244
+ String(search.value ?? "").trim().toLowerCase(),
245
+ );
246
+
247
+ // The caller's list as it was with NO search - kept so a server answer that
248
+ // misses a row (or drops the selected one) does not hide it.
249
+ const unfilteredItems = shallowRef<Array<Record<string, any>>>([]);
250
+ watch(
251
+ uniqueItems,
252
+ (items) => {
253
+ if (!searchTerm.value) unfilteredItems.value = items;
254
+ },
255
+ { immediate: true },
256
+ );
257
+
258
+ const visibleItems = computed(() => {
259
+ const term = searchTerm.value;
260
+ if (!term) return uniqueItems.value;
261
+ const seen = new Set<unknown>();
262
+ return [...uniqueItems.value, ...unfilteredItems.value].filter((item) => {
263
+ const value = item?.value;
264
+ if (value !== undefined && value !== null && value !== "") {
265
+ if (seen.has(value)) return false;
266
+ seen.add(value);
267
+ }
268
+ return String(item?.text ?? "").toLowerCase().includes(term);
269
+ });
270
+ });
271
+
216
272
  const name = computed(() => {
217
- return uniqueItems.value.find((item) => item.value === selected.value)?.text ?? "";
273
+ const match = (item: Record<string, any>) => item.value === selected.value;
274
+ return (
275
+ uniqueItems.value.find(match)?.text ??
276
+ unfilteredItems.value.find(match)?.text ??
277
+ ""
278
+ );
218
279
  });
219
280
 
220
281
  /**
@@ -236,26 +297,35 @@ watchEffect(() => {
236
297
  });
237
298
 
238
299
  let searchDebounce: ReturnType<typeof setTimeout> | null = null;
239
- let skipNextWatch = false;
240
300
 
241
301
  const triggerSearch = () => {
242
302
  if (searchDebounce) clearTimeout(searchDebounce);
243
303
  emit("search");
244
304
  };
245
305
 
306
+ // Vuetify's clear button sets the field to `null` before `click:clear` fires;
307
+ // normalising to "" here lets the watch below do the one refetch. (The old
308
+ // skip-flag could swallow the user's NEXT keystroke when the two arrived in
309
+ // separate ticks.)
246
310
  const clearSearch = () => {
247
- skipNextWatch = true;
248
311
  search.value = "";
249
- triggerSearch();
250
312
  };
251
313
 
252
- watch(search, () => {
253
- if (skipNextWatch) {
254
- skipNextWatch = false;
314
+ watch(search, (value) => {
315
+ if (value === null || value === undefined) {
316
+ search.value = "";
255
317
  return;
256
318
  }
257
319
  if (searchDebounce) clearTimeout(searchDebounce);
258
- searchDebounce = setTimeout(triggerSearch, 1000);
320
+ // Emptied: restore the full list straight away. Typing: wait for a pause.
321
+ if (!value.trim()) triggerSearch();
322
+ else searchDebounce = setTimeout(triggerSearch, 1000);
323
+ });
324
+
325
+ // Closing the panel drops the search, so the list the caller holds (and the
326
+ // next opening) is the full one again rather than the last filtered answer.
327
+ watch(menu, (open) => {
328
+ if (!open && search.value) search.value = "";
259
329
  });
260
330
 
261
331
  onBeforeUnmount(() => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.97.1-staging.659",
5
+ "version": "4.97.1-staging.660",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",