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

feat(editor): Add workflow evaluation edit and list views (no-changelog) #11719

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
75970bf
wip: DB migration
burivuhster Nov 12, 2024
d2798f0
wip: add description to test-definitions API
burivuhster Nov 12, 2024
a271dc3
Setup routes
OlegIvaniv Nov 11, 2024
64cc052
Finish edit UI
OlegIvaniv Nov 12, 2024
479456b
Add test definitions API and store
OlegIvaniv Nov 12, 2024
8401857
Refactor maxWidth to CSS variable
OlegIvaniv Nov 12, 2024
24e1f7b
Refactor workflow evaluation components and improve code organization
OlegIvaniv Nov 12, 2024
ff12775
Refactor workflow evaluation list view and add new components
OlegIvaniv Nov 12, 2024
22f78aa
Implement feature flag for workflow evaluation experiment
OlegIvaniv Nov 12, 2024
1d8f44d
Refine UI for TestItem and TestsList components in WorkflowEvaluation
OlegIvaniv Nov 12, 2024
d55144e
Make TagsDropdown component more flexible and reusable
OlegIvaniv Nov 12, 2024
81a2564
Remove console.logs
OlegIvaniv Nov 12, 2024
f0aa7ad
Enhance workflow evaluation UI with localization and styling improvem…
OlegIvaniv Nov 12, 2024
2a9496d
Improve workflow evaluation UI and add localization for test list
OlegIvaniv Nov 12, 2024
229f54a
Refactor evaluation form and improve error handling in workflow evalu…
OlegIvaniv Nov 12, 2024
34bd0fc
Update evaluation UI components and add test IDs
OlegIvaniv Nov 12, 2024
bb231ea
Add tests for WorkflowEvaluation components and EvaluationEditView
OlegIvaniv Nov 12, 2024
d379db2
Remove unused CHAT_TRIGGER_NODE_TYPE import from viewsData.ts
OlegIvaniv Nov 13, 2024
f245048
Fix stray character
OlegIvaniv Nov 13, 2024
c1b3a1a
Remove unused view file
OlegIvaniv Nov 13, 2024
4af1e7f
Enhance evaluation form with auto-save and improved error handling
OlegIvaniv Nov 13, 2024
cdd3d84
Merge remote-tracking branch 'origin/ai-455-add-description-field-to-…
OlegIvaniv Nov 13, 2024
9b5be7a
Enhance test definition creation and editing with description support
OlegIvaniv Nov 13, 2024
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
3 changes: 3 additions & 0 deletions packages/cli/src/databases/entities/test-definition.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class TestDefinition extends WithTimestamps {
})
name: string;

@Column('text')
description: string;

