From 0ec27f2a2ae7c599a46935ffd94e365e340e2b33 Mon Sep 17 00:00:00 2001 From: Jeff Pamer Date: Thu, 31 Aug 2023 10:37:19 -0700 Subject: [PATCH 01/27] Rough first pass at fetching changelog and displaying results per activity --- .../ActivityDirectiveChangelog.svelte | 112 ++++++++++++++++++ .../activity/ActivityFormPanel.svelte | 16 ++- src/types/activity.ts | 8 ++ src/utilities/effects.ts | 24 ++++ src/utilities/gql.ts | 19 +++ 5 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 src/components/activity/ActivityDirectiveChangelog.svelte diff --git a/src/components/activity/ActivityDirectiveChangelog.svelte b/src/components/activity/ActivityDirectiveChangelog.svelte new file mode 100644 index 0000000000..5262ef5c5c --- /dev/null +++ b/src/components/activity/ActivityDirectiveChangelog.svelte @@ -0,0 +1,112 @@ + + + + +
+ {#each activityRevisions as revision} +
+
{formatDate(revision.changed_at)}
+
Change Summary
+
{revision.changed_by}
+
New Value
+
+
Previous Value
+
+ {/each} +
+ + diff --git a/src/components/activity/ActivityFormPanel.svelte b/src/components/activity/ActivityFormPanel.svelte index f0f06de12c..0e568c1b24 100644 --- a/src/components/activity/ActivityFormPanel.svelte +++ b/src/components/activity/ActivityFormPanel.svelte @@ -32,6 +32,7 @@ import GridMenu from '../menus/GridMenu.svelte'; import Panel from '../ui/Panel.svelte'; import PanelHeaderActions from '../ui/PanelHeaderActions.svelte'; + import ActivityDirectiveChangelog from './ActivityDirectiveChangelog.svelte'; import ActivityDirectiveForm from './ActivityDirectiveForm.svelte'; import ActivitySpanForm from './ActivitySpanForm.svelte'; @@ -39,6 +40,7 @@ export let user: User | null; let hasDeletePermission: boolean = false; + let viewingActivityDirectiveChangelog: boolean = false; $: deletePermissionError = $planReadOnly ? PlanStatusMessages.READ_ONLY @@ -91,12 +93,24 @@ > + + {/if} - {#if $selectedActivityDirective && $plan !== null} + {#if $selectedActivityDirective && $plan !== null && viewingActivityDirectiveChangelog} + + {:else if $selectedActivityDirective && $plan !== null} ; +export type ActivityDirectiveRevision = + | Partial + | { + changed_at: string; + changed_by: string; + revision: number; + }; + export type AppliedPreset = { activity_id: ActivityDirectiveId; plan_id: number; diff --git a/src/utilities/effects.ts b/src/utilities/effects.ts index f1f7abadfa..f0b52e2221 100644 --- a/src/utilities/effects.ts +++ b/src/utilities/effects.ts @@ -23,6 +23,7 @@ import type { ActivityDirective, ActivityDirectiveId, ActivityDirectiveInsertInput, + ActivityDirectiveRevision, ActivityDirectiveSetInput, ActivityDirectivesMap, ActivityPreset, @@ -2228,6 +2229,29 @@ const effects = { } }, + async getActivityDirectiveChangelog( + planId: number, + activityId: number, + user: User | null, + ): Promise { + try { + const data = await reqHasura( + gql.GET_ACTIVITY_DIRECTIVE_CHANGELOG, + { activityId, planId }, + user, + ); + const { activityDirectiveRevisions } = data; + if (activityDirectiveRevisions != null) { + return activityDirectiveRevisions; + } else { + throw Error('Unable to retrieve activity directive changelog'); + } + } catch (e) { + catchError(e as Error); + return []; + } + }, + async getActivityTypes(modelId: number, user: User | null): Promise { try { const query = convertToQuery(gql.SUB_ACTIVITY_TYPES); diff --git a/src/utilities/gql.ts b/src/utilities/gql.ts index cc51bfdc77..2e16cb49da 100644 --- a/src/utilities/gql.ts +++ b/src/utilities/gql.ts @@ -620,6 +620,25 @@ const gql = { } `, + GET_ACTIVITY_DIRECTIVE_CHANGELOG: `#graphql + query GetActivityTypesExpansionRules($activityId: Int!, $planId: Int!) { + activityDirectiveRevisions: activity_directive_changelog( + where: { plan_id: { _eq: $planId }, _and: { activity_directive_id: { _eq: $activityId }}}, + order_by: { revision: desc } + ) { + revision + changed_by + changed_at + anchor_id + anchored_to_start + arguments + metadata + name + start_offset + } + } + `, + GET_ACTIVITY_TYPES_EXPANSION_RULES: `#graphql query GetActivityTypesExpansionRules($modelId: Int!) { activity_types: activity_type(where: { model_id: { _eq: $modelId } }) { From aae33764c65e79540b85820b5a962036e2d2a036 Mon Sep 17 00:00:00 2001 From: Jeff Pamer Date: Thu, 21 Sep 2023 16:31:52 -0700 Subject: [PATCH 02/27] Basic working UI for change log, no restore or preview --- .../ActivityDirectiveChangelog.svelte | 123 +++++++++++++----- .../activity/ActivityFormPanel.svelte | 7 +- src/types/activity.ts | 18 ++- 3 files changed, 106 insertions(+), 42 deletions(-) diff --git a/src/components/activity/ActivityDirectiveChangelog.svelte b/src/components/activity/ActivityDirectiveChangelog.svelte index 5262ef5c5c..065547f3f8 100644 --- a/src/components/activity/ActivityDirectiveChangelog.svelte +++ b/src/components/activity/ActivityDirectiveChangelog.svelte @@ -2,64 +2,116 @@
- {#each activityRevisions as revision} -
-
{formatDate(revision.changed_at)}
-
Change Summary
-
{revision.changed_by}
-
New Value
-
-
Previous Value
-
- {/each} + {#if activityRevisionChangeMap.length} + {#each activityRevisions as revision, i} +
+
{formatDate(revision.changed_at)}
+
+ {activityRevisionChangeMap[i].name} +
+
{revision.changed_by}
+
+ {activityRevisionChangeMap[i].currentValue} +
+
+ {#if i == 0} + Current Revision + {:else} + + {/if} +
+
+ {activityRevisionChangeMap[i].previousValue} +
+
+ {/each} + {/if}