fix(input-number): change step to 1 (#2104)

This commit is contained in:
chenos 2023-06-24 17:15:59 +08:00 committed by GitHub
parent 7bd3168422
commit 8b03dfa96b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 7 deletions

View File

@ -24,7 +24,7 @@ export const integer: IField = {
'x-component': 'InputNumber',
'x-component-props': {
stringMode: true,
step: '0',
step: '1',
},
'x-validator': 'integer',
},

View File

@ -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' },

View File

@ -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%' },

View File

@ -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<FieldModel> = 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;
}
}
}