mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
B: Fix cstUpdate
This commit is contained in:
parent
86f90149ee
commit
cc6e592149
|
@ -12,23 +12,12 @@ export const useCstUpdate = () => {
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
mutationKey: [rsformsApi.baseKey, 'update-cst'],
|
mutationKey: [rsformsApi.baseKey, 'update-cst'],
|
||||||
mutationFn: rsformsApi.cstUpdate,
|
mutationFn: rsformsApi.cstUpdate,
|
||||||
onSuccess: (newCst, variables) => {
|
onSuccess: (_, 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))
|
|
||||||
}
|
|
||||||
);
|
|
||||||
updateTimestamp(variables.itemID);
|
updateTimestamp(variables.itemID);
|
||||||
|
|
||||||
return Promise.allSettled([
|
return Promise.allSettled([
|
||||||
client.invalidateQueries({ queryKey: [ossApi.baseKey] }),
|
client.invalidateQueries({ queryKey: [ossApi.baseKey] }),
|
||||||
client.invalidateQueries({
|
client.invalidateQueries({ queryKey: [rsformsApi.baseKey] })
|
||||||
queryKey: [rsformsApi.baseKey],
|
|
||||||
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== variables.itemID
|
|
||||||
})
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -115,8 +115,8 @@ function EditorConstituenta() {
|
||||||
onKeyDown={handleInput}
|
onKeyDown={handleInput}
|
||||||
>
|
>
|
||||||
<FormConstituenta
|
<FormConstituenta
|
||||||
disabled={disabled}
|
|
||||||
id={globals.constituenta_editor}
|
id={globals.constituenta_editor}
|
||||||
|
disabled={disabled}
|
||||||
toggleReset={toggleReset}
|
toggleReset={toggleReset}
|
||||||
onEditTerm={handleEditTermForms}
|
onEditTerm={handleEditTermForms}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -17,10 +17,11 @@ interface ConstituentsSearchProps {
|
||||||
dense?: boolean;
|
dense?: boolean;
|
||||||
activeID?: ConstituentaID;
|
activeID?: ConstituentaID;
|
||||||
activeExpression: string;
|
activeExpression: string;
|
||||||
setFiltered: React.Dispatch<React.SetStateAction<IConstituenta[]>>;
|
|
||||||
|
onChange: React.Dispatch<React.SetStateAction<IConstituenta[]>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ConstituentsSearch({ schema, activeID, activeExpression, dense, setFiltered }: ConstituentsSearchProps) {
|
function ConstituentsSearch({ schema, activeID, activeExpression, dense, onChange }: ConstituentsSearchProps) {
|
||||||
const query = useCstSearchStore(state => state.query);
|
const query = useCstSearchStore(state => state.query);
|
||||||
const filterMatch = useCstSearchStore(state => state.match);
|
const filterMatch = useCstSearchStore(state => state.match);
|
||||||
const filterSource = useCstSearchStore(state => state.source);
|
const filterSource = useCstSearchStore(state => state.source);
|
||||||
|
@ -32,7 +33,7 @@ function ConstituentsSearch({ schema, activeID, activeExpression, dense, setFilt
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (schema.items.length === 0) {
|
if (schema.items.length === 0) {
|
||||||
setFiltered([]);
|
onChange([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let result: IConstituenta[] = [];
|
let result: IConstituenta[] = [];
|
||||||
|
@ -47,18 +48,8 @@ function ConstituentsSearch({ schema, activeID, activeExpression, dense, setFilt
|
||||||
if (!includeInherited) {
|
if (!includeInherited) {
|
||||||
result = result.filter(cst => !cst.is_inherited);
|
result = result.filter(cst => !cst.is_inherited);
|
||||||
}
|
}
|
||||||
setFiltered(result);
|
onChange(result);
|
||||||
}, [
|
}, [query, onChange, filterSource, activeExpression, schema.items, schema, filterMatch, activeID, includeInherited]);
|
||||||
query,
|
|
||||||
setFiltered,
|
|
||||||
filterSource,
|
|
||||||
activeExpression,
|
|
||||||
schema.items,
|
|
||||||
schema,
|
|
||||||
filterMatch,
|
|
||||||
activeID,
|
|
||||||
includeInherited
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex border-b clr-input rounded-t-md'>
|
<div className='flex border-b clr-input rounded-t-md'>
|
||||||
|
@ -69,8 +60,8 @@ function ConstituentsSearch({ schema, activeID, activeExpression, dense, setFilt
|
||||||
query={query}
|
query={query}
|
||||||
onChangeQuery={setQuery}
|
onChangeQuery={setQuery}
|
||||||
/>
|
/>
|
||||||
<SelectMatchMode value={filterMatch} onChange={newValue => setMatch(newValue)} dense={dense} />
|
<SelectMatchMode value={filterMatch} onChange={setMatch} dense={dense} />
|
||||||
<SelectGraphFilter value={filterSource} onChange={newValue => setSource(newValue)} dense={dense} />
|
<SelectGraphFilter value={filterSource} onChange={setSource} dense={dense} />
|
||||||
{schema.stats.count_inherited > 0 ? (
|
{schema.stats.count_inherited > 0 ? (
|
||||||
<MiniButton
|
<MiniButton
|
||||||
noHover
|
noHover
|
||||||
|
|
|
@ -53,7 +53,7 @@ function ViewConstituents({ expression, isBottom, isMounted }: ViewConstituentsP
|
||||||
schema={schema}
|
schema={schema}
|
||||||
activeID={activeCst?.id}
|
activeID={activeCst?.id}
|
||||||
activeExpression={expression}
|
activeExpression={expression}
|
||||||
setFiltered={setFilteredData}
|
onChange={setFilteredData}
|
||||||
/>
|
/>
|
||||||
<TableSideConstituents
|
<TableSideConstituents
|
||||||
maxHeight={listHeight}
|
maxHeight={listHeight}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user