/**
* Relation to the workflow under test
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { MigrationContext, ReversibleMigration } from '@/databases/types';

export class AddDescriptionToTestDefinition1731404028106 implements ReversibleMigration {
async up({ schemaBuilder: { addColumns, column } }: MigrationContext) {
await addColumns('test_definition', [column('description').text]);
}

async down({ schemaBuilder: { dropColumns } }: MigrationContext) {
await dropColumns('test_definition', ['description']);
}
}
2 changes: 2 additions & 0 deletions packages/cli/src/databases/migrations/mysqldb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { SeparateExecutionCreationFromStart1727427440136 } from '../common/17274
import { AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644 } from '../common/1728659839644-AddMissingPrimaryKeyOnAnnotationTagMapping';
import { UpdateProcessedDataValueColumnToText1729607673464 } from '../common/1729607673464-UpdateProcessedDataValueColumnToText';
import { CreateTestDefinitionTable1730386903556 } from '../common/1730386903556-CreateTestDefinitionTable';
import { AddDescriptionToTestDefinition1731404028106 } from '../common/1731404028106-AddDescriptionToTestDefinition';

export const mysqlMigrations: Migration[] = [
InitialMigration1588157391238,
Expand Down Expand Up @@ -140,4 +141,5 @@ export const mysqlMigrations: Migration[] = [
AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644,
UpdateProcessedDataValueColumnToText1729607673464,
CreateTestDefinitionTable1730386903556,
AddDescriptionToTestDefinition1731404028106,
];
2 changes: 2 additions & 0 deletions packages/cli/src/databases/migrations/postgresdb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { SeparateExecutionCreationFromStart1727427440136 } from '../common/17274
import { AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644 } from '../common/1728659839644-AddMissingPrimaryKeyOnAnnotationTagMapping';
import { UpdateProcessedDataValueColumnToText1729607673464 } from '../common/1729607673464-UpdateProcessedDataValueColumnToText';
import { CreateTestDefinitionTable1730386903556 } from '../common/1730386903556-CreateTestDefinitionTable';
import { AddDescriptionToTestDefinition1731404028106 } from '../common/1731404028106-AddDescriptionToTestDefinition';

export const postgresMigrations: Migration[] = [
InitialMigration1587669153312,
Expand Down Expand Up @@ -140,4 +141,5 @@ export const postgresMigrations: Migration[] = [
AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644,
UpdateProcessedDataValueColumnToText1729607673464,
CreateTestDefinitionTable1730386903556,
AddDescriptionToTestDefinition1731404028106,
];
2 changes: 2 additions & 0 deletions packages/cli/src/databases/migrations/sqlite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { CreateProcessedDataTable1726606152711 } from '../common/1726606152711-C
import { SeparateExecutionCreationFromStart1727427440136 } from '../common/1727427440136-SeparateExecutionCreationFromStart';
import { UpdateProcessedDataValueColumnToText1729607673464 } from '../common/1729607673464-UpdateProcessedDataValueColumnToText';
import { CreateTestDefinitionTable1730386903556 } from '../common/1730386903556-CreateTestDefinitionTable';
import { AddDescriptionToTestDefinition1731404028106 } from '../common/1731404028106-AddDescriptionToTestDefinition';

const sqliteMigrations: Migration[] = [
InitialMigration1588102412422,
Expand Down Expand Up @@ -134,6 +135,7 @@ const sqliteMigrations: Migration[] = [
AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644,
UpdateProcessedDataValueColumnToText1729607673464,
CreateTestDefinitionTable1730386903556,
AddDescriptionToTestDefinition1731404028106,
];

export { sqliteMigrations };
3 changes: 3 additions & 0 deletions packages/cli/src/evaluation/test-definition.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ export const testDefinitionCreateRequestBodySchema = z
.object({
name: z.string().min(1).max(255),
workflowId: z.string().min(1),
description: z.string().optional(),
evaluationWorkflowId: z.string().min(1).optional(),
annotationTagId: z.string().min(1).optional(),
})
.strict();

export const testDefinitionPatchRequestBodySchema = z
.object({
name: z.string().min(1).max(255).optional(),
description: z.string().optional(),
evaluationWorkflowId: z.string().min(1).optional(),
annotationTagId: z.string().min(1).optional(),
})
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/evaluation/test-definition.service.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class TestDefinitionService {

private toEntityLike(attrs: {
name?: string;
description?: string;
workflowId?: string;
evaluationWorkflowId?: string;
annotationTagId?: string;
Expand All @@ -41,6 +42,10 @@ export class TestDefinitionService {
entity.name = attrs.name?.trim();
}

if (attrs.description) {
entity.description = attrs.description.trim();
}

if (attrs.workflowId) {
entity.workflow = {
id: attrs.workflowId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,36 @@ describe('POST /evaluation/test-definitions', () => {
});

expect(resp.statusCode).toBe(200);
expect(resp.body.data.name).toBe('test');
expect(resp.body.data.workflowId).toBe(workflowUnderTest.id);
expect(resp.body.data.evaluationWorkflowId).toBe(evaluationWorkflow.id);
expect(resp.body.data).toEqual(
expect.objectContaining({
name: 'test',
workflowId: workflowUnderTest.id,
evaluationWorkflowId: evaluationWorkflow.id,
}),
);
});

test('should create test definition with all fields', async () => {
const resp = await authOwnerAgent.post('/evaluation/test-definitions').send({
name: 'test',
description: 'test description',
workflowId: workflowUnderTest.id,
evaluationWorkflowId: evaluationWorkflow.id,
annotationTagId: annotationTag.id,
});

expect(resp.statusCode).toBe(200);
expect(resp.body.data).toEqual(
expect.objectContaining({
name: 'test',
description: 'test description',
workflowId: workflowUnderTest.id,
evaluationWorkflowId: evaluationWorkflow.id,
annotationTag: expect.objectContaining({
id: annotationTag.id,
}),
}),
);
});

test('should return error if name is empty', async () => {
Expand Down
82 changes: 82 additions & 0 deletions packages/editor-ui/src/api/evaluations.ee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import type { IRestApiContext } from '@/Interface';
import { makeRestApiRequest } from '@/utils/apiUtils';

// Base interface for common properties
export interface ITestDefinitionBase {
name: string;
workflowId: string;
evaluationWorkflowId?: string;
description?: string;
annotationTagId?: string;
}

export interface ITestDefinition extends ITestDefinitionBase {
id: number;
}

export type CreateTestDefinitionParams = Pick<
ITestDefinitionBase,
'name' | 'workflowId' | 'description' | 'evaluationWorkflowId'
>;

export type UpdateTestDefinitionParams = Partial<ITestDefinitionBase>;

// Query options type
export interface ITestDefinitionsQueryOptions {
includeScopes?: boolean;
}

export interface ITestDefinitionsApi {
getTestDefinitions: (
context: IRestApiContext,
options?: ITestDefinitionsQueryOptions,
) => Promise<{ count: number; testDefinitions: ITestDefinition[] }>;

getTestDefinition: (context: IRestApiContext, id: number) => Promise<ITestDefinition>;

createTestDefinition: (
context: IRestApiContext,
params: CreateTestDefinitionParams,
) => Promise<ITestDefinition>;

updateTestDefinition: (
context: IRestApiContext,
id: number,
params: UpdateTestDefinitionParams,
) => Promise<ITestDefinition>;

deleteTestDefinition: (context: IRestApiContext, id: number) => Promise<{ success: boolean }>;
}

export function createTestDefinitionsApi(): ITestDefinitionsApi {
const endpoint = '/evaluation/test-definitions';

return {
getTestDefinitions: async (
context: IRestApiContext,
options?: ITestDefinitionsQueryOptions,
) => {
return await makeRestApiRequest(context, 'GET', endpoint, options);
},

getTestDefinition: async (context: IRestApiContext, id: number) => {
return await makeRestApiRequest(context, 'GET', `${endpoint}/${id}`);
},

createTestDefinition: async (context: IRestApiContext, params: CreateTestDefinitionParams) => {
return await makeRestApiRequest(context, 'POST', endpoint, params);
},

updateTestDefinition: async (
context: IRestApiContext,
id: number,
params: UpdateTestDefinitionParams,
) => {
return await makeRestApiRequest(context, 'PATCH', `${endpoint}/${id}`, params);
},

deleteTestDefinition: async (context: IRestApiContext, id: number) => {
return await makeRestApiRequest(context, 'DELETE', `${endpoint}/${id}`);
},
};
}
26 changes: 22 additions & 4 deletions packages/editor-ui/src/components/MainHeader/MainHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PLACEHOLDER_EMPTY_WORKFLOW_ID,
STICKY_NODE_TYPE,
VIEWS,
WORKFLOW_EVALUATION_EXPERIMENT,
} from '@/constants';
import { useI18n } from '@/composables/useI18n';
import { useNDVStore } from '@/stores/ndv.store';
Expand All @@ -17,6 +18,7 @@ import { useUIStore } from '@/stores/ui.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { useExecutionsStore } from '@/stores/executions.store';
import { usePushConnection } from '@/composables/usePushConnection';
import { usePostHog } from '@/stores/posthog.store';

const router = useRouter();
const route = useRoute();
Expand All @@ -27,16 +29,24 @@ const uiStore = useUIStore();
const sourceControlStore = useSourceControlStore();
const workflowsStore = useWorkflowsStore();
const executionsStore = useExecutionsStore();
const posthogStore = usePostHog();

const activeHeaderTab = ref(MAIN_HEADER_TABS.WORKFLOW);
const workflowToReturnTo = ref('');
const executionToReturnTo = ref('');
const dirtyState = ref(false);

const tabBarItems = computed(() => [
{ value: MAIN_HEADER_TABS.WORKFLOW, label: locale.baseText('generic.editor') },
{ value: MAIN_HEADER_TABS.EXECUTIONS, label: locale.baseText('generic.executions') },
]);
const tabBarItems = computed(() => {
const items = [
{ value: MAIN_HEADER_TABS.WORKFLOW, label: locale.baseText('generic.editor') },
{ value: MAIN_HEADER_TABS.EXECUTIONS, label: locale.baseText('generic.executions') },
];

if (posthogStore.isFeatureEnabled(WORKFLOW_EVALUATION_EXPERIMENT)) {
items.push({ value: MAIN_HEADER_TABS.EVALUATION, label: locale.baseText('generic.tests') });
}
return items;
});

const activeNode = computed(() => ndvStore.activeNode);
const hideMenuBar = computed(() =>
Expand Down Expand Up @@ -67,6 +77,9 @@ onMounted(async () => {
});

function syncTabsWithRoute(to: RouteLocation, from?: RouteLocation): void {
if (to.matched.some((record) => record.name === VIEWS.WORKFLOW_EVALUATION)) {
activeHeaderTab.value = MAIN_HEADER_TABS.EVALUATION;
}
if (
to.name === VIEWS.EXECUTION_HOME ||
to.name === VIEWS.WORKFLOW_EXECUTIONS ||
Expand Down Expand Up @@ -106,6 +119,11 @@ function onTabSelected(tab: MAIN_HEADER_TABS, event: MouseEvent) {
void navigateToExecutionsView(openInNewTab);
break;

case MAIN_HEADER_TABS.EVALUATION:
activeHeaderTab.value = MAIN_HEADER_TABS.EVALUATION;
void router.push({ name: VIEWS.WORKFLOW_EVALUATION });
break;

default:
break;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/editor-ui/src/components/TagsDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { useToast } from '@/composables/useToast';
interface TagsDropdownProps {
placeholder: string;
modelValue: string[];
createTag: (name: string) => Promise<ITag>;
eventBus: EventBus | null;
allTags: ITag[];
isLoading: boolean;
tagsById: Record<string, ITag>;
createTag?: (name: string) => Promise<ITag>;
}

const i18n = useI18n();
Expand Down Expand Up @@ -109,6 +109,8 @@ function filterOptions(value = '') {
}

async function onCreate() {
if (!props.createTag) return;

const name = filter.value;
try {
const newTag = await props.createTag(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script setup lang="ts">
interface Props {
modelValue: string;
}

withDefaults(defineProps<Props>(), {
modelValue: '',
});

defineEmits<{ 'update:modelValue': [value: string] }>();
</script>

<template>
<div :class="[$style.formGroup, $style.description]">
<n8n-input-label label="Description" :bold="false" size="small" :class="$style.field">
<N8nInput
:model-value="modelValue"
type="textarea"
:placeholder="$locale.baseText('workflowEvaluation.edit.descriptionPlaceholder')"
@update:model-value="$emit('update:modelValue', $event)"
/>
</n8n-input-label>
</div>
</template>

<style module lang="scss">
.formGroup {
margin-bottom: var(--spacing-l);

:global(.n8n-input-label) {
margin-bottom: var(--spacing-2xs);
}
}

.field {
width: 100%;
margin-top: var(--spacing-xs);
}
</style>
Loading
Loading