diff --git a/src/components/plan/PlanForm.svelte b/src/components/plan/PlanForm.svelte index af576be102..b5e39fa4e3 100644 --- a/src/components/plan/PlanForm.svelte +++ b/src/components/plan/PlanForm.svelte @@ -14,8 +14,10 @@ import { viewTogglePanel } from '../../stores/views'; import type { ActivityDirective, ActivityDirectiveId } from '../../types/activity'; import type { User, UserId } from '../../types/app'; + import type { ArgumentsMap } from '../../types/parameter'; import type { Plan, PlanCollaborator, PlanSlimmer, PlanTransfer } from '../../types/plan'; import type { PlanSnapshot as PlanSnapshotType } from '../../types/plan-snapshot'; + import type { Simulation } from '../../types/simulation'; import type { PlanTagsInsertInput, Tag, TagsChangeEvent } from '../../types/tags'; import effects from '../../utilities/effects'; import { removeQueryParam, setQueryParam } from '../../utilities/generic'; @@ -166,35 +168,54 @@ let totalProgress = 0; const numOfDirectives = Object.values(activityDirectivesMap).length; - qualifiedActivityDirectives = await Promise.all( - Object.values(activityDirectivesMap).map(async activityDirective => { - if (plan) { - const effectiveArguments = await effects.getEffectiveActivityArguments( - plan?.model_id, - activityDirective.type, - activityDirective.arguments, - user, - planExportAbortController?.signal, - ); + const simulation: Simulation | null = await effects.getPlanLatestSimulation(plan.id, user); - totalProgress++; - planExportProgress = (totalProgress / numOfDirectives) * 100; - - return { - ...activityDirective, - arguments: effectiveArguments?.arguments ?? activityDirective.arguments, - }; + const simulationArguments: ArgumentsMap = simulation + ? { + ...simulation.template?.arguments, + ...simulation.arguments, } + : {}; + + qualifiedActivityDirectives = ( + await Promise.all( + Object.values(activityDirectivesMap).map(async activityDirective => { + if (plan) { + const effectiveArguments = await effects.getEffectiveActivityArguments( + plan?.model_id, + activityDirective.type, + activityDirective.arguments, + user, + planExportAbortController?.signal, + ); + + totalProgress++; + planExportProgress = (totalProgress / numOfDirectives) * 100; + + return { + ...activityDirective, + arguments: effectiveArguments?.arguments ?? activityDirective.arguments, + }; + } - totalProgress++; - planExportProgress = (totalProgress / numOfDirectives) * 100; + totalProgress++; + planExportProgress = (totalProgress / numOfDirectives) * 100; - return activityDirective; - }), - ); + return activityDirective; + }), + ) + ).sort((directiveA, directiveB) => { + if (directiveA.id < directiveB.id) { + return -1; + } + if (directiveA.id > directiveB.id) { + return 1; + } + return 0; + }); if (planExportAbortController && !planExportAbortController.signal.aborted) { - const planExport: PlanTransfer = getPlanForTransfer(plan, qualifiedActivityDirectives); + const planExport: PlanTransfer = getPlanForTransfer(plan, qualifiedActivityDirectives, simulationArguments); const a = document.createElement('a'); a.href = URL.createObjectURL(new Blob([JSON.stringify(planExport, null, 2)], { type: 'application/json' })); @@ -226,7 +247,6 @@