fix before and after filters

This commit is contained in:
Josh Hawkins 2024-09-25 08:23:04 -05:00
parent a33bc563bc
commit eff13c77fd
4 changed files with 23 additions and 8 deletions

View File

@ -188,7 +188,11 @@ export default function InputWithTags({
const createFilter = useCallback( const createFilter = useCallback(
(type: FilterType, value: string) => { (type: FilterType, value: string) => {
if (allSuggestions[type as FilterType]?.includes(value)) { if (
allSuggestions[type as FilterType]?.includes(value) ||
type == "before" ||
type == "after"
) {
const newFilters = { ...filters }; const newFilters = { ...filters };
let timestamp = 0; let timestamp = 0;
@ -318,6 +322,7 @@ export default function InputWithTags({
((filterType === "before" || filterType === "after") && ((filterType === "before" || filterType === "after") &&
trimmedValue.match(/^\d{8}$/)) trimmedValue.match(/^\d{8}$/))
) { ) {
console.log(filterType, trimmedValue);
createFilter(filterType, trimmedValue); createFilter(filterType, trimmedValue);
setInputValue((prev) => { setInputValue((prev) => {
const regex = new RegExp( const regex = new RegExp(
@ -355,11 +360,7 @@ export default function InputWithTags({
]; ];
// Check if filter type is valid // Check if filter type is valid
if ( if (filterType in allSuggestions) {
filterType in allSuggestions ||
filterType === "before" ||
filterType === "after"
) {
setCurrentFilterType(filterType); setCurrentFilterType(filterType);
if (filterType === "before" || filterType === "after") { if (filterType === "before" || filterType === "after") {

View File

@ -48,8 +48,6 @@ export default function useSuggestions(
setSuggestions([ setSuggestions([
...(searchHistory?.map((search) => search.name) ?? []), ...(searchHistory?.map((search) => search.name) ?? []),
...availableFilters, ...availableFilters,
"before",
"after",
]); ]);
} }
}, },

View File

@ -374,6 +374,19 @@ export function getIntlDateFormat() {
.join(""); .join("");
} }
export function formatDateToLocaleString(daysOffset: number = 0): string {
const date = new Date();
date.setDate(date.getDate() + daysOffset);
return new Intl.DateTimeFormat(window.navigator.language, {
day: "2-digit",
month: "2-digit",
year: "numeric",
})
.format(date)
.replace(/[^\d]/g, "");
}
export function isValidTimeRange(rangeString: string): boolean { export function isValidTimeRange(rangeString: string): boolean {
const range = rangeString.split(","); const range = rangeString.split(",");

View File

@ -30,6 +30,7 @@ import scrollIntoView from "scroll-into-view-if-needed";
import InputWithTags from "@/components/input/InputWithTags"; import InputWithTags from "@/components/input/InputWithTags";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
import { isEqual } from "lodash"; import { isEqual } from "lodash";
import { formatDateToLocaleString } from "@/utils/dateUtil";
type SearchViewProps = { type SearchViewProps = {
search: string; search: string;
@ -121,6 +122,8 @@ export default function SearchView({
sub_labels: allSubLabels, sub_labels: allSubLabels,
search_type: ["thumbnail", "description"] as SearchSource[], search_type: ["thumbnail", "description"] as SearchSource[],
time_range: ["00:00,24:00"], time_range: ["00:00,24:00"],
before: [formatDateToLocaleString()],
after: [formatDateToLocaleString(-5)],
}), }),
[config, allLabels, allZones, allSubLabels], [config, allLabels, allZones, allSubLabels],
); );