-
Notifications
You must be signed in to change notification settings - Fork 362
Feat/company custom fields #39
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
ea2c4dc
b69db90
ce7336c
bf9aae4
61f74d3
273154e
1bf8170
6794ce9
5c8b7de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -517,6 +517,14 @@ export const useAddDealItem = () => { | |||||||||||||||||||||||||||||||||||||||||||||
| if (error) throw error; | ||||||||||||||||||||||||||||||||||||||||||||||
| return { dealId, item: data! }; | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| onSuccess: (data, { dealId }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| queryClient.setQueryData(DEALS_VIEW_KEY, (old) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!old) return old; | ||||||||||||||||||||||||||||||||||||||||||||||
| return old.map((d) => | ||||||||||||||||||||||||||||||||||||||||||||||
| d.id === dealId ? { ...d, items: [...(d.items ?? []), data.item] } : d | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| onSettled: (_data, _error, { dealId }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| queryClient.invalidateQueries({ queryKey: queryKeys.deals.detail(dealId) }); | ||||||||||||||||||||||||||||||||||||||||||||||
| queryClient.invalidateQueries({ queryKey: queryKeys.deals.lists() }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -536,6 +544,14 @@ export const useRemoveDealItem = () => { | |||||||||||||||||||||||||||||||||||||||||||||
| if (error) throw error; | ||||||||||||||||||||||||||||||||||||||||||||||
| return { dealId, itemId }; | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| onSuccess: (data) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| queryClient.setQueryData(DEALS_VIEW_KEY, (old) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!old) return old; | ||||||||||||||||||||||||||||||||||||||||||||||
| return old.map((d) => | ||||||||||||||||||||||||||||||||||||||||||||||
| d.id === data.dealId ? { ...d, items: (d.items ?? []).filter((i) => i.id !== data.itemId) } : d | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+547
to
+554
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same cascade-invalidation and missing-generic issues as The Based on learnings: "For Deals entity mutations, always use ♻️ Proposed fix- onSuccess: (data) => {
- queryClient.setQueryData(DEALS_VIEW_KEY, (old) => {
- if (!old) return old;
- return old.map((d) =>
- d.id === data.dealId ? { ...d, items: (d.items ?? []).filter((i) => i.id !== data.itemId) } : d
- );
- });
- },
- onSettled: (_data, _error, { dealId }) => {
- queryClient.invalidateQueries({ queryKey: queryKeys.deals.detail(dealId) });
- queryClient.invalidateQueries({ queryKey: queryKeys.deals.lists() });
- },
+ onSuccess: (data) => {
+ queryClient.setQueryData<DealView[]>(DEALS_VIEW_KEY, (old) => {
+ if (!old) return old;
+ return old.map((d) =>
+ d.id === data.dealId
+ ? { ...d, items: (d.items ?? []).filter((i) => i.id !== data.itemId) }
+ : d
+ );
+ });
+ },
+ onSettled: (_data, _error, { dealId }) => {
+ // Mesmo motivo de useAddDealItem: lists() cascateia em DEALS_VIEW_KEY.
+ queryClient.invalidateQueries({ queryKey: queryKeys.deals.detail(dealId) });
+ },📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| onSettled: (_data, _error, { dealId }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| queryClient.invalidateQueries({ queryKey: queryKeys.deals.detail(dealId) }); | ||||||||||||||||||||||||||||||||||||||||||||||
| queryClient.invalidateQueries({ queryKey: queryKeys.deals.lists() }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
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.
onSettledinvalidation cascades toDEALS_VIEW_KEY, undoing this optimization; also missing<DealView[]>generic.Two concerns with the new direct cache update:
The unchanged
onSettledat line 530 callsqueryClient.invalidateQueries({ queryKey: queryKeys.deals.lists() }). BecauseDEALS_VIEW_KEY = [...queryKeys.deals.lists(), 'view'], TanStack's prefix matching will invalidateDEALS_VIEW_KEYas well, triggering an immediate refetch right after thissetQueryData. That largely defeats the "optimize deal item cache updates" intent, and it diverges from the pattern used everywhere else in this file (e.g.useUpdateDeal,useDeleteDeal) where the explicit comment is "NÃO fazer invalidateQueries para deals - Realtime gerencia a sincronização".setQueryDatais called without the<DealView[]>generic, sooldis inferred asunknownandold.map(...)is not type-safe under strict mode. Every other call site in this file passes the generic explicitly (e.g. lines 272, 299, 363, 487).Based on learnings: "For Deals entity mutations, always use
[...queryKeys.deals.lists(), 'view']cache key pattern" and "PrefersetQueryDataoverinvalidateQueriesfor instant UI updates".♻️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents