From 8b03dfa96b360f3079b11833a79a789dd188640d Mon Sep 17 00:00:00 2001 From: chenos Date: Sat, 24 Jun 2023 17:15:59 +0800 Subject: [PATCH] fix(input-number): change step to 1 (#2104) --- .../collection-manager/interfaces/integer.ts | 2 +- .../collection-manager/interfaces/number.ts | 6 +-- .../collection-manager/interfaces/percent.ts | 6 +-- .../migrations/20230623145414-number-step.ts | 44 +++++++++++++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 packages/plugins/collection-manager/src/migrations/20230623145414-number-step.ts diff --git a/packages/core/client/src/collection-manager/interfaces/integer.ts b/packages/core/client/src/collection-manager/interfaces/integer.ts index 5267d6ec6..baf8c32c9 100644 --- a/packages/core/client/src/collection-manager/interfaces/integer.ts +++ b/packages/core/client/src/collection-manager/interfaces/integer.ts @@ -24,7 +24,7 @@ export const integer: IField = { 'x-component': 'InputNumber', 'x-component-props': { stringMode: true, - step: '0', + step: '1', }, 'x-validator': 'integer', }, diff --git a/packages/core/client/src/collection-manager/interfaces/number.ts b/packages/core/client/src/collection-manager/interfaces/number.ts index 73d61a98f..525dc17d8 100644 --- a/packages/core/client/src/collection-manager/interfaces/number.ts +++ b/packages/core/client/src/collection-manager/interfaces/number.ts @@ -18,7 +18,7 @@ export const number: IField = { 'x-component': 'InputNumber', 'x-component-props': { stringMode: true, - step: '0', + step: '1', }, }, }, @@ -32,9 +32,9 @@ export const number: IField = { title: '{{t("Precision")}}', 'x-component': 'Select', 'x-decorator': 'FormItem', - default: '0', + default: '1', enum: [ - { value: '0', label: '1' }, + { value: '1', label: '1' }, { value: '0.1', label: '1.0' }, { value: '0.01', label: '1.00' }, { value: '0.001', label: '1.000' }, diff --git a/packages/core/client/src/collection-manager/interfaces/percent.ts b/packages/core/client/src/collection-manager/interfaces/percent.ts index 35d42452f..38e316ecd 100644 --- a/packages/core/client/src/collection-manager/interfaces/percent.ts +++ b/packages/core/client/src/collection-manager/interfaces/percent.ts @@ -63,7 +63,7 @@ export const percent: IField = { 'x-component': 'Percent', 'x-component-props': { stringMode: true, - step: '0', + step: '1', addonAfter: '%', }, }, @@ -85,9 +85,9 @@ export const percent: IField = { title: '{{t("Precision")}}', 'x-component': 'Select', 'x-decorator': 'FormItem', - default: '0', + default: '1', enum: [ - { value: '0', label: '1%' }, + { value: '1', label: '1%' }, { value: '0.1', label: '1.0%' }, { value: '0.01', label: '1.00%' }, { value: '0.001', label: '1.000%' }, diff --git a/packages/plugins/collection-manager/src/migrations/20230623145414-number-step.ts b/packages/plugins/collection-manager/src/migrations/20230623145414-number-step.ts new file mode 100644 index 000000000..c37491100 --- /dev/null +++ b/packages/plugins/collection-manager/src/migrations/20230623145414-number-step.ts @@ -0,0 +1,44 @@ +import { Collection } from '@nocobase/database'; +import { Migration } from '@nocobase/server'; +import { FieldModel } from '../models'; + +export default class extends Migration { + async up() { + const transaction = await this.db.sequelize.transaction(); + + const migrateFieldsSchema = async (collection: Collection) => { + this.app.log.info(`Start to migrate ${collection.name} collection's ui schema`); + + const fieldRecords: Array = await collection.repository.find({ + transaction, + filter: { + type: ['bigInt', 'float', 'double'], + }, + }); + + this.app.log.info(`Total ${fieldRecords.length} fields need to be migrated`); + + for (const fieldRecord of fieldRecords) { + const uiSchema = fieldRecord.get('uiSchema'); + if (uiSchema?.['x-component-props']?.step !== '0') { + continue; + } + uiSchema['x-component-props']['step'] = '1'; + fieldRecord.set('uiSchema', uiSchema); + await fieldRecord.save({ + transaction, + }); + console.log(`changed: ${fieldRecord.get('collectionName')}.${fieldRecord.get('name')}`); + } + }; + + try { + await migrateFieldsSchema(this.db.getCollection('fields')); + await transaction.commit(); + } catch (error) { + await transaction.rollback(); + this.app.log.error(error); + throw error; + } + } +}