Apply searchbar logic

This commit is contained in:
William Buezas 2024-05-20 15:53:38 -03:00
parent 7466d03f15
commit b26bf10e70
3 changed files with 30 additions and 21 deletions

View File

@ -20,6 +20,8 @@ const props = defineProps({
searchUrl: { type: String, default: undefined }, searchUrl: { type: String, default: undefined },
searchbarLabel: { type: String, default: '' }, searchbarLabel: { type: String, default: '' },
searchbarInfo: { type: String, default: '' }, searchbarInfo: { type: String, default: '' },
searchCustomRouteRedirect: { type: String, default: undefined },
searchRedirect: { type: Boolean, default: false },
}); });
const stateStore = useStateStore(); const stateStore = useStateStore();
@ -62,6 +64,8 @@ watchEffect(() => {
:url="props.searchUrl" :url="props.searchUrl"
:label="props.searchbarLabel" :label="props.searchbarLabel"
:info="props.searchbarInfo" :info="props.searchbarInfo"
:custom-route-redirect-name="searchCustomRouteRedirect"
:redirect="searchRedirect"
/> />
</slot> </slot>
</Teleport> </Teleport>

View File

@ -5,38 +5,29 @@ import { computed } from 'vue';
import VnCard from 'components/common/VnCard.vue'; import VnCard from 'components/common/VnCard.vue';
import ZoneDescriptor from './ZoneDescriptor.vue'; import ZoneDescriptor from './ZoneDescriptor.vue';
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
import { useStateStore } from 'stores/useStateStore';
const { t } = useI18n(); const { t } = useI18n();
const stateStore = useStateStore();
const route = useRoute(); const route = useRoute();
const routeName = computed(() => route.name); const routeName = computed(() => route.name);
const customRouteRedirectName = computed(() => {
if (routeName.value === 'ZoneLocations') return null;
return routeName.value;
});
const searchBarDataKeys = { const searchBarDataKeys = {
ZoneWarehouses: 'ZoneWarehouses', ZoneWarehouses: 'ZoneWarehouses',
ZoneSummary: 'ZoneSummary', ZoneSummary: 'ZoneSummary',
ZoneLocations: 'ZoneLocations',
}; };
</script> </script>
<template> <template>
<template v-if="stateStore.isHeaderMounted()">
<Teleport to="#searchbar">
<VnSearchbar
:data-key="searchBarDataKeys[routeName]"
:custom-route-redirect-name="routeName"
:label="t('list.searchZone')"
:info="t('list.searchInfo')"
/>
</Teleport>
</template>
<VnCard <VnCard
data-key="Zone" data-key="Zone"
base-url="Zones"
:descriptor="ZoneDescriptor" :descriptor="ZoneDescriptor"
searchbar-data-key="ZoneList" :search-data-key="searchBarDataKeys[routeName]"
searchbar-url="Zones/filter" :search-custom-route-redirect="customRouteRedirectName"
searchbar-label="Search zones" :search-redirect="!!customRouteRedirectName"
searchbar-info="You can search by zone reference" :searchbar-label="t('list.searchZone')"
:searchbar-info="t('list.searchInfo')"
/> />
</template> </template>

View File

@ -1,18 +1,25 @@
<script setup> <script setup>
import { onMounted, ref } from 'vue'; import { onMounted, ref, computed, watch } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useState } from 'src/composables/useState'; import { useState } from 'src/composables/useState';
import axios from 'axios'; import axios from 'axios';
import { useArrayData } from 'composables/useArrayData';
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const state = useState(); const state = useState();
const treeRef = ref(); const treeRef = ref();
const expanded = ref([]); const expanded = ref([]);
const arrayData = useArrayData('ZoneLocations', {
url: `Zones/${route.params.id}/getLeaves`,
});
const { store } = arrayData;
const storeData = computed(() => store.data);
const nodes = ref([ const nodes = ref([
{ id: null, name: t('zoneLocations.locations'), sons: true, children: [{}] }, { id: null, name: t('zoneLocations.locations'), sons: true, children: [{}] },
]); ]);
@ -75,6 +82,12 @@ const onSelected = async (val, node) => {
} }
}; };
watch(storeData, async (val) => {
// Se triggerea cuando se actualiza el store.data, el cual es el resultado del fetch de la searchbar
nodes.value[0].children = [...val];
await fetchNodeLeaves(1);
});
onMounted(async (n) => { onMounted(async (n) => {
const tree = [...state.get('Tree'), 1]; const tree = [...state.get('Tree'), 1];
const lastStateTree = state.get('TreeState'); const lastStateTree = state.get('TreeState');
@ -89,6 +102,7 @@ onMounted(async (n) => {
await fetchNodeLeaves(lastStateTree); await fetchNodeLeaves(lastStateTree);
} }
} }
setTimeout(() => { setTimeout(() => {
if (lastStateTree) { if (lastStateTree) {
document.getElementById(lastStateTree).scrollIntoView(); document.getElementById(lastStateTree).scrollIntoView();