-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add current workspace member option to workspaceMember relation field filter (#8016) #8950
base: main
Are you sure you want to change the base?
Add current workspace member option to workspaceMember relation field filter (#8016) #8950
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR adds a "current user" filter option for workspace member relations, similar to Linear's implementation, by refactoring filter-related functionality into hooks and adding special ID handling.
Key changes:
- Moves filter computation from utility functions to hooks (
useComputeContextStoreFilters
,useResolveFilterValue
) for better state management - Adds special
CURRENT_WORKSPACE_MEMBER
ID handling inuseResolveRelationViewFilterValue
to support "me" filter option - Introduces
safeStringArrayJSONSchema
for consistent JSON string array validation - Refactors filter value resolution to use simpler function signatures and improved type safety
- Consolidates query variable generation in new
useGetQueryVariablesFromView
hook
💡 (4/5) You can add custom instructions or style guidelines for the bot here!
27 file(s) reviewed, 17 comment(s)
Edit PR Review Bot Settings | Greptile
packages/twenty-front/src/modules/context-store/hooks/useComputeContextStoreFilters.ts
Show resolved
Hide resolved
packages/twenty-front/src/modules/context-store/hooks/useComputeContextStoreFilters.ts
Show resolved
Hide resolved
...rc/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownDateInput.tsx
Show resolved
Hide resolved
...ront/src/modules/object-record/record-filter/hooks/useComputeViewRecordGqlOperationFilter.ts
Outdated
Show resolved
Hide resolved
if (recordIds.length === 0) return; | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: redundant check for recordIds.length === 0, already checked on line 317
const recordIdsAndSpecialIds = | ||
safeStringArrayJSONSchema.parse(viewFilterValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The parse operation could throw if viewFilterValue is not a valid JSON array of strings. Need to handle this error case.
if (viewFilterOperand === ViewFilterOperand.IsRelative) { | ||
return resolveVariableDateViewFilterValue( | ||
viewFilter.value, | ||
viewFilterValue, | ||
) as ResolvedDateViewFilterValue<O>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: No validation is performed on viewFilterValue before passing to resolveVariableDateViewFilterValue, which could throw if value is invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The entire file is being removed but there's no clear replacement shown in the PR. Need to ensure the new implementation maintains all existing filter value resolution functionality.
) => { | ||
return viewFilter.value === '' ? null : +viewFilter.value; | ||
return viewFilterValue === '' ? null : +viewFilterValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: unary plus operator could produce NaN for invalid number strings - consider adding validation
}, z.array(z.string())) | ||
.catch([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: schema allows any string array - may want to add additional validation for specific string formats or lengths
Great work as always! Starting to play around with it, noticed a first bug: Screen.Recording.2024-12-09.at.09.02.50.movEdit: maybe that's what you meant by 'fix unselected values - broken on main'? |
In a followup PR / issue, could you maybe add an "assigned to me" view in "tasks-all.view.ts" file (this will only apply to new workspaces). This will make your feature more discoverable |
I think we can forget the "No assignee" from the initial issue as there is already "is empty" which is good enough |
Please fix the tests |
Could you also verify that your IDE is correctly configured ? The lint problem on the tests and the prettier/eslint problems should not be part of your commit since it should be auto-fixed at save or outputing red squiggles in your console. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With selectedRecordIdsAndSpecialIds, the naming tells us that there's a code smell, "DoingThisAndThat" indicates that we should split this into two distinc flows that join at the right abstraction level.
Here we should keep the previous flow as it is, with utils instead of hooks.
The changes seem to be only for relations and selection. You should explore a solution where you create recoil atoms for storing the state of what your new UI components are doing, then using those atoms where it's really needed, and copy/paste at multiple place if that's the things to do.
For example here contextStoreFilters seems to be more appropriate to store your additional current workspace member filter, and maybe a specific parallel hook/util could handle turning the click into a record filter and modify this state ?
throw new Error('Current workspace member is not defined'); | ||
} | ||
|
||
return recordIdOrSpecialId === 'CURRENT_WORKSPACE_MEMBER' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't seem like the right way to go, storing magic ids to bypass the normal flow is always an anti-pattern for lack of a better solution.
Also special id is too vague as a naming and feels too "magic" which is something we really want to avoid
The fact that a lot of utils has been turned to hooks to accomodate a edge case for relation type is a code smell.
We can definitely find a solution that leaves those utils as is. I feel like we're not implemeting this on the right abstraction level.
) => { | ||
return viewFilter.value === 'true'; | ||
}; | ||
export const resolveBooleanViewFilterValue = (viewFilterValue: string) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep the previous function, we don't strive to compact the code in this codebase, it's okay to keep things explicit and less compact.
ViewFilter, | ||
'value' | ||
> & { operand: O }; | ||
|
||
export const resolveDateViewFilterValue = <O extends ViewFilterOperand>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this refactor needed for this feature ?
export const useResolveFilterValue = () => { | ||
const { resolveRelationViewFilterValue } = useResolveRelationViewFilterValue(); | ||
|
||
const resolveFilterValue = < |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep this as a util
@@ -1,7 +1,6 @@ | |||
import { ViewFilter } from '@/views/types/ViewFilter'; | |||
|
|||
export const resolveNumberViewFilterValue = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this refactor needed ?
@@ -0,0 +1,14 @@ | |||
import { z } from 'zod'; | |||
|
|||
export const safeStringArrayJSONSchema = z |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok to extract this as it was but the validation seems to introduce a silent error that returns [], could we throw or return a wrong validation state instead when the value is really not parsable as an array ?
…s://github.com/eliasylonen/twenty into feat/8016-workspace-member-current-user-filter
Issue: #8016
Almost ready to be merged.
This touches so many files that it could be good to: