@xy-planning-network/trees 0.6.8 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xy-planning-network/trees",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "repository": "github:xy-planning-network/trees",
@@ -11,11 +11,13 @@ const props = withDefaults(
11
11
  minDate: number
12
12
  maxDate: number
13
13
  }
14
+ maxRange?: number
14
15
  startDate?: number
15
16
  label?: string
16
17
  help?: string
17
18
  }>(),
18
19
  {
20
+ maxRange: 0,
19
21
  startDate: 0,
20
22
  label: "",
21
23
  help: "",
@@ -31,7 +33,7 @@ const updateModelValue = (value: { minDate: number; maxDate: number }) => {
31
33
  }
32
34
 
33
35
  onMounted(() => {
34
- flatpickr(`#${uuid}`, {
36
+ const opts: flatpickr.Options.Options = {
35
37
  dateFormat: "m-d-Y",
36
38
  mode: "range",
37
39
  maxDate: new Date(), // So far, we cannot have options past today for ranges
@@ -51,7 +53,40 @@ onMounted(() => {
51
53
  })
52
54
  }
53
55
  },
54
- })
56
+ }
57
+
58
+ if (props.maxRange) {
59
+ // Set the range to a prefilled value given the allowed range
60
+ const daysAgo = new Date()
61
+ const minDate = daysAgo.setDate(daysAgo.getDate() - props.maxRange)
62
+ const maxDate = new Date()
63
+ opts.defaultDate = [minDate, maxDate]
64
+ updateModelValue({
65
+ minDate: Math.floor(minDate / 1000),
66
+ maxDate: Math.floor(maxDate.getTime() / 1000),
67
+ })
68
+
69
+ // Handle onChange to dynamically adjust maxDate to x days ahead of the selected start date
70
+ opts.onChange = (selectedDates, _, self) => {
71
+ if (selectedDates.length === 1) {
72
+ // Clone date so as to not change selectedDates[0] value
73
+ var daysAhead = new Date(selectedDates[0].getTime())
74
+ var daysBefore = new Date(selectedDates[0].getTime())
75
+ daysAhead.setDate(daysAhead.getDate() + props.maxRange)
76
+ daysBefore.setDate(daysBefore.getDate() - props.maxRange)
77
+ const now = new Date()
78
+
79
+ if (daysAhead > now) {
80
+ daysAhead = now
81
+ }
82
+
83
+ self.set("minDate", daysBefore)
84
+ self.set("maxDate", daysAhead)
85
+ }
86
+ }
87
+ }
88
+
89
+ flatpickr(`#${uuid}`, opts)
55
90
  })
56
91
  </script>
57
92
  <template>
@@ -12,6 +12,7 @@ import type {
12
12
  } from "@/composables/table"
13
13
  import { useAppFlasher } from "@/composables/useFlashes"
14
14
  import { TrailsRespPaged } from "@/api/client"
15
+ import { DateRangeProps } from "@/composables/date"
15
16
  import { useTable } from "@/composables/useTable"
16
17
  import TableActionButtons from "./TableActionButtons.vue"
17
18
 
@@ -121,6 +122,12 @@ const handleSort = (selectedSort: string): void => {
121
122
  loadAndRender()
122
123
  }
123
124
 
125
+ const dateSearchProps = computed((): DateRangeProps => {
126
+ if (typeof props.tableOptions.dateSearch === "object")
127
+ return props.tableOptions.dateSearch
128
+ return {}
129
+ })
130
+
124
131
  const hasContent = computed((): boolean => {
125
132
  return rows.value.length ? true : false
126
133
  })
@@ -181,6 +188,7 @@ loadAndRender()
181
188
  <div v-if="tableOptions.dateSearch" class="w-full max-w-lg lg:max-w-xs">
182
189
  <DateRangePicker
183
190
  v-model="dateRange"
191
+ v-bind="{ ...dateSearchProps }"
184
192
  @update:model-value="dateRangeChanged"
185
193
  />
186
194
  </div>
@@ -2,3 +2,9 @@ export interface DateRange {
2
2
  minDate: number;
3
3
  maxDate: number;
4
4
  }
5
+ export interface DateRangeProps {
6
+ help?: string;
7
+ label?: string;
8
+ maxRange?: number;
9
+ startDate?: number;
10
+ }
@@ -1,7 +1,8 @@
1
1
  import { VNodeChild } from "vue";
2
2
  import { ActionItem } from "../composables/nav";
3
+ import { DateRangeProps } from "./date";
3
4
  export interface DynamicTableOptions {
4
- dateSearch?: boolean;
5
+ dateSearch?: boolean | DateRangeProps;
5
6
  defaultSort?: string;
6
7
  defaultSortDirection?: string;
7
8
  refreshTrigger: number;
@@ -4,10 +4,12 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
4
4
  minDate: number;
5
5
  maxDate: number;
6
6
  };
7
+ maxRange?: number | undefined;
7
8
  startDate?: number | undefined;
8
9
  label?: string | undefined;
9
10
  help?: string | undefined;
10
11
  }>, {
12
+ maxRange: number;
11
13
  startDate: number;
12
14
  label: string;
13
15
  help: string;
@@ -16,10 +18,12 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
16
18
  minDate: number;
17
19
  maxDate: number;
18
20
  };
21
+ maxRange?: number | undefined;
19
22
  startDate?: number | undefined;
20
23
  label?: string | undefined;
21
24
  help?: string | undefined;
22
25
  }>, {
26
+ maxRange: number;
23
27
  startDate: number;
24
28
  label: string;
25
29
  help: string;
@@ -28,6 +32,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
28
32
  }, {
29
33
  label: string;
30
34
  help: string;
35
+ maxRange: number;
31
36
  startDate: number;
32
37
  }, {}>;
33
38
  export default _default;