Repository: temporalio/ui
Pull request #393 (2022-03-30 23:29:44)

Correct workflow syntax with API path
<!--- Note to EXTERNAL Contributors -->
<!-- Thanks for opening a PR! 
If it is a significant code change, please **make sure there is an open issue** for this. 
We work best with you when we have accepted the idea first before you code. -->

<!--- For ALL Contributors 👇 -->

## What was changed
<!-- Describe what has changed in this PR -->

Corrected workflow related syntax and API

related: https://github.com/temporalio/ui-server/pull/124

## Why?
<!-- Tell your future self why have you made these changes -->

wrong syntax could confuse

## Checklist
<!--- add/delete as needed --->

1. Closes <!-- add issue number here -->

2. How was this tested:
<!--- Please describe how you tested your changes/how we can test them -->

3. Any docs updates needed?
<!--- update README if applicable
      or point out where to update docs.temporal.io -->


cloudflare-pages[bot]: ## Deploying with &nbsp;<a href="https://pages.dev"><img alt="Cloudflare Pages" src="https://user-images.githubusercontent.com/23264/106598434-9e719e00-654f-11eb-9e59-6167043cfa01.png" width="16"></a> &nbsp;Cloudflare Pages

<table><tr><td><strong>Latest commit:</strong> </td><td>
<code>b68a30e</code>
</td></tr>
<tr><td><strong>Status:</strong></td><td>&nbsp;✅&nbsp; Deploy successful!</td></tr>
<tr><td><strong>Preview URL:</strong></td><td>
<a href='https://03ccdfde.ui-c3x.pages.dev'>https://03ccdfde.ui-c3x.pages.dev</a>
</td></tr>
</table>

