Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<script lang="ts">
import { cva } from 'class-variance-authority';

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

import Icon from '$lib/holocene/icon';
import type { RootNode } from '$lib/services/workflow-service';
import { fullEventHistory } from '$lib/stores/events';
import { namespaces } from '$lib/stores/namespaces';
import { workflowRun } from '$lib/stores/workflow-run';
import type { WorkflowExecution } from '$lib/types/workflows';
import { getWorkflowRelationships } from '$lib/utilities/get-workflow-relationships';
Expand All @@ -29,12 +28,12 @@
export let onNodeClick: (node: RootNode, generation: number) => void;
export let activeWorkflow: WorkflowExecution | undefined = undefined;

$: ({ workflow, run, namespace } = $page.params);
$: ({ workflow, run, namespace } = page.params);
$: ({ workflow: fullWorkflow } = $workflowRun);
$: workflowRelationships = getWorkflowRelationships(
fullWorkflow,
$fullEventHistory,
$namespaces,
page.data.namespace,
);
$: ({ first, next, previous } = workflowRelationships);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script lang="ts">
import { page } from '$app/stores';
import { page } from '$app/state';

import { fetchAllChildWorkflows } from '$lib/services/workflow-service';
import { fullEventHistory } from '$lib/stores/events';
import { namespaces } from '$lib/stores/namespaces';
import { workflowRun } from '$lib/stores/workflow-run';
import { getWorkflowRelationships } from '$lib/utilities/get-workflow-relationships';

Expand All @@ -13,13 +12,13 @@
import ParentWorkflowTable from './parent-workflow-table.svelte';
import SchedulerTable from './scheduler-table.svelte';

$: ({ namespace, workflow: workflowId, run: runId } = $page.params);
$: ({ namespace, workflow: workflowId, run: runId } = page.params);
$: ({ workflow } = $workflowRun);

$: workflowRelationships = getWorkflowRelationships(
workflow,
$fullEventHistory,
$namespaces,
page.data.namespace,
);

