Refactor searchComponent function to use optional chaining in index.blade.php

This commit is contained in:
Andras Bacsai 2024-05-03 11:34:45 +02:00
parent a8520f6593
commit a401d4e760

View File

@ -395,7 +395,7 @@ function searchComponent() {
} }
this.applications = Object.values(this.applications); this.applications = Object.values(this.applications);
return this.applications.filter(item => { return this.applications.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.fqdn?.toLowerCase().includes(this.search.toLowerCase()) || item.fqdn?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
@ -407,7 +407,7 @@ function searchComponent() {
} }
this.postgresqls = Object.values(this.postgresqls); this.postgresqls = Object.values(this.postgresqls);
return this.postgresqls.filter(item => { return this.postgresqls.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
}).sort(sortFn); }).sort(sortFn);
@ -418,7 +418,7 @@ function searchComponent() {
} }
this.redis = Object.values(this.redis); this.redis = Object.values(this.redis);
return this.redis.filter(item => { return this.redis.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
}).sort(sortFn); }).sort(sortFn);
@ -429,7 +429,7 @@ function searchComponent() {
} }
this.mongodbs = Object.values(this.mongodbs); this.mongodbs = Object.values(this.mongodbs);
return this.mongodbs.filter(item => { return this.mongodbs.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
}).sort(sortFn); }).sort(sortFn);
@ -440,7 +440,7 @@ function searchComponent() {
} }
this.mysqls = Object.values(this.mysqls); this.mysqls = Object.values(this.mysqls);
return this.mysqls.filter(item => { return this.mysqls.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
}).sort(sortFn); }).sort(sortFn);
@ -451,7 +451,7 @@ function searchComponent() {
} }
this.mariadbs = Object.values(this.mariadbs); this.mariadbs = Object.values(this.mariadbs);
return this.mariadbs.filter(item => { return this.mariadbs.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
}).sort(sortFn); }).sort(sortFn);
@ -462,7 +462,7 @@ function searchComponent() {
} }
this.keydbs = Object.values(this.keydbs); this.keydbs = Object.values(this.keydbs);
return this.keydbs.filter(item => { return this.keydbs.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
}).sort(sortFn); }).sort(sortFn);
@ -473,7 +473,7 @@ function searchComponent() {
} }
this.dragonflies = Object.values(this.dragonflies); this.dragonflies = Object.values(this.dragonflies);
return this.dragonflies.filter(item => { return this.dragonflies.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
}).sort(sortFn); }).sort(sortFn);
@ -484,7 +484,7 @@ function searchComponent() {
} }
this.clickhouses = Object.values(this.clickhouses); this.clickhouses = Object.values(this.clickhouses);
return this.clickhouses.filter(item => { return this.clickhouses.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
}).sort(sortFn); }).sort(sortFn);
@ -495,7 +495,7 @@ function searchComponent() {
} }
this.services = Object.values(this.services); this.services = Object.values(this.services);
return this.services.filter(item => { return this.services.filter(item => {
return item.name.toLowerCase().includes(this.search.toLowerCase()) || return item.name?.toLowerCase().includes(this.search.toLowerCase()) ||
item.description?.toLowerCase().includes(this.search.toLowerCase()) || item.description?.toLowerCase().includes(this.search.toLowerCase()) ||
item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase())); item.tags?.some(tag => tag.name.toLowerCase().includes(this.search.toLowerCase()));
}).sort(sortFn); }).sort(sortFn);