-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Solves issue #5917. This PR is now ready for the first review! Filters do not fully work yet, there's a problem applying multiple filters like the following: ``` { and: [ { [correspondingField.name]: { gte: start.toISOString(), } as DateFilter, }, { [correspondingField.name]: { lte: end.toISOString(), } as DateFilter, }, ], } ``` I'll do my best to dig into it tonight! --------- Co-authored-by: Félix Malfait <[email protected]>
- Loading branch information
1 parent
c9c2f32
commit 9d36493
Showing
28 changed files
with
979 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
packages/twenty-front/src/modules/object-record/object-filter-dropdown/types/Filter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...nty-front/src/modules/object-record/object-filter-dropdown/utils/getInitialFilterValue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Filter } from '@/object-record/object-filter-dropdown/types/Filter'; | ||
import { FilterType } from '@/object-record/object-filter-dropdown/types/FilterType'; | ||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand'; | ||
import { z } from 'zod'; | ||
|
||
export const getInitialFilterValue = ( | ||
newType: FilterType, | ||
newOperand: ViewFilterOperand, | ||
oldValue?: string, | ||
oldDisplayValue?: string, | ||
): Pick<Filter, 'value' | 'displayValue'> | Record<string, never> => { | ||
switch (newType) { | ||
case 'DATE': | ||
case 'DATE_TIME': { | ||
const activeDatePickerOperands = [ | ||
ViewFilterOperand.IsBefore, | ||
ViewFilterOperand.Is, | ||
ViewFilterOperand.IsAfter, | ||
]; | ||
|
||
if (activeDatePickerOperands.includes(newOperand)) { | ||
const date = z.coerce.date().safeParse(oldValue).data ?? new Date(); | ||
const value = date.toISOString(); | ||
const displayValue = | ||
newType === 'DATE' | ||
? date.toLocaleString() | ||
: date.toLocaleDateString(); | ||
|
||
return { value, displayValue }; | ||
} | ||
|
||
if (newOperand === ViewFilterOperand.IsRelative) { | ||
return { value: '', displayValue: '' }; | ||
} | ||
break; | ||
} | ||
} | ||
return { | ||
value: oldValue ?? '', | ||
displayValue: oldDisplayValue ?? '', | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.