Skip to content

Conversation

@tahmidrahman-dsi
Copy link
Contributor

@tahmidrahman-dsi tahmidrahman-dsi commented Nov 17, 2025

To use conditionals like: event.hasAction(ActionType.DECLARE) in forms and review pages

@github-actions

This comment has been minimized.

@euanmillar
Copy link
Contributor

@tahmidrahman-dsi can you tell me, what git issue is this related to and what release please?

@tahmidrahman-dsi
Copy link
Contributor Author

@tahmidrahman-dsi can you tell me, what git issue is this related to and what release please?

@euanmillar I dont think there is a ticket yet. As part of my farajaland configuration work, I had to configure ALPHA_PRINT_BUTTON so that it can only be visible for a Registrar first creating a declaration (that means using conditionals like not(event.hasAction(ActionType.DECLARE)). But it appeared that the conditional did not work for the form fields and only worked when serving certificates

Copy link
Contributor

@makelicious makelicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write a test case for the form and to conditionals that uses this. Otherwise we don't know if it breaks again.

@euanmillar
Copy link
Contributor

@tahmidrahman-dsi @makelicious it turns out that Madagascar also require this. I guess it could be triaged into 1.9.2 scope to ensure it makes it into the "to be created" release-v1.9.2 branch? But we need an associated issue. FYI @SyedaAfrida @ThierryMyshepherd @pankaj-pant @Zangetsu101 @rikukissa Can you create one? I'm just passing on information here and dont know the specifics

setFormData={(data) => setFormValues(data)}
showReviewButton={searchParams.from === 'review'}
validatorContext={validatorContext}
validatorContext={{ ...validatorContext, event }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed if you already are passing event in useValidatorContext, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, good catch, thanks @pankaj-pant ! forgot to update this, I will do it

@rikukissa
Copy link
Member

@SyedaAfrida
Copy link

#11074

Copy link
Contributor

@makelicious makelicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write a test case for the form and to conditionals that uses this. Otherwise we don't know if it breaks again.

]}
id="my-form"
validatorContext={getTestValidatorContext()}
onChange={() => noop()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might just pass args since you define them above args: { onChange: fn() },

msw: {
handlers: {
event: [
tRPCMsw.event.config.get.query(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might not need this? By default, mocks come from packages/client/.storybook/default-request-handlers.ts

const StyledFormFieldGenerator = styled(FormFieldGenerator)`
width: 400px;
`
export const Default: StoryObj<typeof FormFieldGenerator> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not have any interaction. Consider separate file if needed.

import { getTestValidatorContext } from '../../../../../.storybook/decorators'

const meta: Meta<typeof FormFieldGenerator> = {
title: 'Inputs/AlphaPrintButton',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider separating interaction tests from others. e.g.

const meta: Meta<typeof Pages> = {
  title: 'Declare/Interaction',

parameters: {
reactRouter: {
router: {
path: ROUTES.V2.EVENTS.DECLARE.REVIEW.buildPath({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might not need this? could you define the parameters under meta if they are all the same

role: TestUserRole
fullEvent: EventDocument
}> = {
parameters: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by giving userRole: estUserRole.Enum.LOCAL_REGISTRAR mocks the endpoints and makes it explicit what you are testing against. It defaults to Registration Agent, that's why it works.

@tahmidrahman-dsi tahmidrahman-dsi changed the base branch from develop to release-v1.9.2 November 26, 2025 09:15
const StyledFormFieldGenerator = styled(FormFieldGenerator)`
width: 400px;
`
function createAlphaPrintButtonStoryParameters(
Copy link
Contributor Author

@tahmidrahman-dsi tahmidrahman-dsi Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makelicious @Zangetsu101 I wanted to render FormFieldGenerator with different conditional and validatorContext. But could not work it out.
This is as far as I could go to make the tests functional, now tests run fine. But wonder if there is a more storybook way of doing it

@ocrvs-bot
Copy link
Contributor

Your environment is deployed to https://fixpass-event-document-to-cond.e2e-k8s.opencrvs.dev

@tahmidrahman-dsi tahmidrahman-dsi changed the base branch from release-v1.9.2 to release-v1.9.3 December 9, 2025 13:40
Copy link
Contributor

@Zangetsu101 Zangetsu101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Let's just show this in action by using it for some field (or a new field) in tennis club membership event

@tahmidrahman-dsi tahmidrahman-dsi merged commit 1cf6bbd into release-v1.9.3 Dec 12, 2025
79 of 83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow event.hasAction helper to be used in field conditionals

9 participants