Skip to content

Commit

Permalink
feat: field suport change JSExpression value
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Apr 3, 2023
1 parent 5ed7e2b commit 85788ee
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 21 deletions.
54 changes: 33 additions & 21 deletions packages/designer/src/designer/setting/setting-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
import { Transducer } from './utils';
import { ISettingPropEntry, SettingPropEntry } from './setting-prop-entry';
import { computed, obx, makeObservable, action, untracked, intl } from '@alilc/lowcode-editor-core';
import { cloneDeep, isCustomView, isDynamicSetter } from '@alilc/lowcode-utils';
import { cloneDeep, isCustomView, isDynamicSetter, isJSExpression } from '@alilc/lowcode-utils';
import { ISettingTopEntry } from './setting-top-entry';
import { IComponentMeta, INode } from '@alilc/lowcode-designer';

Expand All @@ -38,28 +38,28 @@ export interface ISettingField extends ISettingPropEntry, Omit<IBaseModelSetting
IComponentMeta,
INode
>, 'setValue' | 'key' | 'node'> {
get items(): Array<ISettingField | IPublicTypeCustomView>;

get title(): string | ReactNode | undefined;

readonly isSettingField: true;

purge(): void;
readonly isRequired: boolean;

readonly isGroup: boolean;

extraProps: IPublicTypeFieldExtraProps;

get setter(): IPublicTypeSetterType | null;
get items(): Array<ISettingField | IPublicTypeCustomView>;

get expanded(): boolean;
get title(): string | ReactNode | undefined;

readonly isRequired: boolean;
get setter(): IPublicTypeSetterType | null;

readonly isGroup: boolean;
get expanded(): boolean;

get valueState(): number;

setExpanded(value: boolean): void;

purge(): void;

setValue(
val: any,
isHotValue?: boolean,
Expand Down Expand Up @@ -271,16 +271,29 @@ export class SettingField extends SettingPropEntry implements ISettingField {
}
if (this.isUseVariable()) {
const oldValue = this.getValue();
this.setValue(
{
type: 'JSExpression',
value: oldValue.value,
mock: value,
},
false,
false,
options,
);
if (isJSExpression(value)) {
this.setValue(
{
type: 'JSExpression',
value: value.value,
mock: oldValue.mock,
},
false,
false,
options,
);
} else {
this.setValue(
{
type: 'JSExpression',
value: oldValue.value,
mock: value,
},
false,
false,
options,
);
}
} else {
this.setValue(value, false, false, options);
}
Expand All @@ -297,7 +310,6 @@ export class SettingField extends SettingPropEntry implements ISettingField {
return this.designer!.autorun(action, true);
}


internalToShellField() {
return this.designer!.shellModelFactory.createSettingField(this);
}
Expand Down
34 changes: 34 additions & 0 deletions packages/designer/tests/designer/setting/setting-field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,40 @@ describe('setting-field 测试', () => {
expect(arrField.getHotValue()).toEqual([undefined, {name: '2'}, {name: '3'}]);
});

it('js expression setValue / setHotValue', () => {
const settingEntry = mockNode.settingEntry;
const field = settingEntry.get('behavior');

const subField = field.createField({
name: 'sub',
title: 'sub',
});
subField.setValue({
type: 'JSExpression',
value: 'state.a',
mock: 'haha',
});

subField.setHotValue({
type: 'JSExpression',
value: 'state.b',
});

expect(subField.getValue()).toEqual({
type: 'JSExpression',
value: 'state.b',
mock: 'haha',
});

subField.setHotValue('mock02');

expect(subField.getValue()).toEqual({
type: 'JSExpression',
value: 'state.b',
mock: 'mock02',
});
});

it('onEffect', async () => {
const settingEntry = mockNode.settingEntry as SettingTopEntry;
const field = settingEntry.get('behavior');
Expand Down

0 comments on commit 85788ee

Please sign in to comment.