Skip to content

Commit

Permalink
Ability to filter on DATE fields (#6299) (#6824)
Browse files Browse the repository at this point in the history
This was surprisingly quick, it was already built, just not enabled.
Let's double check it together still on Monday @FelixMalfait!
  • Loading branch information
ad-elias authored Sep 3, 2024
1 parent 6e7cb27 commit bc2227d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const formatFieldMetadataItemsAsFilterDefinitions = ({
if (
![
FieldMetadataType.DateTime,
FieldMetadataType.Date,
FieldMetadataType.Text,
FieldMetadataType.Email,
FieldMetadataType.Emails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export const MultipleFiltersDropdownContent = ({
{filterDefinitionUsedInDropdown.type === 'RATING' && (
<ObjectFilterDropdownRatingInput />
)}
{filterDefinitionUsedInDropdown.type === 'DATE_TIME' && (
<ObjectFilterDropdownDateInput />
)}
{['DATE_TIME', 'DATE'].includes(
filterDefinitionUsedInDropdown.type,
) && <ObjectFilterDropdownDateInput />}
{filterDefinitionUsedInDropdown.type === 'RELATION' && (
<>
<ObjectFilterDropdownSearchInput />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const MultipleFiltersDropdownFilterOnFilterChangedEffect = ({

useEffect(() => {
switch (filterDefinitionUsedInDropdownType) {
case 'DATE':
case 'DATE_TIME':
setDropdownWidth(280);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const ObjectFilterDropdownDateInput = () => {
selectedFilter?.value ? new Date(selectedFilter.value) : new Date(),
);

const isDateTimeInput =
filterDefinitionUsedInDropdown?.type === FieldMetadataType.DateTime;

const handleChange = (date: Date | null) => {
setInternalDate(date);

Expand All @@ -38,7 +41,11 @@ export const ObjectFilterDropdownDateInput = () => {
fieldMetadataId: filterDefinitionUsedInDropdown.fieldMetadataId,
value: isDefined(date) ? date.toISOString() : '',
operand: selectedOperandInDropdown,
displayValue: isDefined(date) ? date.toLocaleString() : '',
displayValue: isDefined(date)
? isDateTimeInput
? date.toLocaleString()
: date.toLocaleDateString()
: '',
definition: filterDefinitionUsedInDropdown,
});

Expand All @@ -50,9 +57,7 @@ export const ObjectFilterDropdownDateInput = () => {
date={internalDate}
onChange={handleChange}
onMouseSelect={handleChange}
isDateTimeInput={
filterDefinitionUsedInDropdown?.type === FieldMetadataType.DateTime
}
isDateTimeInput={isDateTimeInput}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const isRecordMatchingFilter = ({
});
});
}
case FieldMetadataType.Date:
case FieldMetadataType.DateTime: {
return isMatchingDateFilter({
dateFilter: filterValue as DateFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const applyEmptyFilters = (
[correspondingField.name]: { is: 'NULL' } as StringFilter,
};
break;
case 'DATE':
case 'DATE_TIME':
emptyRecordFilter = {
[correspondingField.name]: { is: 'NULL' } as DateFilter,
Expand Down Expand Up @@ -326,6 +327,7 @@ export const turnObjectDropdownFilterIntoQueryFilter = (
);
}
break;
case 'DATE':
case 'DATE_TIME':
switch (rawUIFilter.operand) {
case ViewFilterOperand.GreaterThan:
Expand Down

0 comments on commit bc2227d

Please sign in to comment.