-
Notifications
You must be signed in to change notification settings - Fork 94
Enable user data pre-population in NAME and TEXT fields via user() function #11432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release-v1.9.4
Are you sure you want to change the base?
Conversation
Co-authored-by: rikukissa <1206987+rikukissa@users.noreply.github.com>
Co-authored-by: rikukissa <1206987+rikukissa@users.noreply.github.com>
Co-authored-by: rikukissa <1206987+rikukissa@users.noreply.github.com>
Co-authored-by: rikukissa <1206987+rikukissa@users.noreply.github.com>
| /** | ||
| * Resolves `user('name')` to `$user.name` to allow us to 1) type check system variables 2) change the implementation later if needed | ||
| */ | ||
| export function user( | ||
| key: 'name' | 'fullHonorificName' | 'device' | 'province' | 'district' | ||
| ) { | ||
| return `$user.${key}` | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function already exists with name userSerializer
packages/commons/src/events/serializers/user/serializer.ts
Use it instead. "$user.name" style references are also deprecated.
| return { | ||
| name, | ||
| role: userDetails?.role.id, | ||
| district: '', | ||
| province: '' | ||
| id: userDetails?.id ?? '', | ||
| name: normalizedName ?? [], | ||
| role: userDetails?.role.id ?? '', | ||
| avatar: userDetails?.avatar?.data, | ||
| signature: userDetails?.signature?.data, | ||
| primaryOfficeId: primaryOfficeId ?? '', | ||
| fullHonorificName: userDetails?.fullHonorificName, | ||
| device: userDetails?.device, | ||
| type: 'user' as const, | ||
| district: districtId, | ||
| province: provinceId | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
This PR has been marked with label stale Since it has been inactive for 20 days. It will automatically be closed in 10 days if no further activity occurs. |
NAME fields couldn't resolve user template variables, causing errors when attempting to pre-populate informant names with logged-in user data. TEXT fields also lacked access to user fields like
fullHonorificNameanddevice.Changes
Type system updates
Usertype: Addeddevicefield to support device information pre-populationSystemVariables: Changed$userfrom ad-hoc structure to properUsertypeNew
user()functionCreated type-safe accessor for user fields, replacing deprecated
$user.*string templates:Supports:
name,fullHonorificName,device,province,districtTemplate resolution
replacePlaceholders: Added conversion fromUser.nameformat ({use, given: [], family}) toNameFieldValue({firstname, surname, middlename}) for NAME fields$user.*syntax is detectedHook updates
useUserDetails: Returns completeUserstructure matchingSystemVariables['$user']type instead of partial fieldsExample
Previously failed with "Could not resolve NAME":
Now works:
Original prompt
This section details on the original issue you should resolve
<issue_title>It isnt possible to pre-populate user's name into informant name field</issue_title>
<issue_description>In Uganda, it is a requirement to pre-populate the logged in user's name into the informant's name field.
You can do this in a FieldType.TEXT component:
But you cannot do this in a FieldType.NAME component:
Tech design
It needs to be possible to use user serialiser as part of a name field default value
This should internally translate to a
{firstname: <user's firstname>, surname: '<user's surname>'}so a name field compatible value. The correct place to do this is insidehandleDefaultValue.Also make it so
SystemVariables.$useris not a new arbitrary user type but instead is of typeUserfrom packages/commons/src/users/User.ts.User's name is represented as:
This value should only be converted to the name input value inside
handleDefaultValueand should always be kept as the original structure for as long as possible.Tech tasks
user('name')toNAMEfield value prefils the input properlyuser('fullHonorificName')anduser('device')can both be used as a default value forTEXTtype field</issue_description>
Comments on the Issue (you are @copilot in this section)
@prinzab @euanmillar Note that this behaviour isn't always required. It is only needed when it's HFA / Field Agent type. @SyedaAfrida @rikukissa @Alta-Nel @jpye-finch needs to come up with proper design before we assign any milestone @rikukissa @SyedaAfrida tech design is now done for this item @euanmillar @rikukissa Uganda also use cases to pre-pop with more user information. Ideally Uganda would configure the information they need for the user in this form but it isnt configurable so I am trying to make do with what we have. Maybe they could re-purpose the "Full Honorific Name" and potentially also the "Device" field available in the user form. Is there any way the tech design can include all the fields in the create user form? We could then play with labels to hack a solution that satisfies them to some degree.I'm also noticing here that
devicefield needs to be exposed. Repurposing it for some other use case should be perfectly fine, same withfullHonorificNameif it's not used in the certificate. I'll update the design.For 2.x we should consider adding a customisable section of additional fields to the user form as it seems to be a common request.</comment_new>
<comment_new>@euanmillar
Thanks Riku. That would be wonderful. Some of those fields may exist in the main declaration form so if the same ids can be used it is clearer what can pre-pop. For example, if the user was based in a health institution, the place of birth location could be pre-populated. That is anoth...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.