Hmm. That could make sense. This is the first time I have had to write a function where one of the fields, refData
, is actually an object made of two lists. Here is what I wrote:
const ciCid = "Contract Instance"
const fromDate = "From Date"
const toDate = "To Date"
const holidayCalendarCids = "Holiday Calendar Instance"
const observationCids = "Observation Calendar Instance"
const doTrigger = function (contract, params) {
const payload = {
ciCid: params[ciCid],
fromDate: params[fromDate],
toDate: params[toDate],
refData: {
holidayCalendarCids: params[holidayCalendarCids],
observationCids: params[observationCids]
}
}
ledger.exercise(DeriveEventsWorkflow.Trigger, contract.contractId, payload);
};
I then put this information in a ButtonToForm
component where dialogs
is defined nearly the same as many of the Contracts.js
files found…
<ButtonToForm
contracts={deriveEvents.contracts}
dialogs={[
["Find Upcoming Event",
[
field(ciCid, "menu", contractInstance.contracts.map(c => c.contractId), contractInstance.contracts.map(c => c.payload.d.primeKey)),
field(fromDate, "date"),
field(toDate, "date"),
field(holidayCalendarCids, "menu", holidayCalendar.contracts.map(c => c.contractId), holidayCalendar.contracts.map(c => c.payload.d.label)),
field(observationCids, "menu", rateObservation.contracts.map(c => c.contractId), rateObservation.contracts.map(c => obsDataToText(c.payload)))
],
doTrigger,
"Find Upcoming Event"
],
]}
/>
Do you see anything weird about the function call? I have read over it a few times and nothing jumps out at me. When I click the dialog box, I see all of the fields that I expect to see and am able to select each of them.
Perhaps I need to make an adjustment to addFormFields() because field holidayCalendarCids and observationCids need to accept a list (even though I am only passing one argument).
function addFormFields(name, dialogFieldSpec) {
return (
<>
<Grid container spacing={2}>
{dialogFieldSpec.map(spec =>
<Grid item xs={6} key={spec["name"]} className={classes.formField}>
{(spec["type"] === "menu")
?
<FormControl className={classes.formControl} key={spec["name"]} fullWidth=true}>
<InputLabel>{spec["name"]}</InputLabel>
<Select value={getDialogState(name, spec["name"], spec["items"]0])} defaultValue={spec["items"]0]} onChange=(event) => setDialogState(name, spec["name"], event.target.value)}> {
spec["items"].map((item, i) =>
<MenuItem key={item} value={item}>{spec["itemNames"][i]}</MenuItem>
)
}
</Select>
</FormControl>
: <TextField
required
autoFocus
fullWidth={true}
key={spec["name"]}
label={spec["name"]}
type={spec["type"]}
className={classes.textField}
InputLabelProps={{
shrink: true,
}}
onChange={(event) => setDialogState(name, spec["name"], event.target.value)}
/>}
</Grid>
)}
</Grid>
</>
);
}