Skip to content

Commit

Permalink
feat(): support setting track and lazy in context
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Oct 28, 2022
1 parent c415244 commit c21ec6f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("ContextItemForm", () => {
<Component
data={{
name: "data-a",
track: true,
resolve: {
useProvider: "provider-a",
args: ["arg1"],
Expand All @@ -44,7 +45,7 @@ describe("ContextItemForm", () => {
onContextItemUpdate={onContextItemUpdate}
/>
);
expect(wrapper.find(Form.Item).length).toBe(10);
expect(wrapper.find(Form.Item).length).toBe(12);

mockUseBuilderUIContext.mockReturnValue({
providerList: ["provider-a", "provider-b"],
Expand Down Expand Up @@ -99,14 +100,14 @@ describe("ContextItemForm", () => {
value: "value",
},
} as RadioChangeEvent);
expect(wrapper.find(Form.Item).length).toBe(5);
expect(wrapper.find(Form.Item).length).toBe(6);
wrapper.setProps({
data: {
name: "data-b",
value: "<% QUERY.objectId %>",
},
});
expect(wrapper.find(Form.Item).length).toBe(5);
expect(wrapper.find(Form.Item).length).toBe(6);
expect(wrapper.find(Radio).children().length).toBe(3);

wrapper.setProps({
Expand All @@ -118,6 +119,7 @@ describe("ContextItemForm", () => {
args: "- arg1\n",
if: "false\n",
transform: "value: <% DATA %>\n",
lazy: true,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useState, useEffect } from "react";
import { Input, Radio, Form, AutoComplete, FormItemProps } from "antd";
import { Input, Radio, Form, AutoComplete, FormItemProps, Switch } from "antd";
import {
computeItemToSubmit,
ContextItemFormValue,
Expand Down Expand Up @@ -225,8 +225,14 @@ export function ContextItemForm({
>
{getCodeEditorItem("value")}
</Form.Item>
<Form.Item valuePropName="checked" {...getFormItemProps("lazy")}>
<Switch />
</Form.Item>
</>
)}
<Form.Item valuePropName="checked" {...getFormItemProps("track")}>
<Switch />
</Form.Item>
<Form.Item {...getFormItemProps("if")}>
{getCodeEditorItem("if")}
</Form.Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function DataView({
const formValue = {
name: contextValue?.name,
type: ContextType.VALUE,
track: contextValue?.track,
...safeDumpFields({
value: contextValue?.value,
if: contextValue?.if,
Expand All @@ -116,15 +117,16 @@ export function DataView({
settingItemForm.setFieldsValue(formValue);
} else {
const formValue = {
name: contextValue?.name,
name: contextValue.name,
track: contextValue.track,
...((contextValue.resolve as SelectorProviderResolveConf).provider
? {
type: ContextType.SELECTOR_RESOLVE,
provider: (contextValue.resolve as SelectorProviderResolveConf)
.provider,
}
: (
contextValue?.resolve as UseProviderResolveConf
contextValue.resolve as UseProviderResolveConf
).useProvider?.includes("@")
? {
type: ContextType.FLOW_API,
Expand All @@ -142,8 +144,9 @@ export function DataView({
if: contextValue.if,
resolveIf: contextValue.resolve.if,
transform: contextValue.resolve.transform,
lazy: contextValue.resolve.lazy,
onReject: contextValue.resolve.onReject,
onChange: contextValue?.onChange,
onChange: contextValue.onChange,
}),
};
settingItemForm.setFieldsValue(formValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ describe("computeItemToSubmit", () => {
value: "age: 18",
name: "userInfo",
onChange: 'target: "#id"\nproperties:\n a: 1',
track: true,
},
{
name: "userInfo",
track: true,
value: {
age: 18,
},
Expand All @@ -99,6 +101,7 @@ describe("computeItemToSubmit", () => {
name: "new",
onChange: '- target: "#id"\n properties:\n a: 1',
onReject: "transform:\n value: <% DATA.message %>",
lazy: true,
},
{
value: [],
Expand All @@ -108,6 +111,7 @@ describe("computeItemToSubmit", () => {
useProvider: "provider-a",
if: "<% QUERY.page > 0 %>",
args: ["P-1"],
lazy: true,
transform: {
value: "<% DATA %>",
},
Expand Down
5 changes: 5 additions & 0 deletions bricks/next-builder/src/builder-container/DataView/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface contextItemBaseConf {
value?: string;
if?: string;
onChange?: string;
track?: boolean;
}

interface contextItemValueConf extends contextItemBaseConf {
Expand All @@ -29,6 +30,7 @@ interface contextResolveBaseConf extends contextItemBaseConf {
resolveIf?: string;
args?: string;
transform?: string;
lazy?: boolean;
}

interface contextItemResolveConf extends contextResolveBaseConf {
Expand Down Expand Up @@ -139,6 +141,7 @@ export function computeItemToSubmit(
}
return {
name: contextValue.name,
track: contextValue.track,
...computedFields,
};
} else {
Expand Down Expand Up @@ -177,10 +180,12 @@ export function computeItemToSubmit(
args: computedFields.args,
transform: computedFields.transform,
onReject: computedFields.onReject,
lazy: contextValue.lazy,
},
value: computedFields.value,
if: computedFields.if,
onChange: computedFields.onChange,
track: contextValue.track,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export function doLintStoryboard(storyboard: Storyboard): StoryboardError[] {
const warnedProviders = new Set<string>();

const errors: StoryboardError[] = [];
const ast = parseStoryboard(storyboard);
let usingScriptBrick = false;

const ast = parseStoryboard(storyboard);
traverseStoryboard(ast, (node) => {
switch (node.type) {
case "Brick": {
Expand Down

0 comments on commit c21ec6f

Please sign in to comment.