From da01d47b0ee1b6f8a89d97b1c0032172a0021987 Mon Sep 17 00:00:00 2001 From: Allen Date: Thu, 25 Jan 2024 17:51:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0input-number=20inputE?= =?UTF-8?q?xcel=20service=20tpl=20=E7=9A=84=E9=83=A8=E5=88=86testid=20(#95?= =?UTF-8?q?26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../amis-ui/scss/components/form/_excel.scss | 10 ++++++++++ .../amis-ui/src/components/NumberInput.tsx | 15 +++++++++++++-- packages/amis-ui/src/components/Select.tsx | 1 + .../amis/src/renderers/Form/InputExcel.tsx | 18 ++++++++++++++---- .../amis/src/renderers/Form/InputNumber.tsx | 9 +++++++-- packages/amis/src/renderers/Form/Select.tsx | 10 +++++++--- packages/amis/src/renderers/Service.tsx | 13 ++++++++++--- packages/amis/src/renderers/Tpl.tsx | 8 ++++++-- 8 files changed, 68 insertions(+), 16 deletions(-) diff --git a/packages/amis-ui/scss/components/form/_excel.scss b/packages/amis-ui/scss/components/form/_excel.scss index 549056a19..7ca05ec93 100644 --- a/packages/amis-ui/scss/components/form/_excel.scss +++ b/packages/amis-ui/scss/components/form/_excel.scss @@ -30,6 +30,16 @@ color: #bdbdbd; outline: none; transition: border 0.24s ease-in-out; + position: relative; + > input { + display: block !important; + position: absolute; + top: 0; + right: 0; + left: 0; + bottom: 0; + opacity: 0; + } } &-dropzone:focus { diff --git a/packages/amis-ui/src/components/NumberInput.tsx b/packages/amis-ui/src/components/NumberInput.tsx index 9fb318e49..45f660bd7 100644 --- a/packages/amis-ui/src/components/NumberInput.tsx +++ b/packages/amis-ui/src/components/NumberInput.tsx @@ -10,7 +10,14 @@ import getMiniDecimal, { } from '@rc-component/mini-decimal'; import {Icon} from './icons'; -import {ThemeProps, themeable, isNumeric, autobind, ucFirst} from 'amis-core'; +import { + ThemeProps, + themeable, + isNumeric, + autobind, + ucFirst, + TestIdBuilder +} from 'amis-core'; export type ValueType = string | number; @@ -74,6 +81,8 @@ export interface NumberProps extends ThemeProps { * 数字输入框类名 */ inputControlClassName?: string; + + testIdBuilder?: TestIdBuilder; } export interface NumberState { @@ -317,7 +326,8 @@ export class NumberInput extends React.Component { inputRef, keyboard, inputControlClassName, - mobileUI + mobileUI, + testIdBuilder } = this.props; const precisionProps: any = { precision: NumberInput.normalizePrecision(precision, step) @@ -356,6 +366,7 @@ export class NumberInput extends React.Component { stringMode={this.isBig ? true : false} keyboard={keyboard} {...precisionProps} + {...testIdBuilder?.getTestId()} /> ); } diff --git a/packages/amis-ui/src/components/Select.tsx b/packages/amis-ui/src/components/Select.tsx index 5d1c8d31c..a3e39f58b 100644 --- a/packages/amis-ui/src/components/Select.tsx +++ b/packages/amis-ui/src/components/Select.tsx @@ -1139,6 +1139,7 @@ export class Select extends React.Component { {item.disabled ? label diff --git a/packages/amis/src/renderers/Form/InputExcel.tsx b/packages/amis/src/renderers/Form/InputExcel.tsx index 4a4bd32e0..6e1f31333 100644 --- a/packages/amis/src/renderers/Form/InputExcel.tsx +++ b/packages/amis/src/renderers/Form/InputExcel.tsx @@ -10,7 +10,8 @@ import { autobind, isObject, resolveEventData, - dataMapping + dataMapping, + TestIdBuilder } from 'amis-core'; import {FormBaseControlSchema, SchemaTokenizeableString} from '../../Schema'; import type {CellValue, CellRichTextValue} from 'exceljs'; @@ -64,6 +65,8 @@ export interface InputExcelControlSchema extends FormBaseControlSchema { autoFill?: { [propName: string]: SchemaTokenizeableString; }; + + testIdBuilder?: TestIdBuilder; } export interface ExcelProps @@ -401,7 +404,8 @@ export default class ExcelControl extends React.PureComponent< classPrefix: ns, disabled, translate: __, - placeholder + placeholder, + testIdBuilder } = this.props; return ( @@ -415,8 +419,14 @@ export default class ExcelControl extends React.PureComponent< > {({getRootProps, getInputProps}) => (
-
- +
+ {this.state.filename ? ( __('Excel.parsed', { filename: this.state.filename diff --git a/packages/amis/src/renderers/Form/InputNumber.tsx b/packages/amis/src/renderers/Form/InputNumber.tsx index 6cefadeb5..1f5929bc5 100644 --- a/packages/amis/src/renderers/Form/InputNumber.tsx +++ b/packages/amis/src/renderers/Form/InputNumber.tsx @@ -7,7 +7,8 @@ import { resolveEventData, CustomStyle, formatInputThemeCss, - setThemeClassName + setThemeClassName, + TestIdBuilder } from 'amis-core'; import cx from 'classnames'; import {NumberInput, Select} from 'amis-ui'; @@ -158,6 +159,8 @@ export interface NumberProps extends FormControlProps { * 是否在清空内容时从数据域中删除该表单项对应的值 */ clearValueOnEmpty?: boolean; + + testIdBuilder?: TestIdBuilder; } interface NumberState { @@ -445,7 +448,8 @@ export default class NumberControl extends React.Component< themeCss, inputControlClassName, id, - env + env, + testIdBuilder } = this.props; const {unit} = this.state; const finalPrecision = this.filterNum(precision); @@ -523,6 +527,7 @@ export default class NumberControl extends React.Component< displayMode={displayMode} big={big} clearValueOnEmpty={clearValueOnEmpty} + testIdBuilder={testIdBuilder} /> {Array.isArray(unitOptions) && unitOptions.length !== 0 ? ( unitOptions.length > 1 ? ( diff --git a/packages/amis/src/renderers/Form/Select.tsx b/packages/amis/src/renderers/Form/Select.tsx index d1803b314..2a1e5b530 100644 --- a/packages/amis/src/renderers/Form/Select.tsx +++ b/packages/amis/src/renderers/Form/Select.tsx @@ -14,7 +14,8 @@ import { isEffectiveApi, isApiOutdated, createObject, - autobind + autobind, + TestIdBuilder } from 'amis-core'; import {TransferDropDown, Spinner, Select, SpinnerExtraProps} from 'amis-ui'; import {FormOptionsSchema, SchemaApi} from '../../Schema'; @@ -155,6 +156,8 @@ export interface SelectControlSchema */ filterOption?: 'string'; }; + + testIdBuilder?: TestIdBuilder; } export interface SelectProps extends OptionsControlProps, SpinnerExtraProps { @@ -409,12 +412,13 @@ export default class SelectControl extends React.Component { @autobind renderMenu(option: Option, state: any) { - const {menuTpl, render, data, optionClassName} = this.props; + const {menuTpl, render, data, optionClassName, testIdBuilder} = this.props; return render(`menu/${state.index}`, menuTpl, { showNativeTitle: true, className: cx('Select-option-content', optionClassName), - data: createObject(createObject(data, state), option) + data: createObject(createObject(data, state), option), + testIdBuilder: testIdBuilder?.getChild('option-' + state.index) }); } diff --git a/packages/amis/src/renderers/Service.tsx b/packages/amis/src/renderers/Service.tsx index 771fb6e48..fb7581955 100644 --- a/packages/amis/src/renderers/Service.tsx +++ b/packages/amis/src/renderers/Service.tsx @@ -21,7 +21,8 @@ import { isVisible, qsstringify, createObject, - extendObject + extendObject, + TestIdBuilder } from 'amis-core'; import { BaseSchema, @@ -151,6 +152,7 @@ export interface ServiceProps Omit { store: IServiceStore; messages: SchemaMessage; + testIdBuilder?: TestIdBuilder; } export default class Service extends React.Component { timer: ReturnType; @@ -797,11 +799,16 @@ export default class Service extends React.Component { classPrefix: ns, classnames: cx, loadingConfig, - showErrorMsg + showErrorMsg, + testIdBuilder } = this.props; return ( -
+
{!env.forceSilenceInsideError && store.error && showErrorMsg !== false ? ( diff --git a/packages/amis/src/renderers/Tpl.tsx b/packages/amis/src/renderers/Tpl.tsx index ad867d741..56cd808ac 100644 --- a/packages/amis/src/renderers/Tpl.tsx +++ b/packages/amis/src/renderers/Tpl.tsx @@ -7,7 +7,7 @@ import { CustomStyle, setThemeClassName } from 'amis-core'; -import {filter, asyncFilter} from 'amis-core'; +import {filter, asyncFilter, TestIdBuilder} from 'amis-core'; import isEmpty from 'lodash/isEmpty'; import {anyChanged, getPropValue} from 'amis-core'; import {escapeHtml} from 'amis-core'; @@ -52,6 +52,8 @@ export interface TplSchema extends BaseSchema { * 角标 */ badge?: BadgeObject; + + testidBuilder?: TestIdBuilder; } export interface TplProps extends RendererProps, TplSchema { @@ -200,7 +202,8 @@ export class Tpl extends React.Component { id, wrapperCustomStyle, env, - themeCss + themeCss, + testIdBuilder } = this.props; const Component = wrapperComponent || (inline ? 'span' : 'div'); const {content} = this.state; @@ -236,6 +239,7 @@ export class Tpl extends React.Component { onClick={this.handleClick} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave} + {...testIdBuilder?.getChild('tpl')?.getTestId()} >