Skip to content

Commit

Permalink
use ref for layoutsets to ensure updated layoutsets is passed to onPr…
Browse files Browse the repository at this point in the history
…ocessTaskRemove
  • Loading branch information
standeren committed Dec 27, 2024
1 parent 7738e18 commit 20aa461
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useAppPolicyQuery } from '../../hooks/queries';
import type { OnProcessTaskEvent } from '@altinn/process-editor/types/OnProcessTask';
import { OnProcessTaskAddHandler } from './handlers/OnProcessTaskAddHandler';
import { OnProcessTaskRemoveHandler } from './handlers/OnProcessTaskRemoveHandler';
import type { LayoutSets } from 'app-shared/types/api/LayoutSetsResponse';

export const ProcessEditor = (): React.ReactElement => {
const { t } = useTranslation();
Expand Down Expand Up @@ -60,6 +61,11 @@ export const ProcessEditor = (): React.ReactElement => {
false,
);
const { data: layoutSets } = useLayoutSetsQuery(org, app);
const layoutSetsRef = React.useRef<LayoutSets>(layoutSets);

React.useEffect(() => {
layoutSetsRef.current = layoutSets;
}, [layoutSets]);

const pendingApiOperations: boolean =
mutateBpmnPending ||
Expand Down Expand Up @@ -104,7 +110,7 @@ export const ProcessEditor = (): React.ReactElement => {
org,
app,
currentPolicy,
layoutSets,
layoutSetsRef.current,
mutateApplicationPolicy,
deleteDataTypeFromAppMetadata,
deleteLayoutSet,
Expand All @@ -121,7 +127,7 @@ export const ProcessEditor = (): React.ReactElement => {
availableDataTypeIds={appMetadata?.dataTypes?.map((dataType) => dataType.id)}
availableDataModelIds={availableDataModelIds}
allDataModelIds={allDataModelIds}
layoutSets={layoutSets}
layoutSets={layoutSetsRef.current}
pendingApiOperations={pendingApiOperations}
existingCustomReceiptLayoutSetId={existingCustomReceiptId}
addLayoutSet={addLayoutSet}
Expand Down

0 comments on commit 20aa461

Please sign in to comment.