Improved search input (#13815)

* create input with tags component

* tweaks

* only show filters pane when there are actual filters

* special case for similarity searches

* similarity search tweaks

* populate suggestions values

* scrollbar on outer div

* clean up

* separate custom hook

* use command component

* tooltips

* regex tweaks

* saved searches with confirmation dialogs

* better date handling

* fix filters

* filter capitalization

* filter instructions

* replace underscore in filter type

* alert dialog button color

* toaster on success
This commit is contained in:
Josh Hawkins
2024-09-18 13:18:16 -05:00
committed by GitHub
parent 5e0d8fe4c7
commit efd1194307
12 changed files with 1580 additions and 40 deletions

View File

@@ -296,3 +296,75 @@ export function isCurrentHour(timestamp: number) {
return timestamp > now.getTime() / 1000;
}
export const convertLocalDateToTimestamp = (dateString: string): number => {
// Ensure the date string is in the correct format (8 digits)
if (!/^\d{8}$/.test(dateString)) {
return 0;
}
// Determine the local date format
const format = new Intl.DateTimeFormat()
.formatToParts(new Date())
.reduce((acc, part) => {
if (part.type === "day") acc.push("D");
if (part.type === "month") acc.push("M");
if (part.type === "year") acc.push("Y");
return acc;
}, [] as string[])
.join("");
let day: string, month: string, year: string;
// Parse the date string according to the detected format
switch (format) {
case "DMY":
[day, month, year] = [
dateString.slice(0, 2),
dateString.slice(2, 4),
dateString.slice(4),
];
break;
case "MDY":
[month, day, year] = [
dateString.slice(0, 2),
dateString.slice(2, 4),
dateString.slice(4),
];
break;
case "YMD":
[year, month, day] = [
dateString.slice(0, 2),
dateString.slice(2, 4),
dateString.slice(4),
];
break;
default:
return 0;
}
// Create a Date object based on the local timezone
const localDate = new Date(`${year}-${month}-${day}T00:00:00`);
// Check if the date is valid
if (isNaN(localDate.getTime())) {
return 0;
}
// Convert local date to UTC timestamp
const timestamp = localDate.getTime();
return timestamp;
};
export function getIntlDateFormat() {
return new Intl.DateTimeFormat()
.formatToParts(new Date())
.reduce((acc, part) => {
if (part.type === "day") acc.push("DD");
if (part.type === "month") acc.push("MM");
if (part.type === "year") acc.push("YYYY");
return acc;
}, [] as string[])
.join("");
}