Fix form record picker field (#11817)

- enrich response so the record is available in the step output. Today
this is available in the schema but only the id is set
- make the full record picker clickable instead of the arrow only

<img width="467" alt="Capture d’écran 2025-04-30 à 16 08 04"
src="https://github.com/user-attachments/assets/db74b9a6-7f1d-4e54-bf06-9be3d67ee398"
/>
This commit is contained in:
Thomas Trompette
2025-05-05 14:58:11 +02:00
committed by GitHub
parent c9eff401df
commit 6128d660c2
8 changed files with 270 additions and 54 deletions

View File

@ -10,4 +10,5 @@ export enum WorkflowVersionStepExceptionCode {
NOT_FOUND = 'NOT_FOUND',
UNDEFINED = 'UNDEFINED',
FAILURE = 'FAILURE',
INVALID = 'INVALID',
}

View File

@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { FieldMetadataType } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { isDefined, isValidUuid } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
import { v4 } from 'uuid';
@ -25,6 +25,7 @@ import { BaseWorkflowActionSettings } from 'src/modules/workflow/workflow-execut
import {
WorkflowAction,
WorkflowActionType,
WorkflowFormAction,
} from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
import { WorkflowRunWorkspaceService } from 'src/modules/workflow/workflow-runner/workflow-run/workflow-run.workspace-service';
import { WorkflowRunnerWorkspaceService } from 'src/modules/workflow/workflow-runner/workspace-services/workflow-runner.workspace-service';
@ -287,16 +288,28 @@ export class WorkflowVersionStepWorkspaceService {
);
}
if (step.type !== WorkflowActionType.FORM) {
throw new WorkflowVersionStepException(
'Step is not a form',
WorkflowVersionStepExceptionCode.INVALID,
);
}
const enrichedResponse = await this.enrichFormStepResponse({
step,
response,
});
const newStepOutput: StepOutput = {
id: stepId,
output: {
result: response,
result: enrichedResponse,
},
};
const updatedContext = {
...workflowRun.context,
[stepId]: response,
[stepId]: enrichedResponse,
};
await this.workflowRunWorkspaceService.saveWorkflowRunState({
@ -547,4 +560,49 @@ export class WorkflowVersionStepWorkspaceService {
);
}
}
private async enrichFormStepResponse({
step,
response,
}: {
step: WorkflowFormAction;
response: object;
}) {
const responseKeys = Object.keys(response);
const enrichedResponses = await Promise.all(
responseKeys.map(async (key) => {
if (!isDefined(response[key])) {
return { key, value: response[key] };
}
const field = step.settings.input.find((field) => field.name === key);
if (
field?.type === 'RECORD' &&
field?.settings?.objectName &&
isDefined(response[key].id) &&
isValidUuid(response[key].id)
) {
const repository = await this.twentyORMManager.getRepository(
field.settings.objectName,
);
const record = await repository.findOne({
where: { id: response[key].id },
});
return { key, value: record };
} else {
return { key, value: response[key] };
}
}),
);
return enrichedResponses.reduce((acc, { key, value }) => {
acc[key] = value;
return acc;
}, {});
}
}

View File

@ -1,6 +1,8 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { isDefined } from 'class-validator';
import { isValidUuid } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
import { WorkflowExecutor } from 'src/modules/workflow/workflow-executor/interfaces/workflow-executor.interface';
@ -59,6 +61,17 @@ export class DeleteRecordWorkflowAction implements WorkflowExecutor {
context,
) as WorkflowDeleteRecordActionInput;
if (
!isDefined(workflowActionInput.objectRecordId) ||
!isValidUuid(workflowActionInput.objectRecordId) ||
!isDefined(workflowActionInput.objectName)
) {
throw new RecordCRUDActionException(
'Failed to update: Object record ID and name are required',
RecordCRUDActionExceptionCode.INVALID_REQUEST,
);
}
const repository = await this.twentyORMManager.getRepository(
workflowActionInput.objectName,
);

View File

@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import deepEqual from 'deep-equal';
import { isDefined, isValidUuid } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
import { WorkflowExecutor } from 'src/modules/workflow/workflow-executor/interfaces/workflow-executor.interface';
@ -67,6 +68,17 @@ export class UpdateRecordWorkflowAction implements WorkflowExecutor {
context,
) as WorkflowUpdateRecordActionInput;
if (
!isDefined(workflowActionInput.objectRecordId) ||
!isValidUuid(workflowActionInput.objectRecordId) ||
!isDefined(workflowActionInput.objectName)
) {
throw new RecordCRUDActionException(
'Failed to update: Object record ID and name are required',
RecordCRUDActionExceptionCode.INVALID_REQUEST,
);
}
const repository = await this.twentyORMManager.getRepository(
workflowActionInput.objectName,
);