Skip to content

Commit c97939e

Browse files
committed
feat: object list search. resolved rustfs/backlog#278
1 parent 3b8ca7c commit c97939e

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

components/object/list.vue

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<n-page-header subtitle="" @back="router.back()">
33
<template #title>
44
<div class="flex items-center justify-between">
5-
<n-input placeholder="搜索">
5+
<n-input placeholder="搜索" v-model:value="searchTerm" @update:value="handleSearch">
66
<template #prefix>
77
<Icon name="ri:search-2-line" />
88
</template>
@@ -48,7 +48,7 @@
4848
</div>
4949
</template>
5050
</n-page-header>
51-
<n-data-table class="border dark:border-neutral-700 rounded overflow-hidden" :columns="columns" :data="objects" :row-key="rowKey" @update:checked-row-keys="handleCheck"
51+
<n-data-table class="border dark:border-neutral-700 rounded overflow-hidden" :columns="columns" :data="filteredObjects" :row-key="rowKey" @update:checked-row-keys="handleCheck"
5252
:pagination="false" :bordered="false" />
5353
<object-upload-picker :show="uploadPickerVisible" @update:show="(val) => (uploadPickerVisible = val && refresh())" :bucketName="bucketName" :prefix="prefix" />
5454
<object-new-form :show="newObjectFormVisible" :asPrefix="newObjectAsPrefix" @update:show="(val) => (newObjectFormVisible = val && refresh())" :bucketName="bucketName"
@@ -86,6 +86,26 @@ const props = defineProps<{ bucket: string; path: string }>();
8686
const uploadPickerVisible = ref(false);
8787
const newObjectFormVisible = ref(false);
8888
const newObjectAsPrefix = ref(false);
89+
const searchTerm = ref('');
90+
91+
// Add debounce function for search
92+
const debounce = (fn: Function, delay: number) => {
93+
let timer: NodeJS.Timeout | null = null;
94+
return (...args: any[]) => {
95+
if (timer) clearTimeout(timer);
96+
timer = setTimeout(() => {
97+
fn(...args);
98+
}, delay);
99+
};
100+
};
101+
102+
const handleSearch = debounce(() => {
103+
// Reset pagination when searching
104+
if (continuationToken.value) {
105+
continuationToken.value = undefined;
106+
tokenHistory.value = [];
107+
}
108+
}, 300);
89109
90110
// 上传任务
91111
const uploadTaskStore = useUploadTaskManagerStore();
@@ -232,7 +252,18 @@ const objects = computed(() => {
232252
);
233253
});
234254
255+
// New computed property to filter objects based on search term
256+
const filteredObjects = computed(() => {
257+
if (!searchTerm.value.trim()) {
258+
return objects.value;
259+
}
235260
261+
const term = searchTerm.value.toLowerCase();
262+
return objects.value.filter(obj => {
263+
const displayKey = prefix.value ? obj.Key?.substring(prefix.value.length) : obj.Key;
264+
return displayKey?.toLowerCase().includes(term);
265+
});
266+
});
236267
237268
/** ************************************批量删除 */
238269
function rowKey(row: any): string {

0 commit comments

Comments
 (0)