$: ({
Expand Down Expand Up @@ -59,7 +58,7 @@
<ChildWorkflowsTable
{children}
pendingChildren={$workflowRun.workflow.pendingChildren}
namespace={$page.params.namespace}
namespace={page.params.namespace}
/>
{/if}
{/await}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/layouts/workflow-header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import { getInboundNexusLinkEvents } from '$lib/runes/inbound-nexus-links.svelte';
import { getWorkflowPollersWithVersions } from '$lib/runes/workflow-versions.svelte';
import { fullEventHistory } from '$lib/stores/events';
import { namespaces } from '$lib/stores/namespaces';
import { resetWorkflows } from '$lib/stores/reset-workflows';
import { workflowRun } from '$lib/stores/workflow-run';
import { workflowsSearchParams } from '$lib/stores/workflows';
Expand Down Expand Up @@ -70,7 +69,7 @@
);
const workflowHasBeenReset = $derived(!!resetRunId);
const workflowRelationships = $derived(
getWorkflowRelationships(workflow, $fullEventHistory, $namespaces),
getWorkflowRelationships(workflow, $fullEventHistory, page.data.namespace),
);
const workflowsHref = $derived(
`${routeForWorkflows({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/namespaces-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function fetchNamespace(
const results = await requestFromAPI<DescribeNamespaceResponse>(route, {
request,
onError: () =>
toaster.push({ variant: 'error', message: 'Unable to fetch namespaces' }),
toaster.push({ variant: 'error', message: 'Unable to fetch namespace' }),
});

return results ? toNamespaceDetails(results) : empty;
Expand Down
56 changes: 28 additions & 28 deletions src/lib/utilities/get-workflow-relationships.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(pendingChildrenWorkflow),
completedEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).hasChildren,
).toBe(true);
});
Expand All @@ -35,24 +35,34 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(pendingChildrenWorkflow),
childEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).hasChildren,
).toBe(true);
expect(
getWorkflowRelationships(
toWorkflowExecution(pendingChildrenWorkflow),
childEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).children.length,
).toBe(15);
});

it('parentNamespaceName should return undefined if parentNamespaceId does not match namespaces list', () => {
it('parentNamespaceName should return the namespace name', () => {
expect(
getWorkflowRelationships(
toWorkflowExecution(pendingChildrenWorkflow),
childEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).parentNamespaceName,
).toBe('my-namespace-name');
});

it('parentNamespaceName should return undefined if namespace name does not exist', () => {
expect(
getWorkflowRelationships(
toWorkflowExecution(pendingChildrenWorkflow),
childEvents,
{ namespaceInfo: {} },
).parentNamespaceName,
).toBe(undefined);
});
Expand All @@ -62,14 +72,14 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(runningWorkflow),
childEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).hasChildren,
).toBe(true);
expect(
getWorkflowRelationships(
toWorkflowExecution(runningWorkflow),
childEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).children.length,
).toBe(15);
});
Expand All @@ -79,21 +89,11 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(runningWorkflow),
completedEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).hasChildren,
).toBe(false);
});

it('parentNamespaceName should return namespace name if parentNamespaceId does match namespaces list', () => {
expect(
getWorkflowRelationships(
toWorkflowExecution(runningWorkflow),
completedEvents,
namespaces.namespaces,
).parentNamespaceName,
).toBe('canary');
});

it('should return the firstExecutionRunId for first on a workflowExecutionStartedEvent', () => {
const workflowExecutionStartedEvent = continuedAsNewEvents.find(
(event) => event?.name === 'WorkflowExecutionStarted',
Expand All @@ -105,7 +105,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(continuedAsNewWorkflow),
continuedAsNewEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).first,
).toBe(firstExecutionRunId);
});
Expand All @@ -123,7 +123,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(continuedAsNewWorkflowCopy),
continuedAsNewEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).first,
).toBe(firstExecutionRunId);

Expand All @@ -134,7 +134,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(continuedAsNewWorkflowCopy),
continuedAsNewEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).first,
).toBe(undefined);
});
Expand All @@ -149,7 +149,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(continuedAsNewWorkflow),
continuedAsNewEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).previous,
).toBe(continuedExecutionRunId);
});
Expand All @@ -165,7 +165,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(continuedAsNewWorkflow),
continuedAsNewEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).next,
).toBe(newExecutionRunId);
});
Expand All @@ -181,7 +181,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(completedWorkflow),
completedEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).next,
).toBe(newExecutionRunId);
});
Expand All @@ -197,7 +197,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(timedOutWorkflow),
timedOutEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).next,
).toBe(newExecutionRunId);
});
Expand All @@ -213,7 +213,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(failedWorkflow),
failedEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).next,
).toBe(newExecutionRunId);
});
Expand All @@ -227,7 +227,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(scheduledWorkflow),
completedEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).scheduleId,
).toBe(workflowScheduledId);
});
Expand All @@ -237,7 +237,7 @@ describe('getWorkflowRelationships', () => {
getWorkflowRelationships(
toWorkflowExecution(completedWorkflow),
completedEvents,
namespaces.namespaces,
namespaces.namespaces[0],
).scheduleId,
).toBe('');
});
Expand Down
7 changes: 2 additions & 5 deletions src/lib/utilities/get-workflow-relationships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,14 @@ type WorkflowRelationships = {
export const getWorkflowRelationships = (
workflow: WorkflowExecution | null,
fullEventHistory: WorkflowEvents,
namespaces: DescribeNamespaceResponse[],
namespace: DescribeNamespaceResponse,
): WorkflowRelationships => {
const children = fullEventHistory.filter((event) =>
isChildWorkflowClosedEvent(event),
) as ChildWorkflowClosedEvent[];
const hasChildren = !!workflow?.pendingChildren.length || !!children.length;
const parent = workflow?.parent;

const parentNamespaceName = namespaces?.find((namespace) => {
return namespace.namespaceInfo.id === workflow.parentNamespaceId;
})?.namespaceInfo?.name;
const parentNamespaceName = namespace.namespaceInfo?.name;

const workflowExecutionStartedEvent = fullEventHistory.find(
isWorkflowExecutionStartedEvent,
Expand Down
7 changes: 7 additions & 0 deletions src/routes/(app)/namespaces/[namespace]/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { LayoutData, LayoutLoad } from './$types';

import { fetchNamespace } from '$lib/services/namespaces-service';
import { fetchSearchAttributesForNamespace } from '$lib/services/search-attributes-service';
import { allSearchAttributes } from '$lib/stores/search-attributes';

Expand All @@ -15,4 +16,10 @@ export const load: LayoutLoad = async ({
);

allSearchAttributes.set(attributes);

const namespace = await fetchNamespace(params.namespace);

return {
namespace,
};
};
7 changes: 2 additions & 5 deletions src/routes/(app)/namespaces/[namespace]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import type { PageLoad } from './$types';

import { fetchNamespace } from '$lib/services/namespaces-service';
import { getClusters } from '$lib/utilities/get-clusters';

export const load: PageLoad = async function ({ params, parent, url }) {
export const load: PageLoad = async function ({ parent, url }) {
const { searchParams } = url;

if (searchParams.has('time-range')) searchParams.delete('time-range');

await parent();
const namespace = await fetchNamespace(params.namespace);
const { namespace } = await parent();
const clusters = getClusters(namespace);

return {
namespace,
clusters,
};
};
2 changes: 2 additions & 0 deletions tests/integration/start-a-workflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test';

import {
mockGlobalApis,
mockNamespaceApi,
mockSearchAttributesApi,
mockSettingsApi,
mockTaskQueuesApi,
Expand All @@ -11,6 +12,7 @@ test.describe('Start a Workflow', () => {
const startWorkflowUrl = '/namespaces/default/workflows/start-workflow';
test.beforeEach(async ({ page }) => {
await mockGlobalApis(page);
await mockNamespaceApi(page);
});

test.describe('Start a Workflow - Disabled', () => {
Expand Down
3 changes: 3 additions & 0 deletions tests/test-utilities/mock-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const mockGlobalApis = (page: Page) => {
export const mockWorkflowsApis = (page: Page) => {
return Promise.all([
mockGlobalApis(page),
mockNamespaceApi(page),
mockWorkflowsApi(page),
mockSearchAttributesApi(page),
mockWorkflowsCountApi(page),
Expand All @@ -82,6 +83,7 @@ export const mockSchedulesApis = (
) => {
return Promise.all([
mockGlobalApis(page),
mockNamespaceApis(page),
mockSearchAttributesApi(page, customSearchAttributes),
mockSchedulesApi(page, empty),
mockWorkflowsCountApi(page, emptyWorkflowsCount),
Expand Down Expand Up @@ -109,6 +111,7 @@ export const mockWorkflowApis = (
) => {
return Promise.all([
mockNamespaceApis(page),
mockNamespaceApi(page),
mockWorkflowApi(page, workflow),
mockEventHistoryApi(page),
mockTaskQueuesApi(page),
Expand Down
Loading