From ff239c9f7391a293f72bce1ab75be314a86fba24 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Wed, 5 Feb 2025 13:23:17 +0300 Subject: [PATCH] B: Fix cstUpdate --- .../src/backend/rsform/useCstUpdate.tsx | 15 ++--------- .../EditorConstituenta/EditorConstituenta.tsx | 2 +- .../ViewConstituents/ConstituentsSearch.tsx | 25 ++++++------------- .../ViewConstituents/ViewConstituents.tsx | 2 +- 4 files changed, 12 insertions(+), 32 deletions(-) diff --git a/rsconcept/frontend/src/backend/rsform/useCstUpdate.tsx b/rsconcept/frontend/src/backend/rsform/useCstUpdate.tsx index 4de86d32..5bab1566 100644 --- a/rsconcept/frontend/src/backend/rsform/useCstUpdate.tsx +++ b/rsconcept/frontend/src/backend/rsform/useCstUpdate.tsx @@ -12,23 +12,12 @@ export const useCstUpdate = () => { const mutation = useMutation({ mutationKey: [rsformsApi.baseKey, 'update-cst'], mutationFn: rsformsApi.cstUpdate, - onSuccess: (newCst, variables) => { - client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: variables.itemID }).queryKey, prev => - !prev - ? undefined - : { - ...prev, - items: prev.items.map(item => (item.id === newCst.id ? { ...item, ...newCst } : item)) - } - ); + onSuccess: (_, variables) => { updateTimestamp(variables.itemID); return Promise.allSettled([ client.invalidateQueries({ queryKey: [ossApi.baseKey] }), - client.invalidateQueries({ - queryKey: [rsformsApi.baseKey], - predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== variables.itemID - }) + client.invalidateQueries({ queryKey: [rsformsApi.baseKey] }) ]); } }); diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/EditorConstituenta.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/EditorConstituenta.tsx index c091b1f3..251dba82 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/EditorConstituenta.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/EditorConstituenta.tsx @@ -115,8 +115,8 @@ function EditorConstituenta() { onKeyDown={handleInput} > diff --git a/rsconcept/frontend/src/pages/RSFormPage/ViewConstituents/ConstituentsSearch.tsx b/rsconcept/frontend/src/pages/RSFormPage/ViewConstituents/ConstituentsSearch.tsx index c634b78c..0882254f 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/ViewConstituents/ConstituentsSearch.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/ViewConstituents/ConstituentsSearch.tsx @@ -17,10 +17,11 @@ interface ConstituentsSearchProps { dense?: boolean; activeID?: ConstituentaID; activeExpression: string; - setFiltered: React.Dispatch>; + + onChange: React.Dispatch>; } -function ConstituentsSearch({ schema, activeID, activeExpression, dense, setFiltered }: ConstituentsSearchProps) { +function ConstituentsSearch({ schema, activeID, activeExpression, dense, onChange }: ConstituentsSearchProps) { const query = useCstSearchStore(state => state.query); const filterMatch = useCstSearchStore(state => state.match); const filterSource = useCstSearchStore(state => state.source); @@ -32,7 +33,7 @@ function ConstituentsSearch({ schema, activeID, activeExpression, dense, setFilt useEffect(() => { if (schema.items.length === 0) { - setFiltered([]); + onChange([]); return; } let result: IConstituenta[] = []; @@ -47,18 +48,8 @@ function ConstituentsSearch({ schema, activeID, activeExpression, dense, setFilt if (!includeInherited) { result = result.filter(cst => !cst.is_inherited); } - setFiltered(result); - }, [ - query, - setFiltered, - filterSource, - activeExpression, - schema.items, - schema, - filterMatch, - activeID, - includeInherited - ]); + onChange(result); + }, [query, onChange, filterSource, activeExpression, schema.items, schema, filterMatch, activeID, includeInherited]); return (
@@ -69,8 +60,8 @@ function ConstituentsSearch({ schema, activeID, activeExpression, dense, setFilt query={query} onChangeQuery={setQuery} /> - setMatch(newValue)} dense={dense} /> - setSource(newValue)} dense={dense} /> + + {schema.stats.count_inherited > 0 ? (