Ver código fonte

fix: components

Muhammad Iqbal Afandi 3 anos atrás
pai
commit
ce5b5144df

+ 13
- 17
resources/js/components/AppDateRangeFilter.vue Ver arquivo

@@ -10,15 +10,6 @@ const props = defineProps({
10 10
     type: Object,
11 11
     required: true,
12 12
   },
13
-  url: {
14
-    type: String,
15
-    required: true,
16
-  },
17
-  refreshData: {
18
-    type: Array,
19
-    default: [],
20
-    required: false,
21
-  },
22 13
 })
23 14
 
24 15
 const initialFilter = computed(() => {
@@ -34,6 +25,14 @@ const initialFilter = computed(() => {
34 25
   }
35 26
 })
36 27
 
28
+const removeParams = (...params) => {
29
+  const urlParams = new URLSearchParams(location.search)
30
+
31
+  params.forEach((value) => urlParams.delete(value))
32
+
33
+  history.replaceState({}, '', `${location.pathname}?${urlParams}`)
34
+}
35
+
37 36
 const dates = ref(initialFilter.value)
38 37
 
39 38
 watch(dates, (value) => {
@@ -47,17 +46,14 @@ watch(dates, (value) => {
47 46
     var end_date = null
48 47
   }
49 48
 
50
-  Inertia.get(
51
-    props.url,
52
-    pickBy({
49
+  removeParams('start_date', 'end_date')
50
+
51
+  Inertia.reload({
52
+    data: pickBy({
53 53
       start_date,
54 54
       end_date,
55 55
     }),
56
-    {
57
-      preserveState: true,
58
-      only: [...props.refreshData],
59
-    }
60
-  )
56
+  })
61 57
 })
62 58
 </script>
63 59
 

+ 6
- 12
resources/js/components/AppDropdown.vue Ver arquivo

@@ -4,7 +4,7 @@ import { computed } from 'vue'
4 4
 const props = defineProps({
5 5
   label: {
6 6
     type: String,
7
-    required: true,
7
+    required: false,
8 8
   },
9 9
   labelClass: {
10 10
     type: String,
@@ -59,9 +59,11 @@ const ariaDescribedbyLabel = computed(
59 59
 )
60 60
 
61 61
 const selectedDropdownLabel = (value) => {
62
-  const result = props.options.find(
63
-    (option) => option[props.optionValue] == value
64
-  )
62
+  const result = props.options.find((option) => {
63
+    if (option !== null) {
64
+      return option[props.optionValue] == value
65
+    }
66
+  })
65 67
 
66 68
   if (result) {
67 69
     return result[props.optionLabel]
@@ -92,14 +94,6 @@ const selectedDropdownLabel = (value) => {
92 94
         <div v-if="slotProps.value">
93 95
           {{ selectedDropdownLabel(slotProps.value) }}
94 96
         </div>
95
-
96
-        <div v-else>
97
-          {{ slotProps.placeholder }}
98
-        </div>
99
-      </template>
100
-
101
-      <template #option="{ option, index }">
102
-        <slot name="option" :option="option" :index="index" />
103 97
       </template>
104 98
     </Dropdown>
105 99
 

+ 37
- 0
resources/js/components/AppDropdownFilter.vue Ver arquivo

@@ -0,0 +1,37 @@
1
+<script setup>
2
+import { ref, watch } from 'vue'
3
+import { Inertia } from '@inertiajs/inertia'
4
+import { pickBy } from 'lodash'
5
+import AppDropdown from '@/components/AppDropdown.vue'
6
+
7
+defineProps({
8
+  options: {
9
+    type: Array,
10
+    required: true,
11
+  },
12
+})
13
+
14
+const removeParams = (...params) => {
15
+  const urlParams = new URLSearchParams(location.search)
16
+
17
+  params.forEach((value) => urlParams.delete(value))
18
+
19
+  history.replaceState({}, '', `${location.pathname}?${urlParams}`)
20
+}
21
+
22
+const status = ref()
23
+
24
+watch(status, (status) => {
25
+  removeParams('status')
26
+
27
+  Inertia.reload({
28
+    data: pickBy({
29
+      status,
30
+    }),
31
+  })
32
+})
33
+</script>
34
+
35
+<template>
36
+  <AppDropdown placeholder="status" :options="options" v-model="status" />
37
+</template>

+ 13
- 13
resources/js/components/AppSearchFilter.vue Ver arquivo

@@ -7,23 +7,23 @@ const props = defineProps({
7 7
   initialSearch: {
8 8
     required: true,
9 9
   },
10
-  url: {
11
-    type: String,
12
-    required: true,
13
-  },
14
-  refreshData: {
15
-    type: Array,
16
-    default: [],
17
-    required: false,
18
-  },
19 10
 })
20 11
 
12
+const removeParams = (...params) => {
13
+  const urlParams = new URLSearchParams(location.search)
14
+
15
+  params.forEach((value) => urlParams.delete(value))
16
+
17
+  history.replaceState({}, '', `${location.pathname}?${urlParams}`)
18
+}
19
+
21 20
 const search = ref(props.initialSearch)
22 21
 
23
-watch(search, (value) => {
24
-  Inertia.get(props.url, pickBy({ search: value }), {
25
-    preserveState: true,
26
-    only: [...props.refreshData],
22
+watch(search, (search) => {
23
+  removeParams('search')
24
+
25
+  Inertia.reload({
26
+    data: pickBy({ search }),
27 27
   })
28 28
 })
29 29
 </script>