From 5fb4313742e2e308afd0d55aacf63ffb1d713faa Mon Sep 17 00:00:00 2001 From: Chet Joswig Date: Fri, 27 Oct 2023 16:32:33 -0700 Subject: [PATCH] use displayed arguments --- .../activity/ActivityDirectiveForm.svelte | 21 +++++++++---- src/utilities/effects.ts | 30 +------------------ 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/components/activity/ActivityDirectiveForm.svelte b/src/components/activity/ActivityDirectiveForm.svelte index 44662bbc9f..8839a837aa 100644 --- a/src/components/activity/ActivityDirectiveForm.svelte +++ b/src/components/activity/ActivityDirectiveForm.svelte @@ -21,7 +21,7 @@ import type { ActivityMetadataDefinition } from '../../types/activity-metadata'; import type { User } from '../../types/app'; import type { FieldStore } from '../../types/form'; - import type { ArgumentsMap, FormParameter } from '../../types/parameter'; + import type { Argument, ArgumentsMap, FormParameter, ParameterName } from '../../types/parameter'; import type { ActivityDirectiveTagsInsertInput, Tag, TagsChangeEvent } from '../../types/tags'; import { getActivityMetadata } from '../../utilities/activities'; import effects from '../../utilities/effects'; @@ -144,6 +144,16 @@ editingActivityName = true; } + function getDisplayedArguments(): ArgumentsMap { + return formParameters.reduce( + (args: ArgumentsMap, { name, value }: { name: ParameterName; value: Argument }) => ({ + ...args, + [name]: value, + }), + {}, + ); + } + function updateAnchor({ detail: anchorId }: CustomEvent) { const { id } = activityDirective; if ($plan) { @@ -224,7 +234,7 @@ detail: { name }, } = event; const createdActivityPreset = await effects.createActivityPreset( - activityDirective.arguments, + getDisplayedArguments(), activityDirective.type, name, modelId, @@ -236,14 +246,15 @@ } async function onSavePreset(event: CustomEvent) { - const { detail } = event; - const { name } = detail; + const { + detail: { name }, + } = event; if (activityDirective.applied_preset) { await effects.updateActivityPreset( activityDirective.applied_preset.preset_id, { ...activityDirective.applied_preset.preset_applied, - arguments: activityDirective.arguments, + arguments: getDisplayedArguments(), model_id: modelId, name, }, diff --git a/src/utilities/effects.ts b/src/utilities/effects.ts index 283ce43789..1fba8d0aca 100644 --- a/src/utilities/effects.ts +++ b/src/utilities/effects.ts @@ -410,19 +410,8 @@ const effects = { throwPermissionError('create an activity preset'); } - const effectiveArgs = await this.getEffectiveActivityArguments( - modelId, - associatedActivityType, - argumentsMap, - user, - ); - - if (!effectiveArgs?.arguments) { - throw Error('Unable to get arguments for preset'); - } - const activityPresetInsertInput: ActivityPresetInsertInput = { - arguments: effectiveArgs.arguments, + arguments: argumentsMap, associated_activity_type: associatedActivityType, model_id: modelId, name, @@ -3726,29 +3715,12 @@ const effects = { if (!queryPermissions.UPDATE_ACTIVITY_PRESET(user, updatedActivityPreset)) { throwPermissionError('update this activity preset'); } - if ( - updatedActivityPreset.model_id === undefined || - updatedActivityPreset.associated_activity_type === undefined || - updatedActivityPreset.arguments === undefined - ) { - throw Error('Unable to get arguments for preset'); - } - const effectiveArgs = await this.getEffectiveActivityArguments( - updatedActivityPreset.model_id, - updatedActivityPreset.associated_activity_type, - updatedActivityPreset.arguments, - user, - ); - if (!effectiveArgs?.arguments) { - throw Error('Unable to get arguments for preset'); - } const { update_activity_presets_by_pk } = await reqHasura( gql.UPDATE_ACTIVITY_PRESET, { activityPresetSetInput: { ...updatedActivityPreset, - arguments: effectiveArgs.arguments, id: undefined, }, id,