Skip to content

Commit

Permalink
20989-add initial value prop (#255)
Browse files Browse the repository at this point in the history
* 20989-add initial value prop

* 20989-update logic
  • Loading branch information
ketaki-deodhar authored May 10, 2024
1 parent 287bcdd commit 83b5fc2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
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: {
country: 'CA',
region: 'FD'
}
}
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
}

0 comments on commit 83b5fc2

Please sign in to comment.