Skip to content

Commit 1369ad7

Browse files
committed
optimize TimeRange
1 parent 72d4d54 commit 1369ad7

6 files changed

Lines changed: 27 additions & 24 deletions

File tree

src/lib/helpers/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export const IMAGE_DATA_PREFIX = 'data:image';
4949
export const INTEGER_REGEX = "[0-9]+";
5050
export const DECIMAL_REGEX = "[0-9.]+";
5151

52+
// Custom date range identifier (not in TimeRange enum)
53+
export const CUSTOM_DATE_RANGE = "Custom date";
54+
5255
export const TIME_RANGE_OPTIONS = [
5356
{ label: TimeRange.Last15Minutes, value: TimeRange.Last15Minutes, qty: 15, unit: 'minutes' },
5457
{ label: TimeRange.Last30Minutes, value: TimeRange.Last30Minutes, qty: 30, unit: 'minutes' },
@@ -57,7 +60,6 @@ export const TIME_RANGE_OPTIONS = [
5760
{ label: TimeRange.Last12Hours, value: TimeRange.Last12Hours, qty: 12, unit: 'hours' },
5861
{ label: TimeRange.Today, value: TimeRange.Today, qty: 1, unit: 'days' },
5962
{ label: TimeRange.Yesterday, value: TimeRange.Yesterday, qty: 1, unit: 'days' },
60-
{ label: TimeRange.SpecificDay, value: TimeRange.SpecificDay, isSpecificDay: true },
6163
{ label: TimeRange.Last3Days, value: TimeRange.Last3Days, qty: 3, unit: 'days' },
6264
{ label: TimeRange.Last7Days, value: TimeRange.Last7Days, qty: 7, unit: 'days' },
6365
{ label: TimeRange.Last30Days, value: TimeRange.Last30Days, qty: 30, unit: 'days' },

src/lib/helpers/enums.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ const timeRange = {
257257
Last12Hours: "Last 12 hours",
258258
Today: "Today",
259259
Yesterday: "Yesterday",
260-
SpecificDay: "Specific day",
261260
Last3Days: "Last 3 days",
262261
Last7Days: "Last 7 days",
263262
Last30Days: "Last 30 days",

src/lib/helpers/types/conversationTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ IRichContent.prototype.language;
324324
* @property {UserStateDetailModel[]} states
325325
* @property {string[]} tags
326326
* @property {string?} [timeRange]
327-
* @property {string} [startDate] - When timeRange is SpecificDay, start date in YYYY-MM-DD format (e.g. 2026-01-25)
328-
* @property {string} [endDate] - When timeRange is SpecificDay, end date in YYYY-MM-DD format (e.g. 2026-01-30). Defaults to startDate if not provided
327+
* @property {string} [startDate] - When timeRange is "Custom date", start date in YYYY-MM-DD format (e.g. 2026-01-25)
328+
* @property {string} [endDate] - When timeRange is "Custom date", end date in YYYY-MM-DD format (e.g. 2026-01-30). Defaults to startDate if not provided
329329
*/
330330

331331
/**

src/lib/helpers/utils/common.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { goto } from '$app/navigation';
22
import moment from 'moment';
3-
import { TIME_RANGE_OPTIONS } from '../constants';
3+
import { TIME_RANGE_OPTIONS, CUSTOM_DATE_RANGE } from '../constants';
44
import { TimeRange } from '../enums';
55

66
export function range(size = 3, startAt = 0) {
@@ -192,8 +192,8 @@ export function getCleanUrl(url) {
192192

193193
/**
194194
* @param {string} timeRange
195-
* @param {string} [startDate] - When timeRange is SpecificDay, start date in YYYY-MM-DD format (e.g. 2026-01-25)
196-
* @param {string} [endDate] - When timeRange is SpecificDay, end date in YYYY-MM-DD format (e.g. 2026-01-30). If not provided, uses startDate
195+
* @param {string} [startDate] - When timeRange is "Custom date", start date in YYYY-MM-DD format (e.g. 2026-01-25)
196+
* @param {string} [endDate] - When timeRange is "Custom date", end date in YYYY-MM-DD format (e.g. 2026-01-30). If not provided, uses startDate
197197
* @returns {{ startTime: string | null, endTime: string | null }}
198198
*/
199199
export function convertTimeRange(timeRange, startDate, endDate) {
@@ -242,7 +242,7 @@ export function convertTimeRange(timeRange, startDate, endDate) {
242242
endTime: moment().subtract(1, 'days').endOf('day').utc().format()
243243
};
244244
break;
245-
case TimeRange.SpecificDay:
245+
case CUSTOM_DATE_RANGE:
246246
if (startDate && moment(startDate).isValid()) {
247247
const endDateToUse = endDate && moment(endDate).isValid() ? endDate : startDate;
248248
ret = {

src/routes/page/conversation/+page.svelte

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import { getAgentOptions } from '$lib/services/agent-service';
2323
import { utcToLocal } from '$lib/helpers/datetime';
2424
import { ConversationChannel, TimeRange } from '$lib/helpers/enums';
25-
import { TIME_RANGE_OPTIONS } from '$lib/helpers/constants';
25+
import { TIME_RANGE_OPTIONS, CUSTOM_DATE_RANGE } from '$lib/helpers/constants';
2626
import { clickoutsideDirective } from '$lib/helpers/directives';
2727
import {
2828
getConversations,
@@ -63,7 +63,7 @@
6363
6464
// Get time range display text
6565
const getTimeRangeDisplayText = () => {
66-
if (searchOption.timeRange === TimeRange.SpecificDay) {
66+
if (searchOption.timeRange === CUSTOM_DATE_RANGE) {
6767
if (searchOption.startDate && searchOption.endDate) {
6868
const start = formatDateForDisplay(searchOption.startDate);
6969
const end = formatDateForDisplay(searchOption.endDate);
@@ -96,15 +96,15 @@
9696
9797
// Update time range display text reactively
9898
$: {
99-
if (searchOption.timeRange === TimeRange.SpecificDay && searchOption.startDate && searchOption.endDate) {
99+
if (searchOption.timeRange === CUSTOM_DATE_RANGE && searchOption.startDate && searchOption.endDate) {
100100
const start = formatDateForDisplay(searchOption.startDate);
101101
const end = formatDateForDisplay(searchOption.endDate);
102102
if (start === end) {
103103
timeRangeDisplayText = start;
104104
} else {
105105
timeRangeDisplayText = `${start} - ${end}`;
106106
}
107-
} else if (searchOption.timeRange === TimeRange.SpecificDay) {
107+
} else if (searchOption.timeRange === CUSTOM_DATE_RANGE) {
108108
timeRangeDisplayText = 'Custom';
109109
} else {
110110
const selected = presetTimeRangeOptions.find(x => x.value === searchOption.timeRange);
@@ -143,9 +143,9 @@
143143
{ value: k.toLowerCase(), label: v }
144144
));
145145
146-
// Preset time range options (excluding SpecificDay)
146+
// Preset time range options (excluding custom date)
147147
const presetTimeRangeOptions = TIME_RANGE_OPTIONS
148-
.filter(x => x.value !== TimeRange.SpecificDay)
148+
.filter(x => x.value !== CUSTOM_DATE_RANGE)
149149
.map(x => ({
150150
label: x.label,
151151
value: x.value
@@ -586,7 +586,8 @@
586586
on:click={() => {
587587
showDatePicker = !showDatePicker;
588588
if (showDatePicker) {
589-
datePickerTab = 'relative';
589+
// If custom date is selected, switch to custom tab; otherwise use relative tab
590+
datePickerTab = searchOption.timeRange === CUSTOM_DATE_RANGE ? 'custom' : 'relative';
590591
}
591592
}}
592593
style="cursor: pointer;"
@@ -710,7 +711,7 @@
710711
// Force reactivity by reassigning the object
711712
searchOption = {
712713
...searchOption,
713-
timeRange: TimeRange.SpecificDay
714+
timeRange: CUSTOM_DATE_RANGE
714715
};
715716
}
716717
showDatePicker = false;

src/routes/page/instruction/log/+page.svelte

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
goToUrl
2222
} from '$lib/helpers/utils/common';
2323
import { TimeRange } from '$lib/helpers/enums';
24-
import { TIME_RANGE_OPTIONS } from '$lib/helpers/constants';
24+
import { TIME_RANGE_OPTIONS, CUSTOM_DATE_RANGE } from '$lib/helpers/constants';
2525
import { clickoutsideDirective } from '$lib/helpers/directives';
2626
import LogItem from './log-item.svelte';
2727
@@ -32,9 +32,9 @@
3232
3333
const initPager = { page: firstPage, size: pageSize };
3434
35-
// Preset time range options (excluding SpecificDay)
35+
// Preset time range options (excluding custom date)
3636
const presetTimeRangeOptions = TIME_RANGE_OPTIONS
37-
.filter(x => x.value !== TimeRange.SpecificDay)
37+
.filter(x => x.value !== CUSTOM_DATE_RANGE)
3838
.map(x => ({
3939
label: x.label,
4040
value: x.value
@@ -65,7 +65,7 @@
6565
6666
// Get time range display text
6767
const getTimeRangeDisplayText = () => {
68-
if (searchOption.timeRange === TimeRange.SpecificDay) {
68+
if (searchOption.timeRange === CUSTOM_DATE_RANGE) {
6969
if (searchOption.startDate && searchOption.endDate) {
7070
const start = formatDateForDisplay(searchOption.startDate);
7171
const end = formatDateForDisplay(searchOption.endDate);
@@ -128,15 +128,15 @@
128128
129129
// Update time range display text reactively
130130
$: {
131-
if (searchOption.timeRange === TimeRange.SpecificDay && searchOption.startDate && searchOption.endDate) {
131+
if (searchOption.timeRange === CUSTOM_DATE_RANGE && searchOption.startDate && searchOption.endDate) {
132132
const start = formatDateForDisplay(searchOption.startDate);
133133
const end = formatDateForDisplay(searchOption.endDate);
134134
if (start === end) {
135135
timeRangeDisplayText = start;
136136
} else {
137137
timeRangeDisplayText = `${start} - ${end}`;
138138
}
139-
} else if (searchOption.timeRange === TimeRange.SpecificDay) {
139+
} else if (searchOption.timeRange === CUSTOM_DATE_RANGE) {
140140
timeRangeDisplayText = 'Custom';
141141
} else {
142142
const selected = presetTimeRangeOptions.find(x => x.value === searchOption.timeRange);
@@ -451,7 +451,8 @@
451451
on:click={() => {
452452
showDatePicker = !showDatePicker;
453453
if (showDatePicker) {
454-
datePickerTab = 'relative';
454+
// If custom date is selected, switch to custom tab; otherwise use relative tab
455+
datePickerTab = searchOption.timeRange === CUSTOM_DATE_RANGE ? 'custom' : 'relative';
455456
}
456457
}}
457458
style="cursor: pointer;"
@@ -573,7 +574,7 @@
573574
// Force reactivity by reassigning the object
574575
searchOption = {
575576
...searchOption,
576-
timeRange: TimeRange.SpecificDay
577+
timeRange: CUSTOM_DATE_RANGE
577578
};
578579
}
579580
showDatePicker = false;

0 commit comments

Comments
 (0)