Browse Source

refactor: renaming variables

percentOption -> precision
allowNegativeNumber -> negative
defaultNumber -> default
test/percent
Wing-Kam Wong 2 years ago
parent
commit
1d515ad40a
  1. 4
      packages/nc-gui/components/project/spreadsheet/components/EditColumn.vue
  2. 6
      packages/nc-gui/components/project/spreadsheet/components/cell/PercentCell.vue
  3. 20
      packages/nc-gui/components/project/spreadsheet/components/editColumn/PercentOptions.vue
  4. 8
      packages/nc-gui/components/project/spreadsheet/components/editableCell/PercentCell.vue
  5. 10
      packages/nc-gui/helpers/percentHelper.js
  6. 4
      packages/nocodb/src/lib/meta/api/sync/helpers/job.ts

4
packages/nc-gui/components/project/spreadsheet/components/EditColumn.vue

@ -637,8 +637,8 @@ export default {
// return this.$toast.info('Coming Soon...').goAway(3000) // return this.$toast.info('Coming Soon...').goAway(3000)
} }
if (this.newColumn.uidt === UITypes.Percent && this.newColumn?.meta?.defaultNumber) { if (this.newColumn.uidt === UITypes.Percent && this.newColumn?.meta?.default) {
this.newColumn.cdf = Number(this.newColumn?.meta?.defaultNumber) / 100; this.newColumn.cdf = Number(this.newColumn?.meta?.default) / 100;
} }
if (this.isLinkToAnotherRecord && this.$refs.relation) { if (this.isLinkToAnotherRecord && this.$refs.relation) {

6
packages/nc-gui/components/project/spreadsheet/components/cell/PercentCell.vue

@ -16,17 +16,17 @@ export default {
}), }),
computed: {}, computed: {},
watch: { watch: {
'column.meta.percentOption'(newValue, oldValue) { 'column.meta.precision'(newValue, oldValue) {
if (oldValue !== newValue) { if (oldValue !== newValue) {
this.localValue = renderPercent(this.value, newValue); this.localValue = renderPercent(this.value, newValue);
} }
}, },
value(val, oldVal) { value(val, oldVal) {
this.localValue = renderPercent(val, this.column?.meta?.percentOption || 0); this.localValue = renderPercent(val, this.column?.meta?.precision || 0);
}, },
}, },
created() { created() {
this.localValue = renderPercent(this.value, this.column?.meta?.percentOption || 0); this.localValue = renderPercent(this.value, this.column?.meta?.precision || 0);
}, },
methods: {}, methods: {},
}; };

20
packages/nc-gui/components/project/spreadsheet/components/editColumn/PercentOptions.vue

