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)
}
if (this.newColumn.uidt === UITypes.Percent && this.newColumn?.meta?.defaultNumber) {
this.newColumn.cdf = Number(this.newColumn?.meta?.defaultNumber) / 100;
if (this.newColumn.uidt === UITypes.Percent && this.newColumn?.meta?.default) {
this.newColumn.cdf = Number(this.newColumn?.meta?.default) / 100;
}
if (this.isLinkToAnotherRecord && this.$refs.relation) {

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

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

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

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

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

@ -43,13 +43,13 @@ export default {
if (val === null) {
val = 0;
}
if (isValidPercent(val, this.column?.meta?.allowNegativeNumber)) {
if (isValidPercent(val, this.column?.meta?.negative)) {
this.percent = val / 100;
}
},
},
percentType() {
return this.column?.meta?.percentOption || 0;
return this.column?.meta?.precision || 0;
},
parentListeners() {
const $listeners = {};
@ -82,7 +82,7 @@ export default {
const CAPTIAL_LETTER_E = charCode === 69;
const SMALL_LETTER_E = charCode === 101;
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) {
this.warningMessage = 'Negative Number is not allowed. Please configure it in Column setting.';
evt.preventDefault();
@ -98,7 +98,7 @@ export default {
// only allow:
// 1. digits
// 2. '.'
// 3. '-' if this.column?.meta?.allowNegativeNumber is true
// 3. '-' if this.column?.meta?.negative is 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: 1, title: '1.0' },
{ id: 2, title: '1.00' },
@ -10,15 +10,15 @@ export const percentOptions = [
{ id: 8, title: '1.00000000' }
]
export const renderPercent = (value, percentOption, withPercentSymbol = true) => {
export const renderPercent = (value, precision, withPercentSymbol = true) => {
if (!value) { return value }
value = (Number(value) * 100).toFixed(percentOption)
value = (Number(value) * 100).toFixed(precision)
if (withPercentSymbol) { return padPercentSymbol(value) }
return value
}
export const isValidPercent = (val, allowNegativeNumber) => {
if (allowNegativeNumber) { return /^-?\d{1,20}(\.\d+)?$/.test(val) }
export const isValidPercent = (val, negative) => {
if (negative) { 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 {
type: UITypes.Percent,
data: {
percentOption: col.typeOptions?.precision,
allowNegativeNumber: col.typeOptions?.negative,
precision: col.typeOptions?.precision,
negative: col.typeOptions?.negative,
},
};
return { type: undefined };

Loading…
Cancel
Save