Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DT-1740 - update workflow reset UI for new reapply types in 1.24 #2014

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import Checkbox from '$lib/holocene/checkbox.svelte';
import Input from '$lib/holocene/input/input.svelte';
import Modal from '$lib/holocene/modal.svelte';
import RadioGroup from '$lib/holocene/radio-input/radio-group.svelte';
import RadioInput from '$lib/holocene/radio-input/radio-input.svelte';
import Option from '$lib/holocene/select/option.svelte';
import Select from '$lib/holocene/select/select.svelte';
import { translate } from '$lib/i18n/translate';
import { ResetReapplyType } from '$lib/models/workflow-actions';
import { resetWorkflow } from '$lib/services/workflow-service';
import { resetEvents } from '$lib/stores/events';
import { resetWorkflows } from '$lib/stores/reset-workflows';
import { temporalVersion } from '$lib/stores/versions';
import type { WorkflowExecution } from '$lib/types/workflows';
import { isNetworkError } from '$lib/utilities/is-network-error';
import { minimumVersionRequired } from '$lib/utilities/version-check';

export let open: boolean;
export let workflow: WorkflowExecution;
Expand All @@ -21,25 +22,21 @@

let error = '';
let loading = false;
let reapplyType: ResetReapplyType;
let eventId: Writable<string> = writable('');
let reason: string;
let includeSignals = true;
let excludeSignals = false;
let excludeUpdates = false;

const hideResetModal = () => {
open = false;
reapplyType = ResetReapplyType.Signal;
includeSignals = true;
excludeSignals = false;
excludeUpdates = false;
$eventId = '';
reason = '';
};

const handleReapplyTypeChange = (
event: CustomEvent<{ checked: boolean }>,
) => {
reapplyType = event.detail.checked
? ResetReapplyType.Signal
: ResetReapplyType.None;
};

const reset = async () => {
error = '';
loading = true;
Expand All @@ -49,7 +46,9 @@
workflow,
eventId: $eventId,
reason,
reapplyType,
includeSignals,
excludeSignals,
excludeUpdates,
});

