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-add initial value prop #255

Merged
merged 2 commits into from
May 10, 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
9 changes: 9 additions & 0 deletions src/components/jurisdiction/Jurisdiction.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ export const Default = Template.bind({})
Default['args'] = {
showUsaJurisdictions: false
}

export const JurisdictionInitialValue = Template.bind({})
JurisdictionInitialValue['args'] = {
showUsaJurisdictions: false,
initialValue: {
Copy link
Collaborator

@JazzarKarim JazzarKarim May 9, 2024

Choose a reason for hiding this comment

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

Wait, so I see below the type of this prop is a string while here it's an object?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

looking into it....

country: 'CA',
region: 'FD'
}
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
}
50 changes: 48 additions & 2 deletions src/components/jurisdiction/Jurisdiction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,69 @@
</template>

<script lang="ts">
import { Component, Emit, Prop, Vue } from 'vue-property-decorator'
import { Component, Emit, Mixins, Prop } from 'vue-property-decorator'
import NestedSelect from './NestedSelect.vue'
import { JurisdictionLocation } from '@bcrs-shared-components/enums'
import { ForeignJurisdictionIF } from '@bcrs-shared-components/interfaces'
import { CountriesProvincesMixin } from '@bcrs-shared-components/mixins'
import { CanJurisdictions, IntlJurisdictions, UsaJurisdiction } from './list-data'

@Component({
components: { NestedSelect }
})
export default class Jurisdiction extends Vue {
export default class Jurisdiction extends Mixins(CountriesProvincesMixin) {
// props
@Prop({ default: 'Select the home jurisdiction' }) readonly label!: string
@Prop() readonly errorMessages!: string
@Prop({ default: false }) readonly showUsaJurisdictions!: boolean
@Prop({ default: null }) readonly initialValue!: ForeignJurisdictionIF[]

// variables
jurisdiction = null

/** Called when component is created. */
created (): void {
if (this.initialValue) {
this.setInitialValue()
}
}

/** Set initial value of jurisdiction */
setInitialValue (): void {
let jurisdictionGroup
let jurisdictionValue = ''
let jurisdictionText = ''

const initialJurValue = this.initialValue as ForeignJurisdictionIF
const country = initialJurValue.country
const region = initialJurValue.region ? initialJurValue.region : ''

if (country === JurisdictionLocation.CA) {
jurisdictionGroup = 0
} else if (country === JurisdictionLocation.US) {
jurisdictionGroup = 1
} else {
jurisdictionGroup = 2
}

if (region) {
if (region === JurisdictionLocation.FD) {
jurisdictionText = 'Federal'
} else {
let regions = this.getCountryRegions(country) as any[]
jurisdictionText = regions.find(p => p.short === region).name
}
} else {
jurisdictionText = this.getCountryName(country)
}

this.jurisdiction = {
group: jurisdictionGroup,
text: jurisdictionText,
value: jurisdictionValue
}
}

/** The jursidiction select options */
get jurisdictionOptions (): Array<any> {
const array = [] as Array<any>
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/foreign-jurisdiction-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* See:
* https://github.com/bcgov/business-schemas/blob/main/src/registry_schemas/schemas/foreign_jurisdiction.json
*/
export interface ForeignJurisdictionIF {
country: string
region?: string
}
Loading