Skip to content

Commit 2e757c5

Browse files
fix(query): use native date inputs in query options (#953)
* fix(query): use native date inputs in query options Git-Session-Id: 7ccb * fix(query): normalize date input values Git-Session-Id: 7ccb * fix(query): preserve native date value format Git-Session-Id: 7ccb
1 parent 13a9428 commit 2e757c5

6 files changed

Lines changed: 79 additions & 9 deletions

File tree

src/components/QueryOptions.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ div
55
option(v-for="hostname in hostnameChoices")
66
| {{hostname}}
77
b-form-group(label="Start" label-cols=2)
8-
b-form-datepicker(v-model="queryOptionsData.start")
8+
input.form-control(type="date" v-model="queryOptionsData.start")
99
b-form-group(label="Stop" label-cols=2)
10-
b-form-datepicker(v-model="queryOptionsData.stop")
10+
input.form-control(type="date" v-model="queryOptionsData.stop")
1111
b-form-group(label="Toggles" label-cols=2)
1212
b-form-checkbox(type="checkbox" v-model="queryOptionsData.filter_afk" label="Filter AFK" description="")
1313
label Exclude time away from computer

src/views/Graph.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ export default {
207207
return { nodes, links };
208208
},
209209
extendByWeek() {
210-
this.queryOptions.start = moment(this.queryOptions.start).subtract(1, 'week');
210+
this.queryOptions.start = moment(this.queryOptions.start)
211+
.subtract(1, 'week')
212+
.format('YYYY-MM-DD');
211213
this.generate();
212214
},
213215
},

src/views/Report.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ export default {
176176
},
177177
178178
extendByWeek() {
179-
this.queryOptions.start = moment(this.queryOptions.start).subtract(1, 'week');
179+
this.queryOptions.start = moment(this.queryOptions.start)
180+
.subtract(1, 'week')
181+
.format('YYYY-MM-DD');
180182
this.generate();
181183
},
182184
},

src/views/Search.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export default {
6464
// Options
6565
show_options: false,
6666
queryOptions: {
67-
start: moment().subtract(1, 'day'),
68-
stop: moment().add(1, 'day'),
67+
start: moment().subtract(1, 'day').format('YYYY-MM-DD'),
68+
stop: moment().add(1, 'day').format('YYYY-MM-DD'),
6969
},
7070
};
7171
},
@@ -97,7 +97,9 @@ export default {
9797
}
9898
},
9999
extendByWeek() {
100-
this.queryOptions.start = moment(this.queryOptions.start).subtract(1, 'week');
100+
this.queryOptions.start = moment(this.queryOptions.start)
101+
.subtract(1, 'week')
102+
.format('YYYY-MM-DD');
101103
this.search();
102104
},
103105
},

src/views/settings/CategoryBuilder.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ export default {
150150
show_options: false,
151151
queryOptions: {
152152
hostname: '',
153-
start: moment().subtract(1, 'day'),
154-
stop: moment().add(1, 'day'),
153+
start: moment().subtract(1, 'day').format('YYYY-MM-DD'),
154+
stop: moment().add(1, 'day').format('YYYY-MM-DD'),
155155
},
156156
157157
// TODO: Support inspecting a different category than Uncategorized (e.g. to make some category more precise)

test/unit/QueryOptions.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import moment from 'moment';
2+
import { createPinia, setActivePinia } from 'pinia';
3+
import { shallowMount } from '@vue/test-utils';
4+
import QueryOptions from '~/components/QueryOptions.vue';
5+
import Search from '~/views/Search.vue';
6+
7+
const mockEnsureLoaded = jest.fn().mockResolvedValue(undefined);
8+
9+
jest.mock('~/stores/buckets', () => ({
10+
useBucketsStore: () => ({
11+
ensureLoaded: mockEnsureLoaded,
12+
hosts: ['laptop'],
13+
}),
14+
}));
15+
16+
describe('QueryOptions', () => {
17+
beforeEach(() => {
18+
setActivePinia(createPinia());
19+
mockEnsureLoaded.mockClear();
20+
});
21+
22+
test('renders date range values in native date inputs', async () => {
23+
const wrapper = shallowMount(QueryOptions, {
24+
propsData: {
25+
queryOptions: {
26+
start: '2026-08-15',
27+
stop: '2026-08-16',
28+
},
29+
},
30+
stubs: {
31+
'b-form-group': { template: '<div><slot /></div>' },
32+
'b-form-select': true,
33+
'b-form-checkbox': true,
34+
},
35+
});
36+
37+
await wrapper.vm.$nextTick();
38+
await wrapper.vm.$nextTick();
39+
40+
const dateInputs = wrapper.findAll('input[type="date"]');
41+
expect(dateInputs).toHaveLength(2);
42+
expect(dateInputs.at(0).element.value).toBe('2026-08-15');
43+
expect(dateInputs.at(1).element.value).toBe('2026-08-16');
44+
});
45+
46+
test.each([Search])('initializes date ranges as YYYY-MM-DD strings', view => {
47+
const data = view.data();
48+
49+
expect(data.queryOptions.start).toMatch(/^\d{4}-\d{2}-\d{2}$/);
50+
expect(data.queryOptions.stop).toMatch(/^\d{4}-\d{2}-\d{2}$/);
51+
});
52+
53+
test.each([Search])('keeps extended ranges compatible with date inputs', view => {
54+
const vm = {
55+
queryOptions: { start: moment('2026-08-15') },
56+
search: jest.fn(),
57+
generate: jest.fn(),
58+
};
59+
60+
view.methods.extendByWeek.call(vm);
61+
62+
expect(vm.queryOptions.start).toBe('2026-08-08');
63+
});
64+
});

0 commit comments

Comments
 (0)