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

20989 - Exclude USA conditionally #254

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/jurisdiction/Jurisdiction.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ const Template = (args, { argTypes }) => ({

export const Default = Template.bind({})
Default['args'] = {
showUsJurisdictions: false
showUsaJurisdictions: false
}
23 changes: 20 additions & 3 deletions src/components/jurisdiction/Jurisdiction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class Jurisdiction extends Vue {
// props
@Prop({ default: 'Select the home jurisdiction' }) readonly label!: string
@Prop() readonly errorMessages!: string
@Prop({ default: false }) readonly showUsJurisdictions!: boolean
@Prop({ default: false }) readonly showUsaJurisdictions!: boolean

// variables
jurisdiction = null
Expand All @@ -42,7 +42,8 @@ export default class Jurisdiction extends Vue {
separator: (jur.value === JurisdictionLocation.FD)
}))

if (this.showUsJurisdictions) {
// add USA jurisdictions (conditionally)
if (this.showUsaJurisdictions) {
array.push({ isHeader: true, group: 1, text: 'United States' })
UsaJurisdiction
.forEach(jur => array.push({
Expand All @@ -56,7 +57,7 @@ export default class Jurisdiction extends Vue {
// add in International jurisdictions (not including CA)
array.push({ isHeader: true, group: 2, text: 'International' })
IntlJurisdictions
.filter(jur => jur.value !== JurisdictionLocation.CA)
.filter(jur => this.excludeJurisdictions(jur.value))
.forEach(jur => array.push({
group: 2,
text: jur.text,
Expand All @@ -67,6 +68,22 @@ export default class Jurisdiction extends Vue {
return array
}

/**
* Always exclude CA
* Exclude USA when states are listed in the jurisdiction list based on showUsaJurisdictions flag
*/
excludeJurisdictions (jurisdiction): boolean {
if (jurisdiction === JurisdictionLocation.CA) {
return false
}

if (this.showUsaJurisdictions && (jurisdiction === JurisdictionLocation.US)) {
return false
}

return true
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whoa, this gets called for every item in the Intl list. And it does a lot of work.

Try something simpler.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you only need a simple conditional here that returns False if filter should exclude it, else True.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good.


@Emit('change')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
emitChangeEvent (jurisdiction: any): void {}
Expand Down
Loading