Skip to content

Commit c7987f9

Browse files
ggbond2077QIQI03
authored andcommitted
- fix: table performance
- feat: resource dropdown support search - feat: branding - fix: scanner comp adapt oppo - fix: chrome86 link issue - fix: input validate ref self
1 parent f5f999b commit c7987f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+548
-288
lines changed

client/packages/openblocks-comps/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "openblocks-comps",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"type": "module",
55
"license": "MIT",
66
"dependencies": {
77
"@types/react": "17",
88
"@types/react-dom": "17",
9+
"big.js": "^6.2.1",
910
"openblocks-cli": "workspace:^",
1011
"openblocks-sdk": "workspace:^",
1112
"react": "17",

client/packages/openblocks-comps/src/comps/chartComp/chartConstants.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ScatterChartConfig } from "./chartConfigs/scatterChartConfig";
1515
import { SeriesListComp } from "./seriesComp";
1616
import { EChartsOption } from "echarts";
1717
import { i18nObjs, trans } from "i18n/comps";
18+
import { JSONValue } from "openblocks";
1819

1920
export const ChartTypeOptions = [
2021
{
@@ -183,7 +184,18 @@ export const noDataPieChartConfig = {
183184
export type ChartSize = { w: number; h: number };
184185

185186
export const getDataKeys = (data: Array<JSONObject>) => {
186-
return data && data[0] ? Object.keys(data[0]) : [];
187+
if (!data) {
188+
return [];
189+
}
190+
const dataKeys: Array<string> = [];
191+
data.slice(0, 50).forEach((d) => {
192+
Object.keys(d).forEach((key) => {
193+
if (!dataKeys.includes(key)) {
194+
dataKeys.push(key);
195+
}
196+
});
197+
});
198+
return dataKeys;
187199
};
188200

189201
const ChartOptionMap = {

client/packages/openblocks-comps/src/comps/chartComp/chartUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { EChartsOption } from "echarts";
1010
import _ from "lodash";
1111
import { chartColorPalette, isNumeric, JSONObject } from "openblocks-sdk";
1212
import { calcXYConfig } from "comps/chartComp/chartConfigs/cartesianAxisConfig";
13+
import Big from "big.js";
1314

1415
export function transformData(
1516
originData: JSONObject[],
@@ -38,7 +39,8 @@ export function transformData(
3839
if (key === xAxis) {
3940
return;
4041
} else if (isNumeric(cur[key])) {
41-
prev[groupValue][key] += Number(cur[key]);
42+
const bigNum = Big(cur[key]);
43+
prev[groupValue][key] = bigNum.add(prev[groupValue][key]).toNumber();
4244
} else {
4345
prev[groupValue][key] += 1;
4446
}

client/packages/openblocks-core/lib/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ReactNode } from "react";
22

33
declare type EvalMethods = Record<string, Record<string, Function>>;
44
declare type CodeType = undefined | "JSON" | "Function";
5+
declare type CodeFunction = (args?: Record<string, unknown>, runInHost?: boolean) => any;
56

67
declare type NodeToValue<NodeT> = NodeT extends Node<infer ValueType> ? ValueType : never;
78
declare type FetchInfo = {
@@ -284,7 +285,7 @@ declare class WrapNode<T> extends AbstractNode<T> {
284285
dependValues(): Record<string, unknown>;
285286
}
286287

287-
declare type WrapContextFn<T> = (params: Record<string, unknown>) => T;
288+
declare type WrapContextFn<T> = (params?: Record<string, unknown>) => T;
288289
declare function wrapContext<T>(node: Node<T>): Node<WrapContextFn<T>>;
289290

290291
/**
@@ -760,6 +761,7 @@ export {
760761
BroadcastAction,
761762
CachedNode,
762763
ChangeValueAction,
764+
CodeFunction,
763765
CodeNode,
764766
CodeNodeOptions,
765767
CodeType,

client/packages/openblocks-core/lib/index.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,19 +1497,13 @@ var RelaxedJsonParser = /** @class */ (function (_super) {
14971497
};
14981498
return RelaxedJsonParser;
14991499
}(DefaultParser));
1500-
function mergeContext(context, args) {
1501-
if (!args) {
1502-
return context;
1503-
}
1504-
return Object.assign(Object.assign({}, args), context);
1505-
}
15061500
function evalFunction(unevaledValue, context, methods, isAsync) {
15071501
try {
15081502
return new ValueAndMsg(function (args, runInHost) {
15091503
if (runInHost === void 0) { runInHost = false; }
15101504
return evalFunc(unevaledValue.startsWith("return")
15111505
? unevaledValue + "\n"
1512-
: "return function(){'use strict'; " + unevaledValue + "\n}()", mergeContext(context, args), methods, { disableLimit: runInHost }, isAsync);
1506+
: "return function(){'use strict'; " + unevaledValue + "\n}()", args ? __assign(__assign({}, context), args) : context, methods, { disableLimit: runInHost }, isAsync);
15131507
});
15141508
}
15151509
catch (err) {
@@ -2897,17 +2891,19 @@ var WrapContextNode = /** @class */ (function (_super) {
28972891
};
28982892
WrapContextNode.prototype.justEval = function (exposingNodes, methods) {
28992893
var _this = this;
2900-
var paramNodes = {};
29012894
return function (params) {
2902-
Object.entries(params).forEach(function (_a) {
2903-
var paramName = _a[0], value = _a[1];
2904-
// node remains unchanged if value doesn't change, to keep the cache valid
2905-
var paramNode = paramNodes[paramName];
2906-
if (!paramNode || value !== paramNode.value) {
2907-
paramNodes[paramName] = fromValueWithCache(value); // requires cache
2908-
}
2909-
});
2910-
return _this.child.evaluate(__assign(__assign({}, exposingNodes), paramNodes), methods);
2895+
var nodes;
2896+
if (params) {
2897+
nodes = __assign({}, exposingNodes);
2898+
Object.entries(params).forEach(function (_a) {
2899+
var key = _a[0], value = _a[1];
2900+
nodes[key] = fromValueWithCache(value);
2901+
});
2902+
}
2903+
else {
2904+
nodes = exposingNodes;
2905+
}
2906+
return _this.child.evaluate(nodes, methods);
29112907
};
29122908
};
29132909
WrapContextNode.prototype.getChildren = function () {

client/packages/openblocks-core/src/eval/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export * from "./wrapContextNodeV2";
1111
export { transformWrapper } from "./utils/codeNodeUtils";
1212
export { evalPerfUtil } from "./utils/perfUtils";
1313

14-
export type { EvalMethods, CodeType } from "./types/evalTypes";
14+
export type { EvalMethods, CodeType, CodeFunction } from "./types/evalTypes";
1515
export { ValueAndMsg } from "./types/valueAndMsg";
1616
export { relaxedJSONToJSON } from "./utils/relaxedJson";
1717
export { getDynamicStringSegments, isDynamicSegment } from "./utils/segmentUtils";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export type EvalMethods = Record<string, Record<string, Function>>;
22

33
export type CodeType = undefined | "JSON" | "Function";
4+
5+
export type CodeFunction = (args?: Record<string, unknown>, runInHost?: boolean) => any;

client/packages/openblocks-core/src/eval/utils/evaluate.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ describe("deps", () => {
2929
expect(depsD.has(context.data)).toBe(true);
3030
expect(depsD.has(context.str)).toBe(true);
3131
expect(depsD.has(context.i)).toBe(false);
32+
33+
expect(filterDepends("{{new Date().toLocaleString()}}", context)).toStrictEqual(new Map());
3234
});
3335
});
3436

client/packages/openblocks-core/src/eval/utils/string2Fn.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import _ from "lodash";
33
import { getErrorMessage } from "./nodeUtils";
44
import { evalFunc, evalScript } from "./evalScript";
55
import { getDynamicStringSegments, isDynamicSegment } from "./segmentUtils";
6-
import { CodeType, EvalMethods } from "../types/evalTypes";
6+
import { CodeFunction, CodeType, EvalMethods } from "../types/evalTypes";
77
import { relaxedJSONToJSON } from "./relaxedJson";
88

99
export type Fn = (context: Record<string, unknown>) => ValueAndMsg<unknown>;
@@ -154,26 +154,19 @@ class RelaxedJsonParser extends DefaultParser {
154154
}
155155
}
156156

157-
function mergeContext(context: Record<string, unknown>, args?: Record<string, unknown>) {
158-
if (!args) {
159-
return context;
160-
}
161-
return Object.assign(Object.assign({}, args), context);
162-
}
163-
164157
export function evalFunction(
165158
unevaledValue: string,
166159
context: Record<string, unknown>,
167160
methods?: EvalMethods,
168161
isAsync?: boolean
169-
): ValueAndMsg<Function> {
162+
): ValueAndMsg<CodeFunction> {
170163
try {
171164
return new ValueAndMsg((args?: Record<string, unknown>, runInHost: boolean = false) =>
172165
evalFunc(
173166
unevaledValue.startsWith("return")
174167
? unevaledValue + "\n"
175168
: "return function(){'use strict'; " + unevaledValue + "\n}()",
176-
mergeContext(context, args),
169+
args ? { ...context, ...args } : context,
177170
methods,
178171
{ disableLimit: runInHost },
179172
isAsync

client/packages/openblocks-core/src/eval/wrapContextNode.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ it("context test", () => {
1010
const c1Value = c1.evaluate();
1111
expect(c1Value({ v1: 10, v2: 10 }).xx).toStrictEqual("11 30");
1212
expect(c1Value({ v1: 11, v2: 11 }).xx).toStrictEqual("11 32");
13+
expect(c1Value({ v1: 11 }).xx).toStrictEqual("11 NaN");
14+
expect(c1Value().xx).toStrictEqual("11 NaN");
1315
});
1416

1517
it("context test 2", () => {
@@ -21,4 +23,6 @@ it("context test 2", () => {
2123
const c1Value = c1.evaluate();
2224
expect(c1Value({ i: 1 }).xx).toStrictEqual(1);
2325
expect(c1Value({ i: 1 }).yy).toStrictEqual("a1");
26+
expect(c1Value({}).yy).toStrictEqual("a");
27+
expect(c1Value().yy).toStrictEqual("a");
2428
});

client/packages/openblocks-core/src/eval/wrapContextNode.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { memoized } from "util/memoize";
22
import { EvalMethods } from "./types/evalTypes";
33
import { Node, AbstractNode } from "./node";
4-
import { fromValueWithCache, SimpleNode } from "./simpleNode";
4+
import { fromValueWithCache } from "./simpleNode";
55

6-
export type WrapContextFn<T> = (params: Record<string, unknown>) => T;
6+
export type WrapContextFn<T> = (params?: Record<string, unknown>) => T;
77

88
class WrapContextNode<T> extends AbstractNode<WrapContextFn<T>> {
99
readonly type = "wrapContext";
@@ -18,16 +18,17 @@ class WrapContextNode<T> extends AbstractNode<WrapContextFn<T>> {
1818
exposingNodes: Record<string, Node<unknown>>,
1919
methods?: EvalMethods
2020
): WrapContextFn<T> {
21-
const paramNodes: Record<string, SimpleNode<unknown>> = {};
22-
return (params: Record<string, unknown>) => {
23-
Object.entries(params).forEach(([paramName, value]) => {
24-
// node remains unchanged if value doesn't change, to keep the cache valid
25-
const paramNode = paramNodes[paramName];
26-
if (!paramNode || value !== paramNode.value) {
27-
paramNodes[paramName] = fromValueWithCache(value); // requires cache
28-
}
29-
});
30-
return this.child.evaluate({ ...exposingNodes, ...paramNodes }, methods);
21+
return (params?: Record<string, unknown>) => {
22+
let nodes: Record<string, Node<unknown>>;
23+
if (params) {
24+
nodes = { ...exposingNodes };
25+
Object.entries(params).forEach(([key, value]) => {
26+
nodes[key] = fromValueWithCache(value);
27+
});
28+
} else {
29+
nodes = exposingNodes;
30+
}
31+
return this.child.evaluate(nodes, methods);
3132
};
3233
}
3334
override getChildren(): Node<unknown>[] {

client/packages/openblocks-design/src/components/Search.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import styled from "styled-components";
2-
import { Input } from "antd";
2+
import { Input, InputProps } from "antd";
33
import { ReactComponent as Icon } from "icons/icon-Search.svg";
44
import React, { CSSProperties } from "react";
55

6-
const SerachInput = styled(Input)`
6+
const SearchInput = styled(Input)`
77
margin: 0;
8-
padding: 0;
8+
padding: 0 11px 0 0;
99
height: 32px;
1010
width: 100%;
1111
border: 1px solid #d7d9e0;
@@ -54,19 +54,20 @@ interface ISearch {
5454
disabled?: boolean;
5555
}
5656

57-
export const Search = (props: ISearch) => {
58-
const { value, onChange } = props;
57+
export const Search = (props: ISearch & InputProps) => {
58+
const { value, onChange, style, disabled, placeholder, ...others } = props;
5959
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
6060
onChange && onChange(e);
6161
};
6262
return (
63-
<SearchDiv style={props.style}>
64-
<SerachInput
65-
disabled={props.disabled}
66-
placeholder={props.placeholder}
63+
<SearchDiv style={style}>
64+
<SearchInput
65+
disabled={disabled}
66+
placeholder={placeholder}
6767
onChange={handleChange}
6868
value={value}
6969
prefix={<SearchIcon />}
70+
{...others}
7071
/>
7172
</SearchDiv>
7273
);

client/packages/openblocks-design/src/components/colorSelect/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
isValidColor,
99
} from "components/colorSelect/colorUtils";
1010
import styled, { css } from "styled-components";
11-
import { useCallback, useMemo, useState } from "react";
11+
import { useCallback, useRef, useState } from "react";
1212
import { throttle } from "lodash";
1313
import { changeValueAction } from "openblocks-core";
1414

@@ -21,6 +21,7 @@ interface ColorSelectProps {
2121

2222
export const ColorSelect = (props: ColorSelectProps) => {
2323
const { color, trigger = "click", dispatch, changeColor } = props;
24+
let pickerColor = useRef(toRGBA(color));
2425
const [visible, setVisible] = useState(false);
2526
const throttleChange = useCallback(
2627
throttle((rgbaColor: string) => {
@@ -29,19 +30,19 @@ export const ColorSelect = (props: ColorSelectProps) => {
2930
}, 200),
3031
[dispatch]
3132
);
32-
const rgbaColor = useMemo(() => {
33-
return toRGBA(color);
34-
}, [visible])
3533

3634
return (
3735
<Popover
3836
trigger={trigger}
3937
destroyTooltipOnHide={true}
40-
onVisibleChange={(value) => setVisible(value)}
38+
onVisibleChange={(value) => {
39+
pickerColor.current = toRGBA(color);
40+
setVisible(value);
41+
}}
4142
content={
4243
<PopoverContainer>
4344
<div style={{ position: "relative" }}>
44-
<RgbaStringColorPicker color={rgbaColor} onChange={throttleChange} />
45+
<RgbaStringColorPicker color={pickerColor.current} onChange={throttleChange} />
4546
<AlphaDiv color={color?.substring(0, 7)}>
4647
<BackDiv color={alphaOfRgba(toRGBA(color))}></BackDiv>
4748
</AlphaDiv>
@@ -54,6 +55,7 @@ export const ColorSelect = (props: ColorSelectProps) => {
5455
key={item.id}
5556
onClick={() => {
5657
throttleChange(item.color);
58+
pickerColor.current = toRGBA(item.color);
5759
}}
5860
/>
5961
);
Lines changed: 11 additions & 0 deletions
Loading

client/packages/openblocks-design/src/icons/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,4 @@ export { ReactComponent as LeftVideo } from "./icon-left-comp-video.svg";
248248
export { ReactComponent as LeftOpen } from "./icon-left-comp-open.svg";
249249
export { ReactComponent as LeftClose } from "./icon-left-comp-close.svg";
250250
export { ReactComponent as ScannerIcon } from "./icon-scanner.svg";
251+
export { ReactComponent as MaterialUploadIcon } from "./icon-material-upload.svg";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Api from "./api";
2+
import { AxiosPromise } from "axios";
3+
import { GenericApiResponse } from "./apiResponses";
4+
5+
interface UploadResponse {
6+
id: string;
7+
filename: string;
8+
}
9+
10+
export enum MaterialUploadTypeEnum {
11+
LOGO = "LOGO",
12+
FAVICON = "FAVICON",
13+
}
14+
15+
class MaterialApi extends Api {
16+
static configURL = "/materials";
17+
18+
static upload(
19+
filename: string,
20+
type: MaterialUploadTypeEnum,
21+
content: string
22+
): AxiosPromise<GenericApiResponse<UploadResponse>> {
23+
return Api.post(MaterialApi.configURL, {
24+
content: content,
25+
filename: filename,
26+
type: type,
27+
});
28+
}
29+
}
30+
31+
export default MaterialApi;

0 commit comments

Comments
 (0)