-
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.
Refactor & make 'valueType' required in frontend
- Loading branch information
Showing
17 changed files
with
108 additions
and
24 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
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
21 changes: 21 additions & 0 deletions
21
...ty-front/src/modules/object-record/object-filter-dropdown/utils/getViewFilterValueType.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,21 @@ | ||
import { FilterDefinition } from '@/object-record/object-filter-dropdown/types/FilterDefinition'; | ||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand'; | ||
import { ViewFilterValueType } from '@/views/types/ViewFilterValueType'; | ||
|
||
export const getViewFilterValueType = ( | ||
filterDefinition: Pick<FilterDefinition, 'type'>, | ||
operand: ViewFilterOperand, | ||
) => { | ||
switch (filterDefinition.type) { | ||
case 'DATE': | ||
case 'DATE_TIME': | ||
switch (operand) { | ||
case ViewFilterOperand.IsRelative: | ||
return ViewFilterValueType.VARIABLE; | ||
default: | ||
return ViewFilterValueType.STATIC; | ||
} | ||
default: | ||
return ViewFilterValueType.STATIC; | ||
} | ||
}; |
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
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
36 changes: 27 additions & 9 deletions
36
packages/twenty-front/src/modules/views/utils/view-filter-value/resolveFilterValue.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 |
---|---|---|
@@ -1,24 +1,42 @@ | ||
import { Filter } from '@/object-record/object-filter-dropdown/types/Filter'; | ||
import { FilterType } from '@/object-record/object-filter-dropdown/types/FilterType'; | ||
import { ViewFilterValueType } from '@/views/types/ViewFilterValueType'; | ||
import { resolveNumberViewFilterValue } from '@/views/utils/view-filter-value/resolveNumberViewFilterValue'; | ||
import { resolveDateViewFilterValue } from './resolveDateViewFilterValue'; | ||
import { | ||
resolveDateViewFilterValue, | ||
ResolvedDateViewFilterValue, | ||
} from './resolveDateViewFilterValue'; | ||
|
||
type ResolvedFilterValue<T extends FilterType> = T extends 'DATE' | 'DATE_TIME' | ||
? ReturnType<typeof resolveDateViewFilterValue> | ||
: T extends 'NUMBER' | ||
type ResolvedFilterValue< | ||
F extends FilterType, | ||
V extends ViewFilterValueType, | ||
> = F extends 'DATE' | 'DATE_TIME' | ||
? ResolvedDateViewFilterValue<V> | ||
: F extends 'NUMBER' | ||
? ReturnType<typeof resolveNumberViewFilterValue> | ||
: string; | ||
|
||
export const resolveFilterValue = <T extends FilterType>( | ||
filter: Pick<Filter, 'value' | 'valueType'> & { definition: { type: T } }, | ||
type PartialFilter<F extends FilterType, V extends ViewFilterValueType> = Pick< | ||
Filter, | ||
'value' | ||
> & { | ||
definition: { type: F }; | ||
valueType: V; | ||
}; | ||
|
||
export const resolveFilterValue = < | ||
F extends FilterType, | ||
V extends ViewFilterValueType, | ||
>( | ||
filter: PartialFilter<F, V>, | ||
) => { | ||
switch (filter.definition.type) { | ||
case 'DATE': | ||
case 'DATE_TIME': | ||
return resolveDateViewFilterValue(filter) as ResolvedFilterValue<T>; | ||
return resolveDateViewFilterValue(filter) as ResolvedFilterValue<F, V>; | ||
case 'NUMBER': | ||
return resolveNumberViewFilterValue(filter) as ResolvedFilterValue<T>; | ||
return resolveNumberViewFilterValue(filter) as ResolvedFilterValue<F, V>; | ||
default: | ||
return filter.value as ResolvedFilterValue<T>; | ||
return filter.value as ResolvedFilterValue<F, V>; | ||
} | ||
}; |