Skip to content

Commit d1d0d46

Browse files
ggbond2077QIQI03
authored andcommitted
1. [MongoQuery]: mongo support datasource meta completion
2. [jsQuery] query allow auto trigger,add run script action 3. [header] change view header ui, add clone button 4. some bug fix
1 parent 3143507 commit d1d0d46

Some content is hidden

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

42 files changed

+421
-257
lines changed

client/.yarnrc.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@ plugins:
66
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
77
spec: "@yarnpkg/plugin-workspace-tools"
88

9-
unsafeHttpWhitelist:
10-
- 8.141.152.4
11-
129
yarnPath: .yarn/releases/yarn-3.2.4.cjs

client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"@testing-library/react": "^12.0.0",
2828
"@testing-library/user-event": "^13.2.1",
2929
"@types/ali-oss": "^6.16.4",
30-
"@types/big.js": "^6.1.5",
3130
"@types/file-saver": "^2.0.5",
3231
"@types/jest": "^29.2.2",
3332
"@types/mime": "^2.0.3",

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

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -545,19 +545,47 @@ function changeDependName(unevaledValue, oldName, name, isFunction) {
545545
.join("");
546546
}
547547
function rename(segment, oldName, name) {
548-
return segment.replace(/[a-zA-Z_$][a-zA-Z_$0-9.[\]]*/g, function (s) {
549-
if (s === oldName) {
550-
return name;
551-
}
552-
if (s.startsWith(oldName + ".")) {
553-
return name + "." + s.substring(oldName.length + 1);
554-
}
555-
return s;
548+
var accessors = [".", "["];
549+
var regStrList = ["[a-zA-Z_$][a-zA-Z_$0-9.[\\]]*", "(?<=\\[)[a-zA-Z_][a-zA-Z_0-9.]*"];
550+
var ret = segment;
551+
for (var _i = 0, regStrList_1 = regStrList; _i < regStrList_1.length; _i++) {
552+
var regStr = regStrList_1[_i];
553+
var reg = new RegExp(regStr, "g");
554+
ret = ret.replace(reg, function (s) {
555+
if (s === oldName) {
556+
return name;
557+
}
558+
for (var _i = 0, accessors_1 = accessors; _i < accessors_1.length; _i++) {
559+
var accessor = accessors_1[_i];
560+
if (s.startsWith(oldName + accessor)) {
561+
return name + accessor + s.substring(oldName.length + accessor.length);
562+
}
563+
}
564+
return s;
565+
});
566+
}
567+
return ret;
568+
}
569+
function getIdentifiers(jsSnippet) {
570+
var ret = [];
571+
var commonReg = /[a-zA-Z_$][a-zA-Z_$0-9.[\]]*/g;
572+
var commonIds = jsSnippet.match(commonReg);
573+
if (commonIds) {
574+
ret.push.apply(ret, commonIds);
575+
}
576+
var indexIds = [];
577+
(jsSnippet.match(/\[[a-zA-Z_][a-zA-Z_0-9\[\].]*\]/g) || []).forEach(function (i) {
578+
indexIds.push.apply(indexIds, getIdentifiers(i.slice(1, -1)));
556579
});
580+
ret.push.apply(ret, indexIds);
581+
if (ret.length === 0) {
582+
return [jsSnippet];
583+
}
584+
return ret;
557585
}
558586
function parseDepends(jsSnippet, exposingNodes) {
559587
var depends = new Map();
560-
var identifiers = jsSnippet.match(/[a-zA-Z_$][a-zA-Z_$0-9.[\]]*/g) || [jsSnippet];
588+
var identifiers = getIdentifiers(jsSnippet);
561589
identifiers.forEach(function (identifier) {
562590
var subpaths = _.toPath(identifier);
563591
var dependAndPath = getDependNode(subpaths, exposingNodes);
@@ -570,7 +598,7 @@ function parseDepends(jsSnippet, exposingNodes) {
570598
}
571599
function parseTopDepends(jsSnippet, exposingNodes) {
572600
var depends = new Map();
573-
var identifiers = jsSnippet.match(/[a-zA-Z_$][a-zA-Z_$0-9.[\]]*/g) || [jsSnippet];
601+
var identifiers = getIdentifiers(jsSnippet);
574602
identifiers.forEach(function (identifier) {
575603
var subpaths = _.toPath(identifier).slice(0, 1);
576604
var dependAndPath = getDependNode(subpaths, exposingNodes);

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1-
import { changeDependName } from "./evaluate";
1+
import { fromValue } from "eval/simpleNode";
2+
import _ from "lodash";
3+
import { changeDependName, filterDepends } from "./evaluate";
4+
5+
describe("deps", () => {
6+
test("filterDeps", () => {
7+
const context = {
8+
data: fromValue([]),
9+
i: fromValue(0),
10+
str: fromValue(""),
11+
};
12+
13+
const depsA = filterDepends("{{data[str].b}}", context);
14+
expect(depsA.has(context.data)).toBe(true);
15+
expect(depsA.has(context.str)).toBe(true);
16+
expect(depsA.has(context.i)).toBe(false);
17+
18+
const depsB = filterDepends("{{data[i]['a']}}", context);
19+
expect(depsB.has(context.data)).toBe(true);
20+
expect(depsB.has(context.str)).toBe(false);
21+
expect(depsB.has(context.i)).toBe(true);
22+
23+
const depsC = filterDepends("{{str[data[i].length]}}", context);
24+
expect(depsC.has(context.data)).toBe(true);
25+
expect(depsC.has(context.str)).toBe(true);
26+
expect(depsC.has(context.i)).toBe(true);
27+
28+
const depsD = filterDepends("{{str[data.length]}}", context);
29+
expect(depsD.has(context.data)).toBe(true);
30+
expect(depsD.has(context.str)).toBe(true);
31+
expect(depsD.has(context.i)).toBe(false);
32+
});
33+
});
234

335
describe("changeDependName", () => {
436
it("changeDependName", () => {
@@ -44,5 +76,17 @@ describe("changeDependName", () => {
4476
);
4577
expect(changeDependName(" abc input1{{a2}} de ", "a", "hello")).toBe(" abc input1{{a2}} de ");
4678
expect(changeDependName(" abc input1{{aa}} de ", "a", "hello")).toBe(" abc input1{{aa}} de ");
79+
expect(changeDependName(" abc input1{{a[b]}} de ", "b", "hello")).toBe(
80+
" abc input1{{a[hello]}} de "
81+
);
82+
expect(changeDependName(" abc input1{{a[b.length]}} de ", "b", "b2")).toBe(
83+
" abc input1{{a[b2.length]}} de "
84+
);
85+
expect(changeDependName(" abc input1{{a[b[i].length]}} de ", "i", "j")).toBe(
86+
" abc input1{{a[b[j].length]}} de "
87+
);
88+
expect(changeDependName(" abc input1{{a[b[i].length]}} de ", "b", "b2")).toBe(
89+
" abc input1{{a[b2[i].length]}} de "
90+
);
4791
});
4892
});

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,54 @@ export function changeDependName(
8585
}
8686

8787
function rename(segment: string, oldName: string, name: string) {
88-
return segment.replace(/[a-zA-Z_$][a-zA-Z_$0-9.[\]]*/g, (s) => {
89-
if (s === oldName) {
90-
return name;
91-
}
92-
if (s.startsWith(oldName + ".")) {
93-
return name + "." + s.substring(oldName.length + 1);
94-
}
95-
return s;
88+
const accessors = [".", "["];
89+
const regStrList = ["[a-zA-Z_$][a-zA-Z_$0-9.[\\]]*", "(?<=\\[)[a-zA-Z_][a-zA-Z_0-9.]*"];
90+
91+
let ret = segment;
92+
for (const regStr of regStrList) {
93+
const reg = new RegExp(regStr, "g");
94+
ret = ret.replace(reg, (s) => {
95+
if (s === oldName) {
96+
return name;
97+
}
98+
for (const accessor of accessors) {
99+
if (s.startsWith(oldName + accessor)) {
100+
return name + accessor + s.substring(oldName.length + accessor.length);
101+
}
102+
}
103+
return s;
104+
});
105+
}
106+
107+
return ret;
108+
}
109+
110+
function getIdentifiers(jsSnippet: string): string[] {
111+
const ret: string[] = [];
112+
const commonReg = /[a-zA-Z_$][a-zA-Z_$0-9.[\]]*/g;
113+
const commonIds = jsSnippet.match(commonReg);
114+
if (commonIds) {
115+
ret.push(...commonIds);
116+
}
117+
118+
const indexIds: string[] = [];
119+
(jsSnippet.match(/\[[a-zA-Z_][a-zA-Z_0-9\[\].]*\]/g) || []).forEach((i) => {
120+
indexIds.push(...getIdentifiers(i.slice(1, -1)));
96121
});
122+
ret.push(...indexIds);
123+
124+
if (ret.length === 0) {
125+
return [jsSnippet];
126+
}
127+
return ret;
97128
}
98129

99130
function parseDepends(
100131
jsSnippet: string,
101132
exposingNodes: Record<string, Node<unknown>>
102133
): Map<Node<unknown>, string[]> {
103134
const depends: Map<Node<unknown>, string[]> = new Map();
104-
const identifiers = jsSnippet.match(/[a-zA-Z_$][a-zA-Z_$0-9.[\]]*/g) || [jsSnippet];
135+
const identifiers = getIdentifiers(jsSnippet);
105136
identifiers.forEach((identifier) => {
106137
const subpaths = _.toPath(identifier);
107138
const dependAndPath = getDependNode(subpaths, exposingNodes);
@@ -118,7 +149,7 @@ function parseTopDepends(
118149
exposingNodes: Record<string, Node<unknown>>
119150
): Map<Node<unknown>, string> {
120151
const depends: Map<Node<unknown>, string> = new Map();
121-
const identifiers = jsSnippet.match(/[a-zA-Z_$][a-zA-Z_$0-9.[\]]*/g) || [jsSnippet];
152+
const identifiers = getIdentifiers(jsSnippet);
122153
identifiers.forEach((identifier) => {
123154
const subpaths = _.toPath(identifier).slice(0, 1);
124155
const dependAndPath = getDependNode(subpaths, exposingNodes);

client/packages/openblocks/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"antd": "4.22.8",
3737
"antd-img-crop": "^4.0.2",
3838
"axios": "^0.21.1",
39-
"big.js": "^6.2.1",
4039
"buffer": "^6.0.3",
4140
"clsx": "^1.2.1",
4241
"copy-to-clipboard": "^3.3.1",

client/packages/openblocks/src/api/datasourceApi.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DEFAULT_TEST_DATA_SOURCE_TIMEOUT_MS } from "../constants/apiConstants";
55
import { DatasourceType } from "@openblocks-ee/constants/queryConstants";
66
import { JSONArray } from "../util/jsonTypes";
77
import { AuthType, HttpOAuthGrantType } from "../pages/datasource/form/httpDatasourceForm";
8-
import { Datasource as FinalDatasource } from "@openblocks-ee/api/datasourceApi";
8+
import { Datasource } from "@openblocks-ee/constants/datasourceConstants";
99

1010
// FIXME(zhangqinyao): extract a common config
1111
export interface MysqlConfig {
@@ -98,21 +98,8 @@ export type DatasourceConfigType =
9898
| OracleConfig
9999
| GoogleSheetsConfig;
100100

101-
export interface Datasource {
102-
id: string;
103-
name: string;
104-
type: DatasourceType;
105-
organizationId: string;
106-
datasourceConfig: DatasourceConfigType;
107-
// USER_CREATED(0): user self create
108-
// SYSTEM_TEMPLATE(1) for example: onboard datasource、template datasource
109-
// SYSTEM_PREDEFINED(2) for example: rest api empty datasource
110-
creationSource: 0 | 1 | 2;
111-
createTime: number;
112-
}
113-
114101
export interface DatasourceInfo {
115-
datasource: FinalDatasource;
102+
datasource: Datasource;
116103
edit: boolean;
117104
creatorName?: string;
118105
}
@@ -150,27 +137,27 @@ export class DatasourceApi extends Api {
150137
}
151138

152139
static createDatasource(
153-
datasourceConfig: Partial<FinalDatasource>
154-
): AxiosPromise<GenericApiResponse<FinalDatasource>> {
140+
datasourceConfig: Partial<Datasource>
141+
): AxiosPromise<GenericApiResponse<Datasource>> {
155142
return Api.post(DatasourceApi.url, datasourceConfig);
156143
}
157144

158145
static testDatasource(
159-
datasourceConfig: Partial<FinalDatasource>
160-
): AxiosPromise<GenericApiResponse<FinalDatasource>> {
146+
datasourceConfig: Partial<Datasource>
147+
): AxiosPromise<GenericApiResponse<Datasource>> {
161148
return Api.post(`${DatasourceApi.url}/test`, datasourceConfig, undefined, {
162149
timeout: DEFAULT_TEST_DATA_SOURCE_TIMEOUT_MS,
163150
});
164151
}
165152

166153
static updateDatasource(
167-
datasourceConfig: Partial<FinalDatasource>,
154+
datasourceConfig: Partial<Datasource>,
168155
id: string
169-
): AxiosPromise<GenericApiResponse<FinalDatasource>> {
156+
): AxiosPromise<GenericApiResponse<Datasource>> {
170157
return Api.put(DatasourceApi.url + `/${id}`, datasourceConfig);
171158
}
172159

173-
static deleteDatasource(id: string): AxiosPromise<GenericApiResponse<FinalDatasource>> {
160+
static deleteDatasource(id: string): AxiosPromise<GenericApiResponse<Datasource>> {
174161
return Api.delete(DatasourceApi.url + `/${id}`);
175162
}
176163

client/packages/openblocks/src/base/codeEditor/codeEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export function CodeEditor(props: CodeEditorProps) {
382382
{expandable && (
383383
<CodeEditorPanel
384384
breadcrumb={[props.label ?? ""]}
385-
editor={<CodeEditorForPanel {...props} styleName="window" />}
385+
editor={<CodeEditorForPanel {...props} styleName="window" showLineNum />}
386386
onVisibleChange={(visible) => setDisabled(visible)}
387387
/>
388388
)}

client/packages/openblocks/src/base/codeEditor/codeEditorTypes.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ export interface CodeEditorControlParams {
1616
tooltipContainer?: HTMLElement;
1717
expandable?: boolean;
1818
onFocus?: (focused: boolean) => void;
19+
showLineNum?: boolean;
1920

2021
enableIcon?: boolean;
2122
widgetPopup?: (v: EditorView) => ReactNode;
2223
onClick?: (e: React.MouseEvent, v: EditorView) => void;
2324
extraOnChange?: (state: EditorState) => void;
2425
cardRichContent?: (s: string) => ReactNode;
2526
cardTips?: ReactNode;
27+
enableMetaCompletion?: boolean;
2628
}
2729

2830
export interface CodeEditorProps extends CodeEditorControlParams {
@@ -42,7 +44,6 @@ export interface CodeEditorProps extends CodeEditorControlParams {
4244
segments?: { value: string; success: boolean }[];
4345

4446
bordered?: boolean;
45-
showLineNum?: boolean;
4647
}
4748

4849
export const MetaDataContext = React.createContext<Record<string, string> | undefined>(undefined);

client/packages/openblocks/src/base/codeEditor/extensions.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export function useChangeExtension(
304304
}
305305

306306
export function useCompletionSources(props: CodeEditorProps) {
307-
const { language, codeType, exposingData } = props;
307+
const { language, codeType, exposingData, enableMetaCompletion } = props;
308308
const context = useContext(QueryContext); // FIXME: temporarily handle, expect to delete after the backend supports eval
309309
// auto-completion for comp exposing
310310
const exposingSource = useMemo(() => new ExposingCompletionSource(), []);
@@ -334,15 +334,15 @@ export function useCompletionSources(props: CodeEditorProps) {
334334
if (ternServer) {
335335
sources.push(ternServer);
336336
}
337-
if (language === "sql") {
338-
sources.push(sqlSource);
339-
}
337+
}
338+
if (enableMetaCompletion) {
339+
sources.push(sqlSource);
340340
}
341341
return sources.map((c) => {
342342
c.setIsFunction(codeType === "Function");
343343
return c.completionSource;
344344
});
345-
}, [language, codeType, exposingSource, ternServer, sqlSource]);
345+
}, [enableMetaCompletion, language, codeType, exposingSource, ternServer, sqlSource]);
346346
return completionSources;
347347
}
348348

client/packages/openblocks/src/components/ResCreatePanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Datasource } from "@openblocks-ee/api/datasourceApi";
21
import { AddIcon, CloseIcon, CustomModalProps, ScrollBar } from "openblocks-design";
32
import { BottomShadow, GreyTextColor, TabActiveColor } from "constants/style";
43
import { trans } from "i18n";
@@ -13,6 +12,7 @@ import { LargeBottomResIconWrapper } from "util/bottomResUtils";
1312
import { PageType } from "../constants/pageConstants";
1413
import { getBottomResIcon } from "@openblocks-ee/util/bottomResUtils";
1514
import { SizeType } from "antd/lib/config-provider/SizeContext";
15+
import { Datasource } from "@openblocks-ee/constants/datasourceConstants";
1616

1717
const Wrapper = styled.div<{ placement: PageType }>`
1818
width: 100%;

client/packages/openblocks/src/components/layout/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ const HeaderWrapper = styled.header<IHeaderProps>`
99
height: ${TopHeaderHeight};
1010
background-color: #2c2c2c;
1111
/* filter: drop-shadow(0px 1px 0px #ebebeb); */
12-
padding: ${props => props.isEditViewPreview ? '8px 24px 8px 8px' : '8px 24px'};
12+
padding: ${(props) => (props.isEditViewPreview ? "8px 24px 8px 8px" : "8px 24px")};
1313
justify-content: space-between;
1414
> div:nth-of-type(1) svg {
15-
max-width: ${props => props.isEditViewPreview && '24px'};
15+
max-width: ${(props) => props.isEditViewPreview && "24px"};
1616
}
1717
`;
1818

client/packages/openblocks/src/comps/comps/formComp/createForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import { uiCompRegistry } from "comps/uiCompRegistry";
2424
import { arrayMove, SortableContainer, SortableElement, SortableHandle } from "react-sortable-hoc";
2525
import { getBottomResIcon } from "@openblocks-ee/util/bottomResUtils";
2626
import { trans } from "i18n";
27-
import { Datasource } from "@openblocks-ee/api/datasourceApi";
2827
import log from "loglevel";
28+
import { Datasource } from "@openblocks-ee/constants/datasourceConstants";
2929

3030
const OpenDialogButton = styled.span`
3131
:hover {

client/packages/openblocks/src/comps/comps/formComp/generate/comp.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const stringComps: CompConfig[] = [
2929
const numberComps: CompConfig[] = [
3030
{
3131
type: "numberInput",
32+
compInitData: {
33+
allowNull: true,
34+
},
3235
},
3336
{
3437
type: "slider",

0 commit comments

Comments
 (0)