@ -3,7 +3,7 @@
<v-row class="percent-wrapper"> <v-row class="percent-wrapper">
<!-- TODO: i18n --> <!-- TODO: i18n -->
<v-autocomplete <v-autocomplete
v-model="colMeta.percentOption" v-model="colMeta.precision"
hide-details hide-details
class="caption ui-type nc-ui-dt-dropdown" class="caption ui-type nc-ui-dt-dropdown"
label="Precision" label="Precision"
@ -11,7 +11,7 @@
outlined outlined
item-value="id" item-value="id"
item-text="title" item-text="title"
:items="percentOptionsList" :items="precisionsList"
> >
<template #selection="{ item }"> <template #selection="{ item }">
<div> <div>
@ -27,7 +27,7 @@
</template> </template>
</v-autocomplete> </v-autocomplete>
<v-text-field <v-text-field
v-model="colMeta.defaultNumber" v-model="colMeta.default"
type="number" type="number"
hide-details="auto" hide-details="auto"
color="primary" color="primary"
@ -38,7 +38,7 @@
/> />
</v-row> </v-row>
<v-row class="percent-switch-wrapper"> <v-row class="percent-switch-wrapper">
<v-switch v-model="colMeta.allowNegativeNumber" dense> <v-switch v-model="colMeta.negative" dense>
<template #label> <template #label>
<span> <span>
<!-- TODO: i18n --> <!-- TODO: i18n -->
@ -51,20 +51,20 @@
</template> </template>
<script> <script>
import { percentOptions } from '~/helpers/percentHelper'; import { precisions } from '~/helpers/percentHelper';
export default { export default {
name: 'PercentOptions', name: 'precisions',
props: ['column', 'meta', 'value'], props: ['column', 'meta', 'value'],
data: () => ({ data: () => ({
percentOptionsList: percentOptions.map(o => ({ precisionsList: precisions.map(o => ({
...o, ...o,
title: o.title, title: o.title,
})), })),
colMeta: { colMeta: {
percentOption: 0, precision: 0,
allowNegativeNumber: false, negative: false,
defaultNumber: null, default: null,
}, },
}), }),
watch: { watch: {

8
packages/nc-gui/components/project/spreadsheet/components/editableCell/PercentCell.vue

@ -43,13 +43,13 @@ export default {
if (val === null) { if (val === null) {
val = 0; val = 0;
} }
if (isValidPercent(val, this.column?.meta?.allowNegativeNumber)) { if (isValidPercent(val, this.column?.meta?.negative)) {
this.percent = val / 100; this.percent = val / 100;
} }
}, },
}, },
percentType() { percentType() {
return this.column?.meta?.percentOption || 0; return this.column?.meta?.precision || 0;
}, },
parentListeners() { parentListeners() {
const $listeners = {}; const $listeners = {};
@ -82,7 +82,7 @@ export default {
const CAPTIAL_LETTER_E = charCode === 69; const CAPTIAL_LETTER_E = charCode === 69;
const SMALL_LETTER_E = charCode === 101; const SMALL_LETTER_E = charCode === 101;
const NEGATIVE_SIGN = charCode === 45; const NEGATIVE_SIGN = charCode === 45;
const NEGATIVE_SIGN_INVALID = !this.column?.meta?.allowNegativeNumber && NEGATIVE_SIGN; const NEGATIVE_SIGN_INVALID = !this.column?.meta?.negative && NEGATIVE_SIGN;
if (NEGATIVE_SIGN_INVALID) { if (NEGATIVE_SIGN_INVALID) {
this.warningMessage = 'Negative Number is not allowed. Please configure it in Column setting.'; this.warningMessage = 'Negative Number is not allowed. Please configure it in Column setting.';
evt.preventDefault(); evt.preventDefault();
@ -98,7 +98,7 @@ export default {
// only allow: // only allow:
// 1. digits // 1. digits
// 2. '.' // 2. '.'
// 3. '-' if this.column?.meta?.allowNegativeNumber is true // 3. '-' if this.column?.meta?.negative is true
return true; return true;
} }
}, },

10
packages/nc-gui/helpers/percentHelper.js

@ -1,4 +1,4 @@
export const percentOptions = [ export const precisions = [
{ id: 0, title: '1' }, { id: 0, title: '1' },
{ id: 1, title: '1.0' }, { id: 1, title: '1.0' },
{ id: 2, title: '1.00' }, { id: 2, title: '1.00' },
@ -10,15 +10,15 @@ export const percentOptions = [
{ id: 8, title: '1.00000000' } { id: 8, title: '1.00000000' }
] ]
export const renderPercent = (value, percentOption, withPercentSymbol = true) => { export const renderPercent = (value, precision, withPercentSymbol = true) => {
if (!value) { return value } if (!value) { return value }
value = (Number(value) * 100).toFixed(percentOption) value = (Number(value) * 100).toFixed(precision)
if (withPercentSymbol) { return padPercentSymbol(value) } if (withPercentSymbol) { return padPercentSymbol(value) }
return value return value
} }
export const isValidPercent = (val, allowNegativeNumber) => { export const isValidPercent = (val, negative) => {
if (allowNegativeNumber) { return /^-?\d{1,20}(\.\d+)?$/.test(val) } if (negative) { return /^-?\d{1,20}(\.\d+)?$/.test(val) }
return /^\d{1,20}(\.\d+)?$/.test(val) return /^\d{1,20}(\.\d+)?$/.test(val)
} }

4
packages/nocodb/src/lib/meta/api/sync/helpers/job.ts

@ -405,8 +405,8 @@ export default async (
return { return {
type: UITypes.Percent, type: UITypes.Percent,
data: { data: {
percentOption: col.typeOptions?.precision, precision: col.typeOptions?.precision,
allowNegativeNumber: col.typeOptions?.negative, negative: col.typeOptions?.negative,
}, },
}; };
return { type: undefined }; return { type: undefined };

Loading…
Cancel
Save