Skip to content
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

fix(secondary school): Get rid of custom component for SchoolSelection #17882

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

johannaagma
Copy link
Member

@johannaagma johannaagma commented Feb 7, 2025

What

The custom component to select school + programs for the application Secondary School is a bit unreadable because it is doing a bunch of stuff and very conditioned, which makes it hard to maintain. Also, that custom component was only approved by Norda with the condition that it would be fixed into regular form field after the 1. feb release).
Had to change the RepeaterItem in Fields a bit, to be able to handle all conditions/updates that are necessary for that form field.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Warning

Rate limit exceeded

@johannaagma has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 562f106 and 656d4ae.

📒 Files selected for processing (24)
  • libs/application/template-api-modules/src/lib/modules/templates/secondary-school/utils.ts (1 hunks)
  • libs/application/templates/new-primary-school/src/forms/NewPrimarySchoolForm/differentNeedsSection/languageSubSection.ts (1 hunks)
  • libs/application/templates/secondary-school/src/fields/index.ts (0 hunks)
  • libs/application/templates/secondary-school/src/fields/overview/SchoolSelectionOverview.tsx (3 hunks)
  • libs/application/templates/secondary-school/src/fields/schoolSelection/SelectionItem.tsx (0 hunks)
  • libs/application/templates/secondary-school/src/fields/schoolSelection/index.tsx (0 hunks)
  • libs/application/templates/secondary-school/src/forms/secondarySchoolForm/schoolSection/index.ts (2 hunks)
  • libs/application/templates/secondary-school/src/graphql/queries.ts (1 hunks)
  • libs/application/templates/secondary-school/src/lib/dataSchema.ts (4 hunks)
  • libs/application/templates/secondary-school/src/lib/messages/error.ts (1 hunks)
  • libs/application/templates/secondary-school/src/lib/messages/school.ts (0 hunks)
  • libs/application/templates/secondary-school/src/utils/format.ts (1 hunks)
  • libs/application/templates/secondary-school/src/utils/getDate.ts (1 hunks)
  • libs/application/templates/secondary-school/src/utils/index.ts (1 hunks)
  • libs/application/templates/secondary-school/src/utils/schoolSelection.ts (1 hunks)
  • libs/application/types/src/lib/Fields.ts (9 hunks)
  • libs/application/ui-fields/src/lib/AsyncSelectFormField/AsyncSelectFormField.tsx (3 hunks)
  • libs/application/ui-fields/src/lib/FieldsRepeaterFormField/FieldsRepeaterFormField.tsx (4 hunks)
  • libs/application/ui-fields/src/lib/FieldsRepeaterFormField/FieldsRepeaterItem.tsx (9 hunks)
  • libs/application/ui-fields/src/lib/TableRepeaterFormField/TableRepeaterItem.tsx (9 hunks)
  • libs/shared/form-fields/src/lib/SelectController/SelectController.tsx (4 hunks)
  • libs/shared/utils/src/index.ts (1 hunks)
  • libs/shared/utils/src/lib/setInputsOnChange.spec.ts (1 hunks)
  • libs/shared/utils/src/lib/setInputsOnChange.ts (1 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Feb 7, 2025

View your CI Pipeline Execution ↗ for commit 656d4ae.

Command Status Duration Result
nx run-many --projects judicial-system-backend ... ✅ Succeeded 22m 52s View ↗
nx run-many --projects application-system-api -... ✅ Succeeded 21m 4s View ↗
nx run-many --projects application-api-core,app... ✅ Succeeded 21m 12s View ↗
nx run-many --target=build --projects=web --par... ✅ Succeeded 18m 33s View ↗
nx run-many --projects services-auth-admin-api ... ✅ Succeeded 10m 44s View ↗
nx run-many --projects services-auth-delegation... ✅ Succeeded 10m 6s View ↗
nx run-many --projects api,api-consultation-por... ✅ Succeeded 11m 9s View ↗
nx run-many --projects clients-administration-o... ✅ Succeeded 10m 47s View ↗
Additional runs (55) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-14 11:31:44 UTC

@@ -98,32 +105,26 @@ export type RepeaterItem = {
emailLabel?: StaticText
placeholder?: StaticText
options?: TableRepeaterOptions
filterOptions?: (
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: I need this to filter out schoolIds selected in other selections, and in the options field we only have access to application (not updated answers) and activeField (updated answers, but only for the index you are working with - I need to look at all other indexes).
Not sure if I should've added this optional filterOptions field, or if I should add index + (updated)answers in TableRepeaterOptions

@@ -139,6 +143,15 @@ export const SelectController = <Value, IsMulti extends boolean = false>({
if (isClearable && newVal === null) {
clearInputsOnChange([id], setValue)
}

if (setOnChange) {
Copy link
Member Author

Choose a reason for hiding this comment

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

If this change makes sense, then maybe I should add to: CheckboxController, DatePickerController, InputController, PhoneInputController and RadioController (same places where clearInputsOnChange was added)

Copy link
Member

Choose a reason for hiding this comment

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

Lets start with the select an see the need for it

@johannaagma johannaagma marked this pull request as ready for review February 14, 2025 10:48
@johannaagma johannaagma requested review from a team as code owners February 14, 2025 10:48
@johannaagma johannaagma requested a review from snaerth February 14, 2025 10:48
Comment on lines +40 to +45
formTitle: (index) => {
if (index === 0) return school.firstSelection.subtitle
else if (index === 1) return school.secondSelection.subtitle
else if (index === 2) return school.thirdSelection.subtitle
return ''
},
Copy link
Member

Choose a reason for hiding this comment

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

This file is 400 lines, so I would suggest to extract as much as possible to util functions so we don't loos the readability of the file.

Comment on lines +60 to +79
options: (application) => {
const schoolOptions = getValueViaPath<SecondarySchool[]>(
application.externalData,
'schools.data',
)
const isFreshman = checkIsFreshman(application.answers)

return (schoolOptions || [])
.filter((x) =>
isFreshman
? x.isOpenForAdmissionFreshman
: x.isOpenForAdmissionGeneral,
)
.map((school) => {
return {
label: school.name,
value: school.id,
}
})
},
Copy link
Member

Choose a reason for hiding this comment

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

Extract to a util function

Comment on lines +80 to +83
filterOptions: (options, answers, index) => {
const otherSchoolIds = getOtherSchoolIds(answers, index)
return options.filter((x) => !otherSchoolIds.includes(x.value))
},
Copy link
Member

Choose a reason for hiding this comment

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

I would probably extract this even though it's short...

Comment on lines +92 to +109
setOnChange: (option, application, index) => {
const schoolOptions = getValueViaPath<SecondarySchool[]>(
application.externalData,
'schools.data',
)
const selectedSchool = schoolOptions?.find(
(x) => x.id === option.value,
)

return [
{
key: `selection[${index}].school.name`,
value: selectedSchool?.name,
},
{ key: `selection[${index}].requestDormitory`, value: [] }, // clear answer
]
},
},
Copy link
Member

Choose a reason for hiding this comment

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

Extract to a util function

Comment on lines +118 to +166
loadOptions: async (
{ apolloClient, application },
lang,
activeField,
setValueAtIndex,
) => {
const schoolId =
activeField &&
getValueViaPath<string>(activeField, 'school.id')
const secondProgramId =
activeField &&
getValueViaPath<string>(activeField, 'secondProgram.id')

if (schoolId) {
const { data } = await apolloClient.query<
Query,
QuerySecondarySchoolProgramsBySchoolIdArgs
>({
query: PROGRAMS_BY_SCHOOLS_ID_QUERY,
variables: {
isFreshman: checkIsFreshman(application.answers),
schoolId,
},
})

setValueAtIndex?.(
'programOptions',
data?.secondarySchoolProgramsBySchoolId,
)

setValueAtIndex?.(
'secondProgram.include',
data?.secondarySchoolProgramsBySchoolId.length > 1,
)

const options =
data?.secondarySchoolProgramsBySchoolId?.map((program) => ({
value: program.id,
label: getTranslatedProgram(lang, {
nameIs: program.nameIs,
nameEn: program.nameEn,
}),
})) ?? []

return options.filter((x) => x.value !== secondProgramId)
}

return []
},
Copy link
Member

Choose a reason for hiding this comment

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

Extract to a util function

} else {
IsClearable = isClearable
}

let DefaultValue: any
Copy link
Member

Choose a reason for hiding this comment

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

Capitalized is reserved for React components or types

@@ -188,6 +201,20 @@ export const Item = ({
Disabled = disabled
}

let Required: boolean | undefined
Copy link
Member

Choose a reason for hiding this comment

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

Capitalized is reserved for React components or types

@@ -213,6 +240,23 @@ export const Item = ({
getDefaultValue(item, application, activeValues)
}

let ClearOnChange: string[] | undefined
Copy link
Member

Choose a reason for hiding this comment

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

Capitalized is reserved for React components or types

ClearOnChange = clearOnChange
}

const SetOnChange =
Copy link
Member

Choose a reason for hiding this comment

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

Capitalized is reserved for React components or types

@@ -139,6 +143,15 @@ export const SelectController = <Value, IsMulti extends boolean = false>({
if (isClearable && newVal === null) {
clearInputsOnChange([id], setValue)
}

if (setOnChange) {
Copy link
Member

Choose a reason for hiding this comment

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

Lets start with the select an see the need for it

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.

4 participants