ref(seer): Refactor hooks related to the preferred agent option#112042
Conversation
This makes this much easier to read/review and test. The stories are small and still work
| @@ -214,93 +214,6 @@ export function useMutateSelectedAgent({project}: {project: Project}) { | |||
| ); | |||
| } | |||
|
|
|||
| export function useBulkMutateSelectedAgent({projects}: {projects: Project[]}) { | |||
There was a problem hiding this comment.
this big guy just moved over, only changes to the args/types.
1a64a7b to
421f99a
Compare
| }) { | ||
| return useQuery({ | ||
| ...organizationIntegrationsCodingAgents(organization), | ||
| select: (data): ReadonlyArray<SelectValue<PreferredAgent>> => { |
There was a problem hiding this comment.
could this type be inferred?
| select: (data): ReadonlyArray<SelectValue<PreferredAgent>> => { | |
| select: data => { |
There was a problem hiding this comment.
it wasn't working, i can look again though.
It seemed to need the SelectValue<> part in there so that the <Select> field treated it properly. But I was also playing with wrapping it in useCallback which also hurt types, so go at it again.
There was a problem hiding this comment.
i tried to understand how this should work but I’m not sure I could wrap my head around it fully.
the value for the form seems to be either the string literal seer or an object with id, name etc . I’m surprised this even works with out select. Can we not get this into a unified structure?
also when using objects as value for a select, you basically have to provide the isValueEqual function to compare the ids. Otherwise, comparison of values happens with === internally, so values would never be seen as identical.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
There are 3 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| schema={z.object({ | ||
| integration: z.union([z.literal('seer'), z.custom<CodingAgentIntegration>()]), | ||
| })} | ||
| initialValue={initialValue} |
There was a problem hiding this comment.
Form shows wrong initial value after async load
High Severity
When the org has a non-seer preferred agent (via defaultCodingAgentIntegrationId), useFetchPreferredAgent introduces an async loading phase where data is undefined. During loading, initialValue falls back to 'seer', and AutoSaveForm mounts with defaultValues: {integration: 'seer'}. TanStack Form's defaultValues does not update after mount, so once loading completes the form state stays stuck on 'seer' even though the actual agent is different. The old code computed the value synchronously from org props with no loading state, so this is a regression.
Additional Locations (1)
…name from appearing


This makes this much easier to read/review and test. The stories are small and still work
The bigs wins are a) moving a lot of logic out of the component and into hooks, b) and then leveraging useQuery and
select: () => ...inside those hooks to format the data.Everything is more centered around
type PreferredAgent, including the filename. i like how those things align tbh. And the tests are easier to read, and more plentiful, than before.