From ee2ed97598c7b8c048f738b1af53e86d6307ca74 Mon Sep 17 00:00:00 2001 From: qkiroc <30946345+qkiroc@users.noreply.github.com> Date: Tue, 10 Sep 2024 12:27:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=99formItem=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8A=A0data-name=E6=A0=87=E8=AF=86,=E6=96=B9=E4=BE=BFdom?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=20(#10890)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 表单项增加dataAmisName标识 * 更新快照 --------- Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com> --- packages/amis-core/src/renderers/Item.tsx | 6 +- packages/amis-ui/src/components/Checkbox.tsx | 2 + packages/amis-ui/src/components/InputBox.tsx | 3 + packages/amis-ui/src/components/Select.tsx | 3 + .../src/components/schema-editor/Array.tsx | 2 + .../src/components/schema-editor/Common.tsx | 4 + .../src/components/schema-editor/Object.tsx | 152 ++++++++++-------- .../__snapshots__/page.test.tsx.snap | 12 ++ .../__snapshots__/service.test.tsx.snap | 24 +++ .../form/__snapshots__/form.test.tsx.snap | 31 ++++ .../form/__snapshots__/range.test.tsx.snap | 3 + .../validateFormItem.test.tsx.snap | 24 +++ .../Form/__snapshots__/array.test.tsx.snap | 1 + .../Form/__snapshots__/button.test.tsx.snap | 2 + .../buttonGroupSelect.test.tsx.snap | 11 ++ .../__snapshots__/chainedSelect.test.tsx.snap | 1 + .../Form/__snapshots__/checkbox.test.tsx.snap | 4 + .../__snapshots__/checkboxes.test.tsx.snap | 29 ++++ .../Form/__snapshots__/combo.test.tsx.snap | 30 ++++ .../conditionBuilder.test.tsx.snap | 1 + .../__snapshots__/container.test.tsx.snap | 2 + .../Form/__snapshots__/datetime.test.tsx.snap | 1 + .../Form/__snapshots__/fieldSet.test.tsx.snap | 9 ++ .../Form/__snapshots__/formitem.test.tsx.snap | 3 + .../Form/__snapshots__/formula.test.tsx.snap | 6 + .../Form/__snapshots__/grid.test.tsx.snap | 1 + .../Form/__snapshots__/group.test.tsx.snap | 6 + .../Form/__snapshots__/hbox.test.tsx.snap | 1 + .../__snapshots__/iconPicker.test.tsx.snap | 1 + .../Form/__snapshots__/index.test.tsx.snap | 14 ++ .../Form/__snapshots__/initData.test.tsx.snap | 8 + .../__snapshots__/inputArray.test.tsx.snap | 14 ++ .../__snapshots__/inputCity.test.tsx.snap | 2 + .../__snapshots__/inputDate.test.tsx.snap | 10 ++ .../__snapshots__/inputFormula.test.tsx.snap | 2 + .../__snapshots__/inputGroup.test.tsx.snap | 1 + .../inputMonthRange.test.tsx.snap | 1 + .../inputQuarterRange.test.tsx.snap | 1 + .../__snapshots__/inputSubForm.test.tsx.snap | 6 + .../__snapshots__/inputTable.test.tsx.snap | 19 +++ .../Form/__snapshots__/inputTag.test.tsx.snap | 7 + .../inputYearRange.test.tsx.snap | 1 + .../Form/__snapshots__/list.test.tsx.snap | 7 + .../__snapshots__/listSelect.test.tsx.snap | 2 + .../__snapshots__/nestedSelect.test.tsx.snap | 1 + .../Form/__snapshots__/number.test.tsx.snap | 9 ++ .../Form/__snapshots__/options.test.tsx.snap | 8 + .../Form/__snapshots__/panel.test.tsx.snap | 2 + .../Form/__snapshots__/radios.test.tsx.snap | 6 + .../Form/__snapshots__/range.test.tsx.snap | 8 + .../Form/__snapshots__/rating.test.tsx.snap | 10 ++ .../Form/__snapshots__/repeat.test.tsx.snap | 1 + .../Form/__snapshots__/select.test.tsx.snap | 13 ++ .../Form/__snapshots__/service.test.tsx.snap | 7 + .../Form/__snapshots__/static.test.tsx.snap | 13 ++ .../Form/__snapshots__/switch.test.tsx.snap | 2 + .../Form/__snapshots__/tabs.test.tsx.snap | 2 + .../__snapshots__/tabsTransfer.test.tsx.snap | 2 + .../tabsTransferPicker.test.tsx.snap | 2 + .../Form/__snapshots__/text.test.tsx.snap | 29 ++++ .../Form/__snapshots__/textarea.test.tsx.snap | 4 + .../Form/__snapshots__/transfer.test.tsx.snap | 13 ++ .../transferPicker.test.tsx.snap | 1 + .../__snapshots__/usersSelect.test.tsx.snap | 1 + .../__snapshots__/valueFormula.test.tsx.snap | 9 ++ .../__snapshots__/AnchorNav.test.tsx.snap | 20 +++ .../__snapshots__/ButtonToolbar.test.tsx.snap | 1 + .../__snapshots__/Image.test.tsx.snap | 1 + .../__snapshots__/Page.test.tsx.snap | 6 + .../__snapshots__/Picker.test.tsx.snap | 2 + .../__snapshots__/PopOver.test.tsx.snap | 3 + .../__snapshots__/Progress.test.tsx.snap | 1 + .../__snapshots__/Tabs.test.tsx.snap | 2 + .../__snapshots__/Tree.test.tsx.snap | 2 + .../__snapshots__/Wizard.test.tsx.snap | 22 +++ 75 files changed, 604 insertions(+), 69 deletions(-) diff --git a/packages/amis-core/src/renderers/Item.tsx b/packages/amis-core/src/renderers/Item.tsx index 53975e25b..c6e51e6c4 100644 --- a/packages/amis-core/src/renderers/Item.tsx +++ b/packages/amis-core/src/renderers/Item.tsx @@ -1270,6 +1270,7 @@ export class FormItemWrap extends React.Component { return (
{ return (
{ return (
{ return (
{ props.formLabelAlign; const labelWidth = props.labelWidth || props.formLabelWidth; description = description || desc; - return (
; testIdBuilder?: TestIdBuilder; + dataName?: string; } export class Checkbox extends React.Component { @@ -99,6 +100,7 @@ export class Checkbox extends React.Component { })} data-role="checkbox" {...testIdBuilder?.getTestId()} + data-amis-name={this.props.dataName} > JSX.Element; + dataName?: string; } export interface InputBoxState { @@ -91,6 +92,7 @@ export class InputBox extends React.Component { mobileUI, testIdBuilder, inputRender, + dataName, ...rest } = this.props; const isFocused = this.state.isFocused; @@ -106,6 +108,7 @@ export class InputBox extends React.Component { [`InputBox--border${ucFirst(borderMode)}`]: borderMode })} onClick={onClick} + data-amis-name={dataName} > {result} diff --git a/packages/amis-ui/src/components/Select.tsx b/packages/amis-ui/src/components/Select.tsx index 08ebb3669..606c7684d 100644 --- a/packages/amis-ui/src/components/Select.tsx +++ b/packages/amis-ui/src/components/Select.tsx @@ -401,6 +401,8 @@ export interface SelectProps * 检索函数 */ filterOption?: FilterOption; + + dataName?: string; } interface SelectState { @@ -1375,6 +1377,7 @@ export class Select extends React.Component { }, className )} + data-amis-name={this.props.dataName} >
{showInfo !== false ? ( <> diff --git a/packages/amis-ui/src/components/schema-editor/Common.tsx b/packages/amis-ui/src/components/schema-editor/Common.tsx index c702cd921..991e8fee4 100644 --- a/packages/amis-ui/src/components/schema-editor/Common.tsx +++ b/packages/amis-ui/src/components/schema-editor/Common.tsx @@ -27,6 +27,7 @@ export type SchemaEditorItemPlaceholder = Partial< export interface SchemaEditorItemCommonProps extends LocaleProps, ThemeProps { label?: string; value?: JSONSchema; + dataName?: string; onChange: (value: JSONSchema) => void; types: Array<{ label: string; @@ -175,6 +176,7 @@ export class SchemaEditorItemCommon< simpleValue mobileUI={mobileUI} popOverContainer={popOverContainer} + dataName={onRequiredChange ? `${this.props.dataName}-type` : ''} /> ) : null} @@ -185,6 +187,7 @@ export class SchemaEditorItemCommon< value={required} onChange={onRequiredChange} disabled={disabled} + dataName={`${this.props.dataName}-required`} /> ) : null} @@ -371,6 +374,7 @@ export class SchemaEditorItemCommon< className={cx('SchemaEditorItem', { 'SchemaEditorItem--mini': mini })} + data-amis-name={this.props.dataName} > {this.renderCommon()}
diff --git a/packages/amis-ui/src/components/schema-editor/Object.tsx b/packages/amis-ui/src/components/schema-editor/Object.tsx index f4608a153..e22f60945 100644 --- a/packages/amis-ui/src/components/schema-editor/Object.tsx +++ b/packages/amis-ui/src/components/schema-editor/Object.tsx @@ -288,7 +288,8 @@ export class SchemaEditorItemObject extends SchemaEditorItemCommon< placeholder, mobileUI, mini, - addButtonText + addButtonText, + dataName } = this.props; const members = this.state.members; @@ -299,74 +300,88 @@ export class SchemaEditorItemObject extends SchemaEditorItemCommon< })} > {members.length ? ( - members.map((member, index) => ( - - + members.map((member, index) => { + const memberKey = dataName + ? dataName + '-' + member.key + : member.key; + return ( + + - - - ) - } - affix={ - - } - value={ - mini - ? ({ - ...member.schema, - key: member.key, - isRequired: member.required - } as any) - : member.schema - } - onChange={this.handlePropChange.bind(this, index)} - onFormConfirm={this.handleEditProppertyConfirm.bind(this, index)} - renderExtraProps={renderExtraProps} - renderModalProps={renderModalProps} - locale={locale} - translate={__} - classnames={cx} - classPrefix={classPrefix} - disabled={disabled || !!value?.$ref} - required={member.required} - onRequiredChange={this.handlePropRequiredChange.bind(this, index)} - placeholder={placeholder} - formPrefixRender={this.renderFormPrefix} - /> - )) + + + ) + } + affix={ + + } + value={ + mini + ? ({ + ...member.schema, + key: member.key, + isRequired: member.required + } as any) + : member.schema + } + onChange={this.handlePropChange.bind(this, index)} + onFormConfirm={this.handleEditProppertyConfirm.bind( + this, + index + )} + renderExtraProps={renderExtraProps} + renderModalProps={renderModalProps} + locale={locale} + translate={__} + classnames={cx} + classPrefix={classPrefix} + disabled={disabled || !!value?.$ref} + required={member.required} + onRequiredChange={this.handlePropRequiredChange.bind( + this, + index + )} + placeholder={placeholder} + formPrefixRender={this.renderFormPrefix} + /> + ); + }) ) : (
{__(placeholder?.empty ?? '')} @@ -492,6 +507,7 @@ export class SchemaEditorItemObject extends SchemaEditorItemCommon< 'is-collapsed': this.state.collapsed, 'SchemaEditorItem--mini': mini })} + data-amis-name={this.props.dataName} > {showInfo !== false ? ( <> diff --git a/packages/amis/__tests__/event-action/renderers/__snapshots__/page.test.tsx.snap b/packages/amis/__tests__/event-action/renderers/__snapshots__/page.test.tsx.snap index c957494cd..cf4a937c9 100644 --- a/packages/amis/__tests__/event-action/renderers/__snapshots__/page.test.tsx.snap +++ b/packages/amis/__tests__/event-action/renderers/__snapshots__/page.test.tsx.snap @@ -25,6 +25,7 @@ exports[`doAction:page reload 1`] = `