Przeglądaj źródła

fix: components filter

rodzic
commit
ceb761ad4c

+ 22
- 15
resources/js/components/AppDateRangeFilter.vue Wyświetl plik

6
 import { computed } from '@vue/reactivity'
6
 import { computed } from '@vue/reactivity'
7
 
7
 
8
 const props = defineProps({
8
 const props = defineProps({
9
-  initialFilter: {
9
+  initialDateRage: {
10
     type: Object,
10
     type: Object,
11
     required: true,
11
     required: true,
12
   },
12
   },
13
+  nameParam: {
14
+    type: Array,
15
+    required: true,
16
+  },
13
 })
17
 })
14
 
18
 
15
-const initialFilter = computed(() => {
16
-  if (props.initialFilter.start_date || props.initialFilter.end_date) {
17
-    if (props.initialFilter.end_date) {
19
+const initialDateRage = computed(() => {
20
+  if (
21
+    props.initialDateRage[props.nameParam[0]] ||
22
+    props.initialDateRage[props.nameParam[1]]
23
+  ) {
24
+    if (props.initialDateRage[props.nameParam[1]]) {
18
       return [
25
       return [
19
-        new Date(props.initialFilter.start_date),
20
-        new Date(props.initialFilter.end_date),
26
+        new Date(props.initialDateRage[props.nameParam[0]]),
27
+        new Date(props.initialDateRage[props.nameParam[1]]),
21
       ]
28
       ]
22
     } else {
29
     } else {
23
-      return [new Date(props.initialFilter.start_date), null]
30
+      return [new Date(props.initialDateRage[props.nameParam[0]]), null]
24
     }
31
     }
25
   }
32
   }
26
 })
33
 })
33
   history.replaceState({}, '', `${location.pathname}?${urlParams}`)
40
   history.replaceState({}, '', `${location.pathname}?${urlParams}`)
34
 }
41
 }
35
 
42
 
36
-const dates = ref(initialFilter.value)
43
+const dates = ref(initialDateRage.value)
37
 
44
 
38
 watch(dates, (value) => {
45
 watch(dates, (value) => {
39
   if (value[1]) {
46
   if (value[1]) {
40
-    var start_date = dayjs(value[0]).format('YYYY-MM-DD')
47
+    var start = dayjs(value[0]).format('YYYY-MM-DD')
41
 
48
 
42
-    var end_date = dayjs(value[1]).format('YYYY-MM-DD')
49
+    var end = dayjs(value[1]).format('YYYY-MM-DD')
43
   } else if (value[0]) {
50
   } else if (value[0]) {
44
-    var start_date = dayjs(value[0]).format('YYYY-MM-DD')
51
+    var start = dayjs(value[0]).format('YYYY-MM-DD')
45
 
52
 
46
-    var end_date = null
53
+    var end = null
47
   }
54
   }
48
 
55
 
49
-  removeParams('start_date', 'end_date', 'page')
56
+  removeParams(props.nameParam[0], props.nameParam[1], 'page')
50
 
57
 
51
   Inertia.reload({
58
   Inertia.reload({
52
     data: pickBy({
59
     data: pickBy({
53
-      start_date,
54
-      end_date,
60
+      [props.nameParam[0]]: start,
61
+      [props.nameParam[1]]: end,
55
     }),
62
     }),
56
   })
63
   })
57
 })
64
 })

+ 12
- 8
resources/js/components/AppDropdownFilter.vue Wyświetl plik

4
 import { pickBy } from 'lodash'
4
 import { pickBy } from 'lodash'
5
 import AppDropdown from '@/components/AppDropdown.vue'
5
 import AppDropdown from '@/components/AppDropdown.vue'
6
 
6
 
7
-defineProps({
8
-  options: {
9
-    type: Array,
7
+const props = defineProps({
8
+  initialDropdown: {
9
+    type: Object,
10
+    required: true,
11
+  },
12
+  nameParam: {
13
+    type: String,
10
     required: true,
14
     required: true,
11
   },
15
   },
12
 })
16
 })
19
   history.replaceState({}, '', `${location.pathname}?${urlParams}`)
23
   history.replaceState({}, '', `${location.pathname}?${urlParams}`)
20
 }
24
 }
21
 
25
 
22
-const status = ref()
26
+const status = ref(props.initialDropdown[props.nameParam])
23
 
27
 
24
-watch(status, (status) => {
25
-  removeParams('status', 'page')
28
+watch(status, (value) => {
29
+  removeParams(props.nameParam, 'page')
26
 
30
 
27
   Inertia.reload({
31
   Inertia.reload({
28
     data: pickBy({
32
     data: pickBy({
29
-      status,
33
+      [props.nameParam]: value,
30
     }),
34
     }),
31
   })
35
   })
32
 })
36
 })
33
 </script>
37
 </script>
34
 
38
 
35
 <template>
39
 <template>
36
-  <AppDropdown placeholder="status" :options="options" v-model="status" />
40
+  <AppDropdown v-model="status" />
37
 </template>
41
 </template>

+ 11
- 4
resources/js/components/AppSearchFilter.vue Wyświetl plik

5
 
5
 
6
 const props = defineProps({
6
 const props = defineProps({
7
   initialSearch: {
7
   initialSearch: {
8
+    type: Object,
9
+    required: true,
10
+  },
11
+  nameParam: {
12
+    type: String,
8
     required: true,
13
     required: true,
9
   },
14
   },
10
 })
15
 })
17
   history.replaceState({}, '', `${location.pathname}?${urlParams}`)
22
   history.replaceState({}, '', `${location.pathname}?${urlParams}`)
18
 }
23
 }
19
 
24
 
20
-const search = ref(props.initialSearch)
25
+const search = ref(props.initialSearch[props.nameParam])
21
 
26
 
22
-watch(search, (search) => {
23
-  removeParams('search', 'page')
27
+watch(search, (value) => {
28
+  removeParams(props.nameParam, 'page')
24
 
29
 
25
   Inertia.reload({
30
   Inertia.reload({
26
-    data: pickBy({ search }),
31
+    data: pickBy({
32
+      [props.nameParam]: value,
33
+    }),
27
   })
34
   })
28
 })
35
 })
29
 </script>
36
 </script>