Browse Source

Merge pull request #2257 from nocodb/fix/2255-pg-money

fix: pg money database type handling on currency column
pull/2326/head
mertmit 3 years ago committed by GitHub
parent
commit
d6b019883b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      packages/nc-gui/components/project/spreadsheet/components/cell/CurrencyCell.vue
  2. 77
      packages/nc-gui/components/project/spreadsheet/components/editColumn/CurrencyOptions.vue

7
packages/nc-gui/components/project/spreadsheet/components/cell/CurrencyCell.vue

@ -13,8 +13,11 @@ export default {
computed: {
currency() {
try {
return new Intl.NumberFormat(this.currencyMeta.currency_locale || 'en-US',
{ style: 'currency', currency: this.currencyMeta.currency_code || 'USD' }).format(this.value)
return isNaN(this.value)
? this.value
: new Intl.NumberFormat(this.currencyMeta.currency_locale || 'en-US',
{ style: 'currency', currency: this.currencyMeta.currency_code || 'USD' })
.format(this.value)
} catch (e) {
return this.value
}

77
packages/nc-gui/components/project/spreadsheet/components/editColumn/CurrencyOptions.vue

@ -1,32 +1,39 @@
<template>
<v-row class="currency-wrapper">
<v-col cols="6">
<!--label="Format Locale"-->
<v-autocomplete
v-model="colMeta.currency_locale"
dense
class="caption"
label="Currency Locale"
:rules="[isValidCurrencyLocale]"
:items="currencyLocaleList"
outlined
hide-details
/>
</v-col>
<v-col cols="6">
<!--label="Currency Code"-->
<v-autocomplete
v-model="colMeta.currency_code"
dense
class="caption"
label="Currency Code"
:rules="[isValidCurrencyCode]"
:items="currencyList"
outlined
hide-details
/>
</v-col>
</v-row>
<v-tooltip top :disabled="!(isMoney && isPG)">
<template #activator="{ on, attrs }">
<v-row class="currency-wrapper" v-bind="attrs" v-on="on">
<v-col cols="6">
<!--label="Format Locale"-->
<v-autocomplete
v-model="colMeta.currency_locale"
dense
class="caption"
label="Currency Locale"
:rules="[isValidCurrencyLocale]"
:items="currencyLocaleList"
outlined
hide-details
:disabled="isMoney && isPG"
/>
</v-col>
<v-col cols="6">
<!--label="Currency Code"-->
<v-autocomplete
v-model="colMeta.currency_code"
dense
class="caption"
label="Currency Code"
:rules="[isValidCurrencyCode]"
:items="currencyList"
outlined
hide-details
:disabled="isMoney && isPG"
/>
</v-col>
</v-row>
</template>
<span>{{ message }}</span>
</v-tooltip>
</template>
<script>
@ -49,6 +56,20 @@ export default {
return validateCurrencyCode(value) || 'Invalid Currency Code'
}
}),
computed: {
isMoney() {
return this.column.dt === 'money'
},
isPG() {
return ['pg'].includes(this.$store.getters['project/GtrClientType'])
},
message() {
if (this.isMoney && this.isPG) {
return "PostgreSQL 'money' type has own currency settings"
}
return ''
}
},
watch: {
value() {
this.colMeta = this.value || {}

Loading…
Cancel
Save