Skip to content

Commit

Permalink
use displayed arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Chet Joswig authored and Chet Joswig committed Oct 27, 2023
1 parent 7696970 commit 5fb4313
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 34 deletions.
21 changes: 16 additions & 5 deletions src/components/activity/ActivityDirectiveForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<ActivityDirectiveId>) {
const { id } = activityDirective;
if ($plan) {
Expand Down Expand Up @@ -224,7 +234,7 @@
detail: { name },
} = event;
const createdActivityPreset = await effects.createActivityPreset(
activityDirective.arguments,
getDisplayedArguments(),
activityDirective.type,
name,
modelId,
Expand All @@ -236,14 +246,15 @@
}
async function onSavePreset(event: CustomEvent<ActivityPresetInsertInput>) {
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,
},
Expand Down
30 changes: 1 addition & 29 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ActivityPreset>(
gql.UPDATE_ACTIVITY_PRESET,
{
activityPresetSetInput: {
...updatedActivityPreset,
arguments: effectiveArgs.arguments,
id: undefined,
},
id,
Expand Down

0 comments on commit 5fb4313

Please sign in to comment.