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:
@ -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;
|
||||
}, {});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user