mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix: fix search in resources list layout
This commit is contained in:
parent
5d2b09fddb
commit
e60c03f884
|
@ -63,20 +63,20 @@
|
||||||
<div class="mb-xs">
|
<div class="mb-xs">
|
||||||
<div :class="$style['filters-row']">
|
<div :class="$style['filters-row']">
|
||||||
<n8n-input
|
<n8n-input
|
||||||
v-model="filters.search"
|
:modelValue="filtersModel.search"
|
||||||
:class="[$style['search'], 'mr-2xs']"
|
:class="[$style['search'], 'mr-2xs']"
|
||||||
:placeholder="$locale.baseText(`${resourceKey}.search.placeholder`)"
|
:placeholder="$locale.baseText(`${resourceKey}.search.placeholder`)"
|
||||||
size="medium"
|
|
||||||
clearable
|
clearable
|
||||||
ref="search"
|
ref="search"
|
||||||
data-test-id="resources-list-search"
|
data-test-id="resources-list-search"
|
||||||
|
@update:modelValue="onSearch"
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<n8n-icon icon="search" />
|
<n8n-icon icon="search" />
|
||||||
</template>
|
</template>
|
||||||
</n8n-input>
|
</n8n-input>
|
||||||
<div :class="$style['sort-and-filter']">
|
<div :class="$style['sort-and-filter']">
|
||||||
<n8n-select v-model="sortBy" size="medium" data-test-id="resources-list-sort">
|
<n8n-select v-model="sortBy" data-test-id="resources-list-sort">
|
||||||
<n8n-option
|
<n8n-option
|
||||||
v-for="sortOption in sortOptions"
|
v-for="sortOption in sortOptions"
|
||||||
data-test-id="resources-list-sort-item"
|
data-test-id="resources-list-sort-item"
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
v-if="showFiltersDropdown"
|
v-if="showFiltersDropdown"
|
||||||
:keys="filterKeys"
|
:keys="filterKeys"
|
||||||
:reset="resetFilters"
|
:reset="resetFilters"
|
||||||
:modelValue="filters"
|
:modelValue="filtersModel"
|
||||||
:shareable="shareable"
|
:shareable="shareable"
|
||||||
@update:modelValue="$emit('update:filters', $event)"
|
@update:modelValue="$emit('update:filters', $event)"
|
||||||
@update:filtersLength="onUpdateFiltersLength"
|
@update:filtersLength="onUpdateFiltersLength"
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
|
|
||||||
<slot name="callout"></slot>
|
<slot name="callout"></slot>
|
||||||
|
|
||||||
<div v-show="hasFilters" class="mt-xs">
|
<div v-if="showFiltersDropdown" v-show="hasFilters" class="mt-xs">
|
||||||
<n8n-info-tip :bold="false">
|
<n8n-info-tip :bold="false">
|
||||||
{{ $locale.baseText(`${resourceKey}.filters.active`) }}
|
{{ $locale.baseText(`${resourceKey}.filters.active`) }}
|
||||||
<n8n-link @click="resetFilters" size="small">
|
<n8n-link @click="resetFilters" size="small">
|
||||||
|
@ -155,7 +155,7 @@
|
||||||
<n8n-text color="text-base" size="medium" data-test-id="resources-list-empty" v-else>
|
<n8n-text color="text-base" size="medium" data-test-id="resources-list-empty" v-else>
|
||||||
{{ $locale.baseText(`${resourceKey}.noResults`) }}
|
{{ $locale.baseText(`${resourceKey}.noResults`) }}
|
||||||
<template v-if="shouldSwitchToAllSubview">
|
<template v-if="shouldSwitchToAllSubview">
|
||||||
<span v-if="!filters.search">
|
<span v-if="!filtersModel.search">
|
||||||
({{ $locale.baseText(`${resourceKey}.noResults.switchToShared.preamble`) }}
|
({{ $locale.baseText(`${resourceKey}.noResults.switchToShared.preamble`) }}
|
||||||
<n8n-link @click="setOwnerSubview(false)">
|
<n8n-link @click="setOwnerSubview(false)">
|
||||||
{{ $locale.baseText(`${resourceKey}.noResults.switchToShared.link`) }} </n8n-link
|
{{ $locale.baseText(`${resourceKey}.noResults.switchToShared.link`) }} </n8n-link
|
||||||
|
@ -292,6 +292,7 @@ export default defineComponent({
|
||||||
isOwnerSubview: false,
|
isOwnerSubview: false,
|
||||||
sortBy: this.sortOptions[0],
|
sortBy: this.sortOptions[0],
|
||||||
hasFilters: false,
|
hasFilters: false,
|
||||||
|
filtersModel: { ...this.filters },
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
rowsPerPage: 10 as number | '*',
|
rowsPerPage: 10 as number | '*',
|
||||||
resettingFilters: false,
|
resettingFilters: false,
|
||||||
|
@ -317,33 +318,34 @@ export default defineComponent({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
filterKeys(): string[] {
|
filterKeys(): string[] {
|
||||||
return Object.keys(this.filters);
|
return Object.keys(this.filtersModel);
|
||||||
},
|
},
|
||||||
filteredAndSortedSubviewResources(): IResource[] {
|
filteredAndSortedSubviewResources(): IResource[] {
|
||||||
const filtered: IResource[] = this.subviewResources.filter((resource: IResource) => {
|
const filtered: IResource[] = this.subviewResources.filter((resource: IResource) => {
|
||||||
let matches = true;
|
let matches = true;
|
||||||
|
|
||||||
if (this.filters.ownedBy) {
|
if (this.filtersModel.ownedBy) {
|
||||||
matches = matches && !!(resource.ownedBy && resource.ownedBy.id === this.filters.ownedBy);
|
matches =
|
||||||
|
matches && !!(resource.ownedBy && resource.ownedBy.id === this.filtersModel.ownedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.filters.sharedWith) {
|
if (this.filtersModel.sharedWith) {
|
||||||
matches =
|
matches =
|
||||||
matches &&
|
matches &&
|
||||||
!!(
|
!!(
|
||||||
resource.sharedWith &&
|
resource.sharedWith &&
|
||||||
resource.sharedWith.find((sharee) => sharee.id === this.filters.sharedWith)
|
resource.sharedWith.find((sharee) => sharee.id === this.filtersModel.sharedWith)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.filters.search) {
|
if (this.filtersModel.search) {
|
||||||
const searchString = this.filters.search.toLowerCase();
|
const searchString = this.filtersModel.search.toLowerCase();
|
||||||
|
|
||||||
matches = matches && this.displayName(resource).toLowerCase().includes(searchString);
|
matches = matches && this.displayName(resource).toLowerCase().includes(searchString);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.additionalFiltersHandler) {
|
if (this.additionalFiltersHandler) {
|
||||||
matches = this.additionalFiltersHandler(resource, this.filters, matches);
|
matches = this.additionalFiltersHandler(resource, this.filtersModel, matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
return matches;
|
return matches;
|
||||||
|
@ -395,8 +397,8 @@ export default defineComponent({
|
||||||
this.rowsPerPage = rowsPerPage;
|
this.rowsPerPage = rowsPerPage;
|
||||||
},
|
},
|
||||||
resetFilters() {
|
resetFilters() {
|
||||||
Object.keys(this.filters).forEach((key) => {
|
Object.keys(this.filtersModel).forEach((key) => {
|
||||||
this.filters[key] = Array.isArray(this.filters[key]) ? [] : '';
|
this.filtersModel[key] = Array.isArray(this.filtersModel[key]) ? [] : '';
|
||||||
});
|
});
|
||||||
|
|
||||||
this.resettingFilters = true;
|
this.resettingFilters = true;
|
||||||
|
@ -437,7 +439,7 @@ export default defineComponent({
|
||||||
setTimeout(() => (this.resettingFilters = false), 1500);
|
setTimeout(() => (this.resettingFilters = false), 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
const filters = this.filters as Record<string, string[] | string | boolean>;
|
const filters = this.filtersModel as Record<string, string[] | string | boolean>;
|
||||||
const filtersSet: string[] = [];
|
const filtersSet: string[] = [];
|
||||||
const filterValues: Array<string[] | string | boolean | null> = [];
|
const filterValues: Array<string[] | string | boolean | null> = [];
|
||||||
|
|
||||||
|
@ -459,6 +461,10 @@ export default defineComponent({
|
||||||
onUpdateFiltersLength(length: number) {
|
onUpdateFiltersLength(length: number) {
|
||||||
this.hasFilters = length > 0;
|
this.hasFilters = length > 0;
|
||||||
},
|
},
|
||||||
|
onSearch(search: string) {
|
||||||
|
this.filtersModel.search = search;
|
||||||
|
this.$emit('update:filters', this.filtersModel);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
void this.onMounted();
|
void this.onMounted();
|
||||||
|
@ -467,16 +473,16 @@ export default defineComponent({
|
||||||
isOwnerSubview() {
|
isOwnerSubview() {
|
||||||
this.sendSubviewTelemetry();
|
this.sendSubviewTelemetry();
|
||||||
},
|
},
|
||||||
'filters.ownedBy'(value) {
|
'filtersModel.ownedBy'(value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.setOwnerSubview(false);
|
this.setOwnerSubview(false);
|
||||||
}
|
}
|
||||||
this.sendFiltersTelemetry('ownedBy');
|
this.sendFiltersTelemetry('ownedBy');
|
||||||
},
|
},
|
||||||
'filters.sharedWith'() {
|
'filtersModel.sharedWith'() {
|
||||||
this.sendFiltersTelemetry('sharedWith');
|
this.sendFiltersTelemetry('sharedWith');
|
||||||
},
|
},
|
||||||
'filters.search'() {
|
'filtersModel.search'() {
|
||||||
void this.callDebounced(
|
void this.callDebounced(
|
||||||
'sendFiltersTelemetry',
|
'sendFiltersTelemetry',
|
||||||
{ debounceTime: 1000, trailing: true },
|
{ debounceTime: 1000, trailing: true },
|
||||||
|
|
Loading…
Reference in a new issue