0
0
Fork 0

Make searchbar work

This commit is contained in:
William Buezas 2024-05-26 19:35:12 -03:00
parent dbcd701725
commit f52f5df78b
4 changed files with 17 additions and 6 deletions

View File

@ -22,6 +22,7 @@ const props = defineProps({
searchbarInfo: { type: String, default: '' }, searchbarInfo: { type: String, default: '' },
searchCustomRouteRedirect: { type: String, default: undefined }, searchCustomRouteRedirect: { type: String, default: undefined },
searchRedirect: { type: Boolean, default: false }, searchRedirect: { type: Boolean, default: false },
searchMakeFetch: { type: Boolean, default: true },
}); });
const stateStore = useStateStore(); const stateStore = useStateStore();
@ -66,6 +67,7 @@ watchEffect(() => {
:info="props.searchbarInfo" :info="props.searchbarInfo"
:custom-route-redirect-name="searchCustomRouteRedirect" :custom-route-redirect-name="searchCustomRouteRedirect"
:redirect="searchRedirect" :redirect="searchRedirect"
:make-fetch="props.searchMakeFetch"
/> />
</slot> </slot>
</Teleport> </Teleport>

View File

@ -65,6 +65,10 @@ const props = defineProps({
type: String, type: String,
default: '', default: '',
}, },
makeFetch: {
type: Boolean,
default: true,
},
}); });
let arrayData = useArrayData(props.dataKey, { ...props }); let arrayData = useArrayData(props.dataKey, { ...props });
@ -92,12 +96,14 @@ async function search() {
([key, value]) => value && (props.staticParams || []).includes(key) ([key, value]) => value && (props.staticParams || []).includes(key)
); );
store.skip = 0; store.skip = 0;
await arrayData.applyFilter({
params: { if (props.makeFetch)
...Object.fromEntries(staticParams), await arrayData.applyFilter({
search: searchText.value, params: {
}, ...Object.fromEntries(staticParams),
}); search: searchText.value,
},
});
if (!props.redirect) return; if (!props.redirect) return;

View File

@ -14,6 +14,7 @@ const customRouteRedirectName = computed(() => {
if (routeName.value === 'ZoneLocations') return null; if (routeName.value === 'ZoneLocations') return null;
return routeName.value; return routeName.value;
}); });
const searchbarMakeFetch = computed(() => routeName.value !== 'ZoneEvents');
const searchBarDataKeys = { const searchBarDataKeys = {
ZoneWarehouses: 'ZoneWarehouses', ZoneWarehouses: 'ZoneWarehouses',
ZoneSummary: 'ZoneSummary', ZoneSummary: 'ZoneSummary',
@ -28,6 +29,7 @@ const searchBarDataKeys = {
:search-data-key="searchBarDataKeys[routeName]" :search-data-key="searchBarDataKeys[routeName]"
:search-custom-route-redirect="customRouteRedirectName" :search-custom-route-redirect="customRouteRedirectName"
:search-redirect="!!customRouteRedirectName" :search-redirect="!!customRouteRedirectName"
:search-make-fetch="searchbarMakeFetch"
:searchbar-label="t('list.searchZone')" :searchbar-label="t('list.searchZone')"
:searchbar-info="t('list.searchInfo')" :searchbar-info="t('list.searchInfo')"
/> />

View File

@ -68,6 +68,7 @@ const startParamsWatcher = () => {
const fetchData = async () => { const fetchData = async () => {
try { try {
if (!params.value.zoneFk || !params.value.started || !params.value.ended) return;
await arrayData.applyFilter({ await arrayData.applyFilter({
params: params.value, params: params.value,
}); });