Passing complex type to choice from React

Hi,

I need to pass this type to a choice from the React app, but not sure how to specify a default value. I’m using the daml-ui-template.

data Participant = Participant 
  with 
    name : Text 
  deriving (Eq, Show)

The choice is:

nonconsuming CreateParticipant: ContractId ParticipantRole
        with 
           participant : Party 
           participantInfo: Participant
        do 
          create ParticipantRole with ..

I can’t figure out how to specify this in the React code of daml-ui-template.

const defaultCreateParticipantProps: InputDialogProps<CreateParticipant> = {
    open: false,
    title: "Add Participant",
    defaultValue: {participant: "", **participantInfo: null**  },
    fields: {
      participant: {
        label: "Participant Party Id",
        type: "text",
      },
      participantInfo: {
        label: "Information",
        **type: Participant,**
      },
    },
    onClose: async function () {},
  };```
 
I'm getting a compiler error when specifying the default value for the parameters (null), and the "type" cannot be specified as Participant. This is a mandatory field. Can please show me how to specify a default value and type here.

Many thanks!
1 Like

The compiler error for the default value is a bit of a red herring in this case. If you want to fix that, something like {name: ""} will work.

The InputDialogProps was never designed with arbitrary nesting of parameter data structures in mind; you have to write out the HTML manually. There are two solutions; don’t use the nested type in DAML (:troll:) or create an InputDialogProp for the Participant data type. If you do that, you will then need to wrap the final exercise call with the correct arguments. If state is the result of the InputDialogProp<Participant> it will have a type {name: str} , at which point you would pass {participant: *ManishToFigureThisOut*, participantInfo:state} as your argument to CreateParticipant.

2 Likes

@ManishGrover Here’s a branch where I demo the 2nd approach.

1 Like

Thanks Leo. I’m not good at react at all so modified the params to be the simpler data types for now.

2 Likes

Don’t worry, I’m not good at react either. Otherwise that input prop would have been fully recursive.

1 Like