[View logs](https://dash.cloudflare.com/?to=/:account/pages/view/temporal-pizza/03ccdfde-be6a-4899-ba0d-6afbfd3681dc)


Patch:
diff --git a/src/api.d.ts b/src/api.d.ts
index b393c2e0..ef5c54f8 100644
--- a/src/api.d.ts
+++ b/src/api.d.ts
@@ -18,7 +18,7 @@ type APIRoutePath =
 
 type APIRouteParameters = {
   namespace: string;
-  executionId: string;
+  workflowId: string;
   runId: string;
   queue: string;
 };
@@ -27,7 +27,7 @@ type WorkflowListRouteParameters = Pick<APIRouteParameters, 'namespace'>;
 
 type WorkflowRouteParameters = Pick<
   APIRouteParameters,
-  'namespace' | 'executionId' | 'runId'
+  'namespace' | 'workflowId' | 'runId'
 >;
 type TaskQueueRouteParameters = Pick<APIRouteParameters, 'namespace' | 'queue'>;
 
diff --git a/src/lib/components/export-history.svelte b/src/lib/components/export-history.svelte
index e068d9fe..1467dcf8 100644
--- a/src/lib/components/export-history.svelte
+++ b/src/lib/components/export-history.svelte
@@ -5,12 +5,12 @@
   import { fetchRawEvents } from '$lib/services/events-service';
   import { faDownload } from '@fortawesome/free-solid-svg-icons';
 
-  const { workflow: executionId, run: runId, namespace } = $page.params;
+  const { workflow: workflowId, run: runId, namespace } = $page.params;
 
   const exportHistory = async () => {
     const events = await fetchRawEvents({
       namespace,
-      executionId,
+      workflowId,
       runId,
     });
 
diff --git a/src/lib/services/events-service.ts b/src/lib/services/events-service.ts
index a54b6894..3bef96fc 100644
--- a/src/lib/services/events-service.ts
+++ b/src/lib/services/events-service.ts
@@ -7,19 +7,19 @@ import { toEventHistory } from '$lib/models/event-history';
 
 type FetchEvents = NamespaceScopedRequest &
   PaginationCallbacks<GetWorkflowExecutionHistoryResponse> & {
-    executionId: string;
+    workflowId: string;
     runId: string;
     rawPayloads?: boolean;
   };
 
 export const fetchRawEvents = async (
-  { namespace, executionId, runId, onStart, onUpdate, onComplete }: FetchEvents,
+  { namespace, workflowId, runId, onStart, onUpdate, onComplete }: FetchEvents,
   request = fetch,
 ): Promise<HistoryEvent[]> => {
   const response = await paginated(
     async (token: string) => {
       return requestFromAPI<GetWorkflowExecutionHistoryResponse>(
-        routeForApi('events', { namespace, executionId, runId }),
+        routeForApi('events', { namespace, workflowId, runId }),
         {
           token,
           request,
diff --git a/src/lib/services/query-service.ts b/src/lib/services/query-service.ts
index 73e44d2c..803da7b0 100644
--- a/src/lib/services/query-service.ts
+++ b/src/lib/services/query-service.ts
@@ -40,7 +40,7 @@ const formatParameters = async (
   workflow = await workflow;
   return {
     namespace,
-    executionId: workflow.id,
+    workflowId: workflow.id,
     runId: workflow.runId,
   };
 };
diff --git a/src/lib/services/terminate-service.ts b/src/lib/services/terminate-service.ts
index 338bee88..ef9ec1ea 100644
--- a/src/lib/services/terminate-service.ts
+++ b/src/lib/services/terminate-service.ts
@@ -15,7 +15,7 @@ export async function terminateWorkflow({
   return await requestFromAPI<null>(
     routeForApi('workflow.terminate', {
       namespace,
-      executionId: workflow.id,
+      workflowId: workflow.id,
       runId: workflow.runId,
     }),
     {
diff --git a/src/lib/services/workflow-service.ts b/src/lib/services/workflow-service.ts
index 80708221..d2c4081e 100644
--- a/src/lib/services/workflow-service.ts
+++ b/src/lib/services/workflow-service.ts
@@ -11,7 +11,7 @@ import { routeForApi } from '$lib/utilities/route-for-api';
 import { toListWorkflowQuery } from '$lib/utilities/list-workflow-query';
 
 export type GetWorkflowExecutionRequest = NamespaceScopedRequest & {
-  executionId: string;
+  workflowId: string;
   runId: string;
 };
 
diff --git a/src/lib/utilities/route-for-api.ts b/src/lib/utilities/route-for-api.ts
index 20e6c28c..e2c98f89 100644
--- a/src/lib/utilities/route-for-api.ts
+++ b/src/lib/utilities/route-for-api.ts
@@ -38,10 +38,10 @@ export function routeForApi(
     'task-queue': `/namespaces/${parameters?.namespace}/task-queues/${parameters?.queue}`,
     workflows: `/namespaces/${parameters?.namespace}/workflows`,
     'workflows.archived': `/namespaces/${parameters?.namespace}/workflows/archived`,
-    workflow: `/namespaces/${parameters?.namespace}/workflows/${parameters?.executionId}/executions/${parameters?.runId}`,
-    'workflow.terminate': `/namespaces/${parameters?.namespace}/workflows/${parameters?.executionId}/executions/${parameters?.runId}/terminate`,
-    events: `/namespaces/${parameters?.namespace}/workflows/${parameters?.executionId}/executions/${parameters?.runId}/events`,
-    query: `/namespaces/${parameters?.namespace}/workflows/${parameters?.executionId}/executions/${parameters?.runId}/query`,
+    workflow: `/namespaces/${parameters?.namespace}/workflows/${parameters?.workflowId}/runs/${parameters?.runId}`,
+    'workflow.terminate': `/namespaces/${parameters?.namespace}/workflows/${parameters?.workflowId}/runs/${parameters?.runId}/terminate`,
+    events: `/namespaces/${parameters?.namespace}/workflows/${parameters?.workflowId}/runs/${parameters?.runId}/events`,
+    query: `/namespaces/${parameters?.namespace}/workflows/${parameters?.workflowId}/runs/${parameters?.runId}/query`,
   };
 
   return withBase(routes[route]);
diff --git a/src/routes/namespaces/[namespace]/workflows/[workflow]/[run]/__layout.svelte b/src/routes/namespaces/[namespace]/workflows/[workflow]/[run]/__layout.svelte
index 143b2bde..73bf7397 100644
--- a/src/routes/namespaces/[namespace]/workflows/[workflow]/[run]/__layout.svelte
+++ b/src/routes/namespaces/[namespace]/workflows/[workflow]/[run]/__layout.svelte
@@ -6,11 +6,11 @@
   import type { GetPollersResponse } from '$lib/services/pollers-service';
 
   export const load: Load = async function ({ params, fetch }) {
-    const { workflow: executionId, run: runId, namespace } = params;
+    const { workflow: workflowId, run: runId, namespace } = params;
 
     const parameters = {
       namespace,
-      executionId,
+      workflowId,
       runId,
     };
 
diff --git a/src/routes/namespaces/[namespace]/workflows/[workflow]/[run]/history/__layout.svelte b/src/routes/namespaces/[namespace]/workflows/[workflow]/[run]/history/__layout.svelte
index 26384711..ac4dc291 100644
--- a/src/routes/namespaces/[namespace]/workflows/[workflow]/[run]/history/__layout.svelte
+++ b/src/routes/namespaces/[namespace]/workflows/[workflow]/[run]/history/__layout.svelte
@@ -12,7 +12,7 @@
     const { namespace } = params;
     const parameters = {
       namespace,
-      executionId: workflow.id,
+      workflowId: workflow.id,
       runId: workflow.runId,
     };
 


Test patch:
diff --git a/src/lib/utilities/route-for-api.test.ts b/src/lib/utilities/route-for-api.test.ts
index 9b853170..0b28e7f8 100644
--- a/src/lib/utilities/route-for-api.test.ts
+++ b/src/lib/utilities/route-for-api.test.ts
@@ -2,7 +2,7 @@ import { routeForApi } from './route-for-api';
 
 const parameters = {
   namespace: 'namespace',
-  executionId: 'execution',
+  workflowId: 'workflow',
   runId: 'run',
   queue: 'queue',
 };
@@ -10,13 +10,13 @@ const parameters = {
 describe(routeForApi, () => {
   it('should return a route for workflow', () => {
     expect(routeForApi('workflow', parameters)).toBe(
-      'http://localhost:8080/api/v1/namespaces/namespace/workflows/execution/executions/run',
+      'http://localhost:8080/api/v1/namespaces/namespace/workflows/workflow/runs/run',
     );
   });
 
   it('should return a route for events', () => {
     expect(routeForApi('events', parameters)).toBe(
-      'http://localhost:8080/api/v1/namespaces/namespace/workflows/execution/executions/run/events',
+      'http://localhost:8080/api/v1/namespaces/namespace/workflows/workflow/runs/run/events',
     );
   });
 
@@ -42,7 +42,7 @@ describe(routeForApi, () => {
 
   it('should return a route for workflow.terminate', () => {
     expect(routeForApi('workflow.terminate', parameters)).toBe(
-      'http://localhost:8080/api/v1/namespaces/namespace/workflows/execution/executions/run/terminate',
+      'http://localhost:8080/api/v1/namespaces/namespace/workflows/workflow/runs/run/terminate',
     );
   });
 });
@@ -52,10 +52,10 @@ describe('API Request Encoding', () => {
     expect(
       routeForApi('workflow', {
         ...parameters,
-        executionId: 'worflow#with#hashes',
+        workflowId: 'worflow#with#hashes',
       }),
     ).toBe(
-      'http://localhost:8080/api/v1/namespaces/namespace/workflows/worflow%23with%23hashes/executions/run',
+      'http://localhost:8080/api/v1/namespaces/namespace/workflows/worflow%23with%23hashes/runs/run',
     );
   });
 });