Skip to content

Commit 868faf5

Browse files
add version change dropdown for comp plugins
1 parent 982f98b commit 868faf5

File tree

6 files changed

+89
-10
lines changed

6 files changed

+89
-10
lines changed

client/packages/lowcoder/src/components/CompName.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ export const CompName = (props: Iprops) => {
121121
onClick: () => {
122122
},
123123
});
124-
items.push({
125-
text: trans("history.currentVersion") + ": " + compInfo.packageVersion,
126-
onClick: () => {
124+
// items.push({
125+
// text: trans("history.currentVersion") + ": " + compInfo.packageVersion,
126+
// onClick: () => {
127127

128-
},
129-
});
128+
// },
129+
// });
130130

131131
items.push({
132132
text: trans("comp.menuUpgradeToLatest"),

client/packages/lowcoder/src/comps/comps/appSettingsComp.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ function AppSettingsModal(props: ChildrenInstance) {
336336
}
337337
label={'Lowcoder Comps Version'}
338338
placement="bottom"
339-
allowClear
340339
onChange={async (value) => {
341340
await getPromiseAfterDispatch(
342341
lowcoderCompVersion.dispatch,

client/packages/lowcoder/src/comps/comps/remoteComp/remoteComp.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { RemoteCompInfo, RemoteCompLoader } from "types/remoteComp";
1212
import { loaders } from "./loaders";
1313
import { withErrorBoundary } from "comps/generators/withErrorBoundary";
1414
import { EditorContext } from "@lowcoder-ee/comps/editorState";
15+
import { CompContext } from "@lowcoder-ee/comps/utils/compContext";
1516

1617
const ViewError = styled.div`
1718
display: flex;
@@ -56,9 +57,19 @@ function RemoteCompView(props: React.PropsWithChildren<RemoteCompViewProps>) {
5657
const { loadComp, loadingElement, errorElement, isLowcoderComp } = props;
5758
const [error, setError] = useState<any>("");
5859
const editorState = useContext(EditorContext);
60+
const compState = useContext(CompContext);
5961
const lowcoderCompPackageVersion = editorState?.getAppSettings().lowcoderCompVersion || 'latest';
60-
const packageVersion = isLowcoderComp ? lowcoderCompPackageVersion : 'latest';
61-
62+
63+
let packageVersion = 'latest';
64+
// lowcoder-comps's package version
65+
if (isLowcoderComp) {
66+
packageVersion = lowcoderCompPackageVersion;
67+
}
68+
// component plugin's package version
69+
else if (compState.comp?.comp.version) {
70+
packageVersion = compState.comp?.comp.version;
71+
}
72+
6273
useMount(() => {
6374
setError("");
6475
loadComp(packageVersion).catch((e) => {

client/packages/lowcoder/src/comps/generators/uiCompBuilder.tsx

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BoolCodeControl, StringControl } from "comps/controls/codeControl";
2-
import React, { ReactNode, useContext, useRef } from "react";
2+
import React, { ReactNode, useContext, useEffect, useRef, useState } from "react";
33
import { ExternalEditorContext } from "util/context/ExternalEditorContext";
44
import { Comp, CompParams, MultiBaseComp } from "lowcoder-core";
55
import {
@@ -22,17 +22,25 @@ import {
2222
MethodConfigsType,
2323
withMethodExposing,
2424
} from "./withMethodExposing";
25-
import { Section } from "lowcoder-design";
25+
import {Section, controlItem } from "lowcoder-design";
2626
import { trans } from "i18n";
2727
import { BoolControl } from "../controls/boolControl";
2828
import { valueComp, withDefault } from "./simpleGenerators";
29+
import { getPromiseAfterDispatch } from "@lowcoder-ee/util/promiseUtils";
30+
import { EditorContext } from "../editorState";
31+
import { values } from "lodash";
32+
import { UICompType, uiCompRegistry } from "../uiCompRegistry";
33+
import { getNpmPackageMeta } from "../utils/remote";
34+
import { compPluginsList } from "constants/compPluginConstants";
35+
import Select from "antd/es/select";
2936

3037
export type NewChildren<ChildrenCompMap extends Record<string, Comp<unknown>>> =
3138
ChildrenCompMap & {
3239
hidden: InstanceType<typeof BoolCodeControl>;
3340
className: InstanceType<typeof StringControl>;
3441
dataTestId: InstanceType<typeof StringControl>;
3542
preventStyleOverwriting: InstanceType<typeof BoolControl>;
43+
version: InstanceType<typeof StringControl>;
3644
};
3745

3846
export function HidableView(props: {
@@ -64,6 +72,28 @@ export function ExtendedPropertyView<
6472
childrenMap: NewChildren<ChildrenCompMap>
6573
}
6674
) {
75+
const [compVersions, setCompVersions] = useState(['latest']);
76+
const [compName, setCompName] = useState('');
77+
const editorState = useContext(EditorContext);
78+
const selectedComp = values(editorState.selectedComps())[0];
79+
const compType = selectedComp.children.compType.getView() as UICompType;
80+
81+
useEffect(() => {
82+
setCompName(uiCompRegistry[compType].compName || '');
83+
}, [compType]);
84+
85+
useEffect(() => {
86+
const fetchCompsPackageMeta = async () => {
87+
const packageMeta = await getNpmPackageMeta(compName);
88+
if (packageMeta?.versions) {
89+
setCompVersions(Object.keys(packageMeta.versions).reverse())
90+
}
91+
}
92+
if (Boolean(compName) && compPluginsList.includes(compName)) {
93+
fetchCompsPackageMeta();
94+
}
95+
}, [compName]);
96+
6797
return (
6898
<>
6999
{props.children}
@@ -72,6 +102,30 @@ export function ExtendedPropertyView<
72102
{props.childrenMap.dataTestId?.propertyView({ label: trans("prop.dataTestId") })}
73103
{props.childrenMap.preventStyleOverwriting?.propertyView({ label: trans("prop.preventOverwriting") })}
74104
</Section>
105+
{compPluginsList.includes(compName) && (
106+
<Section name={'Component Version'}>
107+
{controlItem({}, (
108+
<Select
109+
defaultValue={props.childrenMap.version.getView()}
110+
placeholder={'Select version'}
111+
options={
112+
compVersions.map(version => ({label: version, value: version}))
113+
}
114+
onChange={async (value) => {
115+
await getPromiseAfterDispatch(
116+
props.childrenMap.version.dispatch,
117+
props.childrenMap.version.changeValueAction(value), {
118+
autoHandleAfterReduce: true,
119+
}
120+
)
121+
setTimeout(() => {
122+
window.location.reload();
123+
}, 1000);
124+
}}
125+
/>
126+
))}
127+
</Section>
128+
)}
75129
</>
76130
);
77131
}
@@ -88,6 +142,7 @@ export function uiChildren<
88142
dataTestId: StringControl,
89143
preventStyleOverwriting: withDefault(BoolControl, false),
90144
appliedThemeId: valueComp<string>(''),
145+
version: withDefault(StringControl, 'latest'),
91146
} as any;
92147
}
93148

client/packages/lowcoder/src/comps/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ export var uiCompMap: Registry = {
314314
source: "npm",
315315
isRemote: true,
316316
}),
317+
compName: "lowcoder-comp-geo",
317318
layoutInfo: {
318319
w: 12,
319320
h: 50,
@@ -365,6 +366,7 @@ export var uiCompMap: Registry = {
365366
source: "npm",
366367
isRemote: true,
367368
}),
369+
compName: "lowcoder-comp-reactpivottable",
368370
layoutInfo: {
369371
w: 12,
370372
h: 50,
@@ -1239,6 +1241,7 @@ export var uiCompMap: Registry = {
12391241
source: "npm",
12401242
isRemote: true,
12411243
}),
1244+
compName: "lowcoder-comp-gantt-chart",
12421245
layoutInfo: {
12431246
w: 20,
12441247
h: 60,
@@ -1258,6 +1261,7 @@ export var uiCompMap: Registry = {
12581261
source: "npm",
12591262
isRemote: true,
12601263
}),
1264+
compName: "lowcoder-comp-hillcharts",
12611265
layoutInfo: {
12621266
w: 12,
12631267
h: 50,
@@ -1276,6 +1280,7 @@ export var uiCompMap: Registry = {
12761280
source: "npm",
12771281
isRemote: true,
12781282
}),
1283+
compName: "lowcoder-comp-bpmn-io",
12791284
layoutInfo: {
12801285
w: 19,
12811286
h: 60,
@@ -1632,6 +1637,7 @@ export var uiCompMap: Registry = {
16321637
source: "npm",
16331638
isRemote: true,
16341639
}),
1640+
compName: "lowcoder-comp-cf-turnstile",
16351641
layoutInfo: {
16361642
w: 8,
16371643
h: 20,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const compPluginsList = [
2+
"lowcoder-comp-geo",
3+
"lowcoder-comp-reactpivottable",
4+
"lowcoder-comp-gantt-chart",
5+
"lowcoder-comp-hillcharts",
6+
"lowcoder-comp-bpmn-io",
7+
"lowcoder-comp-cf-turnstile",
8+
]

0 commit comments

Comments
 (0)