if (response && response.runId) {
Expand Down Expand Up @@ -81,31 +80,39 @@
{loading}
on:confirmModal={reset}
on:cancelModal={hideResetModal}
confirmDisabled={!eventId}
confirmDisabled={!$eventId}
>
<h3 slot="title">{translate('workflows.reset-modal-title')}</h3>
<svelte:fragment slot="content">
<div class="flex w-full flex-col gap-4">
<RadioGroup
name="reset-event-id"
group={eventId}
class="max-h-40 overflow-auto"
description={translate('workflows.reset-event-radio-group-description')}
<Select
menuClass="max-h-[16rem]"
label={translate('workflows.reset-event-radio-group-description')}
bind:value={$eventId}
id="reset-event-id"
>
{#each $resetEvents as event}
<RadioInput
id="reset-event-{event.id}"
value={event.id}
label="{event.id} - {event.eventType}"
/>
<Option value={event.id}>{event.id} - {event.eventType}</Option>
{/each}
</RadioGroup>
<Checkbox
id="reset-reapply-type-checkbox"
checked={reapplyType === ResetReapplyType.Signal}
on:change={handleReapplyTypeChange}
label={translate('workflows.reset-reapply-type-label')}
/>
</Select>
{#if minimumVersionRequired('1.24', $temporalVersion)}
<Checkbox
id="reset-exclude-signals-checkbox"
bind:checked={excludeSignals}
label={translate('workflows.reset-exclude-signals')}
/>
<Checkbox
id="reset-exclude-updates-checkbox"
bind:checked={excludeUpdates}
label={translate('workflows.reset-exclude-updates')}
/>
{:else}
<Checkbox
id="reset-include-signals-checkbox"
bind:checked={includeSignals}
label={translate('workflows.reset-reapply-type-label')}
/>
{/if}

<Input
id="reset-reason"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/holocene/menu/menu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<ul
in:fly={{ duration: 100 }}
role="menu"
class={merge('menu', position, className)}
class={merge('menu', 'max-h-[20rem]', position, className)}
class:hidden={!$open}
aria-labelledby={id}
tabindex={-1}
Expand All @@ -58,7 +58,7 @@

<style lang="postcss">
.menu {
@apply surface-primary absolute z-20 mt-1 max-h-[320px] min-w-full list-none overflow-auto rounded-lg border border-primary text-primary shadow;
@apply surface-primary absolute z-20 mt-1 min-w-full list-none overflow-auto rounded-lg border border-primary text-primary shadow;

&.left {
@apply left-0 origin-top-left;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/holocene/select/select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
unroundLeft?: boolean;
onChange?: (value: T) => void;
'data-testid'?: string;
menuClass?: string;
};

export let label: string;
Expand All @@ -56,6 +57,7 @@
export let unroundRight = false;
export let unroundLeft = false;
export let onChange: (value: T) => void = noop;
export let menuClass: string | undefined = undefined;

// We get the "true" value of this further down but before the mount happens we should have some kind of value
const valueCtx = writable<T>(value);
Expand Down Expand Up @@ -122,7 +124,7 @@
<Icon slot="trailing" name="lock" />
{/if}
</MenuButton>
<Menu role="listbox" id="{id}-select">
<Menu class={menuClass} role="listbox" id="{id}-select">
<slot />
</Menu>
</MenuContainer>
Expand Down
2 changes: 2 additions & 0 deletions src/lib/i18n/locales/en/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export const Strings = {
'reset-event-radio-group-description': 'Choose an Event to reset to',
'reset-reapply-type-label':
'Reapply Signals that happened after the Reset point',
'reset-exclude-signals': 'Exclude signals that occur after the reset point.',
'reset-exclude-updates': 'Exclude updates that occur after the reset point.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's capitalize Signals and Updates here

'cancel-modal-title': 'Cancel Workflow',
'cancel-modal-confirmation':
'Are you sure you want to cancel this workflow? This action cannot be undone.',
Expand Down
6 changes: 0 additions & 6 deletions src/lib/models/workflow-actions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export enum ResetReapplyType {
Unspecified = 0,
Signal = 1,
None = 2,
}

export enum Action {
Cancel,
Reset,
Expand Down
58 changes: 51 additions & 7 deletions src/lib/services/workflow-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import { v4 } from 'uuid';

import { page } from '$app/stores';

import { Action, type ResetReapplyType } from '$lib/models/workflow-actions';
import { Action } from '$lib/models/workflow-actions';
import {
toWorkflowExecution,
toWorkflowExecutions,
} from '$lib/models/workflow-execution';
import { authUser } from '$lib/stores/auth-user';
import type { ResetWorkflowRequest } from '$lib/types';
import { temporalVersion } from '$lib/stores/versions';
import {
ResetReapplyExcludeType,
ResetReapplyType,
type ResetWorkflowRequest,
} from '$lib/types';
import type {
ValidWorkflowEndpoints,
ValidWorkflowParameters,
Expand All @@ -36,7 +41,10 @@ import { toListWorkflowQuery } from '$lib/utilities/query/list-workflow-query';
import type { ErrorCallback } from '$lib/utilities/request-from-api';
import { requestFromAPI } from '$lib/utilities/request-from-api';
import { base, pathForApi, routeForApi } from '$lib/utilities/route-for-api';
import { isVersionNewer } from '$lib/utilities/version-check';
import {
isVersionNewer,
minimumVersionRequired,
} from '$lib/utilities/version-check';
import { formatReason } from '$lib/utilities/workflow-actions';

export type GetWorkflowExecutionRequest = NamespaceScopedRequest & {
Expand Down Expand Up @@ -73,7 +81,11 @@ export type ResetWorkflowOptions = {
workflow: WorkflowExecution;
eventId: string;
reason: string;
reapplyType: ResetReapplyType;
// used pre temporal server v1.24
includeSignals: boolean;
// used post temporal server v1.24
excludeSignals: boolean;
excludeUpdates: boolean;
};

export type FetchWorkflow =
Expand Down Expand Up @@ -326,7 +338,9 @@ export async function resetWorkflow({
workflow: { id: workflowId, runId },
eventId,
reason,
reapplyType,
includeSignals,
excludeSignals,
excludeUpdates,
}: ResetWorkflowOptions): Promise<{ runId: string }> {
const route = routeForApi('workflow.reset', {
namespace,
Expand All @@ -342,18 +356,48 @@ export async function resetWorkflow({

const body: Replace<
ResetWorkflowRequest,
{ workflowTaskFinishEventId: string; resetReapplyType: ResetReapplyType }
{ workflowTaskFinishEventId: string }
> = {
workflowExecution: {
workflowId,
runId,
},
workflowTaskFinishEventId: eventId,
resetReapplyType: reapplyType,
requestId: v4(),
reason: formattedReason,
};

if (minimumVersionRequired('1.24', get(temporalVersion))) {
const resetReapplyExcludeTypes: ResetWorkflowRequest['resetReapplyExcludeTypes'] =
[];

if (excludeSignals) {
resetReapplyExcludeTypes.push(
ResetReapplyExcludeType.RESET_REAPPLY_EXCLUDE_TYPE_SIGNAL,
);
}

if (excludeUpdates) {
resetReapplyExcludeTypes.push(
ResetReapplyExcludeType.RESET_REAPPLY_EXCLUDE_TYPE_UPDATE,
);
}

if (resetReapplyExcludeTypes.length) {
body.resetReapplyExcludeTypes = resetReapplyExcludeTypes;
}
} else {
let resetReapplyType: ResetWorkflowRequest['resetReapplyType'];

if (includeSignals) {
resetReapplyType = ResetReapplyType.RESET_REAPPLY_TYPE_SIGNAL;
} else {
resetReapplyType = ResetReapplyType.RESET_REAPPLY_TYPE_NONE;
}

body.resetReapplyType = resetReapplyType;
}

return requestFromAPI<{ runId: string }>(route, {
notifyOnError: false,
options: {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { google, temporal } from '@temporalio/proto';
import { type google, temporal } from '@temporalio/proto';

// api.workflowservice

Expand Down Expand Up @@ -137,6 +137,9 @@ export type Severity = temporal.api.enums.v1.Severity;
export type ArchivalState = temporal.api.enums.v1.ArchivalState;
export type NamespaceState = temporal.api.enums.v1.NamespaceState;
export type TaskReachability = temporal.api.enums.v1.TaskReachability;
export const ResetReapplyExcludeType =
temporal.api.enums.v1.ResetReapplyExcludeType;
export const ResetReapplyType = temporal.api.enums.v1.ResetReapplyType;

// api.workflow

Expand Down