Skip to content

Commit

Permalink
include all displayed argument values in preset (#969)
Browse files Browse the repository at this point in the history
* use displayed arguments
---------

Co-authored-by: Chet Joswig <[email protected]>
  • Loading branch information
joswig and Chet Joswig authored Oct 30, 2023
1 parent 5bfb333 commit 99bcdad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 17 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,16 @@
}
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,
},
user,
Expand Down
7 changes: 5 additions & 2 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ const effects = {
model_id: modelId,
name,
};

const data = await reqHasura<ActivityPreset>(gql.CREATE_ACTIVITY_PRESET, { activityPresetInsertInput }, user);

if (data.insert_activity_presets_one != null) {
Expand Down Expand Up @@ -3714,10 +3715,12 @@ const effects = {
if (!queryPermissions.UPDATE_ACTIVITY_PRESET(user, updatedActivityPreset)) {
throwPermissionError('update this activity preset');
}

const { id: _id, ...restOfPresetPayload } = updatedActivityPreset;
const { update_activity_presets_by_pk } = await reqHasura<ActivityPreset>(
gql.UPDATE_ACTIVITY_PRESET,
{ ...updatedActivityPreset, id },
{
activityPresetSetInput: restOfPresetPayload,
},
user,
);

Expand Down

0 comments on commit 99bcdad

Please sign in to comment.