Fix the triggering of the event goToGenerateWorkflow when relatedEntityId is not known

The component PickWorkflow emitted the event "goToGenerateWorkflow" when the normal behaviour is intercepted. But that event generated the link to create the workflow to pass it in the payload's event. That generation failed, causing the whole event to fail.

Now, if the link could not been generated, the link is a blank string. There is a supplementary parameter `isLinkValid`, boolean, inform if the link is valid or not.
This commit is contained in:
2024-10-23 13:44:31 +02:00
parent a6480191e5
commit a256307b82
2 changed files with 35 additions and 7 deletions

View File

@@ -20,7 +20,13 @@ import {WorkflowAvailable} from "../../../types";
interface PickWorkflowConfig {
relatedEntityClass: string;
relatedEntityId: number;
/**
* Represents the identifier of a related entity.
* This variable can store either a numerical value representing the entity's ID or an undefined value
* if the related entity is not specified or available, for instance when the entity is created within
* the interface and the id will be available later
*/
relatedEntityId: number|undefined;
workflowsAvailables: WorkflowAvailable[];
preventDefaultMoveToGenerate: boolean;
goToGenerateWorkflowPayload: object;
@@ -29,20 +35,28 @@ interface PickWorkflowConfig {
const props = withDefaults(defineProps<PickWorkflowConfig>(), {preventDefaultMoveToGenerate: false, goToGenerateWorkflowPayload: {}});
const emit = defineEmits<{
(e: 'goToGenerateWorkflow', {event: MouseEvent, workflowName: string, link: string, payload: object}): void;
(e: 'goToGenerateWorkflow', {event: MouseEvent, workflowName: string, isLinkValid: boolean, link: string, payload: object}): void;
}>();
const makeLink = (workflowName: string): string => buildLinkCreate(workflowName, props.relatedEntityClass, props.relatedEntityId);
const goToGenerateWorkflow = (event: MouseEvent, workflowName: string): void => {
console.log('goToGenerateWorkflow', event, workflowName);
let link = '';
let isLinkValid = false;
if (!props.preventDefaultMoveToGenerate) {
console.log('to go generate');
window.location.assign(makeLink(workflowName));
try {
link = makeLink(workflowName);
isLinkValid = true;
} catch (e) {
console.info("could not generate link to create workflow, maybe the relatedEntityId is not yet known", e);
}
emit('goToGenerateWorkflow', {event, workflowName, link: makeLink(workflowName), payload: props.goToGenerateWorkflowPayload});
if (!props.preventDefaultMoveToGenerate) {
window.location.assign(link);
}
emit('goToGenerateWorkflow', {event, workflowName, link, isLinkValid, payload: props.goToGenerateWorkflowPayload});
}
const goToDuplicateRelatedEntity = (event: MouseEvent, workflowName: string): void => {